Skip to content

Commit

Permalink
Replace textThemes with custom extension
Browse files Browse the repository at this point in the history
  • Loading branch information
SinaSys committed Oct 3, 2024
1 parent 0a8552e commit 5f43a3b
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 84 deletions.
36 changes: 14 additions & 22 deletions lib/src/view/screen/cart_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CartScreen extends StatelessWidget {
return AppBar(
title: Text(
"Cart screen",
style: Theme.of(context).textTheme.displayMedium,
style: context.displayMedium,
),
);
}
Expand Down Expand Up @@ -45,12 +45,12 @@ class CartScreen extends StatelessWidget {
children: [
Text(
"Subtotal",
style: Theme.of(context).textTheme.headlineSmall,
style: context.headlineSmall,
),
Obx(() {
return Text(
"\$${controller.subtotalPrice.value}",
style: Theme.of(context).textTheme.displayMedium,
style: context.displayMedium,
);
}),
],
Expand All @@ -64,11 +64,11 @@ class CartScreen extends StatelessWidget {
children: [
Text(
"Taxes",
style: Theme.of(context).textTheme.headlineSmall,
style: context.headlineSmall,
),
Text(
"\$${5.00}",
style: Theme.of(context).textTheme.displayMedium,
style: context.displayMedium,
),
],
),
Expand All @@ -84,13 +84,11 @@ class CartScreen extends StatelessWidget {
children: [
Text(
"Total",
style: Theme.of(context).textTheme.displayMedium,
style: context.displayMedium,
),
Obx(() {
return Text(
controller.totalPrice.value == 5.0
? "\$0.0"
: "\$${controller.totalPrice}",
controller.totalPrice.value == 5.0 ? "\$0.0" : "\$${controller.totalPrice}",
style: h2Style.copyWith(
color: LightThemeColor.accent,
),
Expand Down Expand Up @@ -152,9 +150,7 @@ class CartScreen extends StatelessWidget {
padding: const EdgeInsets.all(5),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: controller.isLightTheme
? Colors.white
: DarkThemeColor.primaryLight,
color: controller.isLightTheme ? Colors.white : DarkThemeColor.primaryLight,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
Expand All @@ -167,28 +163,26 @@ class CartScreen extends StatelessWidget {
children: [
Text(
controller.cartFood[index].name,
style: Theme.of(context).textTheme.displayMedium,
style: context.displayMedium,
),
const SizedBox(height: 5),
Text(
"\$${controller.cartFood[index].price}",
style: Theme.of(context).textTheme.headlineSmall,
style: context.headlineSmall,
),
],
),
const Spacer(),
Column(
children: [
CounterButton(
onIncrementSelected: () =>
controller.increaseItem(controller.cartFood[index]),
onDecrementSelected: () =>
controller.decreaseItem(controller.cartFood[index]),
onIncrementSelected: () => controller.increaseItem(controller.cartFood[index]),
onDecrementSelected: () => controller.decreaseItem(controller.cartFood[index]),
size: const Size(24, 24),
padding: 0,
label: Text(
controller.cartFood[index].quantity.toString(),
style: Theme.of(context).textTheme.displayMedium,
style:context.displayMedium,
),
),
Text(
Expand All @@ -211,9 +205,7 @@ class CartScreen extends StatelessWidget {
double height = MediaQuery.of(context).size.height;
double width = MediaQuery.of(context).size.width;
return Scaffold(
bottomNavigationBar: controller.cartFood.isNotEmpty
? _bottomAppBar(height, width, context)
: const SizedBox(),
bottomNavigationBar: controller.cartFood.isNotEmpty ? _bottomAppBar(height, width, context) : const SizedBox(),
appBar: _appBar(context),
body: EmptyWidget(
title: "Empty cart",
Expand Down
6 changes: 3 additions & 3 deletions lib/src/view/screen/favorite_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FavoriteScreen extends StatelessWidget {
appBar: AppBar(
title: Text(
"Favorite screen",
style: Theme.of(context).textTheme.displayMedium,
style: context.displayMedium,
),
),
body: EmptyWidget(
Expand All @@ -40,13 +40,13 @@ class FavoriteScreen extends StatelessWidget {
child: ListTile(
title: Text(
food.name,
style: Theme.of(context).textTheme.headlineMedium,
style: context.headlineMedium,
),
leading: Image.asset(food.image),
subtitle: Text(
food.description,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.bodyLarge,
style: context.bodyLarge,
),
trailing: const Icon(AppIcon.heart, color: Colors.redAccent),
),
Expand Down
53 changes: 22 additions & 31 deletions lib/src/view/screen/food_detail_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,19 @@ class FoodDetailScreen extends StatelessWidget {
elevation: 0.0,
backgroundColor: LightThemeColor.accent,
onPressed: onPressed,
child: food.isFavorite
? const Icon(AppIcon.heart)
: const Icon(AppIcon.outlinedHeart),
child: food.isFavorite ? const Icon(AppIcon.heart) : const Icon(AppIcon.outlinedHeart),
);
}

@override
Widget build(BuildContext context) {
double height = MediaQuery.of(context).size.height;
double width = MediaQuery.of(context).size.width;
double height = context.height;
double width = context.width;

return Scaffold(
appBar: _appBar(context),
floatingActionButtonLocation: FloatingActionButtonLocation.endDocked,
floatingActionButton:
GetBuilder(builder: (FoodController foodController) {
floatingActionButton: GetBuilder(builder: (FoodController foodController) {
return fab(() => foodController.isFavoriteFood(food));
}),
bottomNavigationBar: BottomAppBar(
Expand All @@ -72,9 +69,7 @@ class FoodDetailScreen extends StatelessWidget {
children: [
Container(
decoration: BoxDecoration(
color: controller.isLightTheme
? Colors.white
: DarkThemeColor.primaryLight,
color: controller.isLightTheme ? Colors.white : DarkThemeColor.primaryLight,
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(30),
topRight: Radius.circular(30),
Expand Down Expand Up @@ -107,12 +102,12 @@ class FoodDetailScreen extends StatelessWidget {
const SizedBox(width: 15),
Text(
food.score.toString(),
style: Theme.of(context).textTheme.titleMedium,
style: context.titleMedium,
),
const SizedBox(width: 5),
Text(
"(${food.voter})",
style: Theme.of(context).textTheme.titleMedium,
style: context.titleMedium,
)
],
).fadeAnimation(0.4),
Expand All @@ -122,22 +117,18 @@ class FoodDetailScreen extends StatelessWidget {
children: [
Text(
"\$${food.price}",
style: Theme.of(context)
.textTheme
.displayLarge
?.copyWith(color: LightThemeColor.accent),
style: context.displayLarge.copyWith(
color: LightThemeColor.accent,
),
),
GetBuilder(
builder: (FoodController foodController) {
return CounterButton(
onIncrementSelected: () =>
foodController.increaseItem(food),
onDecrementSelected: () =>
foodController.decreaseItem(food),
onIncrementSelected: () => foodController.increaseItem(food),
onDecrementSelected: () => foodController.decreaseItem(food),
label: Text(
food.quantity.toString(),
style:
Theme.of(context).textTheme.displayLarge,
style: context.displayLarge,
),
);
},
Expand All @@ -147,12 +138,12 @@ class FoodDetailScreen extends StatelessWidget {
const SizedBox(height: 15),
Text(
"Description",
style: Theme.of(context).textTheme.displayMedium,
style: context.displayMedium,
).fadeAnimation(0.8),
const SizedBox(height: 15),
Text(
food.description,
style: Theme.of(context).textTheme.titleMedium,
style: context.titleMedium,
).fadeAnimation(0.8),
const SizedBox(height: 70),
],
Expand All @@ -172,9 +163,8 @@ class FoodDetailScreen extends StatelessWidget {
child: Text(
"Add to cart",
style: TextStyle(
color: controller.isLightTheme
? Colors.white
: Colors.black),
color: controller.isLightTheme ? Colors.white : Colors.black,
),
),
),
))
Expand All @@ -183,10 +173,11 @@ class FoodDetailScreen extends StatelessWidget {
),
body: ScaleAnimation(
child: Center(
child: Padding(
padding: const EdgeInsets.all(24.0),
child: Image.asset(food.image, scale: 2),
)),
child: Padding(
padding: const EdgeInsets.all(24.0),
child: Image.asset(food.image, scale: 2),
),
),
),
);
}
Expand Down
33 changes: 17 additions & 16 deletions lib/src/view/screen/food_list_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,20 @@ class FoodListScreen extends StatelessWidget {
title: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.location_on_outlined, color: LightThemeColor.accent),
Text("Location", style: Theme.of(context).textTheme.bodyLarge)
const Icon(
Icons.location_on_outlined,
color: LightThemeColor.accent,
),
Text("Location", style: context.bodyLarge)
],
),
actions: [
IconButton(
onPressed: () {},
icon: Badge(
badgeStyle: const BadgeStyle(badgeColor: LightThemeColor.accent),
badgeStyle: const BadgeStyle(
badgeColor: LightThemeColor.accent,
),
badgeContent: const Text(
"2",
style: TextStyle(color: Colors.white),
Expand Down Expand Up @@ -69,16 +74,16 @@ class FoodListScreen extends StatelessWidget {
children: [
Text(
"Morning, Sina",
style: Theme.of(context).textTheme.headlineSmall,
style: context.headlineSmall,
).fadeAnimation(0.2),
Text(
"What do you want to eat \ntoday",
style: Theme.of(context).textTheme.displayLarge,
style: context.displayLarge,
).fadeAnimation(0.4),
_searchBar(),
Text(
"Available for you",
style: Theme.of(context).textTheme.displaySmall,
style: context.displaySmall,
),
Padding(
padding: const EdgeInsets.only(top: 15),
Expand All @@ -100,17 +105,14 @@ class FoodListScreen extends StatelessWidget {
alignment: Alignment.center,
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: category.isSelected
? LightThemeColor.accent
: Colors.transparent,
color: category.isSelected ? LightThemeColor.accent : Colors.transparent,
borderRadius: const BorderRadius.all(
Radius.circular(15),
),
),
child: Text(
category.type.name.toCapital,
style:
Theme.of(context).textTheme.headlineMedium,
style: context.headlineMedium,
),
),
);
Expand All @@ -137,16 +139,15 @@ class FoodListScreen extends StatelessWidget {
children: [
Text(
"Best food of the week",
style: Theme.of(context).textTheme.displaySmall,
style: context.displaySmall,
),
Padding(
padding: const EdgeInsets.only(right: 20),
child: Text(
"See all",
style: Theme.of(context)
.textTheme
.headlineMedium
?.copyWith(color: LightThemeColor.accent),
style: context.headlineMedium.copyWith(
color: LightThemeColor.accent,
),
),
),
],
Expand Down
5 changes: 3 additions & 2 deletions lib/src/view/screen/profile_screen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_japanese_restaurant_app/core/app_asset.dart';
import 'package:flutter_japanese_restaurant_app/core/app_extension.dart';

class ProfileScreen extends StatelessWidget {
const ProfileScreen({super.key});
Expand All @@ -16,7 +17,7 @@ class ProfileScreen extends StatelessWidget {
),
Text(
"Hello Sina!",
style: Theme.of(context).textTheme.displayLarge,
style: context.displayLarge,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
Expand All @@ -25,7 +26,7 @@ class ProfileScreen extends StatelessWidget {
const SizedBox(width: 10),
Text(
"https://github.com/SinaSys",
style: Theme.of(context).textTheme.displaySmall,
style: context.displaySmall,
)
],
)
Expand Down
6 changes: 5 additions & 1 deletion lib/src/view/widget/empty_widget.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_japanese_restaurant_app/core/app_asset.dart';
import 'package:flutter_japanese_restaurant_app/core/app_extension.dart';

enum EmptyWidgetType { cart, favorite }

Expand Down Expand Up @@ -29,7 +30,10 @@ class EmptyWidget extends StatelessWidget {
? Image.asset(AppAsset.emptyCart, width: 300)
: Image.asset(AppAsset.emptyFavorite, width: 300),
const SizedBox(height: 10),
Text(title, style: Theme.of(context).textTheme.displayMedium)
Text(
title,
style: context.displayMedium,
)
],
),
);
Expand Down
Loading

0 comments on commit 5f43a3b

Please sign in to comment.