From 79fd23b4feff189d2ebabc546eacc674ce9ba6db Mon Sep 17 00:00:00 2001 From: Maheresio Date: Tue, 4 Mar 2025 11:05:16 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20(fix)=20update=20null=20safe?= =?UTF-8?q?ty=20in=20models=20and=20widgets=20and=20update=20the=20theme?= =?UTF-8?q?=20date?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/main.dart | 12 +- lib/src/model/category.dart | 14 +- lib/src/model/product.dart | 28 ++- lib/src/pages/home_page.dart | 115 ++++----- lib/src/pages/mainPage.dart | 110 +++++---- lib/src/pages/product_detail.dart | 221 +++++++++--------- lib/src/pages/shopping_cart_page.dart | 6 +- lib/src/themes/theme.dart | 51 ++-- .../bottom_navigation_bar.dart | 86 +++---- lib/src/widgets/customRoute.dart | 2 +- lib/src/widgets/extentions.dart | 54 +++-- lib/src/widgets/product_card.dart | 4 +- lib/src/widgets/product_icon.dart | 80 +++---- 13 files changed, 399 insertions(+), 384 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index d88839c..bd54364 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -15,19 +15,19 @@ class MyApp extends StatelessWidget { return MaterialApp( title: 'E-Commerce ', theme: AppTheme.lightTheme.copyWith( - textTheme: GoogleFonts.mulishTextTheme( - Theme.of(context).textTheme, - ), + textTheme: GoogleFonts.mulishTextTheme(Theme.of(context).textTheme), ), debugShowCheckedModeBanner: false, routes: Routes.getRoute(), onGenerateRoute: (RouteSettings settings) { - if (settings.name.contains('detail')) { + if (settings.name?.contains('detail') ?? false) { return CustomRoute( - builder: (BuildContext context) => ProductDetailPage()); + builder: (BuildContext context) => ProductDetailPage(), + ); } else { return CustomRoute( - builder: (BuildContext context) => MainPage()); + builder: (BuildContext context) => MainPage(), + ); } }, initialRoute: "MainPage", diff --git a/lib/src/model/category.dart b/lib/src/model/category.dart index 85c4081..6f573c2 100644 --- a/lib/src/model/category.dart +++ b/lib/src/model/category.dart @@ -1,7 +1,7 @@ -class Category{ - int id ; - String name ; - String image ; - bool isSelected ; - Category({this.id,this.name,this.isSelected = false,this.image}); -} \ No newline at end of file +class Category { + int? id; + String? name; + String? image; + bool isSelected; + Category({this.id, this.name, this.isSelected = false, this.image}); +} diff --git a/lib/src/model/product.dart b/lib/src/model/product.dart index a257ba8..2660a33 100644 --- a/lib/src/model/product.dart +++ b/lib/src/model/product.dart @@ -1,10 +1,18 @@ -class Product{ - int id; - String name ; - String category ; - String image ; - double price ; - bool isliked ; - bool isSelected ; - Product({this.id,this.name, this.category, this.price, this.isliked,this.isSelected = false,this.image}); -} \ No newline at end of file +class Product { + final int id; + final String name; + final String category; + final String image; + final double price; + final bool isliked; + bool isSelected; + Product({ + required this.id, + required this.name, + required this.category, + required this.price, + required this.isliked, + this.isSelected = false, + required this.image, + }); +} diff --git a/lib/src/pages/home_page.dart b/lib/src/pages/home_page.dart index bc695a9..0a292cf 100644 --- a/lib/src/pages/home_page.dart +++ b/lib/src/pages/home_page.dart @@ -8,9 +8,9 @@ import 'package:flutter_ecommerce_app/src/widgets/product_icon.dart'; import 'package:flutter_ecommerce_app/src/widgets/extentions.dart'; class MyHomePage extends StatefulWidget { - MyHomePage({Key key, this.title}) : super(key: key); + MyHomePage({super.key, this.title}); - final String title; + final String? title; @override _MyHomePageState createState() => _MyHomePageState(); @@ -21,13 +21,11 @@ class _MyHomePageState extends State { return Container( padding: EdgeInsets.all(10), decoration: BoxDecoration( - borderRadius: BorderRadius.all(Radius.circular(13)), - color: Theme.of(context).backgroundColor, - boxShadow: AppTheme.shadow), - child: Icon( - icon, - color: color, + borderRadius: BorderRadius.all(Radius.circular(13)), + color: Theme.of(context).colorScheme.surface, + boxShadow: AppTheme.shadow, ), + child: Icon(icon, color: color), ).ripple(() {}, borderRadius: BorderRadius.all(Radius.circular(13))); } @@ -38,21 +36,22 @@ class _MyHomePageState extends State { height: 80, child: ListView( scrollDirection: Axis.horizontal, - children: AppData.categoryList - .map( - (category) => ProductIcon( - model: category, - onSelected: (model) { - setState(() { - AppData.categoryList.forEach((item) { - item.isSelected = false; - }); - model.isSelected = true; - }); - }, - ), - ) - .toList(), + children: + AppData.categoryList + .map( + (category) => ProductIcon( + model: category, + onSelected: (model) { + setState(() { + AppData.categoryList.forEach((item) { + item.isSelected = false; + }); + model.isSelected = true; + }); + }, + ), + ) + .toList(), ), ); } @@ -64,27 +63,29 @@ class _MyHomePageState extends State { height: AppTheme.fullWidth(context) * .7, child: GridView( gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( - crossAxisCount: 1, - childAspectRatio: 4 / 3, - mainAxisSpacing: 30, - crossAxisSpacing: 20), + crossAxisCount: 1, + childAspectRatio: 4 / 3, + mainAxisSpacing: 30, + crossAxisSpacing: 20, + ), padding: EdgeInsets.only(left: 20), scrollDirection: Axis.horizontal, - children: AppData.productList - .map( - (product) => ProductCard( - product: product, - onSelected: (model) { - setState(() { - AppData.productList.forEach((item) { - item.isSelected = false; - }); - model.isSelected = true; - }); - }, - ), - ) - .toList(), + children: + AppData.productList + .map( + (product) => ProductCard( + product: product, + onSelected: (model) { + setState(() { + AppData.productList.forEach((item) { + item.isSelected = false; + }); + model.isSelected = true; + }); + }, + ), + ) + .toList(), ), ); } @@ -99,21 +100,27 @@ class _MyHomePageState extends State { height: 40, alignment: Alignment.center, decoration: BoxDecoration( - color: LightColor.lightGrey.withAlpha(100), - borderRadius: BorderRadius.all(Radius.circular(10))), + color: LightColor.lightGrey.withAlpha(100), + borderRadius: BorderRadius.all(Radius.circular(10)), + ), child: TextField( decoration: InputDecoration( - border: InputBorder.none, - hintText: "Search Products", - hintStyle: TextStyle(fontSize: 12), - contentPadding: - EdgeInsets.only(left: 10, right: 10, bottom: 0, top: 5), - prefixIcon: Icon(Icons.search, color: Colors.black54)), + border: InputBorder.none, + hintText: "Search Products", + hintStyle: TextStyle(fontSize: 12), + contentPadding: EdgeInsets.only( + left: 10, + right: 10, + bottom: 0, + top: 5, + ), + prefixIcon: Icon(Icons.search, color: Colors.black54), + ), ), ), ), SizedBox(width: 20), - _icon(Icons.filter_list, color: Colors.black54) + _icon(Icons.filter_list, color: Colors.black54), ], ), ); @@ -129,11 +136,7 @@ class _MyHomePageState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start, - children: [ - _search(), - _categoryWidget(), - _productWidget(), - ], + children: [_search(), _categoryWidget(), _productWidget()], ), ), ); diff --git a/lib/src/pages/mainPage.dart b/lib/src/pages/mainPage.dart index fe7cfed..8bf38c1 100644 --- a/lib/src/pages/mainPage.dart +++ b/lib/src/pages/mainPage.dart @@ -8,9 +8,9 @@ import 'package:flutter_ecommerce_app/src/widgets/title_text.dart'; import 'package:flutter_ecommerce_app/src/widgets/extentions.dart'; class MainPage extends StatefulWidget { - MainPage({Key key, this.title}) : super(key: key); + const MainPage({super.key, this.title}); - final String title; + final String? title; @override _MainPageState createState() => _MainPageState(); @@ -32,17 +32,18 @@ class _MainPageState extends State { borderRadius: BorderRadius.all(Radius.circular(13)), child: Container( decoration: BoxDecoration( - color: Theme.of(context).backgroundColor, + color: Theme.of(context).colorScheme.surface, boxShadow: [ BoxShadow( - color: Color(0xfff8f8f8), - blurRadius: 10, - spreadRadius: 10), + color: Color(0xfff8f8f8), + blurRadius: 10, + spreadRadius: 10, + ), ], ), child: Image.asset("assets/user.png"), ), - ).ripple(() {}, borderRadius: BorderRadius.all(Radius.circular(13))) + ).ripple(() {}, borderRadius: BorderRadius.all(Radius.circular(13))), ], ), ); @@ -52,49 +53,48 @@ class _MainPageState extends State { return Container( padding: EdgeInsets.all(10), decoration: BoxDecoration( - borderRadius: BorderRadius.all(Radius.circular(13)), - color: Theme.of(context).backgroundColor, - boxShadow: AppTheme.shadow), - child: Icon( - icon, - color: color, + borderRadius: BorderRadius.all(Radius.circular(13)), + color: Theme.of(context).colorScheme.surface, + boxShadow: AppTheme.shadow, ), + child: Icon(icon, color: color), ).ripple(() {}, borderRadius: BorderRadius.all(Radius.circular(13))); } Widget _title() { return Container( - margin: AppTheme.padding, - child: Row( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - TitleText( - text: isHomePageSelected ? 'Our' : 'Shopping', - fontSize: 27, - fontWeight: FontWeight.w400, - ), - TitleText( - text: isHomePageSelected ? 'Products' : 'Cart', - fontSize: 27, - fontWeight: FontWeight.w700, - ), - ], - ), - Spacer(), - !isHomePageSelected - ? Container( - padding: EdgeInsets.all(10), - child: Icon( - Icons.delete_outline, - color: LightColor.orange, - ), - ).ripple(() {}, borderRadius: BorderRadius.all(Radius.circular(13))) - : SizedBox() - ], - )); + margin: AppTheme.padding, + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + TitleText( + text: isHomePageSelected ? 'Our' : 'Shopping', + fontSize: 27, + fontWeight: FontWeight.w400, + ), + TitleText( + text: isHomePageSelected ? 'Products' : 'Cart', + fontSize: 27, + fontWeight: FontWeight.w700, + ), + ], + ), + Spacer(), + !isHomePageSelected + ? Container( + padding: EdgeInsets.all(10), + child: Icon(Icons.delete_outline, color: LightColor.orange), + ).ripple( + () {}, + borderRadius: BorderRadius.all(Radius.circular(13)), + ) + : SizedBox(), + ], + ), + ); } void onBottomIconPressed(int index) { @@ -121,10 +121,7 @@ class _MainPageState extends State { height: AppTheme.fullHeight(context) - 50, decoration: BoxDecoration( gradient: LinearGradient( - colors: [ - Color(0xfffbfbfb), - Color(0xfff7f7f7), - ], + colors: [Color(0xfffbfbfb), Color(0xfff7f7f7)], begin: Alignment.topCenter, end: Alignment.bottomCenter, ), @@ -139,14 +136,15 @@ class _MainPageState extends State { duration: Duration(milliseconds: 300), switchInCurve: Curves.easeInToLinear, switchOutCurve: Curves.easeOutBack, - child: isHomePageSelected - ? MyHomePage() - : Align( - alignment: Alignment.topCenter, - child: ShoppingCartPage(), - ), + child: + isHomePageSelected + ? MyHomePage() + : Align( + alignment: Alignment.topCenter, + child: ShoppingCartPage(), + ), ), - ) + ), ], ), ), @@ -157,7 +155,7 @@ class _MainPageState extends State { child: CustomBottomNavigationBar( onIconPresedCallback: onBottomIconPressed, ), - ) + ), ], ), ), diff --git a/lib/src/pages/product_detail.dart b/lib/src/pages/product_detail.dart index b8d3ebd..bb3729d 100644 --- a/lib/src/pages/product_detail.dart +++ b/lib/src/pages/product_detail.dart @@ -6,7 +6,7 @@ import 'package:flutter_ecommerce_app/src/widgets/title_text.dart'; import 'package:flutter_ecommerce_app/src/widgets/extentions.dart'; class ProductDetailPage extends StatefulWidget { - ProductDetailPage({Key key}) : super(key: key); + ProductDetailPage({Key ?key}) : super(key: key); @override _ProductDetailPageState createState() => _ProductDetailPageState(); @@ -14,15 +14,18 @@ class ProductDetailPage extends StatefulWidget { class _ProductDetailPageState extends State with TickerProviderStateMixin { - AnimationController controller; - Animation animation; + late final AnimationController controller; + late final Animation animation; @override void initState() { super.initState(); - controller = - AnimationController(vsync: this, duration: Duration(milliseconds: 300)); + controller = AnimationController( + vsync: this, + duration: Duration(milliseconds: 300), + ); animation = Tween(begin: 0, end: 1).animate( - CurvedAnimation(parent: controller, curve: Curves.easeInToLinear)); + CurvedAnimation(parent: controller, curve: Curves.easeInToLinear), + ); controller.forward(); } @@ -49,15 +52,18 @@ class _ProductDetailPageState extends State Navigator.of(context).pop(); }, ), - _icon(isLiked ? Icons.favorite : Icons.favorite_border, - color: isLiked ? LightColor.red : LightColor.lightGrey, - size: 15, - padding: 12, - isOutLine: false, onPressed: () { - setState(() { - isLiked = !isLiked; - }); - }), + _icon( + isLiked ? Icons.favorite : Icons.favorite_border, + color: isLiked ? LightColor.red : LightColor.lightGrey, + size: 15, + padding: 12, + isOutLine: false, + onPressed: () { + setState(() { + isLiked = !isLiked; + }); + }, + ), ], ), ); @@ -69,7 +75,7 @@ class _ProductDetailPageState extends State double size = 20, double padding = 10, bool isOutLine = false, - Function onPressed, + Function ?onPressed, }) { return Container( height: 40, @@ -78,17 +84,19 @@ class _ProductDetailPageState extends State // margin: EdgeInsets.all(padding), decoration: BoxDecoration( border: Border.all( - color: LightColor.iconColor, - style: isOutLine ? BorderStyle.solid : BorderStyle.none), + color: LightColor.iconColor, + style: isOutLine ? BorderStyle.solid : BorderStyle.none, + ), borderRadius: BorderRadius.all(Radius.circular(13)), color: - isOutLine ? Colors.transparent : Theme.of(context).backgroundColor, + isOutLine ? Colors.transparent : Theme.of(context).colorScheme.surface, boxShadow: [ BoxShadow( - color: Color(0xfff8f8f8), - blurRadius: 5, - spreadRadius: 10, - offset: Offset(5, 5)), + color: Color(0xfff8f8f8), + blurRadius: 5, + spreadRadius: 10, + offset: Offset(5, 5), + ), ], ), child: Icon(icon, color: color, size: size), @@ -112,12 +120,8 @@ class _ProductDetailPageState extends State child: Stack( alignment: Alignment.bottomCenter, children: [ - TitleText( - text: "AIP", - fontSize: 160, - color: LightColor.lightGrey, - ), - Image.asset('assets/show_1.png') + TitleText(text: "AIP", fontSize: 160, color: LightColor.lightGrey), + Image.asset('assets/show_1.png'), ], ), ); @@ -129,10 +133,10 @@ class _ProductDetailPageState extends State width: AppTheme.fullWidth(context), height: 80, child: Row( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.center, - children: - AppData.showThumbnailList.map((x) => _thumbnail(x)).toList()), + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.center, + children: AppData.showThumbnailList.map((x) => _thumbnail(x)).toList(), + ), ); } @@ -140,20 +144,19 @@ class _ProductDetailPageState extends State return AnimatedBuilder( animation: animation, // builder: null, - builder: (context, child) => AnimatedOpacity( - opacity: animation.value, - duration: Duration(milliseconds: 500), - child: child, - ), + builder: + (context, child) => AnimatedOpacity( + opacity: animation.value, + duration: Duration(milliseconds: 500), + child: child, + ), child: Container( margin: EdgeInsets.symmetric(horizontal: 10), child: Container( height: 40, width: 50, decoration: BoxDecoration( - border: Border.all( - color: LightColor.grey, - ), + border: Border.all(color: LightColor.grey), borderRadius: BorderRadius.all(Radius.circular(13)), // color: Theme.of(context).backgroundColor, ), @@ -172,11 +175,12 @@ class _ProductDetailPageState extends State return Container( padding: AppTheme.padding.copyWith(bottom: 0), decoration: BoxDecoration( - borderRadius: BorderRadius.only( - topLeft: Radius.circular(40), - topRight: Radius.circular(40), - ), - color: Colors.white), + borderRadius: BorderRadius.only( + topLeft: Radius.circular(40), + topRight: Radius.circular(40), + ), + color: Colors.white, + ), child: SingleChildScrollView( controller: scrollController, child: Column( @@ -190,8 +194,9 @@ class _ProductDetailPageState extends State width: 50, height: 5, decoration: BoxDecoration( - color: LightColor.iconColor, - borderRadius: BorderRadius.all(Radius.circular(10))), + color: LightColor.iconColor, + borderRadius: BorderRadius.all(Radius.circular(10)), + ), ), ), SizedBox(height: 10), @@ -212,22 +217,31 @@ class _ProductDetailPageState extends State fontSize: 18, color: LightColor.red, ), - TitleText( - text: "240", - fontSize: 25, - ), + TitleText(text: "240", fontSize: 25), ], ), Row( children: [ - Icon(Icons.star, - color: LightColor.yellowColor, size: 17), - Icon(Icons.star, - color: LightColor.yellowColor, size: 17), - Icon(Icons.star, - color: LightColor.yellowColor, size: 17), - Icon(Icons.star, - color: LightColor.yellowColor, size: 17), + Icon( + Icons.star, + color: LightColor.yellowColor, + size: 17, + ), + Icon( + Icons.star, + color: LightColor.yellowColor, + size: 17, + ), + Icon( + Icons.star, + color: LightColor.yellowColor, + size: 17, + ), + Icon( + Icons.star, + color: LightColor.yellowColor, + size: 17, + ), Icon(Icons.star_border, size: 17), ], ), @@ -236,17 +250,11 @@ class _ProductDetailPageState extends State ], ), ), - SizedBox( - height: 20, - ), + SizedBox(height: 20), _availableSize(), - SizedBox( - height: 20, - ), + SizedBox(height: 20), _availableColor(), - SizedBox( - height: 20, - ), + SizedBox(height: 20), _description(), ], ), @@ -260,10 +268,7 @@ class _ProductDetailPageState extends State return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - TitleText( - text: "Available Size", - fontSize: 14, - ), + TitleText(text: "Available Size", fontSize: 14), SizedBox(height: 20), Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, @@ -273,7 +278,7 @@ class _ProductDetailPageState extends State _sizeWidget("US 8"), _sizeWidget("US 9"), ], - ) + ), ], ); } @@ -283,11 +288,12 @@ class _ProductDetailPageState extends State padding: EdgeInsets.all(10), decoration: BoxDecoration( border: Border.all( - color: LightColor.iconColor, - style: !isSelected ? BorderStyle.solid : BorderStyle.none), + color: LightColor.iconColor, + style: !isSelected ? BorderStyle.solid : BorderStyle.none, + ), borderRadius: BorderRadius.all(Radius.circular(13)), color: - isSelected ? LightColor.orange : Theme.of(context).backgroundColor, + isSelected ? LightColor.orange : Theme.of(context).colorScheme.surface, ), child: TitleText( text: text, @@ -301,33 +307,22 @@ class _ProductDetailPageState extends State return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - TitleText( - text: "Available Size", - fontSize: 14, - ), + TitleText(text: "Available Size", fontSize: 14), SizedBox(height: 20), Row( mainAxisAlignment: MainAxisAlignment.start, children: [ _colorWidget(LightColor.yellowColor, isSelected: true), - SizedBox( - width: 30, - ), + SizedBox(width: 30), _colorWidget(LightColor.lightBlue), - SizedBox( - width: 30, - ), + SizedBox(width: 30), _colorWidget(LightColor.black), - SizedBox( - width: 30, - ), + SizedBox(width: 30), _colorWidget(LightColor.red), - SizedBox( - width: 30, - ), + SizedBox(width: 30), _colorWidget(LightColor.skyBlue), ], - ) + ), ], ); } @@ -336,13 +331,10 @@ class _ProductDetailPageState extends State return CircleAvatar( radius: 12, backgroundColor: color.withAlpha(150), - child: isSelected - ? Icon( - Icons.check_circle, - color: color, - size: 18, - ) - : CircleAvatar(radius: 7, backgroundColor: color), + child: + isSelected + ? Icon(Icons.check_circle, color: color, size: 18) + : CircleAvatar(radius: 7, backgroundColor: color), ); } @@ -350,10 +342,7 @@ class _ProductDetailPageState extends State return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - TitleText( - text: "Available Size", - fontSize: 14, - ), + TitleText(text: "Available Size", fontSize: 14), SizedBox(height: 20), Text(AppData.description), ], @@ -364,8 +353,10 @@ class _ProductDetailPageState extends State return FloatingActionButton( onPressed: () {}, backgroundColor: LightColor.orange, - child: Icon(Icons.shopping_basket, - color: Theme.of(context).floatingActionButtonTheme.backgroundColor), + child: Icon( + Icons.shopping_basket, + color: Theme.of(context).floatingActionButtonTheme.backgroundColor, + ), ); } @@ -376,14 +367,12 @@ class _ProductDetailPageState extends State body: SafeArea( child: Container( decoration: BoxDecoration( - gradient: LinearGradient( - colors: [ - Color(0xfffbfbfb), - Color(0xfff7f7f7), - ], - begin: Alignment.topCenter, - end: Alignment.bottomCenter, - )), + gradient: LinearGradient( + colors: [Color(0xfffbfbfb), Color(0xfff7f7f7)], + begin: Alignment.topCenter, + end: Alignment.bottomCenter, + ), + ), child: Stack( children: [ Column( @@ -393,7 +382,7 @@ class _ProductDetailPageState extends State _categoryWidget(), ], ), - _detailWidget() + _detailWidget(), ], ), ), diff --git a/lib/src/pages/shopping_cart_page.dart b/lib/src/pages/shopping_cart_page.dart index 8482a9c..3fd2e44 100644 --- a/lib/src/pages/shopping_cart_page.dart +++ b/lib/src/pages/shopping_cart_page.dart @@ -6,7 +6,7 @@ import 'package:flutter_ecommerce_app/src/themes/theme.dart'; import 'package:flutter_ecommerce_app/src/widgets/title_text.dart'; class ShoppingCartPage extends StatelessWidget { - const ShoppingCartPage({Key key}) : super(key: key); + const ShoppingCartPage({Key ?key}) : super(key: key); Widget _cartItems() { return Column(children: AppData.cartList.map((x) => _item(x)).toList()); @@ -107,10 +107,10 @@ class ShoppingCartPage extends StatelessWidget { return TextButton( onPressed: () {}, style: ButtonStyle( - shape: MaterialStateProperty.all( + shape: WidgetStateProperty.all( RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)), ), - backgroundColor: MaterialStateProperty.all(LightColor.orange), + backgroundColor: WidgetStateProperty.all(LightColor.orange), ), child: Container( alignment: Alignment.center, diff --git a/lib/src/themes/theme.dart b/lib/src/themes/theme.dart index 0892ae9..d6e143b 100644 --- a/lib/src/themes/theme.dart +++ b/lib/src/themes/theme.dart @@ -5,23 +5,32 @@ import 'light_color.dart'; class AppTheme { const AppTheme(); static ThemeData lightTheme = ThemeData( - backgroundColor: LightColor.background, - primaryColor: LightColor.background, - cardTheme: CardTheme(color: LightColor.background), - textTheme: TextTheme(bodyText1: TextStyle(color: LightColor.black)), - iconTheme: IconThemeData(color: LightColor.iconColor), - bottomAppBarColor: LightColor.background, - dividerColor: LightColor.lightGrey, - primaryTextTheme: - TextTheme(bodyText1: TextStyle(color: LightColor.titleTextColor))); - - static TextStyle titleStyle = - const TextStyle(color: LightColor.titleTextColor, fontSize: 16); - static TextStyle subTitleStyle = - const TextStyle(color: LightColor.subTitleTextColor, fontSize: 12); - - static TextStyle h1Style = - const TextStyle(fontSize: 24, fontWeight: FontWeight.bold); + colorScheme: ColorScheme.light(surface: LightColor.background), + + primaryColor: LightColor.background, + cardTheme: CardTheme(color: LightColor.background), + textTheme: TextTheme(bodyLarge: TextStyle(color: LightColor.black)), + iconTheme: IconThemeData(color: LightColor.iconColor), + bottomAppBarTheme: BottomAppBarTheme(color: LightColor.background), + dividerColor: LightColor.lightGrey, + primaryTextTheme: TextTheme( + bodyLarge: TextStyle(color: LightColor.titleTextColor), + ), + ); + + static TextStyle titleStyle = const TextStyle( + color: LightColor.titleTextColor, + fontSize: 16, + ); + static TextStyle subTitleStyle = const TextStyle( + color: LightColor.subTitleTextColor, + fontSize: 12, + ); + + static TextStyle h1Style = const TextStyle( + fontSize: 24, + fontWeight: FontWeight.bold, + ); static TextStyle h2Style = const TextStyle(fontSize: 22); static TextStyle h3Style = const TextStyle(fontSize: 20); static TextStyle h4Style = const TextStyle(fontSize: 18); @@ -32,11 +41,11 @@ class AppTheme { BoxShadow(color: Color(0xfff8f8f8), blurRadius: 10, spreadRadius: 15), ]; - static EdgeInsets padding = - const EdgeInsets.symmetric(horizontal: 20, vertical: 10); - static EdgeInsets hPadding = const EdgeInsets.symmetric( - horizontal: 10, + static EdgeInsets padding = const EdgeInsets.symmetric( + horizontal: 20, + vertical: 10, ); + static EdgeInsets hPadding = const EdgeInsets.symmetric(horizontal: 10); static double fullWidth(BuildContext context) { return MediaQuery.of(context).size.width; diff --git a/lib/src/widgets/BottomNavigationBar/bottom_navigation_bar.dart b/lib/src/widgets/BottomNavigationBar/bottom_navigation_bar.dart index 5c25adc..47425d7 100644 --- a/lib/src/widgets/BottomNavigationBar/bottom_navigation_bar.dart +++ b/lib/src/widgets/BottomNavigationBar/bottom_navigation_bar.dart @@ -4,8 +4,8 @@ import 'package:flutter_ecommerce_app/src/widgets/BottomNavigationBar/bottom_cur class CustomBottomNavigationBar extends StatefulWidget { final Function(int) onIconPresedCallback; - CustomBottomNavigationBar({Key key, this.onIconPresedCallback}) - : super(key: key); + CustomBottomNavigationBar({Key? key, required this.onIconPresedCallback}) + : super(key: key); @override _CustomBottomNavigationBarState createState() => @@ -16,14 +16,18 @@ class _CustomBottomNavigationBarState extends State with TickerProviderStateMixin { int _selectedIndex = 0; - AnimationController _xController; - AnimationController _yController; + late final AnimationController _xController; + late final AnimationController _yController; @override void initState() { _xController = AnimationController( - vsync: this, animationBehavior: AnimationBehavior.preserve); + vsync: this, + animationBehavior: AnimationBehavior.preserve, + ); _yController = AnimationController( - vsync: this, animationBehavior: AnimationBehavior.preserve); + vsync: this, + animationBehavior: AnimationBehavior.preserve, + ); Listenable.merge([_xController, _yController]).addListener(() { setState(() {}); @@ -71,27 +75,32 @@ class _CustomBottomNavigationBarState extends State duration: Duration(milliseconds: 500), alignment: isEnable ? Alignment.topCenter : Alignment.center, child: AnimatedContainer( - height: isEnable ? 40 : 20, - duration: Duration(milliseconds: 300), - alignment: Alignment.center, - decoration: BoxDecoration( - color: isEnable ? LightColor.orange : Colors.white, - boxShadow: [ - BoxShadow( - color: isEnable ? Color(0xfffeece2) : Colors.white, - blurRadius: 10, - spreadRadius: 5, - offset: Offset(5, 5), - ), - ], - shape: BoxShape.circle), - child: Opacity( - opacity: isEnable ? _yController.value : 1, - child: Icon(icon, - color: isEnable + height: isEnable ? 40 : 20, + duration: Duration(milliseconds: 300), + alignment: Alignment.center, + decoration: BoxDecoration( + color: isEnable ? LightColor.orange : Colors.white, + boxShadow: [ + BoxShadow( + color: isEnable ? Color(0xfffeece2) : Colors.white, + blurRadius: 10, + spreadRadius: 5, + offset: Offset(5, 5), + ), + ], + shape: BoxShape.circle, + ), + child: Opacity( + opacity: isEnable ? _yController.value : 1, + child: Icon( + icon, + color: + isEnable ? LightColor.background - : Theme.of(context).iconTheme.color), - )), + : Theme.of(context).iconTheme.color, + ), + ), + ), ), ), ); @@ -101,12 +110,13 @@ class _CustomBottomNavigationBarState extends State final inCurve = ElasticOutCurve(0.38); return CustomPaint( painter: BackgroundCurvePainter( - _xController.value * MediaQuery.of(context).size.width, - Tween( - begin: Curves.easeInExpo.transform(_yController.value), - end: inCurve.transform(_yController.value), - ).transform(_yController.velocity.sign * 0.5 + 0.5), - Theme.of(context).backgroundColor), + _xController.value * MediaQuery.of(context).size.width, + Tween( + begin: Curves.easeInExpo.transform(_yController.value), + end: inCurve.transform(_yController.value), + ).transform(_yController.velocity.sign * 0.5 + 0.5), + Theme.of(context).colorScheme.surface, + ), ); } @@ -127,14 +137,12 @@ class _CustomBottomNavigationBarState extends State _yController.value = 1.0; _xController.animateTo( - _indexToPosition(index) / MediaQuery.of(context).size.width, - duration: Duration(milliseconds: 620)); - Future.delayed( - Duration(milliseconds: 500), - () { - _yController.animateTo(1.0, duration: Duration(milliseconds: 1200)); - }, + _indexToPosition(index) / MediaQuery.of(context).size.width, + duration: Duration(milliseconds: 620), ); + Future.delayed(Duration(milliseconds: 500), () { + _yController.animateTo(1.0, duration: Duration(milliseconds: 1200)); + }); _yController.animateTo(0.0, duration: Duration(milliseconds: 300)); } diff --git a/lib/src/widgets/customRoute.dart b/lib/src/widgets/customRoute.dart index c60990c..a04a582 100644 --- a/lib/src/widgets/customRoute.dart +++ b/lib/src/widgets/customRoute.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; class CustomRoute extends MaterialPageRoute { - CustomRoute({WidgetBuilder builder, RouteSettings settings}) + CustomRoute({required WidgetBuilder builder, RouteSettings? settings}) : super(builder: builder, settings: settings); @override Widget buildTransitions(BuildContext context, Animation animation, diff --git a/lib/src/widgets/extentions.dart b/lib/src/widgets/extentions.dart index 6d414c8..60a235c 100644 --- a/lib/src/widgets/extentions.dart +++ b/lib/src/widgets/extentions.dart @@ -1,29 +1,33 @@ import 'package:flutter/material.dart'; extension OnPressed on Widget { - Widget ripple(Function onPressed, - {BorderRadiusGeometry borderRadius = - const BorderRadius.all(Radius.circular(5))}) => - Stack( - children: [ - this, - Positioned( - left: 0, - right: 0, - top: 0, - bottom: 0, - child: TextButton( - style: ButtonStyle( - shape: MaterialStateProperty.all( - RoundedRectangleBorder(borderRadius: borderRadius), - )), - onPressed: () { - if (onPressed != null) { - onPressed(); - } - }, - child: Container()), - ) - ], - ); + Widget ripple( + Function? onPressed, { + BorderRadiusGeometry borderRadius = const BorderRadius.all( + Radius.circular(5), + ), + }) => Stack( + children: [ + this, + Positioned( + left: 0, + right: 0, + top: 0, + bottom: 0, + child: TextButton( + style: ButtonStyle( + shape: WidgetStateProperty.all( + RoundedRectangleBorder(borderRadius: borderRadius), + ), + ), + onPressed: () { + if (onPressed != null) { + onPressed(); + } + }, + child: Container(), + ), + ), + ], + ); } diff --git a/lib/src/widgets/product_card.dart b/lib/src/widgets/product_card.dart index cee4520..99d2af3 100644 --- a/lib/src/widgets/product_card.dart +++ b/lib/src/widgets/product_card.dart @@ -8,7 +8,7 @@ import 'package:flutter_ecommerce_app/src/widgets/extentions.dart'; class ProductCard extends StatelessWidget { final Product product; final ValueChanged onSelected; - ProductCard({Key key, this.product, this.onSelected}) : super(key: key); + ProductCard({Key? key,required this.product,required this.onSelected}) : super(key: key); // @override // _ProductCardState createState() => _ProductCardState(); @@ -32,7 +32,7 @@ class ProductCard extends StatelessWidget { BoxShadow(color: Color(0xfff8f8f8), blurRadius: 15, spreadRadius: 10), ], ), - margin: EdgeInsets.symmetric(vertical: !product.isSelected ? 20 : 0), + margin: EdgeInsets.symmetric(vertical: product.isSelected ? 20 : 0), child: Container( padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10), child: Stack( diff --git a/lib/src/widgets/product_icon.dart b/lib/src/widgets/product_icon.dart index 2693bf0..e7a59f1 100644 --- a/lib/src/widgets/product_icon.dart +++ b/lib/src/widgets/product_icon.dart @@ -10,54 +10,50 @@ class ProductIcon extends StatelessWidget { // final String text; final ValueChanged onSelected; final Category model; - ProductIcon({Key key, this.model, this.onSelected}) : super(key: key); + ProductIcon({super.key, required this.model,required this.onSelected}); Widget build(BuildContext context) { return model.id == null ? Container(width: 5) : Container( - margin: EdgeInsets.symmetric(horizontal: 10, vertical: 15), - child: Container( - padding: AppTheme.hPadding, - alignment: Alignment.center, - decoration: BoxDecoration( - borderRadius: BorderRadius.all(Radius.circular(10)), - color: model.isSelected - ? LightColor.background - : Colors.transparent, - border: Border.all( - color: model.isSelected ? LightColor.orange : LightColor.grey, - width: model.isSelected ? 2 : 1, - ), - boxShadow: [ - BoxShadow( - color: model.isSelected ? Color(0xfffbf2ef) : Colors.white, - blurRadius: 10, - spreadRadius: 5, - offset: Offset(5, 5), - ), - ], - ), - child: Row( - children: [ - model.image != null ? Image.asset(model.image) : SizedBox(), - model.name == null - ? Container() - : Container( - child: TitleText( - text: model.name, - fontWeight: FontWeight.w700, - fontSize: 15, - ), - ) - ], - ), - ).ripple( - () { - onSelected(model); - }, + margin: EdgeInsets.symmetric(horizontal: 10, vertical: 15), + child: Container( + padding: AppTheme.hPadding, + alignment: Alignment.center, + decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(10)), + color: + model.isSelected ? LightColor.background : Colors.transparent, + border: Border.all( + color: model.isSelected ? LightColor.orange : LightColor.grey, + width: model.isSelected ? 2 : 1, + ), + boxShadow: [ + BoxShadow( + color: model.isSelected ? Color(0xfffbf2ef) : Colors.white, + blurRadius: 10, + spreadRadius: 5, + offset: Offset(5, 5), + ), + ], + ), + child: Row( + children: [ + model.image != null ? Image.asset(model.image!) : SizedBox(), + model.name == null + ? Container() + : Container( + child: TitleText( + text: model.name!, + fontWeight: FontWeight.w700, + fontSize: 15, + ), + ), + ], ), - ); + ).ripple(() { + onSelected(model); + }, borderRadius: BorderRadius.all(Radius.circular(10))), + ); } } From 2b5359568e631e57e7d0fddefa5a82a59a55f4e0 Mon Sep 17 00:00:00 2001 From: Maheresio Date: Tue, 4 Mar 2025 11:06:29 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=90=9B=20(fix)=20update=20iOS=20and?= =?UTF-8?q?=20Android=20project=20configurations,=20migrate=20the=20latest?= =?UTF-8?q?=20version=20of=20flutter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- android/.gitignore | 5 +- android/app/build.gradle | 59 ---- android/app/build.gradle.kts | 44 +++ android/app/src/debug/AndroidManifest.xml | 6 +- android/app/src/main/AndroidManifest.xml | 40 ++- .../com/example/test_app/MainActivity.kt | 5 + .../flutter_ecommerce_app/MainActivity.kt | 6 - .../app/src/main/res/values-night/styles.xml | 4 +- android/app/src/main/res/values/styles.xml | 4 +- android/app/src/profile/AndroidManifest.xml | 6 +- android/build.gradle | 29 -- android/build.gradle.kts | 21 ++ android/gradle.properties | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 3 +- android/settings.gradle | 11 - android/settings.gradle.kts | 25 ++ ios/.gitignore | 4 +- ios/Flutter/AppFrameworkInfo.plist | 4 +- ios/Flutter/Debug.xcconfig | 1 - ios/Flutter/Release.xcconfig | 1 - ios/Podfile | 41 --- ios/Podfile.lock | 22 -- ios/Runner.xcodeproj/project.pbxproj | 256 ++++++++++------- .../xcshareddata/xcschemes/Runner.xcscheme | 22 +- .../contents.xcworkspacedata | 3 - ios/Runner/AppDelegate.swift | 4 +- .../AppIcon.appiconset/Icon-App-20x20@1x.png | Bin 564 -> 295 bytes .../AppIcon.appiconset/Icon-App-20x20@2x.png | Bin 1283 -> 406 bytes .../AppIcon.appiconset/Icon-App-20x20@3x.png | Bin 1588 -> 450 bytes .../AppIcon.appiconset/Icon-App-29x29@1x.png | Bin 1025 -> 282 bytes .../AppIcon.appiconset/Icon-App-29x29@2x.png | Bin 1716 -> 462 bytes .../AppIcon.appiconset/Icon-App-29x29@3x.png | Bin 1920 -> 704 bytes .../AppIcon.appiconset/Icon-App-40x40@1x.png | Bin 1283 -> 406 bytes .../AppIcon.appiconset/Icon-App-40x40@2x.png | Bin 1895 -> 586 bytes .../AppIcon.appiconset/Icon-App-40x40@3x.png | Bin 2665 -> 862 bytes .../AppIcon.appiconset/Icon-App-60x60@2x.png | Bin 2665 -> 862 bytes .../AppIcon.appiconset/Icon-App-60x60@3x.png | Bin 3831 -> 1674 bytes .../AppIcon.appiconset/Icon-App-76x76@1x.png | Bin 1888 -> 762 bytes .../AppIcon.appiconset/Icon-App-76x76@2x.png | Bin 3294 -> 1226 bytes .../Icon-App-83.5x83.5@2x.png | Bin 3612 -> 1418 bytes ios/Runner/Info.plist | 10 +- ios/Runner/Runner-Bridging-Header.h | 2 +- ios/RunnerTests/RunnerTests.swift | 12 + lib/src/widgets/title_text.dart | 25 +- pubspec.lock | 260 +++++++++++------- pubspec.yaml | 9 +- 46 files changed, 506 insertions(+), 440 deletions(-) delete mode 100644 android/app/build.gradle create mode 100644 android/app/build.gradle.kts create mode 100644 android/app/src/main/kotlin/com/example/test_app/MainActivity.kt delete mode 100644 android/app/src/main/kotlin/com/thealphamerc/flutter_ecommerce_app/MainActivity.kt delete mode 100644 android/build.gradle create mode 100644 android/build.gradle.kts delete mode 100644 android/settings.gradle create mode 100644 android/settings.gradle.kts delete mode 100644 ios/Podfile delete mode 100644 ios/Podfile.lock create mode 100644 ios/RunnerTests/RunnerTests.swift diff --git a/android/.gitignore b/android/.gitignore index 0a741cb..be3943c 100644 --- a/android/.gitignore +++ b/android/.gitignore @@ -5,7 +5,10 @@ gradle-wrapper.jar /gradlew.bat /local.properties GeneratedPluginRegistrant.java +.cxx/ # Remember to never publicly share your keystore. -# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app +# See https://flutter.dev/to/reference-keystore key.properties +**/*.keystore +**/*.jks diff --git a/android/app/build.gradle b/android/app/build.gradle deleted file mode 100644 index a0b706e..0000000 --- a/android/app/build.gradle +++ /dev/null @@ -1,59 +0,0 @@ -def localProperties = new Properties() -def localPropertiesFile = rootProject.file('local.properties') -if (localPropertiesFile.exists()) { - localPropertiesFile.withReader('UTF-8') { reader -> - localProperties.load(reader) - } -} - -def flutterRoot = localProperties.getProperty('flutter.sdk') -if (flutterRoot == null) { - throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") -} - -def flutterVersionCode = localProperties.getProperty('flutter.versionCode') -if (flutterVersionCode == null) { - flutterVersionCode = '1' -} - -def flutterVersionName = localProperties.getProperty('flutter.versionName') -if (flutterVersionName == null) { - flutterVersionName = '1.0' -} - -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" - -android { - compileSdkVersion 31 - - sourceSets { - main.java.srcDirs += 'src/main/kotlin' - } - - defaultConfig { - // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). - applicationId "com.thealphamerc.flutter_ecommerce_app" - minSdkVersion 16 - targetSdkVersion 30 - versionCode flutterVersionCode.toInteger() - versionName flutterVersionName - } - - buildTypes { - release { - // TODO: Add your own signing config for the release build. - // Signing with the debug keys for now, so `flutter run --release` works. - signingConfig signingConfigs.debug - } - } -} - -flutter { - source '../..' -} - -dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" -} diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts new file mode 100644 index 0000000..0eb4b84 --- /dev/null +++ b/android/app/build.gradle.kts @@ -0,0 +1,44 @@ +plugins { + id("com.android.application") + id("kotlin-android") + // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins. + id("dev.flutter.flutter-gradle-plugin") +} + +android { + namespace = "com.example.test_app" + compileSdk = flutter.compileSdkVersion + ndkVersion = "27.0.12077973" + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + } + + kotlinOptions { + jvmTarget = JavaVersion.VERSION_11.toString() + } + + defaultConfig { + // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). + applicationId = "com.example.test_app" + // You can update the following values to match your application needs. + // For more information, see: https://flutter.dev/to/review-gradle-config. + minSdk = flutter.minSdkVersion + targetSdk = flutter.targetSdkVersion + versionCode = flutter.versionCode + versionName = flutter.versionName + } + + buildTypes { + release { + // TODO: Add your own signing config for the release build. + // Signing with the debug keys for now, so `flutter run --release` works. + signingConfig = signingConfigs.getByName("debug") + } + } +} + +flutter { + source = "../.." +} diff --git a/android/app/src/debug/AndroidManifest.xml b/android/app/src/debug/AndroidManifest.xml index c6cf06a..399f698 100644 --- a/android/app/src/debug/AndroidManifest.xml +++ b/android/app/src/debug/AndroidManifest.xml @@ -1,6 +1,6 @@ - - diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 324939d..07f9e4e 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,11 +1,21 @@ - - + + + + + + + + + - - @@ -38,4 +39,15 @@ android:name="flutterEmbedding" android:value="2" /> + + + + + + + diff --git a/android/app/src/main/kotlin/com/example/test_app/MainActivity.kt b/android/app/src/main/kotlin/com/example/test_app/MainActivity.kt new file mode 100644 index 0000000..845adb2 --- /dev/null +++ b/android/app/src/main/kotlin/com/example/test_app/MainActivity.kt @@ -0,0 +1,5 @@ +package com.example.test_app + +import io.flutter.embedding.android.FlutterActivity + +class MainActivity : FlutterActivity() diff --git a/android/app/src/main/kotlin/com/thealphamerc/flutter_ecommerce_app/MainActivity.kt b/android/app/src/main/kotlin/com/thealphamerc/flutter_ecommerce_app/MainActivity.kt deleted file mode 100644 index 805d875..0000000 --- a/android/app/src/main/kotlin/com/thealphamerc/flutter_ecommerce_app/MainActivity.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.thealphamerc.flutter_ecommerce_app - -import io.flutter.embedding.android.FlutterActivity - -class MainActivity: FlutterActivity() { -} diff --git a/android/app/src/main/res/values-night/styles.xml b/android/app/src/main/res/values-night/styles.xml index 449a9f9..06952be 100644 --- a/android/app/src/main/res/values-night/styles.xml +++ b/android/app/src/main/res/values-night/styles.xml @@ -3,14 +3,14 @@