diff --git a/lib/core/app_export.dart b/lib/core/app_export.dart index 6d11530..fe2ac98 100644 --- a/lib/core/app_export.dart +++ b/lib/core/app_export.dart @@ -10,7 +10,6 @@ export 'package:eatvio_app/core/utils/pref_utils.dart'; export 'package:eatvio_app/core/utils/size_utils.dart'; export 'package:eatvio_app/data/models/selectionPopupModel/selection_popup_model.dart'; export 'package:eatvio_app/localization/app_localization.dart'; -export 'package:eatvio_app/routes/app_routes.dart'; export 'package:eatvio_app/theme/app_decoration.dart'; export 'package:eatvio_app/theme/custom_text_style.dart'; export 'package:eatvio_app/theme/theme_helper.dart'; diff --git a/lib/main.dart b/lib/main.dart index 3e4b3c8..50fb829 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -72,28 +72,28 @@ class MyApp extends StatelessWidget { child: BlocBuilder( builder: (context, state) { return KeyboardDismisser( - gestures: [ - GestureType.onTap, - GestureType.onPanUpdateDownDirection, - ], - child: MaterialApp.router( - theme: theme, - title: 'Eatvio', - routerConfig: AppRouter.appRouter, - debugShowCheckedModeBanner: false, - localizationsDelegates: [ - AppLocalizationDelegate(), - GlobalMaterialLocalizations.delegate, - GlobalWidgetsLocalizations.delegate, - GlobalCupertinoLocalizations.delegate, - ], - supportedLocales: [ - Locale( - 'ru', - '', - ), - ], - )); + gestures: [ + GestureType.onTap, + GestureType.onPanUpdateDownDirection, + ], + child: MaterialApp.router( + theme: theme, + title: 'Eatvio', + routerConfig: AppRouter.appRouter, + debugShowCheckedModeBanner: false, + localizationsDelegates: [ + AppLocalizationDelegate(), + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + GlobalCupertinoLocalizations.delegate, + ], + supportedLocales: [ + Locale( + 'ru', + '', + ), + ], + )); }, ), ); diff --git a/lib/presentation/chat/chat_screen/chat_screen.dart b/lib/presentation/chat/chat_screen/chat_screen.dart index 7ec3ea6..48169f5 100644 --- a/lib/presentation/chat/chat_screen/chat_screen.dart +++ b/lib/presentation/chat/chat_screen/chat_screen.dart @@ -108,7 +108,7 @@ class ChatScreen extends StatelessWidget { String currentRoute, ) { switch (currentRoute) { - case AppRoutes.chatScreen: + case '/chat': return ChatScreen.builder(context); default: return ChatScreen(); diff --git a/lib/presentation/chat/chat_select_screen/widgets/chat_entry_widget.dart b/lib/presentation/chat/chat_select_screen/widgets/chat_entry_widget.dart index 55f5ee4..688999b 100644 --- a/lib/presentation/chat/chat_select_screen/widgets/chat_entry_widget.dart +++ b/lib/presentation/chat/chat_select_screen/widgets/chat_entry_widget.dart @@ -5,6 +5,7 @@ import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:eatvio_app/core/app_export.dart'; import 'package:eatvio_app/presentation/chat/chat_select_screen/models/chat_entry.dart'; import 'package:cached_network_image/cached_network_image.dart'; +import 'package:go_router/go_router.dart'; class ChatEntryWidget extends StatelessWidget { ChatEntryWidget(this.chatEntryObj, {Key? key}) @@ -17,10 +18,9 @@ class ChatEntryWidget extends StatelessWidget { @override Widget build(BuildContext context) { return GestureDetector( - onTap: () => Navigator.pushNamed( - context, - AppRoutes.chatScreen, - arguments: chatEntryObj.id.toString(), + onTap: () => GoRouter.of(context).goNamed( + 'chatScreen', + extra: chatEntryObj.id.toString(), ), child: Container( padding: EdgeInsets.all(8.h), diff --git a/lib/presentation/diets/diet_select_screen/bloc/diet_select_bloc.dart b/lib/presentation/diets/diet_select_screen/bloc/diet_select_bloc.dart index 5776d70..dbc622f 100644 --- a/lib/presentation/diets/diet_select_screen/bloc/diet_select_bloc.dart +++ b/lib/presentation/diets/diet_select_screen/bloc/diet_select_bloc.dart @@ -1,6 +1,7 @@ //import 'package:eatvio_app/presentation/auth/auth_screen/auth_screen.dart'; import 'dart:async'; +import 'package:eatvio_app/app_router.dart'; import 'package:equatable/equatable.dart'; import 'package:flutter/material.dart'; import '/core/app_export.dart'; @@ -10,6 +11,7 @@ import 'dart:convert'; import 'package:hive/hive.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:image_picker/image_picker.dart'; +import 'package:go_router/go_router.dart'; part 'diet_select_event.dart'; part 'diet_select_state.dart'; diff --git a/lib/presentation/diets/diet_select_screen/diet_select_screen.dart b/lib/presentation/diets/diet_select_screen/diet_select_screen.dart index 8b9e215..ef058bd 100644 --- a/lib/presentation/diets/diet_select_screen/diet_select_screen.dart +++ b/lib/presentation/diets/diet_select_screen/diet_select_screen.dart @@ -13,10 +13,7 @@ import 'package:flutter/material.dart'; class DietSelectScreen extends StatelessWidget { static Widget builder(BuildContext context) { return BlocProvider( - create: (context) => DietSelectBloc( - DietSelectState(myProfileModelObj: DietSelectModel())) - ..add(DietSelectInitialEvent()), - child: DietSelectScreen()); + create: (context) => DietSelectBloc(DietSelectState(myProfileModelObj: DietSelectModel()))..add(DietSelectInitialEvent()), child: DietSelectScreen()); } Widget build(BuildContext context) { @@ -80,8 +77,7 @@ class DietSelectScreen extends StatelessWidget { leadingWidth: 28.h, leading: AppbarLeadingImage( imagePath: ImageConstant.imgArrowLeft, - margin: EdgeInsets.only( - left: 16.h, top: 15.v, bottom: 15.v), + margin: EdgeInsets.only(left: 16.h, top: 15.v, bottom: 15.v), onTap: () => GoRouter.of(context).pop(), ), title: Padding( @@ -90,18 +86,15 @@ class DietSelectScreen extends StatelessWidget { children: [ AppbarSubtitle( text: "Диеты", - margin: EdgeInsets.only( - left: 80.h, top: 12.v, bottom: 9.v), + margin: EdgeInsets.only(left: 80.h, top: 12.v, bottom: 9.v), ), Spacer(), Padding( padding: const EdgeInsets.only(right: 20.0), child: GestureDetector( - onTap: () => Navigator.pushNamed( - context, - AppRoutes.dietCreateScreen, - ), - child: Icon(Icons.create_outlined)), + onTap: () => GoRouter.of(context).goNamed('dietCreateScreen'), + child: Icon(Icons.create_outlined), + ), ) ], ), @@ -157,18 +150,17 @@ class DietSelectScreen extends StatelessWidget { style: CustomTextStyles.titleMediumSemiBold, ), subtitle: Text(post?['details'] ?? ''), - onTap: () => Navigator.pushNamed( - context, - AppRoutes.dietScreen, - arguments: post?['id'].toString(), + onTap: () => GoRouter.of(context).goNamed( + 'dietScreen', + extra: post?['id'].toString(), ), trailing: GestureDetector( - onTap: () => Navigator.pushNamed( - context, - AppRoutes.dietEditScreen, - arguments: post?['id'].toString(), - ), - child: Icon(Icons.edit)), + onTap: () => GoRouter.of(context).goNamed( + 'dietEditScreen', + extra: post?['id'].toString(), + ), + child: Icon(Icons.edit), + ), )); }, ); diff --git a/lib/presentation/diets/diet_show_screen/bloc/diet_show_bloc.dart b/lib/presentation/diets/diet_show_screen/bloc/diet_show_bloc.dart index 5c60a1d..5fcd3a1 100644 --- a/lib/presentation/diets/diet_show_screen/bloc/diet_show_bloc.dart +++ b/lib/presentation/diets/diet_show_screen/bloc/diet_show_bloc.dart @@ -1,5 +1,6 @@ import 'dart:async'; +import 'package:eatvio_app/app_router.dart'; import 'package:equatable/equatable.dart'; import 'package:flutter/material.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; @@ -8,7 +9,10 @@ import 'package:http/http.dart' as http; import 'dart:convert'; import '/core/app_export.dart'; import 'package:eatvio_app/presentation/diets/diet_show_screen/models/diet_show_model.dart'; +import 'package:go_router/go_router.dart'; + part 'diet_show_event.dart'; + part 'diet_show_state.dart'; /// A bloc that manages the state of a Diet according to the event that is dispatched to it. @@ -40,9 +44,7 @@ class DietBloc extends Bloc { if (data is Map) { if (state is DietLoadedState) { var currentState = state as DietLoadedState; - emit(currentState.copyWith( - dietModelObj: currentState.dietModelObj, - diet: currentState.diet)); + emit(currentState.copyWith(dietModelObj: currentState.dietModelObj, diet: currentState.diet)); } else { emit(DietLoadedState(diet: data)); } @@ -60,8 +62,7 @@ class DietBloc extends Bloc { } } - FutureOr _deleteEntry( - DeleteEntry event, Emitter emit) async { + FutureOr _deleteEntry(DeleteEntry event, Emitter emit) async { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { @@ -75,7 +76,7 @@ class DietBloc extends Bloc { }, ); if (response.statusCode == 200) { - NavigatorService.pushNamed(AppRoutes.dietSelectScreen); + AppRouter.navigatorKey.currentContext?.goNamed('dietSelectScreen'); } else { // Статус ответа не равен 200, обрабатываем ошибку emit(DietErrorState('Ошибка: ${response.statusCode}')); diff --git a/lib/presentation/diets/diet_show_screen/diet_show_screen.dart b/lib/presentation/diets/diet_show_screen/diet_show_screen.dart index a15c8f6..f6af548 100644 --- a/lib/presentation/diets/diet_show_screen/diet_show_screen.dart +++ b/lib/presentation/diets/diet_show_screen/diet_show_screen.dart @@ -1,3 +1,5 @@ +import 'package:go_router/go_router.dart'; + import 'bloc/diet_show_bloc.dart'; import 'models/diet_show_model.dart'; import 'package:eatvio_app/core/app_export.dart'; @@ -91,10 +93,9 @@ class DietScreen extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ ElevatedButton( - onPressed: () => Navigator.pushNamed( - context, - AppRoutes.dietEditScreen, - arguments: state.diet?['id'].toString(), + onPressed: () => GoRouter.of(context).goNamed( + 'dietEditScreen', + extra: state.diet?['id'].toString(), ), child: Text('Редактировать'), ), @@ -119,7 +120,7 @@ class DietScreen extends StatelessWidget { String currentRoute, ) { switch (currentRoute) { - case AppRoutes.dietScreen: + case '/diet': return DietScreen.builder(context); default: return DietScreen(); diff --git a/lib/presentation/feed/blog_post_create_screen/bloc/blog_post_create_bloc.dart b/lib/presentation/feed/blog_post_create_screen/bloc/blog_post_create_bloc.dart index 3f5d95e..77f0f1a 100644 --- a/lib/presentation/feed/blog_post_create_screen/bloc/blog_post_create_bloc.dart +++ b/lib/presentation/feed/blog_post_create_screen/bloc/blog_post_create_bloc.dart @@ -59,7 +59,7 @@ class BlogPostCreateBloc ); if (response.statusCode == 200) { - NavigatorService.pushNamed(AppRoutes.feedScreen); + AppRouter.navigatorKey.currentContext?.goNamed('feedScreen'); } else { print( 'Failed to create blog post. Status Code: ${response.statusCode} ${response.body}'); diff --git a/lib/presentation/feed/blog_post_edit_screen/bloc/blog_post_edit_bloc.dart b/lib/presentation/feed/blog_post_edit_screen/bloc/blog_post_edit_bloc.dart index 1810faf..b3a3027 100644 --- a/lib/presentation/feed/blog_post_edit_screen/bloc/blog_post_edit_bloc.dart +++ b/lib/presentation/feed/blog_post_edit_screen/bloc/blog_post_edit_bloc.dart @@ -10,7 +10,9 @@ import 'dart:convert'; import '/core/app_export.dart'; import 'package:eatvio_app/presentation/feed/blog_post_edit_screen/models/blog_post_edit_model.dart'; import 'package:go_router/go_router.dart'; + part 'blog_post_edit_event.dart'; + part 'blog_post_edit_state.dart'; /// A bloc that manages the state of a BlogPostEdit according to the event that is dispatched to it. @@ -57,8 +59,7 @@ class BlogPostEditBloc extends Bloc { } } else { // Один или несколько ключевых полей отсутствуют, обрабатываем ошибку - emit(BlogPostEditErrorState( - 'Некоторые необходимые данные отсутствуют.')); + emit(BlogPostEditErrorState('Некоторые необходимые данные отсутствуют.')); } } else { // Статус ответа не равен 200, обрабатываем ошибку @@ -70,8 +71,7 @@ class BlogPostEditBloc extends Bloc { } } - FutureOr _editBlogPost( - EditBlogPost event, Emitter emit) async { + FutureOr _editBlogPost(EditBlogPost event, Emitter emit) async { if (state is BlogPostEditLoadedState) { var currentState = state as BlogPostEditLoadedState; @@ -83,11 +83,9 @@ class BlogPostEditBloc extends Bloc { ); if (response.statusCode == 200) { - NavigatorService.pushNamed(AppRoutes.blogPostScreen, - arguments: currentState.blog_post?['id'].toString()); + AppRouter.navigatorKey.currentContext?.goNamed('blogPostScreen', extra: currentState.blog_post?['id'].toString()); } else { - print( - 'Failed to edit blog post. Status Code: ${response.statusCode} ${response.body}'); + print('Failed to edit blog post. Status Code: ${response.statusCode} ${response.body}'); } } } diff --git a/lib/presentation/feed/blog_post_screen/bloc/blog_post_bloc.dart b/lib/presentation/feed/blog_post_screen/bloc/blog_post_bloc.dart index 19f0c70..9f5f11f 100644 --- a/lib/presentation/feed/blog_post_screen/bloc/blog_post_bloc.dart +++ b/lib/presentation/feed/blog_post_screen/bloc/blog_post_bloc.dart @@ -108,7 +108,7 @@ class BlogPostBloc extends Bloc { }, ); if (response.statusCode == 200) { - NavigatorService.pushNamed(AppRoutes.feedScreen); + AppRouter.navigatorKey.currentContext?.goNamed('feedScreen'); } else { // Статус ответа не равен 200, обрабатываем ошибку emit(BlogPostErrorState('Ошибка: ${response.statusCode}')); diff --git a/lib/presentation/feed/blog_post_screen/blog_post_screen.dart b/lib/presentation/feed/blog_post_screen/blog_post_screen.dart index 0b52412..37a2ce2 100644 --- a/lib/presentation/feed/blog_post_screen/blog_post_screen.dart +++ b/lib/presentation/feed/blog_post_screen/blog_post_screen.dart @@ -308,10 +308,9 @@ class BlogPostScreen extends StatelessWidget { void tapMenu(String value, BuildContext context, BlogPostLoadedState state) { if (value == 'edit') { - Navigator.pushNamed( - context, - AppRoutes.blogPostEditScreen, - arguments: state.blog_post?['id'].toString(), + GoRouter.of(context).goNamed( + 'blogPostEditScreen', + extra: state.blog_post?['id'].toString(), ); } else if (value == 'delete') { context.read().add(DeleteEntry(state.blog_post?['id'])); diff --git a/lib/presentation/glossary/glossary_screen/glossary_screen.dart b/lib/presentation/glossary/glossary_screen/glossary_screen.dart index de262b3..ada1e86 100644 --- a/lib/presentation/glossary/glossary_screen/glossary_screen.dart +++ b/lib/presentation/glossary/glossary_screen/glossary_screen.dart @@ -302,7 +302,7 @@ class GlossaryScreen extends StatelessWidget { String currentRoute, ) { switch (currentRoute) { - case AppRoutes.glossaryScreen: + case '/glossary': return GlossaryScreen.builder(context); default: return GlossaryScreen(); diff --git a/lib/presentation/plans/plan_create_screen/bloc/plan_create_bloc.dart b/lib/presentation/plans/plan_create_screen/bloc/plan_create_bloc.dart index a74e40e..51e08b9 100644 --- a/lib/presentation/plans/plan_create_screen/bloc/plan_create_bloc.dart +++ b/lib/presentation/plans/plan_create_screen/bloc/plan_create_bloc.dart @@ -55,7 +55,7 @@ class PlanCreateBloc extends Bloc { ); if (response.statusCode == 200) { - NavigatorService.pushNamed(AppRoutes.planSelectScreen); + AppRouter.navigatorKey.currentContext?.goNamed('planSelectScreen'); } else { print( 'Failed to create blog post. Status Code: ${response.statusCode} ${response.body}'); diff --git a/lib/presentation/plans/plan_edit_screen/bloc/plan_edit_bloc.dart b/lib/presentation/plans/plan_edit_screen/bloc/plan_edit_bloc.dart index 584f9d2..1e7e4f2 100644 --- a/lib/presentation/plans/plan_edit_screen/bloc/plan_edit_bloc.dart +++ b/lib/presentation/plans/plan_edit_screen/bloc/plan_edit_bloc.dart @@ -10,7 +10,9 @@ import 'dart:convert'; import '/core/app_export.dart'; import 'package:eatvio_app/presentation/plans/plan_edit_screen/models/plan_edit_model.dart'; import 'package:go_router/go_router.dart'; + part 'plan_edit_event.dart'; + part 'plan_edit_state.dart'; /// A bloc that manages the state of a PlanEdit according to the event that is dispatched to it. @@ -53,8 +55,7 @@ class PlanEditBloc extends Bloc { plan: data, name: TextEditingController(text: data['name']), details: TextEditingController(text: data['details']), - duration: - TextEditingController(text: data['duration'].toString()))); + duration: TextEditingController(text: data['duration'].toString()))); } } else { // Один или несколько ключевых полей отсутствуют, обрабатываем ошибку @@ -75,15 +76,15 @@ class PlanEditBloc extends Bloc { var currentState = state as PlanEditLoadedState; int duration = int.parse(currentState.duration!.text) * 7; print(duration); - var response = await sendPlan(currentState.plan, currentState.name?.text, - currentState.details?.text, duration.toString()); + var response = await sendPlan(currentState.plan, currentState.name?.text, currentState.details?.text, duration.toString()); if (response.statusCode == 200) { - NavigatorService.pushNamed(AppRoutes.planScreen, - arguments: currentState.plan?['id'].toString()); + AppRouter.navigatorKey.currentContext?.goNamed( + 'planScreen', + extra: currentState.plan?['id'].toString(), + ); } else { - print( - 'Failed to edit blog post. Status Code: ${response.statusCode} ${response.body}'); + print('Failed to edit blog post. Status Code: ${response.statusCode} ${response.body}'); } } } diff --git a/lib/presentation/plans/plan_select_screen/plan_select_screen.dart b/lib/presentation/plans/plan_select_screen/plan_select_screen.dart index 6dd7e33..519ff0d 100644 --- a/lib/presentation/plans/plan_select_screen/plan_select_screen.dart +++ b/lib/presentation/plans/plan_select_screen/plan_select_screen.dart @@ -13,10 +13,7 @@ import 'package:flutter/material.dart'; class PlanSelectScreen extends StatelessWidget { static Widget builder(BuildContext context) { return BlocProvider( - create: (context) => PlanSelectBloc( - PlanSelectState(myProfileModelObj: PlanSelectModel())) - ..add(PlanSelectInitialEvent()), - child: PlanSelectScreen()); + create: (context) => PlanSelectBloc(PlanSelectState(myProfileModelObj: PlanSelectModel()))..add(PlanSelectInitialEvent()), child: PlanSelectScreen()); } Widget build(BuildContext context) { @@ -80,8 +77,7 @@ class PlanSelectScreen extends StatelessWidget { leadingWidth: 28.h, leading: AppbarLeadingImage( imagePath: ImageConstant.imgArrowLeft, - margin: EdgeInsets.only( - left: 16.h, top: 15.v, bottom: 15.v), + margin: EdgeInsets.only(left: 16.h, top: 15.v, bottom: 15.v), onTap: () => GoRouter.of(context).pop(), ), title: Padding( @@ -90,18 +86,15 @@ class PlanSelectScreen extends StatelessWidget { children: [ AppbarSubtitle( text: "Планы", - margin: EdgeInsets.only( - left: 80.h, top: 12.v, bottom: 9.v), + margin: EdgeInsets.only(left: 80.h, top: 12.v, bottom: 9.v), ), Spacer(), Padding( padding: const EdgeInsets.only(right: 20.0), child: GestureDetector( - onTap: () => Navigator.pushNamed( - context, - AppRoutes.planCreateScreen, - ), - child: Icon(Icons.create_outlined)), + onTap: () => GoRouter.of(context).goNamed('planCreateScreen'), + child: Icon(Icons.create_outlined), + ), ) ], ), @@ -125,51 +118,51 @@ class PlanSelectScreen extends StatelessWidget { itemBuilder: (context, index) { final post = state.posts?[index]; return Container( - margin: EdgeInsets.only(bottom: 10), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: const BorderRadius.all(Radius.circular(12)), - boxShadow: [ - BoxShadow( - color: Colors.grey.withOpacity(0.5), - spreadRadius: 2, - blurRadius: 5, - offset: Offset(0, 3), - ), - ], + margin: EdgeInsets.only(bottom: 10), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: const BorderRadius.all(Radius.circular(12)), + boxShadow: [ + BoxShadow( + color: Colors.grey.withOpacity(0.5), + spreadRadius: 2, + blurRadius: 5, + offset: Offset(0, 3), + ), + ], + ), + child: ListTile( + leading: CachedNetworkImage( + imageUrl: dotenv.env['STORAGE_URL']! + post['image'], + imageBuilder: (context, imageProvider) => CircleAvatar( + backgroundImage: imageProvider, + radius: 25, + ), + placeholder: (context, url) => CircularProgressIndicator(), + errorWidget: (context, url, error) => CircleAvatar( + child: Icon(Icons.person), + backgroundColor: Colors.white, + radius: 25, + ), ), - child: ListTile( - leading: CachedNetworkImage( - imageUrl: dotenv.env['STORAGE_URL']! + post['image'], - imageBuilder: (context, imageProvider) => CircleAvatar( - backgroundImage: imageProvider, - radius: 25, - ), - placeholder: (context, url) => CircularProgressIndicator(), - errorWidget: (context, url, error) => CircleAvatar( - child: Icon(Icons.person), - backgroundColor: Colors.white, - radius: 25, - ), + title: Text( + post?['name'] ?? '', + style: CustomTextStyles.titleMediumSemiBold, + ), + subtitle: Text(post?['details'] ?? ''), + onTap: () => GoRouter.of(context).goNamed( + 'planScreen', + extra: post?['id'].toString(), + ), + trailing: GestureDetector( + onTap: () => GoRouter.of(context).goNamed( + 'planEditScreen', + extra: post?['id'].toString(), ), - title: Text( - post?['name'] ?? '', - style: CustomTextStyles.titleMediumSemiBold, - ), - subtitle: Text(post?['details'] ?? ''), - onTap: () => Navigator.pushNamed( - context, - AppRoutes.planScreen, - arguments: post?['id'].toString(), - ), - trailing: GestureDetector( - onTap: () => Navigator.pushNamed( - context, - AppRoutes.planEditScreen, - arguments: post?['id'].toString(), - ), - child: Icon(Icons.edit)), - )); + child: Icon(Icons.edit), + ), + ), + ); }, ); } diff --git a/lib/presentation/plans/plan_show_screen/bloc/plan_show_bloc.dart b/lib/presentation/plans/plan_show_screen/bloc/plan_show_bloc.dart index 1c29624..e920db8 100644 --- a/lib/presentation/plans/plan_show_screen/bloc/plan_show_bloc.dart +++ b/lib/presentation/plans/plan_show_screen/bloc/plan_show_bloc.dart @@ -10,7 +10,9 @@ import 'dart:convert'; import '/core/app_export.dart'; import 'package:eatvio_app/presentation/plans/plan_show_screen/models/plan_show_model.dart'; import 'package:go_router/go_router.dart'; + part 'plan_show_event.dart'; + part 'plan_show_state.dart'; /// A bloc that manages the state of a Plan according to the event that is dispatched to it. @@ -42,9 +44,7 @@ class PlanBloc extends Bloc { if (data is Map) { if (state is PlanLoadedState) { var currentState = state as PlanLoadedState; - emit(currentState.copyWith( - planModelObj: currentState.planModelObj, - plan: currentState.plan)); + emit(currentState.copyWith(planModelObj: currentState.planModelObj, plan: currentState.plan)); } else { emit(PlanLoadedState(plan: data)); } @@ -62,8 +62,7 @@ class PlanBloc extends Bloc { } } - FutureOr _deleteEntry( - DeleteEntry event, Emitter emit) async { + FutureOr _deleteEntry(DeleteEntry event, Emitter emit) async { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { @@ -77,7 +76,7 @@ class PlanBloc extends Bloc { }, ); if (response.statusCode == 200) { - NavigatorService.pushNamed(AppRoutes.planSelectScreen); + AppRouter.navigatorKey.currentContext?.goNamed('planSelectScreen'); } else { // Статус ответа не равен 200, обрабатываем ошибку emit(PlanErrorState('Ошибка: ${response.statusCode}')); diff --git a/lib/presentation/plans/plan_show_screen/plan_show_screen.dart b/lib/presentation/plans/plan_show_screen/plan_show_screen.dart index 262f876..287cf85 100644 --- a/lib/presentation/plans/plan_show_screen/plan_show_screen.dart +++ b/lib/presentation/plans/plan_show_screen/plan_show_screen.dart @@ -1,3 +1,4 @@ + import 'bloc/plan_show_bloc.dart'; import 'models/plan_show_model.dart'; import 'package:eatvio_app/core/app_export.dart'; @@ -117,7 +118,7 @@ class PlanScreen extends StatelessWidget { String currentRoute, ) { switch (currentRoute) { - case AppRoutes.planScreen: + case '/plan': return PlanScreen.builder(context); default: return PlanScreen(); diff --git a/lib/presentation/profile/my_profile_screen/my_profile_screen.dart b/lib/presentation/profile/my_profile_screen/my_profile_screen.dart index 804bab6..54c0846 100644 --- a/lib/presentation/profile/my_profile_screen/my_profile_screen.dart +++ b/lib/presentation/profile/my_profile_screen/my_profile_screen.dart @@ -188,7 +188,7 @@ class MyProfileScreen extends StatelessWidget { onTapSettings(BuildContext context) { return () { - Navigator.pushNamed(context, AppRoutes.mySettings); + GoRouter.of(context).goNamed('mySettingsScreen'); }; } diff --git a/lib/presentation/recipe/recipe_create_screen/bloc/recipe_create_bloc.dart b/lib/presentation/recipe/recipe_create_screen/bloc/recipe_create_bloc.dart index 1b28e10..881e14a 100644 --- a/lib/presentation/recipe/recipe_create_screen/bloc/recipe_create_bloc.dart +++ b/lib/presentation/recipe/recipe_create_screen/bloc/recipe_create_bloc.dart @@ -109,7 +109,7 @@ class RecipeCreateBloc extends Bloc { ); if (response.statusCode == 200) { - NavigatorService.pushNamed(AppRoutes.recipeSelectScreen); + AppRouter.navigatorKey.currentContext?.goNamed('recipeSelectScreen'); } else { print( 'Failed to create blog post. Status Code: ${response.statusCode} ${response.body}'); diff --git a/lib/presentation/recipe/recipe_edit_screen/bloc/recipe_edit_bloc.dart b/lib/presentation/recipe/recipe_edit_screen/bloc/recipe_edit_bloc.dart index 4a5fce4..9c982dd 100644 --- a/lib/presentation/recipe/recipe_edit_screen/bloc/recipe_edit_bloc.dart +++ b/lib/presentation/recipe/recipe_edit_screen/bloc/recipe_edit_bloc.dart @@ -10,7 +10,9 @@ import 'dart:convert'; import '/core/app_export.dart'; import 'package:eatvio_app/presentation/recipe/recipe_edit_screen/models/recipe_edit_model.dart'; import 'package:go_router/go_router.dart'; + part 'recipe_edit_event.dart'; + part 'recipe_edit_state.dart'; /// A bloc that manages the state of a RecipeEdit according to the event that is dispatched to it. @@ -69,8 +71,7 @@ class RecipeEditBloc extends Bloc { data['steps'].add(defaultStep); } else { for (var step in steps) { - stepDescriptions - .add(TextEditingController(text: step['description'])); + stepDescriptions.add(TextEditingController(text: step['description'])); } } @@ -88,8 +89,7 @@ class RecipeEditBloc extends Bloc { } } else { // Один или несколько ключевых полей отсутствуют, обрабатываем ошибку - emit(RecipeEditErrorState( - 'Некоторые необходимые данные отсутствуют.')); + emit(RecipeEditErrorState('Некоторые необходимые данные отсутствуют.')); } } else { // Статус ответа не равен 200, обрабатываем ошибку @@ -101,8 +101,7 @@ class RecipeEditBloc extends Bloc { } } - FutureOr _editRecipe( - EditRecipe event, Emitter emit) async { + FutureOr _editRecipe(EditRecipe event, Emitter emit) async { if (state is RecipeEditLoadedState) { var currentState = state as RecipeEditLoadedState; @@ -114,11 +113,12 @@ class RecipeEditBloc extends Bloc { ); if (response.statusCode == 200) { - NavigatorService.pushNamed(AppRoutes.recipeScreen, - arguments: currentState.recipe?['id'].toString()); + AppRouter.navigatorKey.currentContext?.goNamed( + 'recipeScreen', + extra: currentState.recipe?['id'].toString(), + ); } else { - print( - 'Failed to edit blog post. Status Code: ${response.statusCode} ${response.body}'); + print('Failed to edit blog post. Status Code: ${response.statusCode} ${response.body}'); } } } @@ -128,33 +128,28 @@ class RecipeEditBloc extends Bloc { var currentState = state as RecipeEditLoadedState; List? updatedSteps = currentState.steps; - List? updatedStepDescriptions = - currentState.stepDescriptions; + List? updatedStepDescriptions = currentState.stepDescriptions; updatedSteps!.add({ 'description': '', 'image': '', }); updatedStepDescriptions!.add(TextEditingController()); - emit(currentState.copyWith( - steps: updatedSteps, stepDescriptions: updatedStepDescriptions)); + emit(currentState.copyWith(steps: updatedSteps, stepDescriptions: updatedStepDescriptions)); await _reloadScreen(event, emit); } } - FutureOr _removeStep( - RemoveStep event, Emitter emit) async { + FutureOr _removeStep(RemoveStep event, Emitter emit) async { if (state is RecipeEditLoadedState) { var currentState = state as RecipeEditLoadedState; List? updatedSteps = currentState.steps; - List? updatedStepDescriptions = - currentState.stepDescriptions; + List? updatedStepDescriptions = currentState.stepDescriptions; updatedSteps!.removeAt(event.id); updatedStepDescriptions!.removeAt(event.id); - emit(currentState.copyWith( - steps: updatedSteps, stepDescriptions: updatedStepDescriptions)); + emit(currentState.copyWith(steps: updatedSteps, stepDescriptions: updatedStepDescriptions)); await _reloadScreen(event, emit); } } @@ -209,8 +204,7 @@ class RecipeEditBloc extends Bloc { return data; } - FutureOr _reloadScreen( - RecipeEditEvent? event, Emitter emit) async { + FutureOr _reloadScreen(RecipeEditEvent? event, Emitter emit) async { print('Reloading..'); final box = await Hive.openBox('token'); final token = box.get('token'); diff --git a/lib/presentation/recipe/recipe_select_screen/recipe_select_screen.dart b/lib/presentation/recipe/recipe_select_screen/recipe_select_screen.dart index 195fab7..8ac9416 100644 --- a/lib/presentation/recipe/recipe_select_screen/recipe_select_screen.dart +++ b/lib/presentation/recipe/recipe_select_screen/recipe_select_screen.dart @@ -91,11 +91,9 @@ class RecipeSelectScreen extends StatelessWidget { Padding( padding: const EdgeInsets.only(right: 20.0), child: GestureDetector( - onTap: () => Navigator.pushNamed( - context, - AppRoutes.recipeCreateScreen, - ), - child: Icon(Icons.create_outlined)), + onTap: () => GoRouter.of(context).goNamed('recipeCreateScreen'), + child: Icon(Icons.create_outlined), + ), ) ], ), @@ -151,18 +149,17 @@ class RecipeSelectScreen extends StatelessWidget { style: CustomTextStyles.titleMediumSemiBold, ), subtitle: Text(post?['description'] ?? ''), - onTap: () => Navigator.pushNamed( - context, - AppRoutes.recipeScreen, - arguments: post?['id'].toString(), + onTap: () => GoRouter.of(context).goNamed( + 'recipeScreen', + extra: post?['id'].toString(), ), trailing: GestureDetector( - onTap: () => Navigator.pushNamed( - context, - AppRoutes.recipeEditScreen, - arguments: post?['id'].toString(), - ), - child: Icon(Icons.edit)), + onTap: () => GoRouter.of(context).goNamed( + 'recipeEditScreen', + extra: post?['id'].toString(), + ), + child: Icon(Icons.edit), + ), )); }, ); diff --git a/lib/presentation/recipe/recipe_show_screen/bloc/recipe_show_bloc.dart b/lib/presentation/recipe/recipe_show_screen/bloc/recipe_show_bloc.dart index aaf8c62..a8b5e19 100644 --- a/lib/presentation/recipe/recipe_show_screen/bloc/recipe_show_bloc.dart +++ b/lib/presentation/recipe/recipe_show_screen/bloc/recipe_show_bloc.dart @@ -12,7 +12,9 @@ import '/core/app_export.dart'; import 'package:eatvio_app/presentation/recipe/recipe_show_screen/models/recipe_show_model.dart'; import 'package:eatvio_app/presentation/feed/blog_post_screen/models/comment_model.dart'; import 'package:go_router/go_router.dart'; + part 'recipe_show_event.dart'; + part 'recipe_show_state.dart'; /// A bloc that manages the state of a Recipe according to the event that is dispatched to it. @@ -77,8 +79,7 @@ class RecipeBloc extends Bloc { } } - FutureOr _deleteEntry( - DeleteEntry event, Emitter emit) async { + FutureOr _deleteEntry(DeleteEntry event, Emitter emit) async { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { @@ -92,27 +93,23 @@ class RecipeBloc extends Bloc { }, ); if (response.statusCode == 200) { - NavigatorService.pushNamed(AppRoutes.recipeSelectScreen); + AppRouter.navigatorKey.currentContext?.goNamed('recipeSelectScreen'); } else { // Статус ответа не равен 200, обрабатываем ошибку emit(RecipeErrorState('Ошибка: ${response.statusCode}')); } } - FutureOr _createComment( - CreateComment event, Emitter emit) async { + FutureOr _createComment(CreateComment event, Emitter emit) async { if (state is RecipeLoadedState) { var currentState = state as RecipeLoadedState; // Отправляем данные по HTTP маршруту и ждем ответ - var response = await _sendCommentData( - currentState.token, event.body, currentState.recipe?['id']); + var response = await _sendCommentData(currentState.token, event.body, currentState.recipe?['id']); if (response.statusCode == 200) { - var updatedComments = - fillCommentList(await _fetchComments(currentState.recipe?['id'])); + var updatedComments = fillCommentList(await _fetchComments(currentState.recipe?['id'])); var updatedState = currentState.copyWith( comments: updatedComments, - commentController: - TextEditingController(), // Clear the comment input field + commentController: TextEditingController(), // Clear the comment input field ); emit(updatedState); // Emit the updated state to trigger a screen update } @@ -178,15 +175,13 @@ class RecipeBloc extends Bloc { id: comments[i]['id'].toString(), userImage: comments[i]['profile_photo_path'], username: comments[i]['name'], - dateText: DateFormat('dd.MM') - .format(DateTime.parse(comments[i]['updated_at'])), + dateText: DateFormat('dd.MM').format(DateTime.parse(comments[i]['updated_at'])), greetingText: comments[i]['body'])); } return list; } - Future _sendCommentData( - String? token, String body, int id) async { + Future _sendCommentData(String? token, String body, int id) async { String url = dotenv.env['SERVER_ROOT']! + '/recipe/createComment/$id'; final Map credentials = { 'id': id, diff --git a/lib/presentation/recipe/recipe_show_screen/recipe_show_screen.dart b/lib/presentation/recipe/recipe_show_screen/recipe_show_screen.dart index 195e3da..a51d7f9 100644 --- a/lib/presentation/recipe/recipe_show_screen/recipe_show_screen.dart +++ b/lib/presentation/recipe/recipe_show_screen/recipe_show_screen.dart @@ -1,3 +1,5 @@ +import 'package:go_router/go_router.dart'; + import 'bloc/recipe_show_bloc.dart'; import 'models/recipe_show_model.dart'; import 'package:eatvio_app/presentation/feed/blog_post_screen/widgets/comment_widget.dart'; @@ -11,12 +13,11 @@ import 'package:flutter_dotenv/flutter_dotenv.dart'; class RecipeScreen extends StatelessWidget { const RecipeScreen({Key? key}) : super(key: key); + static Widget builder(BuildContext context) { final recipeID = ModalRoute.of(context)!.settings.arguments; return BlocProvider( - create: (context) => RecipeBloc(RecipeState( - recipeModelObj: RecipeModel(recipeID: recipeID.toString()))) - ..add(RecipeInitialEvent()), + create: (context) => RecipeBloc(RecipeState(recipeModelObj: RecipeModel(recipeID: recipeID.toString())))..add(RecipeInitialEvent()), child: RecipeScreen()); } @@ -102,9 +103,7 @@ class RecipeScreen extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - CustomImageView( - imagePath: ImageConstant.imgArrowLeft, - onTap: () => NavigatorService.goBack()), + CustomImageView(imagePath: ImageConstant.imgArrowLeft, onTap: () => NavigatorService.goBack()), Padding( padding: EdgeInsets.only(top: 1.v), child: Row( @@ -117,8 +116,7 @@ class RecipeScreen extends StatelessWidget { ), ), CachedNetworkImage( - imageUrl: dotenv.env['STORAGE_URL']! + - (state.author?['profile_photo_path'] ?? ''), + imageUrl: dotenv.env['STORAGE_URL']! + (state.author?['profile_photo_path'] ?? ''), imageBuilder: (context, imageProvider) => CircleAvatar( backgroundImage: imageProvider, radius: 25, @@ -192,8 +190,7 @@ class RecipeScreen extends StatelessWidget { Align( alignment: Alignment.topLeft, child: Text( - DateFormat('dd.MM.yyyy') - .format(DateTime.parse(state.recipe?['updated_at'])), + DateFormat('dd.MM.yyyy').format(DateTime.parse(state.recipe?['updated_at'])), style: theme.textTheme.bodyMedium, )), SizedBox(height: 16.0), @@ -320,10 +317,9 @@ class RecipeScreen extends StatelessWidget { void tapMenu(String value, BuildContext context, RecipeLoadedState state) { if (value == 'edit') { - Navigator.pushNamed( - context, - AppRoutes.recipeEditScreen, - arguments: state.recipe?['id'].toString(), + GoRouter.of(context).goNamed( + 'recipeEditScreen', + extra: state.recipe?['id'].toString(), ); } else if (value == 'delete') { context.read().add(DeleteEntry(state.recipe?['id'])); @@ -367,9 +363,7 @@ class RecipeScreen extends StatelessWidget { decoration: BoxDecoration( color: Colors.transparent, ), - onPressed: () => context - .read() - .add(CreateComment(state.commentController!.text)), + onPressed: () => context.read().add(CreateComment(state.commentController!.text)), // Установите прозрачный фон ) ], @@ -445,9 +439,10 @@ class RecipeScreen extends StatelessWidget { SizedBox(height: 16.0), CachedNetworkImage( imageUrl: dotenv.env['STORAGE_URL']! + (state.steps?[i]['image']), - width: double - .infinity, // Установите ширину равной ширине родительского элемента - height: 200.0, // Задайте постоянную высоту элемента + width: double.infinity, + // Установите ширину равной ширине родительского элемента + height: 200.0, + // Задайте постоянную высоту элемента fit: BoxFit.cover, placeholder: (context, url) => CircularProgressIndicator(), errorWidget: (context, url, error) => Icon(Icons.error), diff --git a/lib/presentation/registration/additional_information_screen/additional_information_screen.dart b/lib/presentation/registration/additional_information_screen/additional_information_screen.dart index c1d7037..47c01b3 100644 --- a/lib/presentation/registration/additional_information_screen/additional_information_screen.dart +++ b/lib/presentation/registration/additional_information_screen/additional_information_screen.dart @@ -1,3 +1,5 @@ +import 'package:go_router/go_router.dart'; + import 'bloc/additional_information_bloc.dart'; import 'models/additional_information_model.dart'; import 'package:eatvio_app/core/app_export.dart'; @@ -91,10 +93,7 @@ class AdditionalInformationScreen extends StatelessWidget { final box = await Hive.openBox('token'); final token = res['token']; box.put('token', token); - Navigator.pushNamed( - context, - AppRoutes.myProfile, - ); + GoRouter.of(context).goNamed('myProfileScreen'); } else { showErrorMessage(context, res['message']); } diff --git a/lib/presentation/registration/allergies_screen/allergies_screen.dart b/lib/presentation/registration/allergies_screen/allergies_screen.dart index 9f4c6b0..75528b6 100644 --- a/lib/presentation/registration/allergies_screen/allergies_screen.dart +++ b/lib/presentation/registration/allergies_screen/allergies_screen.dart @@ -1,3 +1,5 @@ +import 'package:go_router/go_router.dart'; + import 'bloc/allergies_bloc.dart'; import 'models/allergies_model.dart'; import 'package:eatvio_app/core/app_export.dart'; @@ -13,12 +15,9 @@ class AllergiesScreen extends StatefulWidget { const AllergiesScreen({Key? key}) : super(key: key); static Widget builder(BuildContext context) { - final sheet = - ModalRoute.of(context)!.settings.arguments as UserRegistrationSheet; + final sheet = ModalRoute.of(context)!.settings.arguments as UserRegistrationSheet; return BlocProvider( - create: (context) => AllergiesBloc(AllergiesState( - allergiesModelObj: AllergiesModel(userRegistrationSheet: sheet))) - ..add(AllergiesInitialEvent()), + create: (context) => AllergiesBloc(AllergiesState(allergiesModelObj: AllergiesModel(userRegistrationSheet: sheet)))..add(AllergiesInitialEvent()), child: AllergiesScreen()); } @@ -45,32 +44,24 @@ class _AllergiesScreenState extends State { decoration: BoxDecoration( color: theme.colorScheme.onPrimary, borderRadius: BorderRadius.circular(8.h), - border: Border.all( - color: theme.colorScheme.primary, width: 1.h)), + border: Border.all(color: theme.colorScheme.primary, width: 1.h)), child: ClipRRect( borderRadius: BorderRadius.circular(8.h), child: LinearProgressIndicator( - value: 0.76, - backgroundColor: theme.colorScheme.onPrimary, - valueColor: AlwaysStoppedAnimation( - appTheme.blueA400)))), + value: 0.76, backgroundColor: theme.colorScheme.onPrimary, valueColor: AlwaysStoppedAnimation(appTheme.blueA400)))), SizedBox(height: 22.v), - Text("allergies_presence".tr, - style: theme.textTheme.headlineSmall), + Text("allergies_presence".tr, style: theme.textTheme.headlineSmall), Spacer(flex: 36), _buildTextFormField(context), Spacer(flex: 54), - BlocBuilder( - builder: (context, state) { + BlocBuilder(builder: (context, state) { return NextStepButton( text: "continue".tr.toUpperCase(), - margin: EdgeInsets.only( - left: 16.h, right: 16.h, bottom: 50.v), + margin: EdgeInsets.only(left: 16.h, right: 16.h, bottom: 50.v), buttonStyle: CustomButtonStyles.outlinePrimaryTL15, onPressed: onTapContinue(state, context)); }), - BlocBuilder( - builder: (context, state) { + BlocBuilder(builder: (context, state) { return GestureDetector( onTap: onTapSkip(state, context), child: Text("skip".tr, style: theme.textTheme.bodyLarge), @@ -81,26 +72,16 @@ class _AllergiesScreenState extends State { onTapSkip(AllergiesState state, BuildContext context) { return () { - UserRegistrationSheet sheet = - state.allergiesModelObj!.userRegistrationSheet; - Navigator.pushNamed( - context, - AppRoutes.medicineIntakeScreen, - arguments: sheet, - ); + UserRegistrationSheet sheet = state.allergiesModelObj!.userRegistrationSheet; + GoRouter.of(context).goNamed('medicineIntakeScreen', extra: sheet); }; } onTapContinue(AllergiesState state, BuildContext context) { return () { - UserRegistrationSheet sheet = - state.allergiesModelObj!.userRegistrationSheet; + UserRegistrationSheet sheet = state.allergiesModelObj!.userRegistrationSheet; sheet.aboutAllergy = state.enterInformationController!.text; - Navigator.pushNamed( - context, - AppRoutes.medicineIntakeScreen, - arguments: sheet, - ); + GoRouter.of(context).goNamed('medicineIntakeScreen', extra: sheet); }; } @@ -108,10 +89,8 @@ class _AllergiesScreenState extends State { _buildAppBar(BuildContext context) { return CustomAppBar( leadingWidth: 31.h, - leading: AppbarLeadingImage( - imagePath: ImageConstant.imgArrowLeft, - margin: EdgeInsets.only(left: 18.h, top: 15.v, bottom: 15.v), - onTap: onTapBack(context)), + leading: + AppbarLeadingImage(imagePath: ImageConstant.imgArrowLeft, margin: EdgeInsets.only(left: 18.h, top: 15.v, bottom: 15.v), onTap: onTapBack(context)), centerTitle: true, title: AppbarTitleImage(imagePath: ImageConstant.imgLogoEatvio)); } @@ -125,17 +104,13 @@ class _AllergiesScreenState extends State { /// Section Widget _buildTextFormField(BuildContext context) { return Column(children: [ - Text("fill_in_information".tr, - style: CustomTextStyles.titleMediumSegoeUI), + Text("fill_in_information".tr, style: CustomTextStyles.titleMediumSegoeUI), SizedBox(height: 2.v), BlocSelector( selector: (state) => state.enterInformationController, builder: (context, enterInformationController) { return CustomTextFormField( - controller: enterInformationController, - hintText: "enter_information".tr, - textInputAction: TextInputAction.done, - maxLines: 8); + controller: enterInformationController, hintText: "enter_information".tr, textInputAction: TextInputAction.done, maxLines: 8); }) ]); } diff --git a/lib/presentation/registration/app_navigation_screen/app_navigation_screen.dart b/lib/presentation/registration/app_navigation_screen/app_navigation_screen.dart index ec34e36..781552e 100644 --- a/lib/presentation/registration/app_navigation_screen/app_navigation_screen.dart +++ b/lib/presentation/registration/app_navigation_screen/app_navigation_screen.dart @@ -1,3 +1,5 @@ +import 'package:go_router/go_router.dart'; + import 'bloc/app_navigation_bloc.dart'; import 'models/app_navigation_model.dart'; import 'package:eatvio_app/core/app_export.dart'; @@ -49,92 +51,77 @@ class _AppNavigationScreenState extends State { _buildScreenTitle( context, screenTitle: "date_of_birth".tr, - onTapScreenTitle: () => - onTapScreenTitle(AppRoutes.dateOfBirthScreen), + onTapScreenTitle: () => GoRouter.of(context).goNamed('dateOfBirthScreen'), ), _buildScreenTitle( context, screenTitle: "city_of_living".tr, - onTapScreenTitle: () => onTapScreenTitle( - AppRoutes.cityOfLivingScreen), + onTapScreenTitle: () => GoRouter.of(context).goNamed('cityOfLivingScreen'), ), _buildScreenTitle( context, screenTitle: "body_circumferences".tr, - onTapScreenTitle: () => onTapScreenTitle( - AppRoutes.bodyCircumferencesScreen), + onTapScreenTitle: () => GoRouter.of(context).goNamed('bodyCircumferencesScreen'), ), _buildScreenTitle( context, screenTitle: "weight".tr, - onTapScreenTitle: () => - onTapScreenTitle(AppRoutes.weightScreen), + onTapScreenTitle: () => GoRouter.of(context).goNamed('weightScreen'), ), _buildScreenTitle( context, screenTitle: "allergies".tr, - onTapScreenTitle: () => - onTapScreenTitle(AppRoutes.allergiesScreen), + onTapScreenTitle: () => GoRouter.of(context).goNamed('allergiesScreen'), ), _buildScreenTitle( context, screenTitle: "medicine_intake".tr, - onTapScreenTitle: () => onTapScreenTitle( - AppRoutes.medicineIntakeScreen), + onTapScreenTitle: () => GoRouter.of(context).goNamed('medicineIntakeScreen'), ), _buildScreenTitle( context, screenTitle: "splash_screen".tr, - onTapScreenTitle: () => - onTapScreenTitle(AppRoutes.splashScreen), + onTapScreenTitle: () => GoRouter.of(context).goNamed('splashScreen'), ), _buildScreenTitle( context, screenTitle: "gender".tr, - onTapScreenTitle: () => - onTapScreenTitle(AppRoutes.genderScreen), + onTapScreenTitle: () => GoRouter.of(context).goNamed('genderScreen'), ), _buildScreenTitle( context, screenTitle: "blood_pressure".tr, - onTapScreenTitle: () => onTapScreenTitle( - AppRoutes.bloodPressureScreen), + onTapScreenTitle: () => GoRouter.of(context).goNamed('bloodPressureScreen'), ), _buildScreenTitle( context, screenTitle: "favorite_sports".tr, - onTapScreenTitle: () => onTapScreenTitle( - AppRoutes.favoriteSportsScreen), + onTapScreenTitle: () => GoRouter.of(context).goNamed('favoriteSportsScreen'), ), _buildScreenTitle( context, screenTitle: "favorite_foods".tr, - onTapScreenTitle: () => onTapScreenTitle( - AppRoutes.favoriteFoodsScreen), + onTapScreenTitle: () => GoRouter.of(context).goNamed('favoriteFoodsScreen'), ), _buildScreenTitle( context, screenTitle: "schedule".tr, - onTapScreenTitle: () => - onTapScreenTitle(AppRoutes.scheduleScreen), + onTapScreenTitle: () => GoRouter.of(context).goNamed('scheduleScreen'), ), _buildScreenTitle( context, screenTitle: "additional_information".tr, - onTapScreenTitle: () => onTapScreenTitle( - AppRoutes.additionalInformationScreen), + onTapScreenTitle: () => GoRouter.of(context).goNamed('additionalInformationScreen'), ), _buildScreenTitle( context, screenTitle: "language_select".tr, - onTapScreenTitle: () => onTapScreenTitle( - AppRoutes.languageSelectScreen), + onTapScreenTitle: () => GoRouter.of(context).goNamed('languageSelectScreen'), ), _buildScreenTitle( context, screenTitle: "auth".tr, - onTapScreenTitle: () => - onTapScreenTitle(AppRoutes.authScreen), + onTapScreenTitle: () => GoRouter.of(context).goNamed('authScreen'), ), ], ), @@ -181,8 +168,7 @@ class _AppNavigationScreenState extends State { child: Padding( padding: EdgeInsets.only(left: 20.h), child: Text( - "Check your app's UI from the below demo screens of your app." - .tr, + "Check your app's UI from the below demo screens of your app.".tr, textAlign: TextAlign.center, style: TextStyle( color: Color(0XFF888888), @@ -247,9 +233,4 @@ class _AppNavigationScreenState extends State { ), ); } - - /// Common click event - void onTapScreenTitle(String routeName) { - NavigatorService.pushNamed(routeName); - } } diff --git a/lib/presentation/registration/blood_pressure_screen/blood_pressure_screen.dart b/lib/presentation/registration/blood_pressure_screen/blood_pressure_screen.dart index f0c26a1..681d5ce 100644 --- a/lib/presentation/registration/blood_pressure_screen/blood_pressure_screen.dart +++ b/lib/presentation/registration/blood_pressure_screen/blood_pressure_screen.dart @@ -1,3 +1,6 @@ +import 'package:eatvio_app/app_router.dart'; +import 'package:go_router/go_router.dart'; + import 'bloc/blood_pressure_bloc.dart'; import 'package:flutter/services.dart'; import 'models/blood_pressure_model.dart'; @@ -15,13 +18,10 @@ class BloodPressureScreen extends StatefulWidget { const BloodPressureScreen({Key? key}) : super(key: key); static Widget builder(BuildContext context) { - final sheet = - ModalRoute.of(context)!.settings.arguments as UserRegistrationSheet; + final sheet = ModalRoute.of(context)!.settings.arguments as UserRegistrationSheet; return BlocProvider( - create: (context) => BloodPressureBloc(BloodPressureState( - bloodPressureModelObj: - BloodPressureModel(userRegistrationSheet: sheet))) - ..add(BloodPressureInitialEvent()), + create: (context) => + BloodPressureBloc(BloodPressureState(bloodPressureModelObj: BloodPressureModel(userRegistrationSheet: sheet)))..add(BloodPressureInitialEvent()), child: BloodPressureScreen()); } @@ -46,9 +46,8 @@ class _BloodPressureScreenState extends State { Container( height: 16.v, width: 343.h, - padding: EdgeInsets.symmetric( - horizontal: - 4.h), // Apply padding directly to the Container + padding: EdgeInsets.symmetric(horizontal: 4.h), + // Apply padding directly to the Container decoration: BoxDecoration( color: theme.colorScheme.onPrimary, borderRadius: BorderRadius.circular(8.h), @@ -62,8 +61,7 @@ class _BloodPressureScreenState extends State { child: LinearProgressIndicator( value: 0.62, backgroundColor: theme.colorScheme.onPrimary, - valueColor: - AlwaysStoppedAnimation(appTheme.blueA400), + valueColor: AlwaysStoppedAnimation(appTheme.blueA400), ), ), ), @@ -71,26 +69,18 @@ class _BloodPressureScreenState extends State { SizedBox( width: 224.h, child: Text("your_blood_pressure".tr, - maxLines: 2, - overflow: TextOverflow.ellipsis, - textAlign: TextAlign.center, - style: theme.textTheme.headlineSmall)), + maxLines: 2, overflow: TextOverflow.ellipsis, textAlign: TextAlign.center, style: theme.textTheme.headlineSmall)), SizedBox(height: 21.v), Container( margin: EdgeInsets.only(right: 1.h), padding: EdgeInsets.symmetric(horizontal: 3.h), child: Column(children: [ - Text("up_pressure".tr, - style: theme.textTheme.bodyLarge), + Text("up_pressure".tr, style: theme.textTheme.bodyLarge), SizedBox(height: 2.v), - BlocSelector( + BlocSelector( selector: (state) => state.upPressureController, builder: (context, upPressureController) { - return CustomTextFormField( - inputFormatters: [digitsOnly], - controller: upPressureController, - hintText: "90".tr); + return CustomTextFormField(inputFormatters: [digitsOnly], controller: upPressureController, hintText: "90".tr); }) ])), SizedBox(height: 21.v), @@ -98,85 +88,57 @@ class _BloodPressureScreenState extends State { margin: EdgeInsets.only(right: 1.h), padding: EdgeInsets.symmetric(horizontal: 3.h), child: Column(children: [ - Text("down_pressure".tr, - style: theme.textTheme.bodyLarge), + Text("down_pressure".tr, style: theme.textTheme.bodyLarge), SizedBox(height: 2.v), - BlocSelector( + BlocSelector( selector: (state) => state.downPressureController, builder: (context, downPressureController) { - return CustomTextFormField( - inputFormatters: [digitsOnly], - controller: downPressureController, - hintText: "90".tr); + return CustomTextFormField(inputFormatters: [digitsOnly], controller: downPressureController, hintText: "90".tr); }) ])), SizedBox(height: 22.v), - Text("do_you_have_hypotension_tendency".tr, - style: theme.textTheme.bodyLarge), + Text("do_you_have_hypotension_tendency".tr, style: theme.textTheme.bodyLarge), SizedBox(height: 2.v), Padding( padding: EdgeInsets.symmetric(horizontal: 4.h), - child: BlocSelector( + child: BlocSelector( selector: (state) => state.bloodPressureModelObj, builder: (context, bloodPressureModelObj) { return CustomDropDown( icon: Container( - margin: EdgeInsets.fromLTRB( - 30.h, 11.v, 13.h, 11.v), - decoration: BoxDecoration( - borderRadius: - BorderRadius.circular(1.h)), - child: CustomImageView( - imagePath: ImageConstant.imgFavorite, - height: 12.adaptSize, - width: 12.adaptSize)), + margin: EdgeInsets.fromLTRB(30.h, 11.v, 13.h, 11.v), + decoration: BoxDecoration(borderRadius: BorderRadius.circular(1.h)), + child: CustomImageView(imagePath: ImageConstant.imgFavorite, height: 12.adaptSize, width: 12.adaptSize)), hintText: "Не выбрано".tr, - items: - bloodPressureModelObj?.dropdownItemList ?? - [], + items: bloodPressureModelObj?.dropdownItemList ?? [], onChanged: onChangeHyper(context)); })), SizedBox(height: 22.v), - Text("do_you_have_hypertension_tendency".tr, - style: theme.textTheme.bodyLarge), + Text("do_you_have_hypertension_tendency".tr, style: theme.textTheme.bodyLarge), SizedBox(height: 2.v), Padding( padding: EdgeInsets.symmetric(horizontal: 4.h), - child: BlocSelector( + child: BlocSelector( selector: (state) => state.bloodPressureModelObj, builder: (context, bloodPressureModelObj) { return CustomDropDown( icon: Container( - margin: EdgeInsets.fromLTRB( - 30.h, 11.v, 13.h, 11.v), - decoration: BoxDecoration( - borderRadius: - BorderRadius.circular(1.h)), - child: CustomImageView( - imagePath: ImageConstant.imgFavorite, - height: 12.adaptSize, - width: 12.adaptSize)), + margin: EdgeInsets.fromLTRB(30.h, 11.v, 13.h, 11.v), + decoration: BoxDecoration(borderRadius: BorderRadius.circular(1.h)), + child: CustomImageView(imagePath: ImageConstant.imgFavorite, height: 12.adaptSize, width: 12.adaptSize)), hintText: "Не выбрано".tr, - items: - bloodPressureModelObj?.dropdownItemList ?? - [], + items: bloodPressureModelObj?.dropdownItemList ?? [], onChanged: onChangeHypo(context)); })), Spacer(), - BlocBuilder( - builder: (context, state) { + BlocBuilder(builder: (context, state) { return NextStepButton( text: "continue".tr.toUpperCase(), - margin: EdgeInsets.only( - left: 16.h, right: 16.h, bottom: 50.v), + margin: EdgeInsets.only(left: 16.h, right: 16.h, bottom: 50.v), buttonStyle: CustomButtonStyles.outlinePrimaryTL15, onPressed: onTapContinue(state, context)); }), - BlocBuilder( - builder: (context, state) { + BlocBuilder(builder: (context, state) { return GestureDetector( onTap: onTapSkip(state, context), child: Text("skip".tr, style: theme.textTheme.bodyLarge), @@ -187,30 +149,19 @@ class _BloodPressureScreenState extends State { onTapSkip(BloodPressureState state, BuildContext context) { return () { - UserRegistrationSheet sheet = - state.bloodPressureModelObj!.userRegistrationSheet; - Navigator.pushNamed( - context, - AppRoutes.allergiesScreen, - arguments: sheet, - ); + UserRegistrationSheet sheet = state.bloodPressureModelObj!.userRegistrationSheet; + AppRouter.navigatorKey.currentContext?.goNamed('allergiesScreen', extra: sheet); }; } onTapContinue(BloodPressureState state, BuildContext context) { return () { - List errors = validateFields( - state.upPressureController!.text, state.downPressureController!.text); + List errors = validateFields(state.upPressureController!.text, state.downPressureController!.text); if (errors.isEmpty) { - UserRegistrationSheet sheet = - state.bloodPressureModelObj!.userRegistrationSheet; + UserRegistrationSheet sheet = state.bloodPressureModelObj!.userRegistrationSheet; sheet.bloodPressureUp = state.upPressureController!.text; sheet.bloodPressureDown = state.downPressureController!.text; - Navigator.pushNamed( - context, - AppRoutes.favoriteSportsScreen, - arguments: sheet, - ); + AppRouter.navigatorKey.currentContext?.goNamed('favoriteSportsScreen', extra: sheet); } else { String errorMessage = ''; @@ -243,9 +194,7 @@ class _BloodPressureScreenState extends State { onChangeHypo(BuildContext context) { return (value) { - context - .read() - .add(ChangeHyperDropDownEvent(value: value)); + context.read().add(ChangeHyperDropDownEvent(value: value)); }; } @@ -259,10 +208,8 @@ class _BloodPressureScreenState extends State { _buildAppBar(BuildContext context) { return CustomAppBar( leadingWidth: 29.h, - leading: AppbarLeadingImage( - imagePath: ImageConstant.imgArrowLeft, - margin: EdgeInsets.only(left: 16.h, top: 15.v, bottom: 15.v), - onTap: onTapBack(context)), + leading: + AppbarLeadingImage(imagePath: ImageConstant.imgArrowLeft, margin: EdgeInsets.only(left: 16.h, top: 15.v, bottom: 15.v), onTap: onTapBack(context)), centerTitle: true, title: AppbarTitleImage(imagePath: ImageConstant.imgLogoEatvio)); } @@ -288,8 +235,7 @@ class _BloodPressureScreenState extends State { errors.add('pressure_empty'.tr); } - if (![bloodPressureUp, bloodPressureDown] - .every((pressure) => int.tryParse(pressure) != null)) { + if (![bloodPressureUp, bloodPressureDown].every((pressure) => int.tryParse(pressure) != null)) { errors.add('pressure_is_not_a_number'.tr); } diff --git a/lib/presentation/registration/body_circumferences_screen/body_circumferences_screen.dart b/lib/presentation/registration/body_circumferences_screen/body_circumferences_screen.dart index 17ce3df..2df67fc 100644 --- a/lib/presentation/registration/body_circumferences_screen/body_circumferences_screen.dart +++ b/lib/presentation/registration/body_circumferences_screen/body_circumferences_screen.dart @@ -1,3 +1,5 @@ +import 'package:go_router/go_router.dart'; + import 'bloc/body_circumferences_bloc.dart'; import 'package:flutter/services.dart'; import 'models/body_circumferences_model.dart'; @@ -14,12 +16,9 @@ class BodyCircumferencesScreen extends StatelessWidget { const BodyCircumferencesScreen({Key? key}) : super(key: key); static Widget builder(BuildContext context) { - final sheet = - ModalRoute.of(context)!.settings.arguments as UserRegistrationSheet; + final sheet = ModalRoute.of(context)!.settings.arguments as UserRegistrationSheet; return BlocProvider( - create: (context) => BodyCircumferencesBloc(BodyCircumferencesState( - bodyCircumferencesModelObj: - BodyCircumferencesModel(userRegistrationSheet: sheet))) + create: (context) => BodyCircumferencesBloc(BodyCircumferencesState(bodyCircumferencesModelObj: BodyCircumferencesModel(userRegistrationSheet: sheet))) ..add(BodyCircumferencesInitialEvent()), child: BodyCircumferencesScreen()); } @@ -43,67 +42,45 @@ class BodyCircumferencesScreen extends StatelessWidget { decoration: BoxDecoration( color: theme.colorScheme.onPrimary, borderRadius: BorderRadius.circular(8.h), - border: Border.all( - color: theme.colorScheme.primary, width: 1.h)), + border: Border.all(color: theme.colorScheme.primary, width: 1.h)), child: ClipRRect( borderRadius: BorderRadius.circular(8.h), child: LinearProgressIndicator( - value: 0.40, - backgroundColor: theme.colorScheme.onPrimary, - valueColor: AlwaysStoppedAnimation( - appTheme.blueA400)))), + value: 0.40, backgroundColor: theme.colorScheme.onPrimary, valueColor: AlwaysStoppedAnimation(appTheme.blueA400)))), SizedBox(height: 39.v), - Text("initial_measurements".tr, - style: theme.textTheme.headlineSmall), + Text("initial_measurements".tr, style: theme.textTheme.headlineSmall), SizedBox(height: 93.v), Column(children: [ - Text("chest_circumference".tr, - style: theme.textTheme.bodyLarge), + Text("chest_circumference".tr, style: theme.textTheme.bodyLarge), SizedBox(height: 3.v), - BlocSelector( + BlocSelector( selector: (state) => state.chestCircumferenceController, builder: (context, chestCircumferenceController) { - return CustomTextFormField( - inputFormatters: [digitsOnly], - controller: chestCircumferenceController, - hintText: "90".tr); + return CustomTextFormField(inputFormatters: [digitsOnly], controller: chestCircumferenceController, hintText: "90".tr); }) ]), SizedBox(height: 19.v), - Text("waist_circumference".tr, - style: theme.textTheme.bodyLarge), + Text("waist_circumference".tr, style: theme.textTheme.bodyLarge), SizedBox(height: 5.v), - BlocSelector( + BlocSelector( selector: (state) => state.waistCircumferenceController, builder: (context, waistCircumferenceController) { - return CustomTextFormField( - inputFormatters: [digitsOnly], - controller: waistCircumferenceController, - hintText: "60".tr); + return CustomTextFormField(inputFormatters: [digitsOnly], controller: waistCircumferenceController, hintText: "60".tr); }), SizedBox(height: 21.v), - Text("hip_circumference".tr, - style: theme.textTheme.bodyLarge), + Text("hip_circumference".tr, style: theme.textTheme.bodyLarge), SizedBox(height: 3.v), - BlocSelector( + BlocSelector( selector: (state) => state.hipCircumferenceController, builder: (context, hipCircumferenceController) { return CustomTextFormField( - inputFormatters: [digitsOnly], - controller: hipCircumferenceController, - hintText: "90".tr, - textInputAction: TextInputAction.done); + inputFormatters: [digitsOnly], controller: hipCircumferenceController, hintText: "90".tr, textInputAction: TextInputAction.done); }), Spacer(), - BlocBuilder( - builder: (context, state) { + BlocBuilder(builder: (context, state) { return NextStepButton( text: "continue".tr.toUpperCase(), - margin: EdgeInsets.only( - left: 16.h, right: 16.h, bottom: 50.v), + margin: EdgeInsets.only(left: 16.h, right: 16.h, bottom: 50.v), buttonStyle: CustomButtonStyles.outlinePrimaryTL15, onPressed: onTapContinue(state, context)); }), @@ -112,21 +89,14 @@ class BodyCircumferencesScreen extends StatelessWidget { onTapContinue(BodyCircumferencesState state, BuildContext context) { return () { - List errors = validateFields( - state.chestCircumferenceController!.text, - state.waistCircumferenceController!.text, - state.hipCircumferenceController!.text); + List errors = + validateFields(state.chestCircumferenceController!.text, state.waistCircumferenceController!.text, state.hipCircumferenceController!.text); if (errors.isEmpty) { - UserRegistrationSheet sheet = - state.bodyCircumferencesModelObj!.userRegistrationSheet; + UserRegistrationSheet sheet = state.bodyCircumferencesModelObj!.userRegistrationSheet; sheet.chestCircumference = state.chestCircumferenceController!.text; sheet.waistCircumference = state.waistCircumferenceController!.text; sheet.hipCircumference = state.hipCircumferenceController!.text; - Navigator.pushNamed( - context, - AppRoutes.weightScreen, - arguments: sheet, - ); + GoRouter.of(context).goNamed('weightScreen', extra: sheet); } else { String errorMessage = ''; @@ -161,10 +131,8 @@ class BodyCircumferencesScreen extends StatelessWidget { _buildAppBar(BuildContext context) { return CustomAppBar( leadingWidth: 29.h, - leading: AppbarLeadingImage( - imagePath: ImageConstant.imgArrowLeft, - margin: EdgeInsets.only(left: 16.h, top: 15.v, bottom: 15.v), - onTap: onTapBack(context)), + leading: + AppbarLeadingImage(imagePath: ImageConstant.imgArrowLeft, margin: EdgeInsets.only(left: 16.h, top: 15.v, bottom: 15.v), onTap: onTapBack(context)), centerTitle: true, title: AppbarTitleImage(imagePath: ImageConstant.imgLogoEatvio)); } @@ -181,11 +149,7 @@ class BodyCircumferencesScreen extends StatelessWidget { } /// Navigates to the weightScreen when the action is triggered. - navigateToWeight(BuildContext context) { - NavigatorService.pushNamed( - AppRoutes.weightScreen, - ); - } + navigateToWeight(BuildContext context) => GoRouter.of(context).goNamed('weightScreen'); List validateFields( String chestCircumference, @@ -194,14 +158,11 @@ class BodyCircumferencesScreen extends StatelessWidget { ) { List errors = []; - if (chestCircumference.isEmpty | - waistCircumference.isEmpty | - hipCircumference.isEmpty) { + if (chestCircumference.isEmpty | waistCircumference.isEmpty | hipCircumference.isEmpty) { errors.add('circumference_empty'.tr); } - if (![chestCircumference, waistCircumference, hipCircumference] - .every((circumference) => int.tryParse(circumference) != null)) { + if (![chestCircumference, waistCircumference, hipCircumference].every((circumference) => int.tryParse(circumference) != null)) { errors.add('circumference_is_not_a_number'.tr); } diff --git a/lib/presentation/registration/city_of_living_screen/city_of_living_screen.dart b/lib/presentation/registration/city_of_living_screen/city_of_living_screen.dart index 20ab28e..3e78a1f 100644 --- a/lib/presentation/registration/city_of_living_screen/city_of_living_screen.dart +++ b/lib/presentation/registration/city_of_living_screen/city_of_living_screen.dart @@ -1,3 +1,5 @@ +import 'package:go_router/go_router.dart'; + import 'bloc/city_of_living_bloc.dart'; import 'models/city_of_living_model.dart'; import 'package:eatvio_app/core/app_export.dart'; @@ -14,13 +16,10 @@ class CityOfLivingScreen extends StatelessWidget { const CityOfLivingScreen({Key? key}) : super(key: key); static Widget builder(BuildContext context) { - final sheet = - ModalRoute.of(context)!.settings.arguments as UserRegistrationSheet; + final sheet = ModalRoute.of(context)!.settings.arguments as UserRegistrationSheet; return BlocProvider( - create: (context) => CityOfLivingBloc(CityOfLivingState( - cityOfLivingModelObj: - CityOfLivingModel(userRegistrationSheet: sheet))) - ..add(CityOfLivingInitialEvent()), + create: (context) => + CityOfLivingBloc(CityOfLivingState(cityOfLivingModelObj: CityOfLivingModel(userRegistrationSheet: sheet)))..add(CityOfLivingInitialEvent()), child: CityOfLivingScreen()); } @@ -1160,35 +1159,24 @@ class CityOfLivingScreen extends StatelessWidget { decoration: BoxDecoration( color: theme.colorScheme.onPrimary, borderRadius: BorderRadius.circular(8.h), - border: Border.all( - color: theme.colorScheme.primary, width: 1.h)), + border: Border.all(color: theme.colorScheme.primary, width: 1.h)), child: ClipRRect( borderRadius: BorderRadius.circular(8.h), child: LinearProgressIndicator( - value: 0.32, - backgroundColor: theme.colorScheme.onPrimary, - valueColor: AlwaysStoppedAnimation( - appTheme.blueA400)))), + value: 0.32, backgroundColor: theme.colorScheme.onPrimary, valueColor: AlwaysStoppedAnimation(appTheme.blueA400)))), SizedBox(height: 39.v), - Text("place_of_living".tr, - style: theme.textTheme.headlineSmall), + Text("place_of_living".tr, style: theme.textTheme.headlineSmall), Spacer(flex: 34), Text("country".tr, style: theme.textTheme.bodyLarge), SizedBox(height: 2.v), - BlocSelector( + BlocSelector( selector: (state) => state.cityOfLivingModelObj, builder: (context, cityOfLivingModelObj) { return CustomDropDown( icon: Container( - margin: - EdgeInsets.fromLTRB(30.h, 11.v, 17.h, 11.v), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(1.h)), - child: CustomImageView( - imagePath: ImageConstant.imgFavorite, - height: 12.adaptSize, - width: 12.adaptSize)), + margin: EdgeInsets.fromLTRB(30.h, 11.v, 17.h, 11.v), + decoration: BoxDecoration(borderRadius: BorderRadius.circular(1.h)), + child: CustomImageView(imagePath: ImageConstant.imgFavorite, height: 12.adaptSize, width: 12.adaptSize)), hintText: "Не выбрано".tr, items: cityOfLivingModelObj?.dropdownItemList ?? [], onChanged: onDropDownChange(context)); @@ -1196,14 +1184,10 @@ class CityOfLivingScreen extends StatelessWidget { SizedBox(height: 22.v), Text("Населенный пункт", style: theme.textTheme.bodyLarge), SizedBox(height: 2.v), - BlocBuilder( - builder: (context, state) { + BlocBuilder(builder: (context, state) { return RawAutocomplete( - optionsBuilder: (TextEditingValue textEditingValue) => - _options.where((String option) { - return option - .toLowerCase() - .startsWith(textEditingValue.text.toLowerCase()); + optionsBuilder: (TextEditingValue textEditingValue) => _options.where((String option) { + return option.toLowerCase().startsWith(textEditingValue.text.toLowerCase()); }), fieldViewBuilder: ( BuildContext context, @@ -1214,8 +1198,7 @@ class CityOfLivingScreen extends StatelessWidget { return CustomTextFormField( controller: textEditingController, focusNode: focusNode, - onFieldSubmitted: (String value) => - onFieldSubmitted(), + onFieldSubmitted: (String value) => onFieldSubmitted(), ); }, optionsViewBuilder: ( @@ -1233,8 +1216,7 @@ class CityOfLivingScreen extends StatelessWidget { padding: const EdgeInsets.all(8.0), itemCount: options.length, itemBuilder: (BuildContext context, int index) { - final String option = - options.elementAt(index); + final String option = options.elementAt(index); return GestureDetector( onTap: () => onSelected(option), child: ListTile( @@ -1250,12 +1232,10 @@ class CityOfLivingScreen extends StatelessWidget { ); }), Spacer(flex: 65), - BlocBuilder( - builder: (context, state) { + BlocBuilder(builder: (context, state) { return NextStepButton( text: "continue".tr.toUpperCase(), - margin: EdgeInsets.only( - left: 16.h, right: 16.h, bottom: 50.v), + margin: EdgeInsets.only(left: 16.h, right: 16.h, bottom: 50.v), buttonStyle: CustomButtonStyles.outlinePrimaryTL15, onPressed: onTapContinue(state, context)); }), @@ -1264,13 +1244,8 @@ class CityOfLivingScreen extends StatelessWidget { onTapContinue(CityOfLivingState state, BuildContext context) { return () { - UserRegistrationSheet sheet = - state.cityOfLivingModelObj!.userRegistrationSheet; - Navigator.pushNamed( - context, - AppRoutes.bodyCircumferencesScreen, - arguments: sheet, - ); + UserRegistrationSheet sheet = state.cityOfLivingModelObj!.userRegistrationSheet; + GoRouter.of(context).goNamed('bodyCircumferencesScreen', extra: sheet); }; } @@ -1284,10 +1259,8 @@ class CityOfLivingScreen extends StatelessWidget { _buildAppBar(BuildContext context) { return CustomAppBar( leadingWidth: 29.h, - leading: AppbarLeadingImage( - imagePath: ImageConstant.imgArrowLeft, - margin: EdgeInsets.only(left: 16.h, top: 15.v, bottom: 15.v), - onTap: onTapBack(context)), + leading: + AppbarLeadingImage(imagePath: ImageConstant.imgArrowLeft, margin: EdgeInsets.only(left: 16.h, top: 15.v, bottom: 15.v), onTap: onTapBack(context)), centerTitle: true, title: AppbarTitleImage(imagePath: ImageConstant.imgLogoEatvio)); } @@ -1304,8 +1277,7 @@ class CityOfLivingScreen extends StatelessWidget { } } -selectProduct(AutocompleteOnSelected onSelected, String option, - CityOfLivingState state) { +selectProduct(AutocompleteOnSelected onSelected, String option, CityOfLivingState state) { state.cityController?.text = option; return () { onSelected(option); diff --git a/lib/presentation/registration/credentials_screen/credentials_screen.dart b/lib/presentation/registration/credentials_screen/credentials_screen.dart index 4897999..ba51783 100644 --- a/lib/presentation/registration/credentials_screen/credentials_screen.dart +++ b/lib/presentation/registration/credentials_screen/credentials_screen.dart @@ -1,3 +1,5 @@ +import 'package:go_router/go_router.dart'; + import 'bloc/credentials_bloc.dart'; import 'models/credentials_model.dart'; import 'package:eatvio_app/core/app_export.dart'; @@ -126,11 +128,7 @@ class CredentialsScreen extends StatelessWidget { sheet.name = state.nameController!.text; sheet.password = state.passwordController!.text; sheet.passwordConfirmation = state.passwordConfirmationController!.text; - Navigator.pushNamed( - context, - AppRoutes.nameScreen, - arguments: sheet, - ); + GoRouter.of(context).goNamed('nameScreen'); } else { String errorMessage = ''; diff --git a/lib/presentation/registration/date_of_birth_screen/date_of_birth_screen.dart b/lib/presentation/registration/date_of_birth_screen/date_of_birth_screen.dart index df85987..7f86075 100644 --- a/lib/presentation/registration/date_of_birth_screen/date_of_birth_screen.dart +++ b/lib/presentation/registration/date_of_birth_screen/date_of_birth_screen.dart @@ -1,3 +1,5 @@ +import 'package:go_router/go_router.dart'; + import 'bloc/date_of_birth_bloc.dart'; import 'models/date_of_birth_model.dart'; import 'package:eatvio_app/core/app_export.dart'; @@ -12,13 +14,10 @@ class DateOfBirthScreen extends StatefulWidget { const DateOfBirthScreen({Key? key}) : super(key: key); static Widget builder(BuildContext context) { - final sheet = - ModalRoute.of(context)!.settings.arguments as UserRegistrationSheet; + final sheet = ModalRoute.of(context)!.settings.arguments as UserRegistrationSheet; return BlocProvider( - create: (context) => DateOfBirthBloc(DateOfBirthState( - dateOfBirthModelObj: - DateOfBirthModel(userRegistrationSheet: sheet))) - ..add(DateOfBirthInitialEvent()), + create: (context) => + DateOfBirthBloc(DateOfBirthState(dateOfBirthModelObj: DateOfBirthModel(userRegistrationSheet: sheet)))..add(DateOfBirthInitialEvent()), child: DateOfBirthScreen()); } @@ -28,18 +27,17 @@ class DateOfBirthScreen extends StatefulWidget { class _DateOfBirthScreenState extends State { DateTime selectedDate = DateTime.now(); + @override Widget build(BuildContext context) { mediaQueryData = MediaQuery.of(context); - return BlocBuilder( - builder: (context, state) { + return BlocBuilder(builder: (context, state) { return SafeArea( child: Scaffold( appBar: _buildAppBar(context), body: Container( width: double.maxFinite, - padding: - EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v), + padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v), child: Column(children: [ Container( height: 16.v, @@ -47,27 +45,20 @@ class _DateOfBirthScreenState extends State { decoration: BoxDecoration( color: theme.colorScheme.onPrimary, borderRadius: BorderRadius.circular(8.h), - border: Border.all( - color: theme.colorScheme.primary, width: 1.h)), + border: Border.all(color: theme.colorScheme.primary, width: 1.h)), child: ClipRRect( borderRadius: BorderRadius.circular(8.h), child: LinearProgressIndicator( - value: 0.24, - backgroundColor: theme.colorScheme.onPrimary, - valueColor: AlwaysStoppedAnimation( - appTheme.blueA400)))), + value: 0.24, backgroundColor: theme.colorScheme.onPrimary, valueColor: AlwaysStoppedAnimation(appTheme.blueA400)))), SizedBox(height: 38.v), - Text("date_of_birth".tr, - style: theme.textTheme.headlineSmall), + Text("date_of_birth".tr, style: theme.textTheme.headlineSmall), Spacer(flex: 39), _buildDateInput(context), Spacer(flex: 60), - BlocBuilder( - builder: (context, state) { + BlocBuilder(builder: (context, state) { return NextStepButton( text: "continue".tr.toUpperCase(), - margin: EdgeInsets.only( - left: 16.h, right: 16.h, bottom: 50.v), + margin: EdgeInsets.only(left: 16.h, right: 16.h, bottom: 50.v), buttonStyle: CustomButtonStyles.outlinePrimaryTL15, onPressed: onTapContinue(state, context)); }), @@ -77,14 +68,9 @@ class _DateOfBirthScreenState extends State { onTapContinue(DateOfBirthState state, BuildContext context) { return () { - UserRegistrationSheet sheet = - state.dateOfBirthModelObj!.userRegistrationSheet; + UserRegistrationSheet sheet = state.dateOfBirthModelObj!.userRegistrationSheet; sheet.birthdate = selectedDate.toString(); - Navigator.pushNamed( - context, - AppRoutes.cityOfLivingScreen, - arguments: sheet, - ); + GoRouter.of(context).goNamed('cityOfLivingScreen', extra: sheet); }; } @@ -92,10 +78,8 @@ class _DateOfBirthScreenState extends State { _buildAppBar(BuildContext context) { return CustomAppBar( leadingWidth: 29.h, - leading: AppbarLeadingImage( - imagePath: ImageConstant.imgArrowLeft, - margin: EdgeInsets.only(left: 16.h, top: 15.v, bottom: 15.v), - onTap: onTapBack(context)), + leading: + AppbarLeadingImage(imagePath: ImageConstant.imgArrowLeft, margin: EdgeInsets.only(left: 16.h, top: 15.v, bottom: 15.v), onTap: onTapBack(context)), centerTitle: true, title: AppbarTitleImage(imagePath: ImageConstant.imgLogoEatvio)); } @@ -111,28 +95,17 @@ class _DateOfBirthScreenState extends State { return Container( width: 343.h, padding: EdgeInsets.symmetric(horizontal: 4.h, vertical: 1.v), - decoration: AppDecoration.outlineBlueA - .copyWith(borderRadius: BorderRadiusStyle.circleBorder8), - child: Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - CustomImageView( - imagePath: ImageConstant.imgFavorite, - height: 12.adaptSize, - width: 12.adaptSize, - radius: BorderRadius.circular(1.h)), - SizedBox(height: 6.v), - Align( - alignment: Alignment.center, - child: GestureDetector( - onTap: onTapCalendar(context), - child: Text( - '${selectedDate.day}.${selectedDate.month}.${selectedDate.year}', - style: theme.textTheme.titleMedium))), - SizedBox(height: 6.v) - ])); + decoration: AppDecoration.outlineBlueA.copyWith(borderRadius: BorderRadiusStyle.circleBorder8), + child: Column(mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.center, children: [ + CustomImageView(imagePath: ImageConstant.imgFavorite, height: 12.adaptSize, width: 12.adaptSize, radius: BorderRadius.circular(1.h)), + SizedBox(height: 6.v), + Align( + alignment: Alignment.center, + child: GestureDetector( + onTap: onTapCalendar(context), + child: Text('${selectedDate.day}.${selectedDate.month}.${selectedDate.year}', style: theme.textTheme.titleMedium))), + SizedBox(height: 6.v) + ])); } onTapCalendar(BuildContext context) { diff --git a/lib/presentation/registration/favorite_foods_screen/favorite_foods_screen.dart b/lib/presentation/registration/favorite_foods_screen/favorite_foods_screen.dart index dac3ebd..a0c35dd 100644 --- a/lib/presentation/registration/favorite_foods_screen/favorite_foods_screen.dart +++ b/lib/presentation/registration/favorite_foods_screen/favorite_foods_screen.dart @@ -1,3 +1,5 @@ +import 'package:go_router/go_router.dart'; + import 'bloc/favorite_foods_bloc.dart'; import 'models/favorite_foods_model.dart'; import 'package:eatvio_app/core/app_export.dart'; @@ -13,13 +15,10 @@ class FavoriteFoodsScreen extends StatefulWidget { const FavoriteFoodsScreen({Key? key}) : super(key: key); static Widget builder(BuildContext context) { - final sheet = - ModalRoute.of(context)!.settings.arguments as UserRegistrationSheet; + final sheet = ModalRoute.of(context)!.settings.arguments as UserRegistrationSheet; return BlocProvider( - create: (context) => FavoriteFoodsBloc(FavoriteFoodsState( - favoriteFoodsModelObj: - FavoriteFoodsModel(userRegistrationSheet: sheet))) - ..add(FavoriteFoodsInitialEvent()), + create: (context) => + FavoriteFoodsBloc(FavoriteFoodsState(favoriteFoodsModelObj: FavoriteFoodsModel(userRegistrationSheet: sheet)))..add(FavoriteFoodsInitialEvent()), child: FavoriteFoodsScreen()); } @@ -46,40 +45,30 @@ class _FavoriteFoodsScreenState extends State { decoration: BoxDecoration( color: theme.colorScheme.onPrimary, borderRadius: BorderRadius.circular(8.h), - border: Border.all( - color: theme.colorScheme.primary, width: 1.h)), + border: Border.all(color: theme.colorScheme.primary, width: 1.h)), child: ClipRRect( borderRadius: BorderRadius.circular(8.h), child: LinearProgressIndicator( - value: 0.90, - backgroundColor: theme.colorScheme.onPrimary, - valueColor: AlwaysStoppedAnimation( - appTheme.blueA400)))), + value: 0.90, backgroundColor: theme.colorScheme.onPrimary, valueColor: AlwaysStoppedAnimation(appTheme.blueA400)))), SizedBox(height: 19.v), Container( width: 327.h, margin: EdgeInsets.only(left: 8.h, right: 7.h), child: Text("favorite_unfavorite_foods".tr, - maxLines: 2, - overflow: TextOverflow.ellipsis, - textAlign: TextAlign.center, - style: theme.textTheme.headlineSmall)), + maxLines: 2, overflow: TextOverflow.ellipsis, textAlign: TextAlign.center, style: theme.textTheme.headlineSmall)), SizedBox(height: 13.v), _buildTextFormFieldFav(context), SizedBox(height: 12.v), _buildTextFormFieldUnfav(context), Spacer(), - BlocBuilder( - builder: (context, state) { + BlocBuilder(builder: (context, state) { return NextStepButton( text: "continue".tr.toUpperCase(), - margin: EdgeInsets.only( - left: 16.h, right: 16.h, bottom: 40.v), + margin: EdgeInsets.only(left: 16.h, right: 16.h, bottom: 40.v), buttonStyle: CustomButtonStyles.outlinePrimaryTL15, onPressed: onTapContinue(state, context)); }), - BlocBuilder( - builder: (context, state) { + BlocBuilder(builder: (context, state) { return GestureDetector( onTap: onTapSkip(state, context), child: Text("skip".tr, style: theme.textTheme.bodyLarge), @@ -90,27 +79,17 @@ class _FavoriteFoodsScreenState extends State { onTapSkip(FavoriteFoodsState state, BuildContext context) { return () { - UserRegistrationSheet sheet = - state.favoriteFoodsModelObj!.userRegistrationSheet; - Navigator.pushNamed( - context, - AppRoutes.additionalInformationScreen, - arguments: sheet, - ); + UserRegistrationSheet sheet = state.favoriteFoodsModelObj!.userRegistrationSheet; + GoRouter.of(context).goNamed('additionalInformationScreen', extra: sheet); }; } onTapContinue(FavoriteFoodsState state, BuildContext context) { return () { - UserRegistrationSheet sheet = - state.favoriteFoodsModelObj!.userRegistrationSheet; + UserRegistrationSheet sheet = state.favoriteFoodsModelObj!.userRegistrationSheet; sheet.favoriteFoods = state.favoriteFoodsController!.text; sheet.unfavoriteFoods = state.unfavoriteFoodsController!.text; - Navigator.pushNamed( - context, - AppRoutes.additionalInformationScreen, - arguments: sheet, - ); + GoRouter.of(context).goNamed('additionalInformationScreen', extra: sheet); }; } @@ -118,10 +97,8 @@ class _FavoriteFoodsScreenState extends State { _buildAppBar(BuildContext context) { return CustomAppBar( leadingWidth: 31.h, - leading: AppbarLeadingImage( - imagePath: ImageConstant.imgArrowLeft, - margin: EdgeInsets.only(left: 18.h, top: 15.v, bottom: 15.v), - onTap: onTapBack(context)), + leading: + AppbarLeadingImage(imagePath: ImageConstant.imgArrowLeft, margin: EdgeInsets.only(left: 18.h, top: 15.v, bottom: 15.v), onTap: onTapBack(context)), centerTitle: true, title: AppbarTitleImage(imagePath: ImageConstant.imgLogoEatvio)); } @@ -137,14 +114,10 @@ class _FavoriteFoodsScreenState extends State { return Column(children: [ Text("favorite_foods".tr, style: CustomTextStyles.titleMediumSegoeUI), SizedBox(height: 2.v), - BlocSelector( + BlocSelector( selector: (state) => state.favoriteFoodsController, builder: (context, favoriteFoodsController) { - return CustomTextFormField( - controller: favoriteFoodsController, - hintText: "enter_information".tr, - maxLines: 7); + return CustomTextFormField(controller: favoriteFoodsController, hintText: "enter_information".tr, maxLines: 7); }) ]); } @@ -154,15 +127,11 @@ class _FavoriteFoodsScreenState extends State { return Column(children: [ Text("unfavorite_foods".tr, style: CustomTextStyles.titleMediumSegoeUI), SizedBox(height: 2.v), - BlocSelector( + BlocSelector( selector: (state) => state.unfavoriteFoodsController, builder: (context, unfavoriteFoodsController) { return CustomTextFormField( - controller: unfavoriteFoodsController, - hintText: "enter_information".tr, - textInputAction: TextInputAction.done, - maxLines: 7); + controller: unfavoriteFoodsController, hintText: "enter_information".tr, textInputAction: TextInputAction.done, maxLines: 7); }) ]); } @@ -174,8 +143,6 @@ class _FavoriteFoodsScreenState extends State { /// Navigates to the scheduleScreen when the action is triggered. navigateToAdditionalInformationScreen(BuildContext context) { - NavigatorService.pushNamed( - AppRoutes.additionalInformationScreen, - ); + GoRouter.of(context).goNamed('additionalInformationScreen'); } } diff --git a/lib/presentation/registration/favorite_sports_screen/favorite_sports_screen.dart b/lib/presentation/registration/favorite_sports_screen/favorite_sports_screen.dart index e4c6f1c..a9217ec 100644 --- a/lib/presentation/registration/favorite_sports_screen/favorite_sports_screen.dart +++ b/lib/presentation/registration/favorite_sports_screen/favorite_sports_screen.dart @@ -1,3 +1,5 @@ +import 'package:go_router/go_router.dart'; + import 'bloc/favorite_sports_bloc.dart'; import 'models/favorite_sports_model.dart'; import 'package:eatvio_app/core/app_export.dart'; @@ -13,12 +15,9 @@ class FavoriteSportsScreen extends StatefulWidget { const FavoriteSportsScreen({Key? key}) : super(key: key); static Widget builder(BuildContext context) { - final sheet = - ModalRoute.of(context)!.settings.arguments as UserRegistrationSheet; + final sheet = ModalRoute.of(context)!.settings.arguments as UserRegistrationSheet; return BlocProvider( - create: (context) => FavoriteSportsBloc(FavoriteSportsState( - favoriteSportsModelObj: - FavoriteSportsModel(userRegistrationSheet: sheet))) + create: (context) => FavoriteSportsBloc(FavoriteSportsState(favoriteSportsModelObj: FavoriteSportsModel(userRegistrationSheet: sheet))) ..add(FavoriteSportsInitialEvent()), child: FavoriteSportsScreen()); } @@ -38,84 +37,60 @@ class _FavoriteSportsScreenState extends State { body: Container( width: double.maxFinite, padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 5.v), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - SizedBox(height: 20.v), - Container( - height: 16.v, - width: 343.h, - decoration: BoxDecoration( - color: theme.colorScheme.onPrimary, - borderRadius: BorderRadius.circular(8.h), - border: Border.all( - color: theme.colorScheme.primary, - width: 1.h)), - child: ClipRRect( - borderRadius: BorderRadius.circular(8.h), - child: LinearProgressIndicator( - value: 0.83, - backgroundColor: theme.colorScheme.onPrimary, - valueColor: AlwaysStoppedAnimation( - appTheme.blueA400)))), - SizedBox(height: 38.v), - Text("your_favorite_sports".tr, - style: theme.textTheme.headlineSmall), - Spacer(flex: 32), - _buildTextFormFieldSection(context), - Spacer(flex: 67), - BlocBuilder( - builder: (context, state) { - return NextStepButton( - text: "continue".tr.toUpperCase(), - margin: EdgeInsets.only( - left: 16.h, right: 16.h, bottom: 50.v), - buttonStyle: CustomButtonStyles.outlinePrimaryTL15, - onPressed: onTapContinue(state, context)); - }), - BlocBuilder( - builder: (context, state) { - return GestureDetector( - onTap: onTapSkip(state, context), - child: - Text("skip".tr, style: theme.textTheme.bodyLarge), - ); - }), - ])))); + child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [ + SizedBox(height: 20.v), + Container( + height: 16.v, + width: 343.h, + decoration: BoxDecoration( + color: theme.colorScheme.onPrimary, + borderRadius: BorderRadius.circular(8.h), + border: Border.all(color: theme.colorScheme.primary, width: 1.h)), + child: ClipRRect( + borderRadius: BorderRadius.circular(8.h), + child: LinearProgressIndicator( + value: 0.83, backgroundColor: theme.colorScheme.onPrimary, valueColor: AlwaysStoppedAnimation(appTheme.blueA400)))), + SizedBox(height: 38.v), + Text("your_favorite_sports".tr, style: theme.textTheme.headlineSmall), + Spacer(flex: 32), + _buildTextFormFieldSection(context), + Spacer(flex: 67), + BlocBuilder(builder: (context, state) { + return NextStepButton( + text: "continue".tr.toUpperCase(), + margin: EdgeInsets.only(left: 16.h, right: 16.h, bottom: 50.v), + buttonStyle: CustomButtonStyles.outlinePrimaryTL15, + onPressed: onTapContinue(state, context)); + }), + BlocBuilder(builder: (context, state) { + return GestureDetector( + onTap: onTapSkip(state, context), + child: Text("skip".tr, style: theme.textTheme.bodyLarge), + ); + }), + ])))); } onTapSkip(FavoriteSportsState state, BuildContext context) { return () { - UserRegistrationSheet sheet = - state.favoriteSportsModelObj!.userRegistrationSheet; - Navigator.pushNamed( - context, - AppRoutes.favoriteFoodsScreen, - arguments: sheet, - ); + UserRegistrationSheet sheet = state.favoriteSportsModelObj!.userRegistrationSheet; + GoRouter.of(context).goNamed('favoriteFoodsScreen', extra: sheet); }; } onTapContinue(FavoriteSportsState state, BuildContext context) { return () { - UserRegistrationSheet sheet = - state.favoriteSportsModelObj!.userRegistrationSheet; + UserRegistrationSheet sheet = state.favoriteSportsModelObj!.userRegistrationSheet; sheet.aboutSportHobbies = state.enterinformationController!.text; - Navigator.pushNamed( - context, - AppRoutes.favoriteFoodsScreen, - arguments: sheet, - ); + GoRouter.of(context).goNamed('favoriteFoodsScreen', extra: sheet); }; } _buildAppBar(BuildContext context) { return CustomAppBar( leadingWidth: 29.h, - leading: AppbarLeadingImage( - imagePath: ImageConstant.imgArrowLeft, - margin: EdgeInsets.only(left: 16.h, top: 15.v, bottom: 15.v), - onTap: onTapBack(context)), + leading: + AppbarLeadingImage(imagePath: ImageConstant.imgArrowLeft, margin: EdgeInsets.only(left: 16.h, top: 15.v, bottom: 15.v), onTap: onTapBack(context)), centerTitle: true, title: AppbarTitleImage(imagePath: ImageConstant.imgLogoEatvio)); } @@ -129,11 +104,9 @@ class _FavoriteSportsScreenState extends State { /// Section Widget _buildTextFormFieldSection(BuildContext context) { return Column(children: [ - Text("fill_in_information".tr, - style: CustomTextStyles.titleMediumSegoeUI), + Text("fill_in_information".tr, style: CustomTextStyles.titleMediumSegoeUI), SizedBox(height: 2.v), - BlocSelector( + BlocSelector( selector: (state) => state.enterinformationController, builder: (context, enterinformationController) { return CustomTextFormField( diff --git a/lib/presentation/registration/gender_screen/gender_screen.dart b/lib/presentation/registration/gender_screen/gender_screen.dart index 1db99ac..4e90621 100644 --- a/lib/presentation/registration/gender_screen/gender_screen.dart +++ b/lib/presentation/registration/gender_screen/gender_screen.dart @@ -1,3 +1,5 @@ +import 'package:go_router/go_router.dart'; + import 'bloc/gender_bloc.dart'; import 'models/gender_model.dart'; import 'package:eatvio_app/data/models/userRegistrationModel/user_registration_model.dart'; @@ -12,8 +14,7 @@ class GenderScreen extends StatefulWidget { const GenderScreen({Key? key}) : super(key: key); static Widget builder(BuildContext context) { - final sheet = - ModalRoute.of(context)!.settings.arguments as UserRegistrationSheet; + final sheet = ModalRoute.of(context)!.settings.arguments as UserRegistrationSheet; return BlocProvider( create: (context) => GenderBloc( GenderState( @@ -37,8 +38,7 @@ class _GenderScreenState extends State { appBar: _buildAppBar(context), body: Container( width: double.maxFinite, - padding: - EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v), + padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v), child: Column(children: [ SizedBox(height: 7.v), Container( @@ -47,18 +47,13 @@ class _GenderScreenState extends State { decoration: BoxDecoration( color: theme.colorScheme.onPrimary, borderRadius: BorderRadius.circular(8.h), - border: Border.all( - color: theme.colorScheme.primary, width: 1.h)), + border: Border.all(color: theme.colorScheme.primary, width: 1.h)), child: ClipRRect( borderRadius: BorderRadius.circular(8.h), child: LinearProgressIndicator( - value: 0.16, - backgroundColor: theme.colorScheme.onPrimary, - valueColor: AlwaysStoppedAnimation( - appTheme.blueA400)))), + value: 0.16, backgroundColor: theme.colorScheme.onPrimary, valueColor: AlwaysStoppedAnimation(appTheme.blueA400)))), SizedBox(height: 36.v), - Text("your_gender".tr, - style: theme.textTheme.headlineSmall), + Text("your_gender".tr, style: theme.textTheme.headlineSmall), RadioListTile( title: Text('Мужской'), value: 'male', @@ -82,12 +77,10 @@ class _GenderScreenState extends State { ), ), Spacer(flex: 66), - BlocBuilder( - builder: (context, state) { + BlocBuilder(builder: (context, state) { return NextStepButton( text: "continue".tr.toUpperCase(), - margin: EdgeInsets.only( - left: 16.h, right: 16.h, bottom: 50.v), + margin: EdgeInsets.only(left: 16.h, right: 16.h, bottom: 50.v), buttonStyle: CustomButtonStyles.outlinePrimaryTL15, onPressed: onTapNext(state, context)); }), @@ -99,25 +92,19 @@ class _GenderScreenState extends State { return () { UserRegistrationSheet sheet = state.genderModelObj!.userRegistrationSheet; sheet.gender = state.selectedRadioValue!; - Navigator.pushNamed( - context, - AppRoutes.dateOfBirthScreen, - arguments: sheet, - ); + GoRouter.of(context).goNamed('dateOfBirthScreen', extra: sheet); }; } onMale(BuildContext context) { return (value) { - BlocProvider.of(context) - .add(GenderSelectEvent(value: 'male')); + BlocProvider.of(context).add(GenderSelectEvent(value: 'male')); }; } onFemale(BuildContext context) { return (value) { - BlocProvider.of(context) - .add(GenderSelectEvent(value: 'female')); + BlocProvider.of(context).add(GenderSelectEvent(value: 'female')); }; } @@ -125,19 +112,14 @@ class _GenderScreenState extends State { _buildAppBar(BuildContext context) { return CustomAppBar( leadingWidth: 29.h, - leading: AppbarLeadingImage( - imagePath: ImageConstant.imgArrowLeft, - margin: EdgeInsets.only(left: 16.h, top: 15.v, bottom: 15.v), - onTap: onTapBack()), + leading: AppbarLeadingImage(imagePath: ImageConstant.imgArrowLeft, margin: EdgeInsets.only(left: 16.h, top: 15.v, bottom: 15.v), onTap: onTapBack()), centerTitle: true, title: AppbarTitleImage(imagePath: ImageConstant.imgLogoEatvio)); } Function onTapBack() { return () { - NavigatorService.pushNamed( - AppRoutes.dateOfBirthScreen, - ); + GoRouter.of(context).goNamed('dateOfBirthScreen'); }; } diff --git a/lib/presentation/registration/height_screen/height_screen.dart b/lib/presentation/registration/height_screen/height_screen.dart index f5bafcb..243fe89 100644 --- a/lib/presentation/registration/height_screen/height_screen.dart +++ b/lib/presentation/registration/height_screen/height_screen.dart @@ -1,3 +1,5 @@ +import 'package:go_router/go_router.dart'; + import 'bloc/height_bloc.dart'; import 'models/height_model.dart'; import 'package:eatvio_app/core/app_export.dart'; @@ -14,12 +16,9 @@ class HeightScreen extends StatelessWidget { const HeightScreen({Key? key}) : super(key: key); static Widget builder(BuildContext context) { - final sheet = - ModalRoute.of(context)!.settings.arguments as UserRegistrationSheet; + final sheet = ModalRoute.of(context)!.settings.arguments as UserRegistrationSheet; return BlocProvider( - create: (context) => HeightBloc(HeightState( - heightModelObj: HeightModel(userRegistrationSheet: sheet))) - ..add(HeightInitialEvent()), + create: (context) => HeightBloc(HeightState(heightModelObj: HeightModel(userRegistrationSheet: sheet)))..add(HeightInitialEvent()), child: HeightScreen()); } @@ -72,8 +71,7 @@ class HeightScreen extends StatelessWidget { style: theme.textTheme.bodyLarge, ), SizedBox(height: 4.v), - BlocBuilder( - builder: (context, state) { + BlocBuilder(builder: (context, state) { return CustomTextFormField( width: 150.h, textInputAction: TextInputAction.done, @@ -113,11 +111,7 @@ class HeightScreen extends StatelessWidget { onTapNext(HeightState state, BuildContext context) { return () { UserRegistrationSheet sheet = state.heightModelObj!.userRegistrationSheet; - Navigator.pushNamed( - context, - AppRoutes.bloodPressureScreen, - arguments: sheet, - ); + GoRouter.of(context).goNamed('bloodPressureScreen', extra: sheet); }; } @@ -125,10 +119,8 @@ class HeightScreen extends StatelessWidget { _buildAppBar(BuildContext context) { return CustomAppBar( leadingWidth: 29.h, - leading: AppbarLeadingImage( - imagePath: ImageConstant.imgArrowLeft, - margin: EdgeInsets.only(left: 16.h, top: 15.v, bottom: 15.v), - onTap: onTapBack(context)), + leading: + AppbarLeadingImage(imagePath: ImageConstant.imgArrowLeft, margin: EdgeInsets.only(left: 16.h, top: 15.v, bottom: 15.v), onTap: onTapBack(context)), centerTitle: true, title: AppbarTitleImage(imagePath: ImageConstant.imgLogoEatvio)); } diff --git a/lib/presentation/registration/language_select_screen/language_select_screen.dart b/lib/presentation/registration/language_select_screen/language_select_screen.dart index 80b3a8b..75a7c1a 100644 --- a/lib/presentation/registration/language_select_screen/language_select_screen.dart +++ b/lib/presentation/registration/language_select_screen/language_select_screen.dart @@ -1,4 +1,5 @@ import 'package:eatvio_app/data/models/userRegistrationModel/user_registration_model.dart'; +import 'package:go_router/go_router.dart'; import 'bloc/language_select_bloc.dart'; import 'models/language_select_model.dart'; @@ -107,10 +108,9 @@ class LanguageSelectScreen extends StatelessWidget { void Function()? _saveAndPush(LanguageSelectState state, BuildContext context) { return () { UserRegistrationSheet sheet = state.languageSelectModelObj!.userRegistrationSheet; - Navigator.pushNamed( - context, - AppRoutes.credentialsScreen, - arguments: sheet, + GoRouter.of(context).goNamed( + 'credentialsScreen', + extra: sheet, ); }; } diff --git a/lib/presentation/registration/medicine_intake_screen/medicine_intake_screen.dart b/lib/presentation/registration/medicine_intake_screen/medicine_intake_screen.dart index 51df64a..a3cc105 100644 --- a/lib/presentation/registration/medicine_intake_screen/medicine_intake_screen.dart +++ b/lib/presentation/registration/medicine_intake_screen/medicine_intake_screen.dart @@ -1,3 +1,5 @@ +import 'package:go_router/go_router.dart'; + import 'bloc/medicine_intake_bloc.dart'; import 'models/medicine_intake_model.dart'; import 'package:eatvio_app/core/app_export.dart'; @@ -13,12 +15,9 @@ class MedicineIntakeScreen extends StatefulWidget { const MedicineIntakeScreen({Key? key}) : super(key: key); static Widget builder(BuildContext context) { - final sheet = - ModalRoute.of(context)!.settings.arguments as UserRegistrationSheet; + final sheet = ModalRoute.of(context)!.settings.arguments as UserRegistrationSheet; return BlocProvider( - create: (context) => MedicineIntakeBloc(MedicineIntakeState( - medicineIntakeModelObj: - MedicineIntakeModel(userRegistrationSheet: sheet))) + create: (context) => MedicineIntakeBloc(MedicineIntakeState(medicineIntakeModelObj: MedicineIntakeModel(userRegistrationSheet: sheet))) ..add(MedicineIntakeInitialEvent()), child: MedicineIntakeScreen()); } @@ -46,38 +45,28 @@ class _MedicineIntakeScreenState extends State { decoration: BoxDecoration( color: theme.colorScheme.onPrimary, borderRadius: BorderRadius.circular(8.h), - border: Border.all( - color: theme.colorScheme.primary, width: 1.h)), + border: Border.all(color: theme.colorScheme.primary, width: 1.h)), child: ClipRRect( borderRadius: BorderRadius.circular(8.h), child: LinearProgressIndicator( - value: 0.69, - backgroundColor: theme.colorScheme.onPrimary, - valueColor: AlwaysStoppedAnimation( - appTheme.blueA400)))), + value: 0.69, backgroundColor: theme.colorScheme.onPrimary, valueColor: AlwaysStoppedAnimation(appTheme.blueA400)))), SizedBox(height: 20.v), Container( width: 271.h, margin: EdgeInsets.only(left: 35.h, right: 36.h), child: Text("do_you_take_pills".tr, - maxLines: 2, - overflow: TextOverflow.ellipsis, - textAlign: TextAlign.center, - style: theme.textTheme.headlineSmall)), + maxLines: 2, overflow: TextOverflow.ellipsis, textAlign: TextAlign.center, style: theme.textTheme.headlineSmall)), SizedBox(height: 86.v), _buildTextFormField(context), Spacer(), - BlocBuilder( - builder: (context, state) { + BlocBuilder(builder: (context, state) { return NextStepButton( text: "continue".tr.toUpperCase(), - margin: EdgeInsets.only( - left: 16.h, right: 16.h, bottom: 50.v), + margin: EdgeInsets.only(left: 16.h, right: 16.h, bottom: 50.v), buttonStyle: CustomButtonStyles.outlinePrimaryTL15, onPressed: onTapNext(state, context)); }), - BlocBuilder( - builder: (context, state) { + BlocBuilder(builder: (context, state) { return GestureDetector( onTap: onTapSkip(state, context), child: Text("skip".tr, style: theme.textTheme.bodyLarge), @@ -88,25 +77,21 @@ class _MedicineIntakeScreenState extends State { onTapSkip(MedicineIntakeState state, BuildContext context) { return () { - UserRegistrationSheet sheet = - state.medicineIntakeModelObj!.userRegistrationSheet; - Navigator.pushNamed( - context, - AppRoutes.bloodPressureScreen, - arguments: sheet, + UserRegistrationSheet sheet = state.medicineIntakeModelObj!.userRegistrationSheet; + GoRouter.of(context).goNamed( + 'bloodPressureScreen', + extra: sheet, ); }; } onTapNext(MedicineIntakeState state, BuildContext context) { return () { - UserRegistrationSheet sheet = - state.medicineIntakeModelObj!.userRegistrationSheet; + UserRegistrationSheet sheet = state.medicineIntakeModelObj!.userRegistrationSheet; sheet.aboutTakingPils = state.enterInformationController!.text; - Navigator.pushNamed( - context, - AppRoutes.bloodPressureScreen, - arguments: sheet, + GoRouter.of(context).goNamed( + 'bloodPressureScreen', + extra: sheet, ); }; } @@ -115,10 +100,8 @@ class _MedicineIntakeScreenState extends State { _buildAppBar(BuildContext context) { return CustomAppBar( leadingWidth: 31.h, - leading: AppbarLeadingImage( - imagePath: ImageConstant.imgArrowLeft, - margin: EdgeInsets.only(left: 18.h, top: 15.v, bottom: 15.v), - onTap: onTapBack(context)), + leading: + AppbarLeadingImage(imagePath: ImageConstant.imgArrowLeft, margin: EdgeInsets.only(left: 18.h, top: 15.v, bottom: 15.v), onTap: onTapBack(context)), centerTitle: true, title: AppbarTitleImage(imagePath: ImageConstant.imgLogoEatvio)); } @@ -132,18 +115,13 @@ class _MedicineIntakeScreenState extends State { /// Section Widget _buildTextFormField(BuildContext context) { return Column(children: [ - Text("fill_in_information".tr, - style: CustomTextStyles.titleMediumSegoeUI), + Text("fill_in_information".tr, style: CustomTextStyles.titleMediumSegoeUI), SizedBox(height: 2.v), - BlocSelector( + BlocSelector( selector: (state) => state.enterInformationController, builder: (context, enterInformationController) { return CustomTextFormField( - controller: enterInformationController, - hintText: "enter_information".tr, - textInputAction: TextInputAction.done, - maxLines: 8); + controller: enterInformationController, hintText: "enter_information".tr, textInputAction: TextInputAction.done, maxLines: 8); }) ]); } diff --git a/lib/presentation/registration/name_screen/name_screen.dart b/lib/presentation/registration/name_screen/name_screen.dart index 23612d7..6501c00 100644 --- a/lib/presentation/registration/name_screen/name_screen.dart +++ b/lib/presentation/registration/name_screen/name_screen.dart @@ -1,3 +1,6 @@ +import 'package:eatvio_app/app_router.dart'; +import 'package:go_router/go_router.dart'; + import 'bloc/name_bloc.dart'; import 'models/name_model.dart'; import 'package:eatvio_app/core/app_export.dart'; @@ -114,12 +117,7 @@ class NameScreen extends StatelessWidget { UserRegistrationSheet sheet = state.nameModelObj!.userRegistrationSheet; sheet.firstName = state.firstNameController!.text; sheet.lastName = state.lastNameController!.text; - - Navigator.pushNamed( - context, - AppRoutes.genderScreen, - arguments: sheet, - ); + AppRouter.navigatorKey.currentContext?.goNamed('genderScreen', extra: sheet); } else { String errorMessage = ''; diff --git a/lib/presentation/registration/splash_screen/bloc/splash_bloc.dart b/lib/presentation/registration/splash_screen/bloc/splash_bloc.dart index 9491b45..bdd396f 100644 --- a/lib/presentation/registration/splash_screen/bloc/splash_bloc.dart +++ b/lib/presentation/registration/splash_screen/bloc/splash_bloc.dart @@ -1,8 +1,12 @@ +import 'package:eatvio_app/app_router.dart'; import 'package:equatable/equatable.dart'; import 'package:flutter/material.dart'; +import 'package:go_router/go_router.dart'; import '/core/app_export.dart'; import 'package:eatvio_app/presentation/registration/splash_screen/models/splash_model.dart'; + part 'splash_event.dart'; + part 'splash_state.dart'; /// A bloc that manages the state of a Splash according to the event that is dispatched to it. @@ -16,9 +20,7 @@ class SplashBloc extends Bloc { Emitter emit, ) async { Future.delayed(const Duration(milliseconds: 3000), () { - NavigatorService.popAndPushNamed( - AppRoutes.myProfile, - ); + AppRouter.navigatorKey.currentContext?.goNamed('myProfileScreen'); }); } } diff --git a/lib/presentation/registration/weight_screen/weight_screen.dart b/lib/presentation/registration/weight_screen/weight_screen.dart index c68ccb8..28b0913 100644 --- a/lib/presentation/registration/weight_screen/weight_screen.dart +++ b/lib/presentation/registration/weight_screen/weight_screen.dart @@ -1,3 +1,5 @@ +import 'package:go_router/go_router.dart'; + import 'bloc/weight_bloc.dart'; import 'models/weight_model.dart'; import 'package:eatvio_app/core/app_export.dart'; @@ -14,12 +16,9 @@ class WeightScreen extends StatelessWidget { const WeightScreen({Key? key}) : super(key: key); static Widget builder(BuildContext context) { - final sheet = - ModalRoute.of(context)!.settings.arguments as UserRegistrationSheet; + final sheet = ModalRoute.of(context)!.settings.arguments as UserRegistrationSheet; return BlocProvider( - create: (context) => WeightBloc(WeightState( - weightModelObj: WeightModel(userRegistrationSheet: sheet))) - ..add(WeightInitialEvent()), + create: (context) => WeightBloc(WeightState(weightModelObj: WeightModel(userRegistrationSheet: sheet)))..add(WeightInitialEvent()), child: WeightScreen()); } @@ -72,8 +71,7 @@ class WeightScreen extends StatelessWidget { style: theme.textTheme.bodyLarge, ), SizedBox(height: 4.v), - BlocBuilder( - builder: (context, state) { + BlocBuilder(builder: (context, state) { return CustomTextFormField( width: 150.h, textInputAction: TextInputAction.done, @@ -113,11 +111,7 @@ class WeightScreen extends StatelessWidget { onTapNext(WeightState state, BuildContext context) { return () { UserRegistrationSheet sheet = state.weightModelObj!.userRegistrationSheet; - Navigator.pushNamed( - context, - AppRoutes.heightScreen, - arguments: sheet, - ); + GoRouter.of(context).goNamed('heightScreen', extra: sheet); }; } @@ -125,10 +119,8 @@ class WeightScreen extends StatelessWidget { _buildAppBar(BuildContext context) { return CustomAppBar( leadingWidth: 29.h, - leading: AppbarLeadingImage( - imagePath: ImageConstant.imgArrowLeft, - margin: EdgeInsets.only(left: 16.h, top: 15.v, bottom: 15.v), - onTap: onTapBack(context)), + leading: + AppbarLeadingImage(imagePath: ImageConstant.imgArrowLeft, margin: EdgeInsets.only(left: 16.h, top: 15.v, bottom: 15.v), onTap: onTapBack(context)), centerTitle: true, title: AppbarTitleImage(imagePath: ImageConstant.imgLogoEatvio)); } diff --git a/lib/routes/app_routes.dart b/lib/routes/app_routes.dart deleted file mode 100644 index d3183f0..0000000 --- a/lib/routes/app_routes.dart +++ /dev/null @@ -1,191 +0,0 @@ -import 'package:eatvio_app/presentation/diets/diet_select_screen/diet_select_screen.dart'; -import 'package:flutter/material.dart'; -import 'package:eatvio_app/presentation/registration/date_of_birth_screen/date_of_birth_screen.dart'; -import 'package:eatvio_app/presentation/registration/city_of_living_screen/city_of_living_screen.dart'; -import 'package:eatvio_app/presentation/registration/body_circumferences_screen/body_circumferences_screen.dart'; -import 'package:eatvio_app/presentation/registration/weight_screen/weight_screen.dart'; -import 'package:eatvio_app/presentation/registration/allergies_screen/allergies_screen.dart'; -import 'package:eatvio_app/presentation/registration/medicine_intake_screen/medicine_intake_screen.dart'; -import 'package:eatvio_app/presentation/registration/splash_screen/splash_screen.dart'; -import 'package:eatvio_app/presentation/registration/gender_screen/gender_screen.dart'; -import 'package:eatvio_app/presentation/registration/blood_pressure_screen/blood_pressure_screen.dart'; -import 'package:eatvio_app/presentation/registration/favorite_sports_screen/favorite_sports_screen.dart'; -import 'package:eatvio_app/presentation/registration/favorite_foods_screen/favorite_foods_screen.dart'; -import 'package:eatvio_app/presentation/registration/additional_information_screen/additional_information_screen.dart'; -import 'package:eatvio_app/presentation/registration/language_select_screen/language_select_screen.dart'; -import 'package:eatvio_app/presentation/registration/height_screen/height_screen.dart'; -import 'package:eatvio_app/presentation/registration/credentials_screen/credentials_screen.dart'; -import 'package:eatvio_app/presentation/registration/name_screen/name_screen.dart'; -import 'package:eatvio_app/presentation/registration/app_navigation_screen/app_navigation_screen.dart'; -import 'package:eatvio_app/presentation/profile/my_profile_screen/my_profile_screen.dart'; -import 'package:eatvio_app/presentation/profile/my_profile_screen/my_settings_screen.dart'; -import 'package:eatvio_app/presentation/diary/diary_edit_screen/diary_edit_screen.dart'; -import 'package:eatvio_app/presentation/chat/chat_screen/chat_screen.dart'; -import 'package:eatvio_app/presentation/chat/chat_select_screen/chat_select_screen.dart'; -import 'package:eatvio_app/presentation/feed/feed_screen/feed_screen.dart'; -import 'package:eatvio_app/presentation/recipe/recipe_select_screen/recipe_select_screen.dart'; -import 'package:eatvio_app/presentation/plans/plan_select_screen/plan_select_screen.dart'; -import 'package:eatvio_app/presentation/plans/plan_edit_screen/plan_edit_screen.dart'; -import 'package:eatvio_app/presentation/plans/plan_create_screen/plan_create_screen.dart'; -import 'package:eatvio_app/presentation/diets/diet_show_screen/diet_show_screen.dart'; -import 'package:eatvio_app/presentation/diets/diet_edit_screen/diet_edit_screen.dart'; -import 'package:eatvio_app/presentation/diets/diet_create_screen/diet_create_screen.dart'; -import 'package:eatvio_app/presentation/plans/plan_show_screen/plan_show_screen.dart'; -import 'package:eatvio_app/presentation/recipe/recipe_show_screen/recipe_show_screen.dart'; -import 'package:eatvio_app/presentation/recipe/recipe_create_screen/recipe_create_screen.dart'; -import 'package:eatvio_app/presentation/recipe/recipe_edit_screen/recipe_edit_screen.dart'; -import 'package:eatvio_app/presentation/feed/blog_post_edit_screen/blog_post_edit_screen.dart'; -import 'package:eatvio_app/presentation/feed/blog_post_create_screen/blog_post_create_screen.dart'; -import 'package:eatvio_app/presentation/glossary/glossary_screen/glossary_screen.dart'; - -class AppRoutesq { - // REGISTRATION - - static const String dateOfBirthScreen = '/date_of_birth_screen'; - - static const String cityOfLivingScreen = '/city_of_living_screen'; - - static const String bodyCircumferencesScreen = '/body_circumferences_screen'; - - static const String weightScreen = '/weight_screen'; - - static const String heightScreen = '/height_screen'; - - static const String allergiesScreen = '/allergies_screen'; - - static const String medicineIntakeScreen = '/medicine_intake_screen'; - - static const String splashScreen = '/splash_screen'; - - static const String genderScreen = '/gender_screen'; - - static const String bloodPressureScreen = '/blood_pressure_screen'; - - static const String favoriteSportsScreen = '/favorite_sports_screen'; - - static const String favoriteFoodsScreen = '/favorite_foods_screen'; - - static const String scheduleScreen = '/schedule_screen'; - - static const String additionalInformationScreen = '/additional_information_screen'; - - static const String languageSelectScreen = '/language_select_screen'; - - static const String nameScreen = '/name_screen'; - - static const String credentialsScreen = '/credentials_screen'; - - static const String appNavigationScreen = '/app_navigation_screen'; - - static const String authScreen = '/auth_screen'; - - static const String initialRoute = '/initialRoute'; - - //PROFILE - static const String myProfile = '/myProfile'; - - static const String mySettings = '/mySettings'; - - static const String diaryEdit = '/diaryEdit'; - - static const String chatScreen = '/chat'; - - static const String chatSelectScreen = '/chatSelect'; - - static const String feedScreen = '/feed'; - - static const String blogPostScreen = '/blogPost'; - - static const String blogPostEditScreen = '/blogPostEdit'; - - static const String blogPostCreateScreen = '/blogPostCreate'; - - static const String recipeSelectScreen = '/recipeSelect'; - - static const String recipeScreen = '/recipe'; - - static const String recipeEditScreen = '/recipeEdit'; - - static const String recipeCreateScreen = '/recipeCreate'; - - static const String dietSelectScreen = '/dietSelect'; - - static const String dietScreen = '/diet'; - - static const String dietEditScreen = '/dietEdit'; - - static const String dietCreateScreen = '/dietCreate'; - - static const String planSelectScreen = '/planSelect'; - - static const String planScreen = '/plan'; - - static const String planEditScreen = '/planEdit'; - - static const String planCreateScreen = '/planCreate'; - - static const String glossaryScreen = '/glossary'; - - static Map get routes => { - dateOfBirthScreen: (context) => _buildFadeRoute(context, DateOfBirthScreen.builder), - cityOfLivingScreen: (context) => _buildFadeRoute(context, CityOfLivingScreen.builder), - bodyCircumferencesScreen: (context) => _buildFadeRoute(context, BodyCircumferencesScreen.builder), - weightScreen: (context) => _buildFadeRoute(context, WeightScreen.builder), - heightScreen: (context) => _buildFadeRoute(context, HeightScreen.builder), - nameScreen: (context) => _buildFadeRoute(context, NameScreen.builder), - credentialsScreen: (context) => _buildFadeRoute(context, CredentialsScreen.builder), - allergiesScreen: (context) => _buildFadeRoute(context, AllergiesScreen.builder), - medicineIntakeScreen: (context) => _buildFadeRoute(context, MedicineIntakeScreen.builder), - splashScreen: (context) => _buildFadeRoute(context, SplashScreen.builder), - genderScreen: (context) => _buildFadeRoute(context, GenderScreen.builder), - bloodPressureScreen: (context) => _buildFadeRoute(context, BloodPressureScreen.builder), - favoriteSportsScreen: (context) => _buildFadeRoute(context, FavoriteSportsScreen.builder), - favoriteFoodsScreen: (context) => _buildFadeRoute(context, FavoriteFoodsScreen.builder), - additionalInformationScreen: (context) => _buildFadeRoute(context, AdditionalInformationScreen.builder), - languageSelectScreen: (context) => _buildFadeRoute(context, LanguageSelectScreen.builder), - appNavigationScreen: (context) => _buildFadeRoute(context, AppNavigationScreen.builder), - initialRoute: (context) => _buildFadeRoute(context, SplashScreen.builder), - myProfile: (context) => _buildFadeRoute(context, MyProfileScreen.builder), - mySettings: (context) => _buildFadeRoute(context, MySettingsScreen.builder), - diaryEdit: (context) => _buildFadeRoute(context, DiaryEditScreen.builder), - chatScreen: (context) => _buildFadeRoute(context, ChatScreen.builder), - chatSelectScreen: (context) => _buildFadeRoute(context, ChatSelectScreen.builder), - recipeSelectScreen: (context) => _buildFadeRoute(context, RecipeSelectScreen.builder), - recipeScreen: (context) => _buildFadeRoute(context, RecipeScreen.builder), - recipeEditScreen: (context) => _buildFadeRoute(context, RecipeEditScreen.builder), - recipeCreateScreen: (context) => _buildFadeRoute(context, RecipeCreateScreen.builder), - dietSelectScreen: (context) => _buildFadeRoute(context, DietSelectScreen.builder), - dietScreen: (context) => _buildFadeRoute(context, DietScreen.builder), - dietEditScreen: (context) => _buildFadeRoute(context, DietEditScreen.builder), - dietCreateScreen: (context) => _buildFadeRoute(context, DietCreateScreen.builder), - planSelectScreen: (context) => _buildFadeRoute(context, PlanSelectScreen.builder), - planScreen: (context) => _buildFadeRoute(context, PlanScreen.builder), - planEditScreen: (context) => _buildFadeRoute(context, PlanEditScreen.builder), - planCreateScreen: (context) => _buildFadeRoute(context, PlanCreateScreen.builder), - feedScreen: (context) => _buildFadeRoute(context, FeedScreen.builder), - blogPostEditScreen: (context) => _buildFadeRoute(context, BlogPostEditScreen.builder), - blogPostCreateScreen: (context) => _buildFadeRoute(context, BlogPostCreateScreen.builder), - glossaryScreen: (context) => _buildFadeRoute(context, GlossaryScreen.builder), - }; - - static Widget _buildFadeRoute(BuildContext context, WidgetBuilder builder) { - return FadeTransition( - opacity: AlwaysStoppedAnimation(1.0), - child: builder(context), - ); - } -} - -class FadeTransitionPage extends PageRouteBuilder { - final WidgetBuilder builder; - - FadeTransitionPage({required this.builder}) - : super( - pageBuilder: (BuildContext context, Animation animation, Animation secondaryAnimation) { - return builder(context); - }, - transitionsBuilder: (BuildContext context, Animation animation, Animation secondaryAnimation, Widget child) { - return FadeTransition(opacity: animation, child: child); - }, - ); -}