Skip to content

Commit

Permalink
adds carousel in services
Browse files Browse the repository at this point in the history
  • Loading branch information
hardikroongta8 committed Aug 19, 2024
1 parent 97127c3 commit f1bac09
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 12 deletions.
81 changes: 69 additions & 12 deletions lib/widgets/home/home_links.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
import 'package:carousel_slider/carousel_slider.dart';
import 'package:dots_indicator/dots_indicator.dart';
import 'package:flutter/material.dart';
import 'package:onestop_dev/globals/my_colors.dart';
import 'package:onestop_dev/globals/my_fonts.dart';
import 'package:onestop_dev/widgets/home/home_tab_tile.dart';
import 'package:onestop_kit/onestop_kit.dart';

class HomeLinks extends StatelessWidget {
class HomeLinks extends StatefulWidget {
final List<HomeTabTile> links;
final String title;

const HomeLinks({Key? key, required this.links, required this.title})
: super(key: key);

@override
State<HomeLinks> createState() => _HomeLinksState();
}

class _HomeLinksState extends State<HomeLinks> {
int activePageIndex = 0;

@override
Widget build(BuildContext context) {
return links.isEmpty
return widget.links.isEmpty
? const SizedBox()
: Container(
padding: const EdgeInsets.all(8),
Expand All @@ -22,26 +31,74 @@ class HomeLinks extends StatelessWidget {
color: kHomeTile,
),
child: Container(
padding: const EdgeInsets.all(4),
padding: const EdgeInsets.symmetric(vertical: 4),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: const EdgeInsets.all(5),
child: Text(
title,
widget.title,
style: MyFonts.w500.size(16).setColor(kWhite),
),
),
GridView.count(
crossAxisCount: 4,
childAspectRatio: 1,
shrinkWrap: true,
mainAxisSpacing: 4,
crossAxisSpacing: 4,
physics: const NeverScrollableScrollPhysics(),
children: links,
CarouselSlider(
items: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 4),
child: GridView.count(
crossAxisCount: 4,
childAspectRatio: 1,
shrinkWrap: true,
mainAxisSpacing: 4,
crossAxisSpacing: 4,
physics: const NeverScrollableScrollPhysics(),
children: widget.links.length <= 8
? widget.links
: widget.links.sublist(0, 8),
),
),
if (widget.links.length > 8)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 4),
child: GridView.count(
crossAxisCount: 4,
childAspectRatio: 1,
shrinkWrap: true,
mainAxisSpacing: 4,
crossAxisSpacing: 4,
physics: const NeverScrollableScrollPhysics(),
children: widget.links.sublist(8),
),
),
],
options: CarouselOptions(
viewportFraction: 1,
pageSnapping: true,
aspectRatio: 2,
autoPlay: false,
animateToClosest: false,
enableInfiniteScroll: false,
padEnds: false,
onPageChanged: (index, reason) {
setState(() {
activePageIndex = index;
});
},
),
),
if (widget.links.length > 8)
DotsIndicator(
position: activePageIndex,
decorator: const DotsDecorator(
activeColor: OneStopColors.kWhite,
color: OneStopColors.cardColor,
spacing: EdgeInsets.symmetric(horizontal: 3),
size: Size(5, 5),
activeSize: Size(5, 5),
),
dotsCount: (widget.links.length / 8).ceil(),
)
],
),
),
Expand Down
5 changes: 5 additions & 0 deletions lib/widgets/home/service_links.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,9 @@ List<HomeTabTile> serviceLinks = [
icon: FluentIcons.desktop_24_regular,
routeId: RouterPage.id,
),
const HomeTabTile(
label: "GC Score Board",
icon: FluentIcons.trophy_48_filled,
routeId: Scoreboard.id,
),
];
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.0"
dots_indicator:
dependency: "direct main"
description:
name: dots_indicator
sha256: "58b6a365744aa62aa1b70c4ea29e5106fbe064f5edaf7e9652e9b856edbfd9bb"
url: "https://pub.dev"
source: hosted
version: "3.0.0"
dotted_border:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ dependencies:
connectivity_plus: ^6.0.3
fluttertoast: ^8.2.8
carousel_slider: ^5.0.0
dots_indicator: ^3.0.0

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit f1bac09

Please sign in to comment.