From 1af0ad52da8c7b630b297aa0d0d120af74363461 Mon Sep 17 00:00:00 2001 From: meylis98 Date: Thu, 2 Mar 2023 08:04:51 +0500 Subject: [PATCH] adding pagination --- lib/screens/drawer/about_us.dart | 13 ++ lib/screens/drawer/contacts.dart | 13 ++ lib/screens/drawer/new_arrival.dart | 13 ++ lib/screens/drawer/sales.dart | 13 ++ lib/screens/drawer/sapaly_drawer.dart | 15 +- lib/screens/drawer/shops.dart | 13 ++ lib/screens/home/home_screen.dart | 314 ++++++++++++++------------ lib/services/auth/login_service.dart | 1 + lib/services/requests.dart | 2 +- 9 files changed, 241 insertions(+), 156 deletions(-) create mode 100644 lib/screens/drawer/about_us.dart create mode 100644 lib/screens/drawer/contacts.dart create mode 100644 lib/screens/drawer/new_arrival.dart create mode 100644 lib/screens/drawer/sales.dart create mode 100644 lib/screens/drawer/shops.dart create mode 100644 lib/services/auth/login_service.dart diff --git a/lib/screens/drawer/about_us.dart b/lib/screens/drawer/about_us.dart new file mode 100644 index 0000000..69ad4a7 --- /dev/null +++ b/lib/screens/drawer/about_us.dart @@ -0,0 +1,13 @@ +import 'package:flutter/material.dart'; + +class AboutUsScreen extends StatelessWidget { + const AboutUsScreen({super.key}); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar(), + body: const Center(child: Text('About Us Screen')), + ); + } +} diff --git a/lib/screens/drawer/contacts.dart b/lib/screens/drawer/contacts.dart new file mode 100644 index 0000000..e12057f --- /dev/null +++ b/lib/screens/drawer/contacts.dart @@ -0,0 +1,13 @@ +import 'package:flutter/material.dart'; + +class ContactsScreen extends StatelessWidget { + const ContactsScreen({super.key}); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar(), + body: const Center(child: Text('Contacts Screen')), + ); + } +} diff --git a/lib/screens/drawer/new_arrival.dart b/lib/screens/drawer/new_arrival.dart new file mode 100644 index 0000000..ca2ebe0 --- /dev/null +++ b/lib/screens/drawer/new_arrival.dart @@ -0,0 +1,13 @@ +import 'package:flutter/material.dart'; + +class NewArrivalScreen extends StatelessWidget { + const NewArrivalScreen({super.key}); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar(), + body: const Center(child: Text('New Arrival Screen')), + ); + } +} diff --git a/lib/screens/drawer/sales.dart b/lib/screens/drawer/sales.dart new file mode 100644 index 0000000..b3f045e --- /dev/null +++ b/lib/screens/drawer/sales.dart @@ -0,0 +1,13 @@ +import 'package:flutter/material.dart'; + +class SalesScreen extends StatelessWidget { + const SalesScreen({super.key}); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar(), + body: const Center(child: Text('Sales Screen')), + ); + } +} diff --git a/lib/screens/drawer/sapaly_drawer.dart b/lib/screens/drawer/sapaly_drawer.dart index 2f82ff4..2d8aa5d 100644 --- a/lib/screens/drawer/sapaly_drawer.dart +++ b/lib/screens/drawer/sapaly_drawer.dart @@ -3,10 +3,15 @@ import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:sapaly_shop/screens/category/category_screen.dart'; +import 'package:sapaly_shop/screens/drawer/contacts.dart'; +import 'package:sapaly_shop/screens/drawer/new_arrival.dart'; +import 'package:sapaly_shop/screens/drawer/sales.dart'; +import 'package:sapaly_shop/screens/drawer/shops.dart'; import 'package:url_launcher/url_launcher_string.dart'; import '../../services/app_constants.dart'; import '../../themes/app_theme.dart'; +import 'about_us.dart'; class SapalyDrawer extends StatelessWidget { SapalyDrawer({super.key}); @@ -31,11 +36,11 @@ class SapalyDrawer extends StatelessWidget { List routes = [ const CategoryScreen(), - Container(), - Container(), - Container(), - Container(), - Container(), + const AboutUsScreen(), + const SalesScreen(), + const NewArrivalScreen(), + const ShopsScreen(), + const ContactsScreen(), ]; @override diff --git a/lib/screens/drawer/shops.dart b/lib/screens/drawer/shops.dart new file mode 100644 index 0000000..aa03a2c --- /dev/null +++ b/lib/screens/drawer/shops.dart @@ -0,0 +1,13 @@ +import 'package:flutter/material.dart'; + +class ShopsScreen extends StatelessWidget { + const ShopsScreen({super.key}); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar(), + body: const Center(child: Text('Shops Screen')), + ); + } +} diff --git a/lib/screens/home/home_screen.dart b/lib/screens/home/home_screen.dart index 0ccb898..3d79720 100644 --- a/lib/screens/home/home_screen.dart +++ b/lib/screens/home/home_screen.dart @@ -91,166 +91,180 @@ class _HomeScreenState extends State with TickerProviderStateMixin { }, actionOnTap: () {}, ), - body: SingleChildScrollView( - physics: const BouncingScrollPhysics(), + body: Padding( padding: EdgeInsets.symmetric( - vertical: AppConstants.verticalPadding(context), + vertical: AppConstants.verticalPadding(context) / 2, horizontal: AppConstants.horizontalPadding(context), ), - child: Column( - children: [ - Container( - height: 50.adaptedPx(), - width: MediaQuery.of(context).size.width, - decoration: BoxDecoration( - color: AppTheme.whiteColor, - borderRadius: BorderRadius.circular(30.adaptedPx()), - ), - child: TextButton( - onPressed: () { - Navigator.of(context).push( - MaterialPageRoute( - builder: (context) => const SearchScreen(), - ), - ); - }, - style: TextButton.styleFrom( - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(30.adaptedPx()), - ), - ), - child: Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Padding( - padding: EdgeInsets.symmetric(horizontal: 15.adaptedPx()), - child: SvgPicture.asset('assets/icons/search.svg'), - ), - Text( - 'searchHint'.translation, - style: GoogleFonts.poppins( - textStyle: Theme.of(context) - .primaryTextTheme - .bodyMedium - ?.copyWith( - fontSize: 16.adaptedPx(), - color: AppTheme.lightTextColor, + child: NestedScrollView( + physics: const BouncingScrollPhysics(), + headerSliverBuilder: (context, innerBoxIsScrolled) => [ + SliverToBoxAdapter( + child: Column( + children: [ + Container( + height: 50.adaptedPx(), + width: MediaQuery.of(context).size.width, + decoration: BoxDecoration( + color: AppTheme.whiteColor, + borderRadius: BorderRadius.circular(30.adaptedPx()), + ), + child: TextButton( + onPressed: () { + Navigator.of(context).push( + MaterialPageRoute( + builder: (context) => const SearchScreen(), + ), + ); + }, + style: TextButton.styleFrom( + shape: RoundedRectangleBorder( + borderRadius: + BorderRadius.circular(30.adaptedPx()), + ), + ), + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Padding( + padding: EdgeInsets.symmetric( + horizontal: 15.adaptedPx()), + child: SvgPicture.asset( + 'assets/icons/search.svg'), + ), + Text( + 'searchHint'.translation, + style: GoogleFonts.poppins( + textStyle: Theme.of(context) + .primaryTextTheme + .bodyMedium + ?.copyWith( + fontSize: 16.adaptedPx(), + color: AppTheme.lightTextColor, + ), + ), + ), + ], ), - ), - ), - ], - ), - ), - ), - CarouselSlider( - items: (sliders != null) - ? [ - for (int i = 0; i < sliders.length; i++) - CachedNetworkImage( - imageUrl: sliders[i].img, - width: AppConstants.deviceWidth(context), - fit: BoxFit.contain, - progressIndicatorBuilder: (context, url, progress) => - const Center( - child: CircularProgressIndicator(), ), ), - ] - : [ - const Center(child: CircularProgressIndicator()), - ], - options: CarouselOptions( - initialPage: 0, - padEnds: true, - scrollPhysics: const BouncingScrollPhysics(), - viewportFraction: 1, - autoPlay: true, - onPageChanged: (index, reason) { - setState(() { - currentPage = index; - }); - }, - autoPlayAnimationDuration: const Duration(seconds: 2), - autoPlayInterval: const Duration(seconds: 5), - ), - ), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: List.generate( - sliders.length, - (index) => buildDot( - index: index, - ), - ), - ), - Padding( - padding: - EdgeInsets.only(top: 20.adaptedPx(), bottom: 10.adaptedPx()), - child: Align( - alignment: Alignment.centerLeft, - child: Text( - 'categories'.translation, - style: - Theme.of(context).primaryTextTheme.bodyMedium?.copyWith( - color: AppTheme.blackColor, - fontSize: 18.adaptedPx(), - fontWeight: FontWeight.w600, + CarouselSlider( + items: (sliders != null) + ? [ + for (int i = 0; i < sliders.length; i++) + CachedNetworkImage( + imageUrl: sliders[i].img, + width: AppConstants.deviceWidth(context), + fit: BoxFit.contain, + progressIndicatorBuilder: + (context, url, progress) => + const Center( + child: CircularProgressIndicator(), + ), + ), + ] + : [ + const Center( + child: CircularProgressIndicator()), + ], + options: CarouselOptions( + initialPage: 0, + padEnds: true, + scrollPhysics: const BouncingScrollPhysics(), + viewportFraction: 1, + autoPlay: true, + onPageChanged: (index, reason) { + setState(() { + currentPage = index; + }); + }, + autoPlayAnimationDuration: + const Duration(seconds: 2), + autoPlayInterval: const Duration(seconds: 5), ), - ), - ), - ), - categories.isEmpty - ? Padding( - padding: EdgeInsets.symmetric(vertical: 10.adaptedPx()), - child: const Center(child: CircularProgressIndicator()), - ) - : Padding( - padding: EdgeInsets.symmetric(vertical: 10.adaptedPx()), - child: ButtonsTabBar( - controller: tabController, - contentPadding: - EdgeInsets.symmetric(horizontal: 20.adaptedPx()), - splashColor: AppTheme.lightPrimaryColor, - radius: 10.adaptedPx(), - backgroundColor: AppTheme.lightPrimaryColor, - buttonMargin: EdgeInsets.only( - left: 0, - right: 15.adaptedPx(), - ), - onTap: (value) { - setState(() { - categoryId = categories[value].id; - debugPrint(categoryId.toString()); - }); - }, - unselectedBackgroundColor: AppTheme.whiteColor, - physics: const BouncingScrollPhysics(), - tabs: [ - for (var category in categories) - Tab(text: category.name) + ), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: List.generate( + sliders.length, + (index) => buildDot( + index: index, + ), + ), + ), + Padding( + padding: EdgeInsets.only( + top: 20.adaptedPx(), bottom: 10.adaptedPx()), + child: Align( + alignment: Alignment.centerLeft, + child: Text( + 'categories'.translation, + style: Theme.of(context) + .primaryTextTheme + .bodyMedium + ?.copyWith( + color: AppTheme.blackColor, + fontSize: 18.adaptedPx(), + fontWeight: FontWeight.w600, + ), + ), + ), + ), + categories.isEmpty + ? Padding( + padding: EdgeInsets.symmetric( + vertical: 10.adaptedPx()), + child: const Center( + child: CircularProgressIndicator()), + ) + : Padding( + padding: EdgeInsets.symmetric( + vertical: 10.adaptedPx()), + child: ButtonsTabBar( + controller: tabController, + contentPadding: EdgeInsets.symmetric( + horizontal: 20.adaptedPx()), + splashColor: AppTheme.lightPrimaryColor, + radius: 10.adaptedPx(), + backgroundColor: AppTheme.lightPrimaryColor, + buttonMargin: EdgeInsets.only( + left: 0, + right: 15.adaptedPx(), + ), + onTap: (value) { + setState(() { + categoryId = categories[value].id; + debugPrint(categoryId.toString()); + }); + }, + unselectedBackgroundColor: + AppTheme.whiteColor, + physics: const BouncingScrollPhysics(), + tabs: [ + for (var category in categories) + Tab(text: category.name) + ], + ), + ), + SizedBox(height: 15.adaptedPx()), ], ), ), - SizedBox(height: 15.adaptedPx()), - SizedBox( - height: AppConstants.deviceHeight(context), - child: tabController != null - ? TabBarView( - controller: tabController, - children: categories.isNotEmpty - ? categories - .map( - (category) => Products( - id: category.id, - ), - ) - .toList() - : [], - ) - : Container(), - ), - ], - ), + ], + body: tabController != null + ? TabBarView( + controller: tabController, + children: categories.isNotEmpty + ? categories + .map( + (category) => Products( + id: category.id, + ), + ) + .toList() + : [], + ) + : Container()), ), ); } diff --git a/lib/services/auth/login_service.dart b/lib/services/auth/login_service.dart new file mode 100644 index 0000000..9e52044 --- /dev/null +++ b/lib/services/auth/login_service.dart @@ -0,0 +1 @@ +abstract class LoginService {} diff --git a/lib/services/requests.dart b/lib/services/requests.dart index ef1f782..ac2fff7 100644 --- a/lib/services/requests.dart +++ b/lib/services/requests.dart @@ -83,7 +83,7 @@ class API { .map((item) => CategoryModel.fromJson(item, currentLanguage)) .toList(); } catch (e) { - debugPrint('Category ' + e.toString()); + debugPrint('Category ' + e.toString()); rethrow; } }