From ffcf1a98f47b88104dfc0f5a35712eecc87e5826 Mon Sep 17 00:00:00 2001 From: DmitriyLabutin Date: Mon, 3 Jun 2024 12:12:54 +0300 Subject: [PATCH 01/17] debugShowCheckedModeBanner --- lib/main.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.dart b/lib/main.dart index 3a5a94b..3ec0c33 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -37,7 +37,7 @@ class MyApp extends StatelessWidget { theme: theme, title: 'Eatvio', navigatorKey: NavigatorService.navigatorKey, - debugShowCheckedModeBanner: false, + debugShowCheckedModeBanner: true, localizationsDelegates: [ AppLocalizationDelegate(), GlobalMaterialLocalizations.delegate, From 425c6600aed32f6b5664a81330f1dee57f484cac Mon Sep 17 00:00:00 2001 From: DmitriyLabutin Date: Tue, 4 Jun 2024 12:35:12 +0300 Subject: [PATCH 02/17] go router + bottom nav bar --- ios/Runner.xcodeproj/project.pbxproj | 2 +- .../xcshareddata/xcschemes/Runner.xcscheme | 2 +- lib/app_router.dart | 41 ++ lib/main.dart | 55 +- .../auth/auth_screen/auth_screen.dart | 104 ++-- .../chat_select_screen.dart | 123 +++-- .../diary_edit_screen/diary_edit_screen.dart | 139 ++---- .../feed/feed_screen/feed_screen.dart | 18 +- .../my_profile_screen/my_profile_screen.dart | 469 +++++++----------- lib/widgets/app_bar/custom_app_bar.dart | 6 +- lib/widgets/custom_bottom_bar.dart | 175 +++++-- pubspec.yaml | 6 +- test/diary_test.dart | 10 +- 13 files changed, 576 insertions(+), 574 deletions(-) create mode 100644 lib/app_router.dart diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index 29940b0..68ec53f 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -156,7 +156,7 @@ isa = PBXProject; attributes = { BuildIndependentTargetsInParallel = YES; - LastUpgradeCheck = 1430; + LastUpgradeCheck = 1510; ORGANIZATIONNAME = ""; TargetAttributes = { 97C146ED1CF9000F007C117D = { diff --git a/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index a6b826d..5e31d3d 100644 --- a/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ MyProfileScreen(), + ), + GoRoute( + path: '/feed-screen', + name: 'feedScreen', + builder: (context, state) => FeedScreen(), + ), + GoRoute( + path: '/diary-screen', + name: 'diaryScreen', + builder: (context, state) => DiaryEditScreen(), + ), + GoRoute( + path: '/chat-select-screen', + name: 'chatSelectScreen', + builder: (context, state) => ChatSelectScreen(), + ), + ], + ), + ], + ); +} diff --git a/lib/main.dart b/lib/main.dart index 3ec0c33..e3ddb1f 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,3 +1,12 @@ +import 'package:eatvio_app/app_router.dart'; +import 'package:eatvio_app/presentation/chat/chat_select_screen/bloc/chat_select_bloc.dart'; +import 'package:eatvio_app/presentation/chat/chat_select_screen/models/chat_select_model.dart'; +import 'package:eatvio_app/presentation/diary/diary_edit_screen/bloc/diary_edit_bloc.dart'; +import 'package:eatvio_app/presentation/diary/diary_edit_screen/models/diary_edit_model.dart'; +import 'package:eatvio_app/presentation/feed/feed_screen/bloc/feed_bloc.dart'; +import 'package:eatvio_app/presentation/feed/feed_screen/models/feed_model.dart'; +import 'package:eatvio_app/presentation/profile/my_profile_screen/bloc/my_profile_bloc.dart'; +import 'package:eatvio_app/presentation/profile/my_profile_screen/models/my_profile_model.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; @@ -7,6 +16,7 @@ import 'package:path_provider/path_provider.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; var globalMessengerKey = GlobalKey(); + void main() async { WidgetsFlutterBinding.ensureInitialized(); final appDocumentDir = await getApplicationDocumentsDirectory(); @@ -25,19 +35,46 @@ void main() async { class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { - return BlocProvider( - create: (context) => ThemeBloc( - ThemeState( - themeType: PrefUtils().getThemeData(), + return MultiBlocProvider( + providers: [ + BlocProvider( + create: (context) => ThemeBloc( + ThemeState(themeType: PrefUtils().getThemeData()), + ), ), - ), + BlocProvider( + create: (context) => MyProfileBloc( + MyProfileState( + myProfileModelObj: MyProfileModel(), + ), + )..add(MyProfileInitialEvent()), + ), + BlocProvider( + create: (context) => FeedBloc(FeedState(myProfileModelObj: FeedModel())) + ..add( + FeedInitialEvent(), + ), + ), + BlocProvider( + create: (context) => DiaryEditBloc(DiaryEditState(diaryEditModelObj: DiaryEditModel())) + ..add( + DiaryEditInitialEvent(), + ), + ), + BlocProvider( + create: (context) => ChatSelectBloc(ChatSelectState(chatSelectModelObj: ChatSelectModel())) + ..add( + ChatSelectInitialEvent(), + ), + ), + ], child: BlocBuilder( builder: (context, state) { - return MaterialApp( + return MaterialApp.router( theme: theme, title: 'Eatvio', - navigatorKey: NavigatorService.navigatorKey, - debugShowCheckedModeBanner: true, + routerConfig: AppRouter.appRouter, + debugShowCheckedModeBanner: false, localizationsDelegates: [ AppLocalizationDelegate(), GlobalMaterialLocalizations.delegate, @@ -50,8 +87,6 @@ class MyApp extends StatelessWidget { '', ), ], - initialRoute: AppRoutes.initialRoute, - routes: AppRoutes.routes, ); }, ), diff --git a/lib/presentation/auth/auth_screen/auth_screen.dart b/lib/presentation/auth/auth_screen/auth_screen.dart index e934925..558d565 100644 --- a/lib/presentation/auth/auth_screen/auth_screen.dart +++ b/lib/presentation/auth/auth_screen/auth_screen.dart @@ -30,44 +30,40 @@ class AuthScreen extends StatelessWidget { return Scaffold( resizeToAvoidBottomInset: false, appBar: _buildAppBar(context), - body:GestureDetector( - onTap: () => FocusScope.of(context).unfocus(), - child: Container( - width: double.maxFinite, - padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v), - child: Column(children: [ - SizedBox(height: 36.v), - Text("user_authorization".tr, - style: theme.textTheme.headlineSmall), - SizedBox(height: 60.v), - Text("email".tr, style: theme.textTheme.bodyLarge), - SizedBox(height: 3.v), - BlocSelector( - selector: (state) => state.emailController, - builder: (context, emailController) { - return CustomTextFormField( - controller: emailController, - textInputAction: TextInputAction.done); - }), - SizedBox(height: 22.v), - Text("password".tr, style: theme.textTheme.bodyLarge), - SizedBox(height: 5.v), - BlocSelector( - selector: (state) => state.passwordController, - builder: (context, passwordController) { - return CustomTextFormField( - obscureText: true, - controller: passwordController, - ); - }), - SizedBox(height: 50.v), - NextStepButton( - text: "no_account".tr.toUpperCase(), - margin: - EdgeInsets.only(left: 16.h, right: 16.h, bottom: 50.v), - buttonStyle: CustomButtonStyles.outlinePrimaryTL15, - onPressed: onTapNoAccount(context)), - /*NextStepButton( + body: GestureDetector( + onTap: () => FocusScope.of(context).unfocus(), + child: Container( + width: double.maxFinite, + padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v), + child: Column(children: [ + SizedBox(height: 36.v), + Text("user_authorization".tr, style: theme.textTheme.headlineSmall), + SizedBox(height: 60.v), + Text("email".tr, style: theme.textTheme.bodyLarge), + SizedBox(height: 3.v), + BlocSelector( + selector: (state) => state.emailController, + builder: (context, emailController) { + return CustomTextFormField(controller: emailController, textInputAction: TextInputAction.done); + }), + SizedBox(height: 22.v), + Text("password".tr, style: theme.textTheme.bodyLarge), + SizedBox(height: 5.v), + BlocSelector( + selector: (state) => state.passwordController, + builder: (context, passwordController) { + return CustomTextFormField( + obscureText: true, + controller: passwordController, + ); + }), + SizedBox(height: 50.v), + NextStepButton( + text: "no_account".tr.toUpperCase(), + margin: EdgeInsets.only(left: 16.h, right: 16.h, bottom: 50.v), + buttonStyle: CustomButtonStyles.outlinePrimaryTL15, + onPressed: onTapNoAccount(context)), + /*NextStepButton( text: "Тест дневника".toUpperCase(), margin: EdgeInsets.only(left: 16.h, right: 16.h, bottom: 50.v), @@ -79,31 +75,26 @@ class AuthScreen extends StatelessWidget { EdgeInsets.only(left: 16.h, right: 16.h, bottom: 50.v), buttonStyle: CustomButtonStyles.outlinePrimaryTL15, onPressed: onTapProfileTest(context)),*/ - BlocBuilder(builder: (context, state) { - return NextStepButton( - text: "authentificate".tr.toUpperCase(), - margin: - EdgeInsets.only(left: 16.h, right: 16.h, bottom: 50.v), - buttonStyle: CustomButtonStyles.outlinePrimaryTL15, - onPressed: onTapAuth(state, context)); - }), - ])))); + BlocBuilder(builder: (context, state) { + return NextStepButton( + text: "authentificate".tr.toUpperCase(), + margin: EdgeInsets.only(left: 16.h, right: 16.h, bottom: 50.v), + buttonStyle: CustomButtonStyles.outlinePrimaryTL15, + onPressed: onTapAuth(state, context)); + }), + ])))); } onTapAuth(AuthState state, BuildContext context) { return () async { - List errors = validateFields( - state.emailController!.text, state.passwordController!.text); + List errors = validateFields(state.emailController!.text, state.passwordController!.text); if (errors.isEmpty) { final Map credentials = { 'email': state.emailController!.text, 'password': state.passwordController!.text, }; - final response = await http.post( - Uri.parse(dotenv.env['SERVER_ROOT']! + '/login'), - headers: {'Content-Type': 'application/json'}, - body: json.encode(credentials), - encoding: utf8); + final response = await http.post(Uri.parse(dotenv.env['SERVER_ROOT']! + '/login'), + headers: {'Content-Type': 'application/json'}, body: json.encode(credentials), encoding: utf8); print(response.statusCode); if (response.statusCode == 200) { var res = await jsonDecode(response.body); @@ -179,10 +170,7 @@ class AuthScreen extends StatelessWidget { /// Section Widget _buildAppBar(BuildContext context) { - return CustomAppBar( - leadingWidth: 29.h, - centerTitle: true, - title: AppbarTitleImage(imagePath: ImageConstant.imgLogoEatvio)); + return CustomAppBar(leadingWidth: 29.h, centerTitle: true, title: AppbarTitleImage(imagePath: ImageConstant.imgLogoEatvio)); } List validateFields(String email, String password) { diff --git a/lib/presentation/chat/chat_select_screen/chat_select_screen.dart b/lib/presentation/chat/chat_select_screen/chat_select_screen.dart index dea9d3b..92bbfe8 100644 --- a/lib/presentation/chat/chat_select_screen/chat_select_screen.dart +++ b/lib/presentation/chat/chat_select_screen/chat_select_screen.dart @@ -9,82 +9,81 @@ import 'package:eatvio_app/presentation/chat/chat_select_screen/widgets/chat_ent class ChatSelectScreen extends StatelessWidget { const ChatSelectScreen({Key? key}) : super(key: key); + static Widget builder(BuildContext context) { return BlocProvider( - create: (context) => ChatSelectBloc( - ChatSelectState(chatSelectModelObj: ChatSelectModel())) - ..add(ChatSelectInitialEvent()), - child: ChatSelectScreen()); + create: (context) => ChatSelectBloc(ChatSelectState(chatSelectModelObj: ChatSelectModel()))..add(ChatSelectInitialEvent()), child: ChatSelectScreen()); } Widget build(BuildContext context) { return BlocBuilder( - builder: (context, state) { - if (state is ChatSelectInitialState) { - // Это начальное состояние, данные ещё не загружены. - return Container( - color: Colors.white, - ); - } else if (state is ChatSelectLoadedState) { - // Данные загружены, можно строить экран. - return _buildScreen(context, state); - } else if (state is ChatSelectErrorState) { - // Произошла ошибка при загрузке данных. - return Center(child: Text(state.errorMessage)); - } else { - // Другие состояния, если они есть. - return Container(); // Пустой контейнер для необработанных состояний. - } - }, + builder: (context, state) { + if (state is ChatSelectInitialState) { + // Это начальное состояние, данные ещё не загружены. + return Container( + color: Colors.white, + ); + } else if (state is ChatSelectLoadedState) { + // Данные загружены, можно строить экран. + return _buildScreen(context, state); + } else if (state is ChatSelectErrorState) { + // Произошла ошибка при загрузке данных. + return Center(child: Text(state.errorMessage)); + } else { + // Другие состояния, если они есть. + return Container(); // Пустой контейнер для необработанных состояний. + } + }, ); } _buildScreen(BuildContext context, ChatSelectLoadedState state) { mediaQueryData = MediaQuery.of(context); return SafeArea( - child: Scaffold( - resizeToAvoidBottomInset: false, - body: Container( - width: double.maxFinite, - decoration: AppDecoration.fillGray, - child: ListView( - children: [ - SizedBox(height: 30.v), - Container( - margin: EdgeInsets.only( - left: 16.h, - right: 20.h, - bottom: 10.h, + child: Scaffold( + resizeToAvoidBottomInset: false, + body: Container( + width: double.maxFinite, + decoration: AppDecoration.fillGray, + child: ListView( + children: [ + SizedBox(height: 30.v), + Container( + margin: EdgeInsets.only( + left: 16.h, + right: 20.h, + bottom: 10.h, + ), + padding: EdgeInsets.all(12.h), + 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), ), - padding: EdgeInsets.all(12.h), - 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: Column( + mainAxisSize: MainAxisSize.min, + children: [ + CustomSearchView( + controller: state.searchController, + hintText: "Поиск", ), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - CustomSearchView( - controller: state.searchController, - hintText: "Поиск", - ), - SizedBox(height: 20.v), - _buildChatList(context, state), - ], - ), - ) - ], - ), - ), - bottomNavigationBar: _buildBottomBar(context))); + SizedBox(height: 20.v), + _buildChatList(context, state), + ], + ), + ) + ], + ), + ), + ), + ); } } diff --git a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart index 1e81c62..2aa53dd 100644 --- a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart +++ b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart @@ -18,17 +18,11 @@ import 'package:carousel_slider/carousel_slider.dart'; // ignore: must_be_immutable class DiaryEditScreen extends StatelessWidget { - final void Function() onInitialize; - DiaryEditScreen({Key? key, required this.onInitialize}) : super(key: key); + DiaryEditScreen({Key? key}) : super(key: key); static Widget builder(BuildContext context) { return BlocProvider( - create: (context) => - DiaryEditBloc(DiaryEditState(diaryEditModelObj: DiaryEditModel())) - ..add(DiaryEditInitialEvent()), - child: DiaryEditScreen( - onInitialize: () {}, - )); + create: (context) => DiaryEditBloc(DiaryEditState(diaryEditModelObj: DiaryEditModel()))..add(DiaryEditInitialEvent()), child: DiaryEditScreen()); } Widget build(BuildContext context) { @@ -53,8 +47,7 @@ class DiaryEditScreen extends StatelessWidget { ); } - Widget _buildDiaryEditScreen( - BuildContext context, DiaryEditLoadedState state) { + Widget _buildDiaryEditScreen(BuildContext context, DiaryEditLoadedState state) { mediaQueryData = MediaQuery.of(context); return RefreshIndicator( onRefresh: refreshPage(context), @@ -94,7 +87,6 @@ class DiaryEditScreen extends StatelessWidget { ], ), ), - bottomNavigationBar: _buildBottomBar(context), ), ), ), @@ -156,8 +148,7 @@ class DiaryEditScreen extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - CustomImageView( - imagePath: ImageConstant.imgArrowLeft, onTap: onTapBack()), + CustomImageView(imagePath: ImageConstant.imgArrowLeft, onTap: onTapBack()), Padding( padding: EdgeInsets.only(top: 1.v), child: Column( @@ -260,9 +251,7 @@ class DiaryEditScreen extends StatelessWidget { borderRadius: BorderRadiusStyle.roundedBorder5, ), child: Center( - child: CircularProgressIndicator( - color: appTheme - .blueGray300), // Замените на свой прелоадер при необходимости + child: CircularProgressIndicator(color: appTheme.blueGray300), // Замените на свой прелоадер при необходимости ), ), ], @@ -286,8 +275,7 @@ class DiaryEditScreen extends StatelessWidget { _buildMeal(BuildContext context, DiaryEditLoadedState state) { final digitsOnly = FilteringTextInputFormatter.digitsOnly; - List _options = - state.autocompleteList!.map((dynamic item) => item as String).toList(); + List _options = state.autocompleteList!.map((dynamic item) => item as String).toList(); //print(_options); FocusNode focusNodeName = FocusNode(); return Container( @@ -332,9 +320,7 @@ class DiaryEditScreen extends StatelessWidget { onTap: () => _selectMealTime(context, state), child: AbsorbPointer( child: CustomTextFormField( - hintText: state.mealTimeController - ?.format(context) - .toString(), + hintText: state.mealTimeController?.format(context).toString(), autofocus: false, ), ), @@ -348,8 +334,7 @@ class DiaryEditScreen extends StatelessWidget { SizedBox(height: 20.v), Padding( padding: EdgeInsets.symmetric(horizontal: 10.h), - child: BlocSelector( + child: BlocSelector( selector: (state) => state.diaryEditModelObj, builder: (context, diaryEditModelObj) { return CustomDropDown( @@ -441,8 +426,7 @@ class DiaryEditScreen extends StatelessWidget { ), Padding( padding: EdgeInsets.only(left: 30.h), - child: BlocSelector( + child: BlocSelector( selector: (state) => state.diaryEditModelObj, builder: (context, diaryEditModelObj) { return CustomDropDown( @@ -460,9 +444,7 @@ class DiaryEditScreen extends StatelessWidget { SizedBox(height: 30.v), _buildAddProduct(context, state), SizedBox(height: 30.v), - ...state.portions! - .map((portion) => _buildProduct(context, portion)) - .toList(), + ...state.portions!.map((portion) => _buildProduct(context, portion)).toList(), SizedBox(height: 30.v), /*...state.photos != null ? state.photos!.isEmpty @@ -575,14 +557,8 @@ class DiaryEditScreen extends StatelessWidget { child: Text('Отмена'), ), TextButton( - onPressed: triggerModeration( - context, - state.productNameController!.text, - state.caloriesController!.text, - state.proteinsController!.text, - state.fatsController!.text, - state.carbsController!.text, - dialogContext), + onPressed: triggerModeration(context, state.productNameController!.text, state.caloriesController!.text, state.proteinsController!.text, + state.fatsController!.text, state.carbsController!.text, dialogContext), child: Text('Отправить'), ), ], @@ -591,30 +567,19 @@ class DiaryEditScreen extends StatelessWidget { ); } - triggerModeration( - BuildContext context, - String name, - String energyOn100gr, - String proteinsOn100gr, - String fatsOn100gr, - String carbohydratesOn100gr, + triggerModeration(BuildContext context, String name, String energyOn100gr, String proteinsOn100gr, String fatsOn100gr, String carbohydratesOn100gr, BuildContext dialogContext) { return () { // Call function to send moderation with the entered values context.read().add(SendModeration( - name: name, - energyOn100gr: energyOn100gr, - proteinsOn100gr: proteinsOn100gr, - fatsOn100gr: fatsOn100gr, - carbohydratesOn100gr: carbohydratesOn100gr)); + name: name, energyOn100gr: energyOn100gr, proteinsOn100gr: proteinsOn100gr, fatsOn100gr: fatsOn100gr, carbohydratesOn100gr: carbohydratesOn100gr)); Navigator.of(dialogContext).pop(); // Dismiss the dialog }; } popDialog(BuildContext dialogContext) { return () { - Navigator.of(dialogContext) - .pop(); // Dismiss the dialog on Cancel button press + Navigator.of(dialogContext).pop(); // Dismiss the dialog on Cancel button press }; } @@ -624,8 +589,7 @@ class DiaryEditScreen extends StatelessWidget { }; } - selectProduct(AutocompleteOnSelected onSelected, String option, - DiaryEditLoadedState state) { + selectProduct(AutocompleteOnSelected onSelected, String option, DiaryEditLoadedState state) { state.productNameController?.text = option; return () { onSelected(option); @@ -653,9 +617,7 @@ class DiaryEditScreen extends StatelessWidget { changeMeal(BuildContext context, DiaryEditLoadedState state) { return (value) { - context - .read() - .add(ChangeMeal(meals: state.meals, value: value)); + context.read().add(ChangeMeal(meals: state.meals, value: value)); }; } @@ -672,8 +634,7 @@ class DiaryEditScreen extends StatelessWidget { return CarouselSlider( options: CarouselOptions(height: 340.0), items: state.photos!.map((photo) { - return _buildPhoto( - context, photo); // Assuming photos are stored as strings + return _buildPhoto(context, photo); // Assuming photos are stored as strings }).toList(), ); } @@ -699,9 +660,7 @@ class DiaryEditScreen extends StatelessWidget { top: 5.v, ), child: Text( - portion['product_name'].length > 8 - ? portion['product_name'].substring(0, 8) - : portion['product_name'], + portion['product_name'].length > 8 ? portion['product_name'].substring(0, 8) : portion['product_name'], style: CustomTextStyles.titleMedium16, )), Padding( @@ -711,9 +670,7 @@ class DiaryEditScreen extends StatelessWidget { bottom: 3.v, ), child: Text( - portion['quantity'].toString() + - ' ' + - portion['portion'].toString().tr, + portion['quantity'].toString() + ' ' + portion['portion'].toString().tr, ), ), Spacer(), @@ -773,15 +730,12 @@ class DiaryEditScreen extends StatelessWidget { removePhoto(BuildContext context, Map photo) { return () { - context - .read() - .add(RemoveImageEvent(photo['id'].toString(), photo['path'])); + context.read().add(RemoveImageEvent(photo['id'].toString(), photo['path'])); }; } _buildNutritionChart(BuildContext context, DiaryEditLoadedState state) { - final List recommendedValues = state - .recommendedChartValues; // Рекомендуемые значения: калории, жиры, белки, углеводы + final List recommendedValues = state.recommendedChartValues; // Рекомендуемые значения: калории, жиры, белки, углеводы final List consumedValues = state.consumedChartValues; // return Container( margin: EdgeInsets.symmetric(horizontal: 16.h), @@ -843,37 +797,25 @@ class DiaryEditScreen extends StatelessWidget { BarChartGroupData(x: 0, barRods: [ BarChartRodData( toY: consumedValues[0] / recommendedValues[0] * 100, - color: checkConsumedValues( - [recommendedValues[0]], [consumedValues[1]]) - ? Colors.red - : Colors.blue, + color: checkConsumedValues([recommendedValues[0]], [consumedValues[1]]) ? Colors.red : Colors.blue, ) ]), BarChartGroupData(x: 1, barRods: [ BarChartRodData( toY: consumedValues[1] / recommendedValues[1] * 100, - color: checkConsumedValues( - [recommendedValues[1]], [consumedValues[1]]) - ? Colors.red - : Colors.blue, + color: checkConsumedValues([recommendedValues[1]], [consumedValues[1]]) ? Colors.red : Colors.blue, ) ]), BarChartGroupData(x: 2, barRods: [ BarChartRodData( toY: consumedValues[2] / recommendedValues[2] * 100, - color: checkConsumedValues( - [recommendedValues[2]], [consumedValues[2]]) - ? Colors.red - : Colors.blue, + color: checkConsumedValues([recommendedValues[2]], [consumedValues[2]]) ? Colors.red : Colors.blue, ) ]), BarChartGroupData(x: 3, barRods: [ BarChartRodData( toY: consumedValues[3] / recommendedValues[3] * 100, - color: checkConsumedValues( - [recommendedValues[3]], [consumedValues[3]]) - ? Colors.red - : Colors.blue, + color: checkConsumedValues([recommendedValues[3]], [consumedValues[3]]) ? Colors.red : Colors.blue, ) ]), ], @@ -1063,9 +1005,7 @@ class DiaryEditScreen extends StatelessWidget { r"Подъем \ отход ко сну", style: CustomTextStyles.bodyMediumBlack900, ), - Icon(state.wakeupExpanded - ? Icons.arrow_drop_up - : Icons.arrow_drop_down), + Icon(state.wakeupExpanded ? Icons.arrow_drop_up : Icons.arrow_drop_down), ], ), ), @@ -1079,8 +1019,7 @@ class DiaryEditScreen extends StatelessWidget { onTap: () => _selectWakeupTime(context, state), child: AbsorbPointer( child: CustomTextFormField( - hintText: - state.wakeupController?.format(context).toString(), + hintText: state.wakeupController?.format(context).toString(), prefix: Icon(Icons.sunny), autofocus: false, ), @@ -1091,8 +1030,7 @@ class DiaryEditScreen extends StatelessWidget { onTap: () => _selectRetireTime(context, state), child: AbsorbPointer( child: CustomTextFormField( - hintText: - state.retireController?.format(context).toString(), + hintText: state.retireController?.format(context).toString(), prefix: Icon(Icons.bed), autofocus: false, ), @@ -1139,8 +1077,7 @@ class DiaryEditScreen extends StatelessWidget { }; } - Function() sendFinishDayData( - BuildContext dialogContext, BuildContext context) { + Function() sendFinishDayData(BuildContext dialogContext, BuildContext context) { return () { closeDialog(dialogContext); context.read().add(FinishDay()); @@ -1182,9 +1119,7 @@ class DiaryEditScreen extends StatelessWidget { "Ваше настроение после приема пищи", style: CustomTextStyles.bodyMediumBlack900, ), - Icon(state.moodExpanded - ? Icons.arrow_drop_up - : Icons.arrow_drop_down), + Icon(state.moodExpanded ? Icons.arrow_drop_up : Icons.arrow_drop_down), ], ), ), @@ -1242,8 +1177,7 @@ class DiaryEditScreen extends StatelessWidget { }; } - Future _selectWakeupTime( - BuildContext context, DiaryEditLoadedState state) async { + Future _selectWakeupTime(BuildContext context, DiaryEditLoadedState state) async { final TimeOfDay? pickedTime = await showTimePicker( context: context, initialTime: state.wakeupController ?? TimeOfDay.now(), @@ -1254,8 +1188,7 @@ class DiaryEditScreen extends StatelessWidget { } } - Future _selectRetireTime( - BuildContext context, DiaryEditLoadedState state) async { + Future _selectRetireTime(BuildContext context, DiaryEditLoadedState state) async { final TimeOfDay? pickedTime = await showTimePicker( context: context, initialTime: state.retireController ?? TimeOfDay.now(), @@ -1266,8 +1199,7 @@ class DiaryEditScreen extends StatelessWidget { } } - Future _selectMealTime( - BuildContext context, DiaryEditLoadedState state) async { + Future _selectMealTime(BuildContext context, DiaryEditLoadedState state) async { final TimeOfDay? pickedTime = await showTimePicker( context: context, initialTime: state.mealTimeController ?? TimeOfDay.now(), @@ -1279,8 +1211,7 @@ class DiaryEditScreen extends StatelessWidget { } } -bool checkConsumedValues( - List recommendedValues, List consumedValues) { +bool checkConsumedValues(List recommendedValues, List consumedValues) { for (int i = 0; i < recommendedValues.length; i++) { if (consumedValues[i] > recommendedValues[i]) { // Если хотя бы одно потребленное значение превышает рекомендованное diff --git a/lib/presentation/feed/feed_screen/feed_screen.dart b/lib/presentation/feed/feed_screen/feed_screen.dart index d5d2500..12c0065 100644 --- a/lib/presentation/feed/feed_screen/feed_screen.dart +++ b/lib/presentation/feed/feed_screen/feed_screen.dart @@ -12,10 +12,7 @@ import 'package:intl/intl.dart'; class FeedScreen extends StatelessWidget { static Widget builder(BuildContext context) { - return BlocProvider( - create: (context) => FeedBloc(FeedState(myProfileModelObj: FeedModel())) - ..add(FeedInitialEvent()), - child: FeedScreen()); + return BlocProvider(create: (context) => FeedBloc(FeedState(myProfileModelObj: FeedModel()))..add(FeedInitialEvent()), child: FeedScreen()); } Widget build(BuildContext context) { @@ -64,7 +61,6 @@ class FeedScreen extends StatelessWidget { ), ), ), - bottomNavigationBar: _buildBottomBar(context), ), ); } @@ -154,8 +150,7 @@ class FeedScreen extends StatelessWidget { child: Column(children: [ ListTile( leading: CachedNetworkImage( - imageUrl: dotenv.env['STORAGE_URL']! + - (post["author"]['profile_photo_path'] ?? ''), + imageUrl: dotenv.env['STORAGE_URL']! + (post["author"]['profile_photo_path'] ?? ''), imageBuilder: (context, imageProvider) => CircleAvatar( backgroundImage: imageProvider, radius: 25, @@ -172,8 +167,7 @@ class FeedScreen extends StatelessWidget { style: CustomTextStyles.titleMediumSemiBold, ), subtitle: Text( - DateFormat('dd.MM.yyyy') - .format(DateTime.parse(post?['post']['updated_at'])), + DateFormat('dd.MM.yyyy').format(DateTime.parse(post?['post']['updated_at'])), style: theme.textTheme.bodyMedium, ), onTap: () => Navigator.pushNamed( @@ -220,13 +214,11 @@ class FeedScreen extends StatelessWidget { ), SizedBox(height: 16.0), CachedNetworkImage( - imageUrl: dotenv.env['STORAGE_URL']! + - (post?['post']['image'] ?? ''), + imageUrl: dotenv.env['STORAGE_URL']! + (post?['post']['image'] ?? ''), imageBuilder: (context, imageProvider) => Stack( children: [ ClipRRect( - borderRadius: - const BorderRadius.all(Radius.circular(8.0)), + borderRadius: const BorderRadius.all(Radius.circular(8.0)), child: Image( image: imageProvider, ), 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 5d1f9bf..d6fe53b 100644 --- a/lib/presentation/profile/my_profile_screen/my_profile_screen.dart +++ b/lib/presentation/profile/my_profile_screen/my_profile_screen.dart @@ -1,3 +1,5 @@ +import 'package:eatvio_app/widgets/app_bar/custom_app_bar.dart'; + import 'bloc/my_profile_bloc.dart'; import 'models/my_profile_model.dart'; import 'package:eatvio_app/core/app_export.dart'; @@ -19,10 +21,13 @@ import 'dart:convert'; class MyProfileScreen extends StatelessWidget { static Widget builder(BuildContext context) { return BlocProvider( - create: (context) => - MyProfileBloc(MyProfileState(myProfileModelObj: MyProfileModel())) - ..add(MyProfileInitialEvent()), - child: MyProfileScreen()); + create: (context) => MyProfileBloc( + MyProfileState( + myProfileModelObj: MyProfileModel(), + ), + )..add(MyProfileInitialEvent()), + child: MyProfileScreen(), + ); } Widget build(BuildContext context) { @@ -50,103 +55,100 @@ class MyProfileScreen extends StatelessWidget { _buildMyProfileScreen(BuildContext context, MyProfileLoadedState state) { mediaQueryData = MediaQuery.of(context); - return SafeArea( - child: Scaffold( - backgroundColor: Colors.grey[200], - resizeToAvoidBottomInset: true, - body: SingleChildScrollView( - child: Container( - width: double.maxFinite, - decoration: BoxDecoration(color: Colors.grey[200]), - child: Padding( - padding: EdgeInsets.all(16), - child: Column(children: [ - SizedBox(height: 30.v), - Container( - padding: EdgeInsets.symmetric( - horizontal: 24.h, - vertical: 12.v, - ), - 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: _buildInfo(context, state)), - SizedBox(height: 15.v), - Container( - padding: EdgeInsets.symmetric( - horizontal: 24.h, - vertical: 12.v, - ), - 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: _buildCarousel(context, state)), - SizedBox(height: 15.v), - if (!state.plans!.isEmpty) - Container( - padding: EdgeInsets.symmetric( - horizontal: 24.h, - vertical: 12.v, - ), - 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: _buildPlans( - context, - state.plans - ?.map((plan) => plan['name']) - .toList(), - state.plans - ?.map((plan) => plan['image']) - .toList(), - state.plans - ?.map((plan) => plan['state']) - .toList(), - )), - SizedBox(height: 5.v), - ])))), - bottomNavigationBar: _buildBottomBar(context))); + return Scaffold( + appBar: CustomAppBar( + height: 0, + ), + backgroundColor: Colors.grey[200], + resizeToAvoidBottomInset: true, + body: SingleChildScrollView( + child: Container( + width: double.maxFinite, + decoration: BoxDecoration(color: Colors.grey[200]), + child: Padding( + padding: EdgeInsets.all(16), + child: Column( + children: [ + SizedBox(height: 30.v), + Container( + padding: EdgeInsets.symmetric( + horizontal: 24.h, + vertical: 12.v, + ), + 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: _buildInfo(context, state)), + SizedBox(height: 15.v), + Container( + padding: EdgeInsets.symmetric( + horizontal: 24.h, + vertical: 12.v, + ), + 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: _buildCarousel(context, state)), + SizedBox(height: 15.v), + if (!state.plans!.isEmpty) + Container( + padding: EdgeInsets.symmetric( + horizontal: 24.h, + vertical: 12.v, + ), + 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: _buildPlans( + context, + state.plans?.map((plan) => plan['name']).toList(), + state.plans?.map((plan) => plan['image']).toList(), + state.plans?.map((plan) => plan['state']).toList(), + )), + SizedBox(height: 5.v), + ], + ), + ), + ), + ), + ); } /// Section Widget - _buildInfo(BuildContext context, MyProfileLoadedState state) { + Widget _buildInfo(BuildContext context, MyProfileLoadedState state) { return Column( children: [ GestureDetector( onTap: () => addImage(context), child: CachedNetworkImage( - imageUrl: dotenv.env['STORAGE_URL']! + - (state.user?['profile_photo_path'] ?? ''), + imageUrl: dotenv.env['STORAGE_URL']! + (state.user?['profile_photo_path'] ?? ''), imageBuilder: (context, imageProvider) => CircleAvatar( backgroundImage: imageProvider, radius: 60, @@ -208,12 +210,7 @@ class MyProfileScreen extends StatelessWidget { SizedBox(height: 50.v), _buildChart( context, - state.chartPoints?.values - .map((e) => e['weight']) - .toList() - .map((i) => i.toDouble()) - .toList() ?? - [0.0, 0.0, 0.0, 0.0], + state.chartPoints?.values.map((e) => e['weight']).toList().map((i) => i.toDouble()).toList() ?? [0.0, 0.0, 0.0, 0.0], state.chartDates, ) ])); @@ -228,13 +225,7 @@ class MyProfileScreen extends StatelessWidget { SizedBox(height: 50.v), _buildChart( context, - _bodyMassIndex( - state.chartPoints?.values - .map((e) => e['weight']) - .toList() - .map((i) => i.toDouble()) - .toList() ?? - [0.0, 0.0, 0.0, 0.0], + _bodyMassIndex(state.chartPoints?.values.map((e) => e['weight']).toList().map((i) => i.toDouble()).toList() ?? [0.0, 0.0, 0.0, 0.0], state.userDetails?['height'].toInt() ?? 160), state.chartDates), ]); @@ -249,8 +240,7 @@ class MyProfileScreen extends StatelessWidget { ), ), SizedBox(height: 30.v), - _buildCircumferenceChart( - context, state.circumferences, state.chartDates), + _buildCircumferenceChart(context, state.circumferences, state.chartDates), _buildChartLegend() ])); default: @@ -294,8 +284,7 @@ class MyProfileScreen extends StatelessWidget { ); } - _buildChart( - BuildContext context, List chartPoints, List? dates) { + _buildChart(BuildContext context, List chartPoints, List? dates) { List spots = []; for (int i = 0; i < 4; i++) { spots.add( @@ -303,8 +292,7 @@ class MyProfileScreen extends StatelessWidget { ); } - Widget bottomTitleWidgets( - double value, TitleMeta meta, double chartWidth, List? dates) { + Widget bottomTitleWidgets(double value, TitleMeta meta, double chartWidth, List? dates) { if (value % 1 != 0) { return Container(); } @@ -316,8 +304,7 @@ class MyProfileScreen extends StatelessWidget { int index = value.toInt(); if (index >= 0 && index < dates!.length) { // Проверка на допустимый индекс в массиве dates - String formattedDate = - DateFormat('dd.MM').format(DateTime.parse(dates[index])); + String formattedDate = DateFormat('dd.MM').format(DateTime.parse(dates[index])); return SideTitleWidget( axisSide: meta.axisSide, space: 16, @@ -374,18 +361,15 @@ class MyProfileScreen extends StatelessWidget { dotData: const FlDotData(show: false), ), ], - minY: chartPoints.reduce( - (value, element) => value < element ? value : element), - maxY: chartPoints.reduce( - (value, element) => value > element ? value : element), + minY: chartPoints.reduce((value, element) => value < element ? value : element), + maxY: chartPoints.reduce((value, element) => value > element ? value : element), minX: 1, maxX: 4, titlesData: FlTitlesData( leftTitles: AxisTitles( sideTitles: SideTitles( showTitles: true, - getTitlesWidget: (value, meta) => - leftTitleWidgets(value, meta, constraints.maxWidth), + getTitlesWidget: (value, meta) => leftTitleWidgets(value, meta, constraints.maxWidth), reservedSize: 56, ), drawBelowEverything: true, @@ -396,8 +380,7 @@ class MyProfileScreen extends StatelessWidget { bottomTitles: AxisTitles( sideTitles: SideTitles( showTitles: true, - getTitlesWidget: (value, meta) => bottomTitleWidgets( - value, meta, constraints.maxWidth, dates), + getTitlesWidget: (value, meta) => bottomTitleWidgets(value, meta, constraints.maxWidth, dates), reservedSize: 36, interval: 1, ), @@ -457,11 +440,9 @@ class MyProfileScreen extends StatelessWidget { }; } - _buildCircumferenceChart( - BuildContext context, chartPoints, List? dates) { + _buildCircumferenceChart(BuildContext context, chartPoints, List? dates) { // Определение осей графика - final chestCircumferences = - chartPoints.values.map((e) => e['chest_circumference']).toList(); + final chestCircumferences = chartPoints.values.map((e) => e['chest_circumference']).toList(); List spotsChest = []; for (int i = 0; i < 4; i++) { chestCircumferences[i] = chestCircumferences[i] * 10 / 10; @@ -469,8 +450,7 @@ class MyProfileScreen extends StatelessWidget { FlSpot((i * 10 / 10) + 1, chestCircumferences[i] * 10 / 10), ); } - final waistCircumferences = - chartPoints.values.map((e) => e['waist_circumference']).toList(); + final waistCircumferences = chartPoints.values.map((e) => e['waist_circumference']).toList(); List spotsWaist = []; for (int i = 0; i < 4; i++) { waistCircumferences[i] = waistCircumferences[i] * 10 / 10; @@ -478,8 +458,7 @@ class MyProfileScreen extends StatelessWidget { FlSpot((i * 10 / 10) + 1, waistCircumferences[i] * 10 / 10), ); } - final hipCircumferences = - chartPoints.values.map((e) => e['hip_circumference']).toList(); + final hipCircumferences = chartPoints.values.map((e) => e['hip_circumference']).toList(); List spotsHip = []; for (int i = 0; i < 4; i++) { hipCircumferences[i] = hipCircumferences[i] * 10 / 10; @@ -488,14 +467,9 @@ class MyProfileScreen extends StatelessWidget { ); } - final allCircumferences = [ - ...chestCircumferences, - ...hipCircumferences, - ...waistCircumferences - ]; + final allCircumferences = [...chestCircumferences, ...hipCircumferences, ...waistCircumferences]; - Widget bottomTitleWidgets( - double value, TitleMeta meta, double chartWidth, List? dates) { + Widget bottomTitleWidgets(double value, TitleMeta meta, double chartWidth, List? dates) { if (value % 1 != 0) { return Container(); } @@ -507,8 +481,7 @@ class MyProfileScreen extends StatelessWidget { int index = value.toInt(); if (index >= 0 && index < dates!.length) { // Проверка на допустимый индекс в массиве dates - String formattedDate = - DateFormat('dd.MM').format(DateTime.parse(dates[index])); + String formattedDate = DateFormat('dd.MM').format(DateTime.parse(dates[index])); return SideTitleWidget( axisSide: meta.axisSide, space: 16, @@ -587,18 +560,15 @@ class MyProfileScreen extends StatelessWidget { dotData: const FlDotData(show: false), ), ], - minY: allCircumferences.reduce( - (value, element) => value < element ? value : element), - maxY: allCircumferences.reduce( - (value, element) => value > element ? value : element), + minY: allCircumferences.reduce((value, element) => value < element ? value : element), + maxY: allCircumferences.reduce((value, element) => value > element ? value : element), minX: 1, maxX: 4, titlesData: FlTitlesData( leftTitles: AxisTitles( sideTitles: SideTitles( showTitles: true, - getTitlesWidget: (value, meta) => - leftTitleWidgets(value, meta, constraints.maxWidth), + getTitlesWidget: (value, meta) => leftTitleWidgets(value, meta, constraints.maxWidth), reservedSize: 56, ), drawBelowEverything: true, @@ -609,8 +579,7 @@ class MyProfileScreen extends StatelessWidget { bottomTitles: AxisTitles( sideTitles: SideTitles( showTitles: true, - getTitlesWidget: (value, meta) => bottomTitleWidgets( - value, meta, constraints.maxWidth, dates), + getTitlesWidget: (value, meta) => bottomTitleWidgets(value, meta, constraints.maxWidth, dates), reservedSize: 36, interval: 1, ), @@ -665,125 +634,80 @@ class MyProfileScreen extends StatelessWidget { } /// Section Widget - _buildPlans(BuildContext context, List? plans, - List? imagePaths, List? states) { + _buildPlans(BuildContext context, List? plans, List? imagePaths, List? states) { return Padding( padding: EdgeInsets.only(left: 7.h), child: Column(children: [ Padding( padding: EdgeInsets.only(left: 15.h), - child: Text("plans_complete".tr, - style: CustomTextStyles.titleMediumBlack - .copyWith(color: appTheme.black900))), + child: Text("plans_complete".tr, style: CustomTextStyles.titleMediumBlack.copyWith(color: appTheme.black900))), SizedBox(height: 5.v), Container( - decoration: AppDecoration.outlineBlueGray - .copyWith(borderRadius: BorderRadiusStyle.roundedBorder5), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - SizedBox( - height: 105.v, - width: 343.h, - child: - Stack(alignment: Alignment.bottomCenter, children: [ - Align( - alignment: Alignment.topCenter, - child: ListView.builder( - itemCount: plans?.length ?? 0, - itemBuilder: (context, i) { - String state = states?[i]; - var boxColor = appTheme.greenA700; - switch (states?[i]) { - case 'active': - boxColor = appTheme.greenA700; - break; - case 'archived': // График ИМТ - boxColor = appTheme.gray400; - break; - case 'draft': - boxColor = appTheme.deepOrange900; - break; - case 'in_progress': //График обхватов - boxColor = appTheme.lightGreen300; - break; - } - return SizedBox( - height: 40.v, - width: 343.h, - child: Stack( - alignment: Alignment.bottomRight, - children: [ - Align( - alignment: - Alignment.topCenter, - child: Container( - margin: EdgeInsets.only( - bottom: 11.v), - padding: - EdgeInsets.symmetric( - horizontal: 6.h, - vertical: 4.v), - decoration: AppDecoration - .fillGray - .copyWith( - borderRadius: - BorderRadiusStyle - .roundedBorder5), - child: Row( - mainAxisAlignment: - MainAxisAlignment - .spaceBetween, - children: [ - Padding( - padding: EdgeInsets - .only( - bottom: 1 - .v), - child: Text( - plans![i], - style: CustomTextStyles - .titleSmallBluegray800Bold)), - Container( - height: 19.v, - width: 100.h, - decoration: BoxDecoration( - color: - boxColor, - borderRadius: - BorderRadius.circular( - 5.h))) - ]))), - Align( - alignment: Alignment.center, - child: Container( - margin: EdgeInsets.only( - bottom: 12.h), - child: Image.network( - dotenv.env[ - 'STORAGE_URL']! + - imagePaths?[i], - height: 25.adaptSize, - width: 25.adaptSize, - ))), - Align( - alignment: - Alignment.bottomRight, - child: Container( - width: 70.h, - margin: EdgeInsets.only( - bottom: 14.h, - right: 22.h), - child: Text("$state".tr, - maxLines: 3, - overflow: TextOverflow - .ellipsis, - style: theme.textTheme - .titleSmall))) - ])); - })), - ])) - ])) + decoration: AppDecoration.outlineBlueGray.copyWith(borderRadius: BorderRadiusStyle.roundedBorder5), + child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ + SizedBox( + height: 105.v, + width: 343.h, + child: Stack(alignment: Alignment.bottomCenter, children: [ + Align( + alignment: Alignment.topCenter, + child: ListView.builder( + itemCount: plans?.length ?? 0, + itemBuilder: (context, i) { + String state = states?[i]; + var boxColor = appTheme.greenA700; + switch (states?[i]) { + case 'active': + boxColor = appTheme.greenA700; + break; + case 'archived': // График ИМТ + boxColor = appTheme.gray400; + break; + case 'draft': + boxColor = appTheme.deepOrange900; + break; + case 'in_progress': //График обхватов + boxColor = appTheme.lightGreen300; + break; + } + return SizedBox( + height: 40.v, + width: 343.h, + child: Stack(alignment: Alignment.bottomRight, children: [ + Align( + alignment: Alignment.topCenter, + child: Container( + margin: EdgeInsets.only(bottom: 11.v), + padding: EdgeInsets.symmetric(horizontal: 6.h, vertical: 4.v), + decoration: AppDecoration.fillGray.copyWith(borderRadius: BorderRadiusStyle.roundedBorder5), + child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ + Padding( + padding: EdgeInsets.only(bottom: 1.v), + child: Text(plans![i], style: CustomTextStyles.titleSmallBluegray800Bold)), + Container( + height: 19.v, + width: 100.h, + decoration: BoxDecoration(color: boxColor, borderRadius: BorderRadius.circular(5.h))) + ]))), + Align( + alignment: Alignment.center, + child: Container( + margin: EdgeInsets.only(bottom: 12.h), + child: Image.network( + dotenv.env['STORAGE_URL']! + imagePaths?[i], + height: 25.adaptSize, + width: 25.adaptSize, + ))), + Align( + alignment: Alignment.bottomRight, + child: Container( + width: 70.h, + margin: EdgeInsets.only(bottom: 14.h, right: 22.h), + child: Text("$state".tr, maxLines: 3, overflow: TextOverflow.ellipsis, style: theme.textTheme.titleSmall))) + ])); + })), + ])) + ])) ])); } @@ -811,44 +735,38 @@ class MyProfileScreen extends StatelessWidget { children: [ Padding( padding: EdgeInsets.symmetric(vertical: 5.v), - child: Text("chest_circumference".tr, - style: theme.textTheme.bodyLarge), + child: Text("chest_circumference".tr, style: theme.textTheme.bodyLarge), ), SizedBox(height: 5.v), CustomTextFormField( controller: state.chestCircumferenceController, keyboardType: TextInputType.number, inputFormatters: [ - FilteringTextInputFormatter - .digitsOnly, // Ограничение ввода только цифрами + FilteringTextInputFormatter.digitsOnly, // Ограничение ввода только цифрами ], ), Padding( padding: EdgeInsets.symmetric(vertical: 15.v), - child: Text("waist_circumference".tr, - style: theme.textTheme.bodyLarge), + child: Text("waist_circumference".tr, style: theme.textTheme.bodyLarge), ), SizedBox(height: 5.v), CustomTextFormField( controller: state.waistCircumferenceController, keyboardType: TextInputType.number, inputFormatters: [ - FilteringTextInputFormatter - .digitsOnly, // Ограничение ввода только цифрами + FilteringTextInputFormatter.digitsOnly, // Ограничение ввода только цифрами ], ), Padding( padding: EdgeInsets.symmetric(vertical: 15.v), - child: Text("hip_circumference".tr, - style: theme.textTheme.bodyLarge), + child: Text("hip_circumference".tr, style: theme.textTheme.bodyLarge), ), SizedBox(height: 5.v), CustomTextFormField( controller: state.hipCircumferenceController, keyboardType: TextInputType.number, inputFormatters: [ - FilteringTextInputFormatter - .digitsOnly, // Ограничение ввода только цифрами + FilteringTextInputFormatter.digitsOnly, // Ограничение ввода только цифрами ], ), ], @@ -867,8 +785,7 @@ class MyProfileScreen extends StatelessWidget { ), ], backgroundColor: Colors.white, - titlePadding: EdgeInsets.all( - 20.0), // Можете настроить отступы по вашему желанию + titlePadding: EdgeInsets.all(20.0), // Можете настроить отступы по вашему желанию ); }, ); @@ -904,8 +821,7 @@ class MyProfileScreen extends StatelessWidget { ); } else { // Ошибка от сервера - print( - "Ошибка при отправке данных. Код ответа: ${response.statusCode}"); + print("Ошибка при отправке данных. Код ответа: ${response.statusCode}"); } } catch (e) { // Обработка ошибок при отправке запроса @@ -997,8 +913,7 @@ class MyProfileScreen extends StatelessWidget { ); } else { // Ошибка от сервера - print( - "Ошибка при отправке данных. Код ответа: ${response.statusCode}"); + print("Ошибка при отправке данных. Код ответа: ${response.statusCode}"); } } catch (e) { // Обработка ошибок при отправке запроса diff --git a/lib/widgets/app_bar/custom_app_bar.dart b/lib/widgets/app_bar/custom_app_bar.dart index 7ffe17b..0581170 100644 --- a/lib/widgets/app_bar/custom_app_bar.dart +++ b/lib/widgets/app_bar/custom_app_bar.dart @@ -1,5 +1,6 @@ import 'package:eatvio_app/core/app_export.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; // ignore: must_be_immutable class CustomAppBar extends StatelessWidget implements PreferredSizeWidget { @@ -30,7 +31,10 @@ class CustomAppBar extends StatelessWidget implements PreferredSizeWidget { @override Widget build(BuildContext context) { return AppBar( - elevation: 0, + systemOverlayStyle: SystemUiOverlayStyle( + statusBarIconBrightness: Brightness.dark, + statusBarBrightness: Brightness.light, + ), toolbarHeight: height ?? 56.v, automaticallyImplyLeading: false, backgroundColor: Colors.transparent, diff --git a/lib/widgets/custom_bottom_bar.dart b/lib/widgets/custom_bottom_bar.dart index d6e47d6..b8e5460 100644 --- a/lib/widgets/custom_bottom_bar.dart +++ b/lib/widgets/custom_bottom_bar.dart @@ -2,6 +2,106 @@ import 'package:eatvio_app/core/app_export.dart'; import 'package:flutter/material.dart'; import 'package:eatvio_app/widgets/app_bar/appbar_title_circleimage.dart'; import 'package:eatvio_app/widgets/custom_navigation_menu.dart'; +import 'package:flutter_svg/flutter_svg.dart'; +import 'package:go_router/go_router.dart'; + +int currentBottomNavBarIndex = 0; + +class BottomNavigationBarWidget extends StatefulWidget { + final Widget child; + + const BottomNavigationBarWidget({ + super.key, + required this.child, + }); + + @override + State createState() => _BottomNavigationBarWidgetState(); +} + +class _BottomNavigationBarWidgetState extends State { + @override + Widget build(BuildContext context) { + return Scaffold( + body: widget.child, + bottomNavigationBar: BottomNavigationBar( + type: BottomNavigationBarType.fixed, + onTap: (index) { + if (currentBottomNavBarIndex != index) { + setState(() { + currentBottomNavBarIndex = index; + }); + } + switch (currentBottomNavBarIndex) { + case 0: + GoRouter.of(context).replace('/my-profile-screen'); + break; + case 1: + GoRouter.of(context).replace('/feed-screen'); + break; + case 2: + GoRouter.of(context).replace('/diary-screen'); + break; + case 3: + GoRouter.of(context).replace('/chat-select-screen'); + break; + case 4: + break; + case 5: + final RenderBox overlay = Overlay.of(context).context.findRenderObject() as RenderBox; + final size = overlay.size; + showMenu( + context: context, + color: Colors.white, + shadowColor: Colors.white, + surfaceTintColor: Colors.white, + items: [ + PopupMenuItem( + child: CustomNavigationMenu(), + ) + ], + position: RelativeRect.fromLTRB(size.width, size.height, 0, 0), + ); + break; + } + }, + selectedFontSize: 12, + unselectedFontSize: 12, + currentIndex: currentBottomNavBarIndex, + items: [ + BottomNavigationBarItem( + label: '', + icon: SvgPicture.asset(ImageConstant.imgLogo), + ), + BottomNavigationBarItem( + label: 'Лента', + icon: SvgPicture.asset(ImageConstant.imgFeed), + ), + BottomNavigationBarItem( + label: "diary".tr, + icon: SvgPicture.asset(ImageConstant.imgDiary), + ), + BottomNavigationBarItem( + label: "chat".tr, + icon: SvgPicture.asset(ImageConstant.imgChat), + ), + BottomNavigationBarItem( + label: '', + icon: SvgPicture.asset(ImageConstant.imgBell), + ), + BottomNavigationBarItem( + label: '', + icon: Image.asset( + ImageConstant.imgEllipse1, + width: 32, + height: 32, + ), + ), + ], + ), + ); + } +} // ignore: must_be_immutable class CustomBottomBar extends StatefulWidget { @@ -18,33 +118,38 @@ class CustomBottomBarState extends State { List bottomMenuList = [ BottomMenuModel( - icon: ImageConstant.imgLogo, - activeIcon: ImageConstant.imgLogo, - type: BottomBarEnum.tf, - image: false), + icon: ImageConstant.imgLogo, + activeIcon: ImageConstant.imgLogo, + type: BottomBarEnum.tf, + image: false, + ), BottomMenuModel( - icon: ImageConstant.imgFeed, - activeIcon: ImageConstant.imgFeed, - title: "Лента", - type: BottomBarEnum.tf, - image: false), + icon: ImageConstant.imgFeed, + activeIcon: ImageConstant.imgFeed, + title: "Лента", + type: BottomBarEnum.tf, + image: false, + ), BottomMenuModel( - icon: ImageConstant.imgDiary, - activeIcon: ImageConstant.imgDiary, - title: "diary".tr, - type: BottomBarEnum.tf, - image: false), + icon: ImageConstant.imgDiary, + activeIcon: ImageConstant.imgDiary, + title: "diary".tr, + type: BottomBarEnum.tf, + image: false, + ), BottomMenuModel( - icon: ImageConstant.imgChat, - activeIcon: ImageConstant.imgChat, - title: "chat".tr, - type: BottomBarEnum.tf, - image: false), + icon: ImageConstant.imgChat, + activeIcon: ImageConstant.imgChat, + title: "chat".tr, + type: BottomBarEnum.tf, + image: false, + ), BottomMenuModel( - icon: ImageConstant.imgBell, - activeIcon: ImageConstant.imgBell, - type: BottomBarEnum.tf, - image: false), + icon: ImageConstant.imgBell, + activeIcon: ImageConstant.imgBell, + type: BottomBarEnum.tf, + image: false, + ), BottomMenuModel( icon: ImageConstant.imgEllipse1, activeIcon: ImageConstant.imgEllipse1, @@ -84,16 +189,16 @@ class CustomBottomBarState extends State { switch (index) { case 0: - Navigator.pushNamed(context, AppRoutes.myProfile); + Navigator.pushReplacementNamed(context, AppRoutes.myProfile); break; case 1: - Navigator.pushNamed(context, AppRoutes.feedScreen); + Navigator.pushReplacementNamed(context, AppRoutes.feedScreen); break; case 2: - Navigator.pushNamed(context, AppRoutes.diaryEdit); + Navigator.pushReplacementNamed(context, AppRoutes.diaryEdit); break; case 3: - Navigator.pushNamed(context, AppRoutes.chatSelectScreen); + Navigator.pushReplacementNamed(context, AppRoutes.chatSelectScreen); break; } } @@ -131,8 +236,7 @@ class CustomBottomBarState extends State { imagePath: bottomMenuList[index].icon, height: iconHeight, width: iconWidth, - color: - isSelected ? theme.colorScheme.primary : appTheme.blueGray400, + color: isSelected ? theme.colorScheme.primary : appTheme.blueGray400, ), if (bottomMenuList[index].image) GestureDetector( @@ -143,16 +247,14 @@ class CustomBottomBarState extends State { surfaceTintColor: Colors.white, position: RelativeRect.fromLTRB( // Указываем позицию справа по центру - MediaQuery.of(context).size.width - - 50, // Расположение от правого края + MediaQuery.of(context).size.width - 50, // Расположение от правого края kToolbarHeight + 340, // Расположение от верхнего края 0, // Не смещаем по горизонтали 0, // Не смещаем по вертикали ), items: [ PopupMenuItem( - child: - CustomNavigationMenu(), // Используйте ваше меню здесь + child: CustomNavigationMenu(), // Используйте ваше меню здесь ) ], ), @@ -160,16 +262,13 @@ class CustomBottomBarState extends State { imagePath: ImageConstant.imgEllipse1, ), ), - if (bottomMenuList[index].title != - null) // Проверяем, существует ли title + if (bottomMenuList[index].title != null) // Проверяем, существует ли title Padding( padding: EdgeInsets.only(top: 8.v), child: Text( bottomMenuList[index].title!, style: CustomTextStyles.bodySmallMulishBluegray80012.copyWith( - color: isSelected - ? theme.colorScheme.primary - : appTheme.blueGray800, + color: isSelected ? theme.colorScheme.primary : appTheme.blueGray800, ), ), ), diff --git a/pubspec.yaml b/pubspec.yaml index 8f1a6f4..26be607 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,8 +1,8 @@ name: eatvio_app description: A new Flutter project. version: 0.0.0+1 -environment: - sdk: '>=2.12.0 <3.0.0' +environment: + sdk: '>=3.3.4 <4.0.0' dependencies: flutter: sdk: flutter @@ -27,6 +27,8 @@ dependencies: image_picker: ^1.0.7 flutter_typeahead: ^5.2.0 bloc_test: ^9.1.6 + # navigation + go_router: ^14.1.4 dev_dependencies: dart_code_metrics: ^5.7.6 diff --git a/test/diary_test.dart b/test/diary_test.dart index 224b05a..c7570d3 100644 --- a/test/diary_test.dart +++ b/test/diary_test.dart @@ -16,10 +16,8 @@ void main() { ); });*/ - testWidgets('renders _buildDiaryEditScreen when in loaded state', - (WidgetTester tester) async { - final diaryEditBloc = - DiaryEditBloc(DiaryEditState(diaryEditModelObj: DiaryEditModel())); + testWidgets('renders _buildDiaryEditScreen when in loaded state', (WidgetTester tester) async { + final diaryEditBloc = DiaryEditBloc(DiaryEditState(diaryEditModelObj: DiaryEditModel())); final loadedState = DiaryEditLoadedState( diaryId: 1, selectedSatiety: 4, @@ -36,9 +34,7 @@ void main() { MaterialApp( home: BlocProvider.value( value: diaryEditBloc, - child: DiaryEditScreen( - onInitialize: () {}, - ), + child: DiaryEditScreen(), ), ), ); From ed0c3fcef1ffe3c343f2d610ba0f7d14020d4389 Mon Sep 17 00:00:00 2001 From: DmitriyLabutin Date: Tue, 4 Jun 2024 18:02:00 +0300 Subject: [PATCH 03/17] fix warnings --- .../chat/chat_select_screen/chat_select_screen.dart | 5 ----- .../diary/diary_edit_screen/diary_edit_screen.dart | 5 ----- lib/presentation/feed/feed_screen/feed_screen.dart | 5 ----- .../profile/my_profile_screen/my_profile_screen.dart | 5 ----- lib/theme/custom_button_style.dart | 4 ++-- 5 files changed, 2 insertions(+), 22 deletions(-) diff --git a/lib/presentation/chat/chat_select_screen/chat_select_screen.dart b/lib/presentation/chat/chat_select_screen/chat_select_screen.dart index 92bbfe8..e59e215 100644 --- a/lib/presentation/chat/chat_select_screen/chat_select_screen.dart +++ b/lib/presentation/chat/chat_select_screen/chat_select_screen.dart @@ -2,7 +2,6 @@ import 'bloc/chat_select_bloc.dart'; import 'models/chat_select_model.dart'; import 'package:eatvio_app/core/app_export.dart'; import '../chat_select_screen/chat_search_view.dart'; -import 'package:eatvio_app/widgets/custom_bottom_bar.dart'; import 'package:flutter/material.dart'; import 'package:eatvio_app/presentation/chat/chat_select_screen/models/chat_entry.dart'; // ignore: must_be_immutable import 'package:eatvio_app/presentation/chat/chat_select_screen/widgets/chat_entry_widget.dart'; // ignore: must_be_immutable @@ -104,7 +103,3 @@ _buildChatList(BuildContext context, ChatSelectLoadedState state) { }, ); } - -_buildBottomBar(BuildContext context) { - return CustomBottomBar(onChanged: (BottomBarEnum type) {}); -} diff --git a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart index 2aa53dd..3de4ff4 100644 --- a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart +++ b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart @@ -13,7 +13,6 @@ import 'package:eatvio_app/widgets/custom_edit_text_form_field.dart'; import 'package:eatvio_app/widgets/custom_edit_drop_down.dart'; import 'package:eatvio_app/widgets/custom_outlined_button.dart'; import 'package:eatvio_app/widgets/custom_scale_element.dart'; -import 'package:eatvio_app/widgets/custom_bottom_bar.dart'; import 'package:carousel_slider/carousel_slider.dart'; // ignore: must_be_immutable @@ -179,10 +178,6 @@ class DiaryEditScreen extends StatelessWidget { }; } - _buildBottomBar(BuildContext context) { - return CustomBottomBar(onChanged: (BottomBarEnum type) {}); - } - /// Section Widget _buildAddProduct(BuildContext context, DiaryEditLoadedState state) { return CustomOutlinedButton( diff --git a/lib/presentation/feed/feed_screen/feed_screen.dart b/lib/presentation/feed/feed_screen/feed_screen.dart index 12c0065..4e8be2c 100644 --- a/lib/presentation/feed/feed_screen/feed_screen.dart +++ b/lib/presentation/feed/feed_screen/feed_screen.dart @@ -3,7 +3,6 @@ import 'models/feed_model.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:eatvio_app/presentation/feed/feed_screen/widgets/feed_search_view.dart'; import 'package:eatvio_app/presentation/feed/feed_screen/widgets/feed_scroll_item.dart'; -import 'package:eatvio_app/widgets/custom_bottom_bar.dart'; import 'package:eatvio_app/widgets/custom_outlined_button.dart'; import 'package:eatvio_app/core/app_export.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; @@ -269,10 +268,6 @@ class FeedScreen extends StatelessWidget { }; } - _buildBottomBar(BuildContext context) { - return CustomBottomBar(onChanged: (BottomBarEnum type) {}); - } - onTapArrowLeft(BuildContext context) { NavigatorService.goBack(); } 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 d6fe53b..3bfb6cc 100644 --- a/lib/presentation/profile/my_profile_screen/my_profile_screen.dart +++ b/lib/presentation/profile/my_profile_screen/my_profile_screen.dart @@ -4,7 +4,6 @@ import 'bloc/my_profile_bloc.dart'; import 'models/my_profile_model.dart'; import 'package:eatvio_app/core/app_export.dart'; import 'package:eatvio_app/widgets/app_bar/appbar_subtitle.dart'; -import 'package:eatvio_app/widgets/custom_bottom_bar.dart'; import 'package:eatvio_app/widgets/custom_text_form_field.dart'; import 'package:carousel_slider/carousel_slider.dart'; import 'package:image_picker/image_picker.dart'; @@ -186,10 +185,6 @@ class MyProfileScreen extends StatelessWidget { }; } - _buildBottomBar(BuildContext context) { - return CustomBottomBar(onChanged: (BottomBarEnum type) {}); - } - _buildCarousel(BuildContext contex, MyProfileLoadedState state) { return CarouselSlider( options: CarouselOptions(height: 320.0), diff --git a/lib/theme/custom_button_style.dart b/lib/theme/custom_button_style.dart index bdd84d9..60204f5 100644 --- a/lib/theme/custom_button_style.dart +++ b/lib/theme/custom_button_style.dart @@ -16,7 +16,7 @@ class CustomButtonStyles { ); // text button style static ButtonStyle get none => ButtonStyle( - backgroundColor: MaterialStateProperty.all(Colors.transparent), - elevation: MaterialStateProperty.all(0), + backgroundColor: WidgetStateProperty.all(Colors.transparent), + elevation: WidgetStateProperty.all(0), ); } From 1951edd8f832a2a2a8332fc109b0c2940df4f049 Mon Sep 17 00:00:00 2001 From: mso7nueh Date: Wed, 5 Jun 2024 12:52:03 +0300 Subject: [PATCH 04/17] go router --- .gitea/workflows/build.yml | 2 +- .gitea/workflows/test.yml | 2 +- lib/app_router.dart | 72 ++++- .../auth/auth_screen/auth_screen.dart | 9 +- .../chat/chat_screen/chat_screen.dart | 13 - .../diary_edit_screen/diary_edit_screen.dart | 24 +- .../diet_create_screen.dart | 101 ++++--- .../diet_edit_screen/diet_edit_screen.dart | 88 +++---- .../diet_select_screen.dart | 126 +++++---- .../diet_show_screen/diet_show_screen.dart | 156 +++++------ .../blog_post_create_screen.dart | 154 +++++------ .../blog_post_edit_screen.dart | 90 ++++--- .../blog_post_screen/blog_post_screen.dart | 101 +++---- .../feed/feed_screen/feed_screen.dart | 14 +- .../glossary_screen/glossary_screen.dart | 73 ++--- .../plan_create_screen.dart | 107 ++++---- .../plan_edit_screen/plan_edit_screen.dart | 88 +++---- .../plan_select_screen.dart | 126 +++++---- .../plan_show_screen/plan_show_screen.dart | 155 +++++------ .../my_profile_screen/my_settings_screen.dart | 246 ++++++++--------- .../recipe_create_screen.dart | 55 ++-- .../recipe_edit_screen.dart | 88 +++---- .../recipe_select_screen.dart | 126 +++++---- .../recipe_show_screen.dart | 151 +++++------ .../language_select_screen.dart | 169 ++++++------ lib/routes/app_routes.dart | 4 +- lib/widgets/custom_bottom_bar.dart | 249 ++---------------- lib/widgets/custom_navigation_menu.dart | 19 +- 28 files changed, 1160 insertions(+), 1448 deletions(-) diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index e8f9d11..4a2d90f 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -3,7 +3,7 @@ name: Android Release on: [push, pull_request] env: - flutter_version: "3.19.0" + flutter_version: "3.22.0" java_version: "12.x" flutter_channel: "stable" diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index b5f7524..27c7c43 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -3,7 +3,7 @@ name: Eatvio App Android Test on: [pull_request] env: - flutter_version: "3.19.0" + flutter_version: "3.22.0" java_version: "12.x" flutter_channel: "stable" diff --git a/lib/app_router.dart b/lib/app_router.dart index b586965..255df7a 100644 --- a/lib/app_router.dart +++ b/lib/app_router.dart @@ -1,14 +1,44 @@ +import 'package:eatvio_app/presentation/auth/auth_screen/auth_screen.dart'; import 'package:eatvio_app/presentation/chat/chat_select_screen/chat_select_screen.dart'; import 'package:eatvio_app/presentation/diary/diary_edit_screen/diary_edit_screen.dart'; +import 'package:eatvio_app/presentation/diets/diet_select_screen/diet_select_screen.dart'; +import 'package:eatvio_app/presentation/feed/blog_post_create_screen/blog_post_create_screen.dart'; +import 'package:eatvio_app/presentation/feed/blog_post_screen/blog_post_screen.dart'; import 'package:eatvio_app/presentation/feed/feed_screen/feed_screen.dart'; +import 'package:eatvio_app/presentation/glossary/glossary_screen/glossary_screen.dart'; +import 'package:eatvio_app/presentation/plans/plan_select_screen/plan_select_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/recipe/recipe_select_screen/recipe_select_screen.dart'; +import 'package:eatvio_app/presentation/registration/language_select_screen/language_select_screen.dart'; import 'package:eatvio_app/widgets/custom_bottom_bar.dart'; import 'package:go_router/go_router.dart'; +import 'package:hive_flutter/hive_flutter.dart'; class AppRouter { static GoRouter appRouter = GoRouter( - initialLocation: '/my-profile-screen', + initialLocation: '/auth-screen', routes: [ + GoRoute( + path: '/auth-screen', + name: 'authScreen', + redirect: (context, state) async { + final box = await Hive.openBox('token'); + final token = box.get('token'); + if (token != null) { + return '/my-profile-screen'; + } + return null; + }, + builder: (context, state) => AuthScreen.builder(context), + routes: [ + GoRoute( + path: 'language-select-screen', + name: 'languageSelectScreen', + builder: (context, state) => LanguageSelectScreen.builder(context), + ), + ], + ), ShellRoute( builder: (context, state, child) { return BottomNavigationBarWidget(child: child); @@ -23,6 +53,21 @@ class AppRouter { path: '/feed-screen', name: 'feedScreen', builder: (context, state) => FeedScreen(), + routes: [ + GoRoute( + path: 'blog-post-create-screen', + name: 'blogPostCreateScreen', + builder: (context, state) => BlogPostCreateScreen.builder(context), + ), + GoRoute( + path: 'blog-post-screen', + name: 'blogPostScreen', + builder: (context, state) => BlogPostScreen.builder( + context, + state.extra.toString(), + ), + ), + ], ), GoRoute( path: '/diary-screen', @@ -36,6 +81,31 @@ class AppRouter { ), ], ), + GoRoute( + path: '/my-settings-screen', + name: 'mySettingsScreen', + builder: (context, state) => MySettingsScreen.builder(context), + ), + GoRoute( + path: '/recipe-select-screen', + name: 'recipeSelectScreen', + builder: (context, state) => RecipeSelectScreen.builder(context), + ), + GoRoute( + path: '/diet-select-screen', + name: 'dietSelectScreen', + builder: (context, state) => DietSelectScreen.builder(context), + ), + GoRoute( + path: '/plan-select-screen', + name: 'planSelectScreen', + builder: (context, state) => PlanSelectScreen.builder(context), + ), + GoRoute( + path: '/glossary-screen', + name: 'glossaryScreen', + builder: (context, state) => GlossaryScreen.builder(context), + ), ], ); } diff --git a/lib/presentation/auth/auth_screen/auth_screen.dart b/lib/presentation/auth/auth_screen/auth_screen.dart index 558d565..ff4408d 100644 --- a/lib/presentation/auth/auth_screen/auth_screen.dart +++ b/lib/presentation/auth/auth_screen/auth_screen.dart @@ -1,3 +1,5 @@ +import 'package:go_router/go_router.dart'; + import 'bloc/auth_bloc.dart'; import 'models/auth_model.dart'; import 'package:eatvio_app/core/app_export.dart'; @@ -101,10 +103,7 @@ class AuthScreen extends StatelessWidget { final box = await Hive.openBox('token'); final token = res['token']; box.put('token', token); - Navigator.pushNamed( - context, - AppRoutes.myProfile, - ); + GoRouter.of(context).go('/my-profile-screen'); } else { showDialog( context: context, @@ -164,7 +163,7 @@ class AuthScreen extends StatelessWidget { onTapNoAccount(BuildContext context) { return () { - Navigator.pushNamed(context, AppRoutes.languageSelectScreen); + GoRouter.of(context).goNamed('languageSelectScreen'); }; } diff --git a/lib/presentation/chat/chat_screen/chat_screen.dart b/lib/presentation/chat/chat_screen/chat_screen.dart index 37c3df5..a132f88 100644 --- a/lib/presentation/chat/chat_screen/chat_screen.dart +++ b/lib/presentation/chat/chat_screen/chat_screen.dart @@ -59,7 +59,6 @@ class ChatScreen extends StatelessWidget { ), ), ), - bottomNavigationBar: _buildTextField(context), ); } @@ -160,18 +159,6 @@ class ChatScreen extends StatelessWidget { ); } - /// Common widget - - ///Handling route based on bottom click actions - String getCurrentRoute(BottomBarEnum type) { - switch (type) { - case BottomBarEnum.tf: - return AppRoutes.chatScreen; - default: - return "/"; - } - } - ///Handling page based on route Widget getCurrentPage( BuildContext context, diff --git a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart index 3de4ff4..698d6e0 100644 --- a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart +++ b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart @@ -1,5 +1,7 @@ // ignore_for_file: unused_local_variable +import 'package:go_router/go_router.dart'; + import 'bloc/diary_edit_bloc.dart'; import 'models/diary_edit_model.dart'; import 'package:flutter/material.dart'; @@ -47,10 +49,10 @@ class DiaryEditScreen extends StatelessWidget { } Widget _buildDiaryEditScreen(BuildContext context, DiaryEditLoadedState state) { - mediaQueryData = MediaQuery.of(context); return RefreshIndicator( onRefresh: refreshPage(context), child: Stack( + alignment: Alignment.bottomCenter, children: [ FormBuilder( child: SafeArea( @@ -89,12 +91,7 @@ class DiaryEditScreen extends StatelessWidget { ), ), ), - Positioned( - left: 16.h, - right: 16.h, - bottom: 50.v, // Adjusted position to lift the button higher - child: _buildEndDay(context), - ), + _buildEndDay(context), ], ), ); @@ -106,7 +103,7 @@ class DiaryEditScreen extends StatelessWidget { margin: EdgeInsets.only( left: 16.h, right: 16.h, - bottom: 41.v, + bottom: 16.v, ), buttonStyle: CustomButtonStyles.outlinePrimaryTL15, decoration: BoxDecoration( @@ -147,7 +144,10 @@ class DiaryEditScreen extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - CustomImageView(imagePath: ImageConstant.imgArrowLeft, onTap: onTapBack()), + CustomImageView( + imagePath: ImageConstant.imgArrowLeft, + onTap: () => GoRouter.of(context).pop(), + ), Padding( padding: EdgeInsets.only(top: 1.v), child: Column( @@ -172,12 +172,6 @@ class DiaryEditScreen extends StatelessWidget { ); } - onTapBack() { - return () { - NavigatorService.goBack(); - }; - } - /// Section Widget _buildAddProduct(BuildContext context, DiaryEditLoadedState state) { return CustomOutlinedButton( diff --git a/lib/presentation/diets/diet_create_screen/diet_create_screen.dart b/lib/presentation/diets/diet_create_screen/diet_create_screen.dart index 6896701..eae238b 100644 --- a/lib/presentation/diets/diet_create_screen/diet_create_screen.dart +++ b/lib/presentation/diets/diet_create_screen/diet_create_screen.dart @@ -6,12 +6,11 @@ import 'package:eatvio_app/widgets/custom_bottom_bar.dart'; class DietCreateScreen extends StatelessWidget { const DietCreateScreen({Key? key}) : super(key: key); + static Widget builder(BuildContext context) { final dietID = ModalRoute.of(context)!.settings.arguments; return BlocProvider( - create: (context) => DietCreateBloc(DietCreateState( - dietModelObj: DietCreateModel(dietID: dietID.toString()))) - ..add(DietCreateInitialEvent()), + create: (context) => DietCreateBloc(DietCreateState(dietModelObj: DietCreateModel(dietID: dietID.toString())))..add(DietCreateInitialEvent()), child: DietCreateScreen()); } @@ -40,58 +39,54 @@ class DietCreateScreen extends StatelessWidget { _buildDietCreate(BuildContext context, DietCreateLoadedState state) { mediaQueryData = MediaQuery.of(context); return SafeArea( - child: Scaffold( - resizeToAvoidBottomInset: false, - body: Container( - width: double.maxFinite, - decoration: AppDecoration.fillGray, - child: ListView(children: [ - SizedBox(height: 30.v), - Container( - margin: EdgeInsets.only( - left: 16.h, - right: 20.h, - bottom: 10.h, + child: Scaffold( + resizeToAvoidBottomInset: false, + body: Container( + width: double.maxFinite, + decoration: AppDecoration.fillGray, + child: ListView(children: [ + SizedBox(height: 30.v), + Container( + margin: EdgeInsets.only( + left: 16.h, + right: 20.h, + bottom: 10.h, + ), + padding: EdgeInsets.all(12.h), + 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), ), - padding: EdgeInsets.all(12.h), - 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: Column(mainAxisSize: MainAxisSize.min, children: [ - SizedBox(height: 16.0), - TextFormField( - controller: state.name, - decoration: InputDecoration(labelText: 'Заголовок'), - ), - SizedBox(height: 16.0), - TextFormField( - controller: state.details, - decoration: InputDecoration(labelText: 'Описание'), - ), - SizedBox(height: 16.0), - // Здесь нужно добавить виджет для загрузки картинки - ElevatedButton( - onPressed: () => - context.read().add(CreateDiet()), - child: Text('Создать'), - ) - ]), + ], + ), + child: Column(mainAxisSize: MainAxisSize.min, children: [ + SizedBox(height: 16.0), + TextFormField( + controller: state.name, + decoration: InputDecoration(labelText: 'Заголовок'), + ), + SizedBox(height: 16.0), + TextFormField( + controller: state.details, + decoration: InputDecoration(labelText: 'Описание'), + ), + SizedBox(height: 16.0), + // Здесь нужно добавить виджет для загрузки картинки + ElevatedButton( + onPressed: () => context.read().add(CreateDiet()), + child: Text('Создать'), ) ]), - ), - bottomNavigationBar: _buildBottomBar(context))); + ) + ]), + ), + ), + ); } } - -_buildBottomBar(BuildContext context) { - return CustomBottomBar(onChanged: (BottomBarEnum type) {}); -} diff --git a/lib/presentation/diets/diet_edit_screen/diet_edit_screen.dart b/lib/presentation/diets/diet_edit_screen/diet_edit_screen.dart index 75f0281..665927b 100644 --- a/lib/presentation/diets/diet_edit_screen/diet_edit_screen.dart +++ b/lib/presentation/diets/diet_edit_screen/diet_edit_screen.dart @@ -8,12 +8,11 @@ import 'package:flutter_dotenv/flutter_dotenv.dart'; class DietEditScreen extends StatelessWidget { const DietEditScreen({Key? key}) : super(key: key); + static Widget builder(BuildContext context) { final dietID = ModalRoute.of(context)!.settings.arguments; return BlocProvider( - create: (context) => DietEditBloc(DietEditState( - dietModelObj: DietEditModel(dietID: dietID.toString()))) - ..add(DietEditInitialEvent()), + create: (context) => DietEditBloc(DietEditState(dietModelObj: DietEditModel(dietID: dietID.toString())))..add(DietEditInitialEvent()), child: DietEditScreen()); } @@ -42,42 +41,43 @@ class DietEditScreen extends StatelessWidget { _buildDietEdit(BuildContext context, DietEditLoadedState state) { mediaQueryData = MediaQuery.of(context); return SafeArea( - child: Scaffold( - resizeToAvoidBottomInset: false, - body: Container( - width: double.maxFinite, - decoration: AppDecoration.fillGray, - child: ListView(children: [ - SizedBox(height: 30.v), - Container( - margin: EdgeInsets.only( - left: 16.h, - right: 20.h, - bottom: 10.h, - ), - padding: EdgeInsets.all(12.h), - 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: Column(mainAxisSize: MainAxisSize.min, children: [ + child: Scaffold( + resizeToAvoidBottomInset: false, + body: Container( + width: double.maxFinite, + decoration: AppDecoration.fillGray, + child: ListView( + children: [ + SizedBox(height: 30.v), + Container( + margin: EdgeInsets.only( + left: 16.h, + right: 20.h, + bottom: 10.h, + ), + padding: EdgeInsets.all(12.h), + 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: Column( + mainAxisSize: MainAxisSize.min, + children: [ CachedNetworkImage( - imageUrl: dotenv.env['STORAGE_URL']! + - (state.diet?['image'] ?? ''), + imageUrl: dotenv.env['STORAGE_URL']! + (state.diet?['image'] ?? ''), imageBuilder: (context, imageProvider) => CircleAvatar( backgroundImage: imageProvider, radius: 25, ), - placeholder: (context, url) => - CircularProgressIndicator(), + placeholder: (context, url) => CircularProgressIndicator(), errorWidget: (context, url, error) => CircleAvatar( child: Icon(Icons.person), backgroundColor: Colors.white, @@ -97,18 +97,16 @@ class DietEditScreen extends StatelessWidget { SizedBox(height: 16.0), // Здесь нужно добавить виджет для загрузки картинки ElevatedButton( - onPressed: () => - context.read().add(EditDiet()), + onPressed: () => context.read().add(EditDiet()), child: Text('Сохранить'), ) - ]), - ) - ]), - ), - bottomNavigationBar: _buildBottomBar(context))); + ], + ), + ) + ], + ), + ), + ), + ); } } - -_buildBottomBar(BuildContext context) { - return CustomBottomBar(onChanged: (BottomBarEnum type) {}); -} 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 c44308d..207cbb6 100644 --- a/lib/presentation/diets/diet_select_screen/diet_select_screen.dart +++ b/lib/presentation/diets/diet_select_screen/diet_select_screen.dart @@ -1,3 +1,5 @@ +import 'package:go_router/go_router.dart'; + import 'bloc/diet_select_bloc.dart'; import 'models/diet_select_model.dart'; import 'package:eatvio_app/core/app_export.dart'; @@ -39,75 +41,71 @@ class DietSelectScreen extends StatelessWidget { } _buildSetingsScreen(BuildContext context, DietSelectLoadedState state) { - mediaQueryData = MediaQuery.of(context); - return SafeArea( - child: Scaffold( - backgroundColor: Colors.grey[200], - resizeToAvoidBottomInset: true, - body: SingleChildScrollView( - child: Container( - width: double.maxFinite, - decoration: BoxDecoration(color: Colors.grey[200]), - child: Padding( - padding: EdgeInsets.all(16), - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - SizedBox(height: 10), - Container( - 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: CustomAppBar( - height: 54.v, - leadingWidth: 28.h, - leading: AppbarLeadingImage( - imagePath: ImageConstant.imgArrowLeft, - margin: EdgeInsets.only( - left: 16.h, top: 15.v, bottom: 15.v), - onTap: onTapBack(context), + return Scaffold( + backgroundColor: Colors.grey[200], + resizeToAvoidBottomInset: true, + body: SingleChildScrollView( + child: Container( + width: double.maxFinite, + decoration: BoxDecoration(color: Colors.grey[200]), + child: Padding( + padding: EdgeInsets.all(16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + SizedBox(height: 10), + Container( + 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), ), - title: Padding( - padding: EdgeInsets.only(left: 20.h), - child: Row( - children: [ - AppbarSubtitle( - text: "Диеты", - 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)), - ) - ], - ), + ], + ), + child: CustomAppBar( + height: 54.v, + leadingWidth: 28.h, + leading: AppbarLeadingImage( + imagePath: ImageConstant.imgArrowLeft, + margin: EdgeInsets.only( + left: 16.h, top: 15.v, bottom: 15.v), + onTap: () => GoRouter.of(context).pop(), + ), + title: Padding( + padding: EdgeInsets.only(left: 20.h), + child: Row( + children: [ + AppbarSubtitle( + text: "Диеты", + 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)), + ) + ], ), ), ), - SizedBox(height: 20), - _buildDietList(context, state) - ], - ), + ), + SizedBox(height: 20), + _buildDietList(context, state) + ], ), ), ), - bottomNavigationBar: _buildBottomBar(context), ), ); } @@ -174,10 +172,6 @@ class DietSelectScreen extends StatelessWidget { }; } - _buildBottomBar(BuildContext context) { - return CustomBottomBar(onChanged: (BottomBarEnum type) {}); - } - onTapArrowLeft(BuildContext context) { NavigatorService.goBack(); } 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 dcc20ae..d05a39a 100644 --- a/lib/presentation/diets/diet_show_screen/diet_show_screen.dart +++ b/lib/presentation/diets/diet_show_screen/diet_show_screen.dart @@ -8,13 +8,11 @@ import 'package:flutter_dotenv/flutter_dotenv.dart'; class DietScreen extends StatelessWidget { const DietScreen({Key? key}) : super(key: key); + static Widget builder(BuildContext context) { final dietID = ModalRoute.of(context)!.settings.arguments; return BlocProvider( - create: (context) => DietBloc( - DietState(dietModelObj: DietModel(dietID: dietID.toString()))) - ..add(DietInitialEvent()), - child: DietScreen()); + create: (context) => DietBloc(DietState(dietModelObj: DietModel(dietID: dietID.toString())))..add(DietInitialEvent()), child: DietScreen()); } Widget build(BuildContext context) { @@ -42,92 +40,78 @@ class DietScreen extends StatelessWidget { _buildDiet(BuildContext context, DietLoadedState state) { mediaQueryData = MediaQuery.of(context); return SafeArea( - child: Scaffold( - resizeToAvoidBottomInset: false, - body: Container( - width: double.maxFinite, - decoration: AppDecoration.fillGray, - child: ListView( - children: [ - SizedBox(height: 30.v), - Container( - margin: EdgeInsets.only( - left: 16.h, - right: 20.h, - bottom: 10.h, + child: Scaffold( + resizeToAvoidBottomInset: false, + body: Container( + width: double.maxFinite, + decoration: AppDecoration.fillGray, + child: ListView( + children: [ + SizedBox(height: 30.v), + Container( + margin: EdgeInsets.only( + left: 16.h, + right: 20.h, + bottom: 10.h, + ), + padding: EdgeInsets.all(12.h), + 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), ), - padding: EdgeInsets.all(12.h), - 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: Column(mainAxisSize: MainAxisSize.min, children: [ + CachedNetworkImage( + imageUrl: dotenv.env['STORAGE_URL']! + (state.diet?['image'] ?? ''), + imageBuilder: (context, imageProvider) => CircleAvatar( + backgroundImage: imageProvider, + radius: 25, ), - child: Column(mainAxisSize: MainAxisSize.min, children: [ - CachedNetworkImage( - imageUrl: dotenv.env['STORAGE_URL']! + - (state.diet?['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, + placeholder: (context, url) => CircularProgressIndicator(), + errorWidget: (context, url, error) => CircleAvatar( + child: Icon(Icons.person), + backgroundColor: Colors.white, + radius: 25, + ), + ), + SizedBox(height: 16.0), + Text(state.diet?['name'], style: CustomTextStyles.titleMediumBlack), + SizedBox(height: 8.0), + Text( + state.diet?['details'], + ), + SizedBox(height: 16.0), + Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + ElevatedButton( + onPressed: () => Navigator.pushNamed( + context, + AppRoutes.dietEditScreen, + arguments: state.diet?['id'].toString(), ), + child: Text('Редактировать'), ), - SizedBox(height: 16.0), - Text(state.diet?['name'], - style: CustomTextStyles.titleMediumBlack), - SizedBox(height: 8.0), - Text( - state.diet?['details'], + ElevatedButton( + onPressed: () => context.read().add(DeleteEntry(state.diet?['id'])), + child: Text('Удалить'), ), - SizedBox(height: 16.0), - Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: [ - ElevatedButton( - onPressed: () => Navigator.pushNamed( - context, - AppRoutes.dietEditScreen, - arguments: state.diet?['id'].toString(), - ), - child: Text('Редактировать'), - ), - ElevatedButton( - onPressed: () => context - .read() - .add(DeleteEntry(state.diet?['id'])), - child: Text('Удалить'), - ), - ], - ) - ]), + ], ) - ], - ), - ), - bottomNavigationBar: _buildBottomBar(context))); - } - - ///Handling route based on bottom click actions - String getCurrentRoute(BottomBarEnum type) { - switch (type) { - case BottomBarEnum.tf: - return AppRoutes.dietScreen; - default: - return "/"; - } + ]), + ) + ], + ), + ), + ), + ); } ///Handling page based on route @@ -143,10 +127,6 @@ class DietScreen extends StatelessWidget { } } - _buildBottomBar(BuildContext context) { - return CustomBottomBar(onChanged: (BottomBarEnum type) {}); - } - /// Navigates to the previous screen. onTapArrowleftone(BuildContext context) { NavigatorService.goBack(); diff --git a/lib/presentation/feed/blog_post_create_screen/blog_post_create_screen.dart b/lib/presentation/feed/blog_post_create_screen/blog_post_create_screen.dart index fc1d7c1..be78f7e 100644 --- a/lib/presentation/feed/blog_post_create_screen/blog_post_create_screen.dart +++ b/lib/presentation/feed/blog_post_create_screen/blog_post_create_screen.dart @@ -2,18 +2,16 @@ import 'bloc/blog_post_create_bloc.dart'; import 'models/blog_post_create_model.dart'; import 'package:eatvio_app/core/app_export.dart'; import 'package:flutter/material.dart'; -import 'package:eatvio_app/widgets/custom_bottom_bar.dart'; import 'package:eatvio_app/widgets/custom_text_form_field.dart'; import 'package:eatvio_app/widgets/custom_outlined_button.dart'; class BlogPostCreateScreen extends StatelessWidget { const BlogPostCreateScreen({Key? key}) : super(key: key); + static Widget builder(BuildContext context) { final blog_postID = ModalRoute.of(context)!.settings.arguments; return BlocProvider( - create: (context) => BlogPostCreateBloc(BlogPostCreateState( - blog_postModelObj: - BlogPostCreateModel(blog_postID: blog_postID.toString()))) + create: (context) => BlogPostCreateBloc(BlogPostCreateState(blog_postModelObj: BlogPostCreateModel(blog_postID: blog_postID.toString()))) ..add(BlogPostCreateInitialEvent()), child: BlogPostCreateScreen()); } @@ -41,92 +39,85 @@ class BlogPostCreateScreen extends StatelessWidget { } _buildBlogPostCreate(BuildContext context, BlogPostCreateLoadedState state) { - mediaQueryData = MediaQuery.of(context); - return SafeArea( - child: Scaffold( - resizeToAvoidBottomInset: false, - body: Container( - width: double.maxFinite, - decoration: AppDecoration.fillGray, - child: ListView(children: [ - SizedBox(height: 30.v), - Container( - margin: EdgeInsets.only( - left: 16.h, - right: 20.h, - bottom: 10.h, + return Scaffold( + resizeToAvoidBottomInset: false, + body: Container( + width: double.maxFinite, + decoration: AppDecoration.fillGray, + child: ListView( + children: [ + SizedBox(height: 30.v), + Container( + margin: EdgeInsets.only( + left: 16.h, + right: 20.h, + bottom: 10.h, + ), + padding: EdgeInsets.all(12.h), + 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: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Column( + children: [ + Text("Заголовок новости", style: theme.textTheme.bodyLarge), + CustomTextFormField( + controller: state.title, + validator: _validateTitle, ), - padding: EdgeInsets.all(12.h), - 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), - ), - ], + SizedBox(height: 8.0), + Text("Ссылка на YouTube", style: theme.textTheme.bodyLarge), + CustomTextFormField( + controller: state.youtube_url, + validator: _validateYouTubeLink, ), - child: Column(mainAxisSize: MainAxisSize.min, children: [ - Column( - children: [ - Text("Заголовок новости", - style: theme.textTheme.bodyLarge), - CustomTextFormField( - controller: state.title, - validator: _validateTitle, - ), - SizedBox(height: 8.0), - Text("Ссылка на YouTube", - style: theme.textTheme.bodyLarge), - CustomTextFormField( - controller: state.youtube_url, - validator: _validateYouTubeLink, - ), - SizedBox(height: 8.0), - Text("Описание", style: theme.textTheme.bodyLarge), - CustomTextFormField( - controller: state.description, - validator: _validateDescription, - maxLines: 6, - ), - SizedBox(height: 16.0), - // Add widget for image upload here - CustomOutlinedButton( - onPressed: () => _submitForm( - context, - state.title!.text, - state.description!.text, - state.youtube_url!.text), - buttonStyle: - CustomButtonStyles.outlinePrimaryTL15, - text: 'Создать', - ), - ], - ), - ])) - ])), - bottomNavigationBar: _buildBottomBar(context))); + SizedBox(height: 8.0), + Text("Описание", style: theme.textTheme.bodyLarge), + CustomTextFormField( + controller: state.description, + validator: _validateDescription, + maxLines: 6, + ), + SizedBox(height: 16.0), + // Add widget for image upload here + CustomOutlinedButton( + onPressed: () => _submitForm(context, state.title!.text, state.description!.text, state.youtube_url!.text), + buttonStyle: CustomButtonStyles.outlinePrimaryTL15, + text: 'Создать', + ), + ], + ), + ], + ), + ) + ], + ), + ), + ); } } -_submitForm( - BuildContext context, String title, String description, String youtubeURL) { +_submitForm(BuildContext context, String title, String description, String youtubeURL) { String? titleError = _validateTitle(title); String? descriptionError = _validateDescription(description); String? youtubeURLError = _validateYouTubeLink(youtubeURL); - if (titleError != null || - descriptionError != null || - youtubeURLError != null) { + if (titleError != null || descriptionError != null || youtubeURLError != null) { // Display error messages or handle invalid input as needed // For example, show a snackbar with the error message ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text(titleError ?? descriptionError ?? youtubeURLError!)), + SnackBar(content: Text(titleError ?? descriptionError ?? youtubeURLError!)), ); } else { // Proceed with form submission @@ -158,11 +149,6 @@ String? _validateYouTubeLink(value) { } bool _isValidUrl(String url) { - final RegExp urlRegExp = - new RegExp(r"^(http|https):\/\/([\w-]+\.)+[\w-]+(\/[\w-./?%&=]*)?$"); + final RegExp urlRegExp = new RegExp(r"^(http|https):\/\/([\w-]+\.)+[\w-]+(\/[\w-./?%&=]*)?$"); return urlRegExp.hasMatch(url); } - -_buildBottomBar(BuildContext context) { - return CustomBottomBar(onChanged: (BottomBarEnum type) {}); -} diff --git a/lib/presentation/feed/blog_post_edit_screen/blog_post_edit_screen.dart b/lib/presentation/feed/blog_post_edit_screen/blog_post_edit_screen.dart index 1bba76d..ac5a833 100644 --- a/lib/presentation/feed/blog_post_edit_screen/blog_post_edit_screen.dart +++ b/lib/presentation/feed/blog_post_edit_screen/blog_post_edit_screen.dart @@ -8,13 +8,12 @@ import 'package:flutter_dotenv/flutter_dotenv.dart'; class BlogPostEditScreen extends StatelessWidget { const BlogPostEditScreen({Key? key}) : super(key: key); + static Widget builder(BuildContext context) { final blog_postID = ModalRoute.of(context)!.settings.arguments; return BlocProvider( - create: (context) => BlogPostEditBloc(BlogPostEditState( - blog_postModelObj: - BlogPostEditModel(blog_postID: blog_postID.toString()))) - ..add(BlogPostEditInitialEvent()), + create: (context) => + BlogPostEditBloc(BlogPostEditState(blog_postModelObj: BlogPostEditModel(blog_postID: blog_postID.toString())))..add(BlogPostEditInitialEvent()), child: BlogPostEditScreen()); } @@ -43,42 +42,43 @@ class BlogPostEditScreen extends StatelessWidget { _buildBlogPostEdit(BuildContext context, BlogPostEditLoadedState state) { mediaQueryData = MediaQuery.of(context); return SafeArea( - child: Scaffold( - resizeToAvoidBottomInset: false, - body: Container( - width: double.maxFinite, - decoration: AppDecoration.fillGray, - child: ListView(children: [ - SizedBox(height: 30.v), - Container( - margin: EdgeInsets.only( - left: 16.h, - right: 20.h, - bottom: 10.h, - ), - padding: EdgeInsets.all(12.h), - 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: Column(mainAxisSize: MainAxisSize.min, children: [ + child: Scaffold( + resizeToAvoidBottomInset: false, + body: Container( + width: double.maxFinite, + decoration: AppDecoration.fillGray, + child: ListView( + children: [ + SizedBox(height: 30.v), + Container( + margin: EdgeInsets.only( + left: 16.h, + right: 20.h, + bottom: 10.h, + ), + padding: EdgeInsets.all(12.h), + 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: Column( + mainAxisSize: MainAxisSize.min, + children: [ CachedNetworkImage( - imageUrl: dotenv.env['STORAGE_URL']! + - (state.blog_post?['image'] ?? ''), + imageUrl: dotenv.env['STORAGE_URL']! + (state.blog_post?['image'] ?? ''), imageBuilder: (context, imageProvider) => CircleAvatar( backgroundImage: imageProvider, radius: 25, ), - placeholder: (context, url) => - CircularProgressIndicator(), + placeholder: (context, url) => CircularProgressIndicator(), errorWidget: (context, url, error) => CircleAvatar( child: Icon(Icons.person), backgroundColor: Colors.white, @@ -103,18 +103,16 @@ class BlogPostEditScreen extends StatelessWidget { SizedBox(height: 16.0), // Здесь нужно добавить виджет для загрузки картинки ElevatedButton( - onPressed: () => - context.read().add(EditBlogPost()), + onPressed: () => context.read().add(EditBlogPost()), child: Text('Сохранить'), ) - ]), - ) - ]), - ), - bottomNavigationBar: _buildBottomBar(context))); + ], + ), + ) + ], + ), + ), + ), + ); } } - -_buildBottomBar(BuildContext context) { - return CustomBottomBar(onChanged: (BottomBarEnum type) {}); -} 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 0463742..0b52412 100644 --- a/lib/presentation/feed/blog_post_screen/blog_post_screen.dart +++ b/lib/presentation/feed/blog_post_screen/blog_post_screen.dart @@ -1,10 +1,11 @@ +import 'package:go_router/go_router.dart'; + import 'bloc/blog_post_bloc.dart'; import 'models/blog_post_model.dart'; import 'widgets/comment_widget.dart'; import 'package:eatvio_app/core/app_export.dart'; import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; -import 'package:eatvio_app/widgets/custom_bottom_bar.dart'; import 'package:eatvio_app/widgets/custom_edit_text_form_field.dart'; import 'package:eatvio_app/widgets/custom_outlined_button.dart'; import 'package:cached_network_image/cached_network_image.dart'; @@ -12,60 +13,73 @@ import 'package:flutter_dotenv/flutter_dotenv.dart'; class BlogPostScreen extends StatelessWidget { const BlogPostScreen({Key? key}) : super(key: key); - static Widget builder(BuildContext context) { - final blog_postID = ModalRoute.of(context)!.settings.arguments; + + static Widget builder(BuildContext context, String blog_postID) { return BlocProvider( - create: (context) => BlogPostBloc(BlogPostState( - blog_postModelObj: - BlogPostModel(blog_postID: blog_postID.toString()))) - ..add(BlogPostInitialEvent()), - child: BlogPostScreen()); + create: (context) => BlogPostBloc( + BlogPostState( + blog_postModelObj: BlogPostModel( + blog_postID: blog_postID.toString(), + ), + ), + )..add( + BlogPostInitialEvent(), + ), + child: BlogPostScreen(), + ); } Widget build(BuildContext context) { return BlocBuilder( builder: (context, state) { if (state is BlogPostInitialState) { - // Это начальное состояние, данные ещё не загружены. - return Container( - color: Colors.white, + return Scaffold( + body: Center( + child: CircularProgressIndicator(), + ), ); } else if (state is BlogPostLoadedState) { // Данные загружены, можно строить экран. return _buildBlogPost(context, state); } else if (state is BlogPostErrorState) { // Произошла ошибка при загрузке данных. - return Center(child: Text(state.errorMessage)); + return Center( + child: Text(state.errorMessage), + ); } else { + return Scaffold( + body: Center( + child: CircularProgressIndicator(), + ), + ); // Другие состояния, если они есть. - return Container(); // Пустой контейнер для необработанных состояний. } }, ); } _buildBlogPost(BuildContext context, BlogPostLoadedState state) { - mediaQueryData = MediaQuery.of(context); return SafeArea( - child: Scaffold( - resizeToAvoidBottomInset: false, - body: Container( - width: double.maxFinite, - decoration: AppDecoration.fillGray, - child: ListView( - children: [ - SizedBox(height: 15.v), - _buildHeaderRow(context, state), - SizedBox(height: 15.v), - _buildBlogPostData(context, state), - SizedBox(height: 15.v), - _buildTextField(context, state), - SizedBox(height: 15.v), - _buildCommentSection(context, state), - ], - ), - ), - bottomNavigationBar: _buildBottomBar(context))); + child: Scaffold( + resizeToAvoidBottomInset: false, + body: Container( + width: double.maxFinite, + decoration: AppDecoration.fillGray, + child: ListView( + children: [ + SizedBox(height: 15.v), + _buildHeaderRow(context, state), + SizedBox(height: 15.v), + _buildBlogPostData(context, state), + SizedBox(height: 15.v), + _buildTextField(context, state), + SizedBox(height: 15.v), + _buildCommentSection(context, state), + ], + ), + ), + ), + ); } _buildHeaderRow(BuildContext context, BlogPostLoadedState state) { @@ -92,8 +106,9 @@ class BlogPostScreen extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ CustomImageView( - imagePath: ImageConstant.imgArrowLeft, - onTap: () => NavigatorService.goBack()), + imagePath: ImageConstant.imgArrowLeft, + onTap: () => GoRouter.of(context).pop(), + ), Padding( padding: EdgeInsets.only(top: 1.v), child: Row( @@ -106,8 +121,7 @@ class BlogPostScreen 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, @@ -181,8 +195,7 @@ class BlogPostScreen extends StatelessWidget { Align( alignment: Alignment.topLeft, child: Text( - DateFormat('dd.MM.yyyy') - .format(DateTime.parse(state.blog_post?['updated_at'])), + DateFormat('dd.MM.yyyy').format(DateTime.parse(state.blog_post?['updated_at'])), style: theme.textTheme.bodyMedium, )), SizedBox(height: 16.0), @@ -342,9 +355,7 @@ class BlogPostScreen extends StatelessWidget { decoration: BoxDecoration( color: Colors.transparent, ), - onPressed: () => context - .read() - .add(CreateComment(state.commentController!.text)), + onPressed: () => context.read().add(CreateComment(state.commentController!.text)), // Установите прозрачный фон ) ], @@ -377,12 +388,8 @@ class BlogPostScreen extends StatelessWidget { } } - _buildBottomBar(BuildContext context) { - return CustomBottomBar(onChanged: (BottomBarEnum type) {}); - } - /// Navigates to the previous screen. onTapArrowleftone(BuildContext context) { - NavigatorService.goBack(); + GoRouter.of(context).pop(); } } diff --git a/lib/presentation/feed/feed_screen/feed_screen.dart b/lib/presentation/feed/feed_screen/feed_screen.dart index 4e8be2c..cddb9cc 100644 --- a/lib/presentation/feed/feed_screen/feed_screen.dart +++ b/lib/presentation/feed/feed_screen/feed_screen.dart @@ -1,3 +1,5 @@ +import 'package:go_router/go_router.dart'; + import 'bloc/feed_bloc.dart'; import 'models/feed_model.dart'; import 'package:cached_network_image/cached_network_image.dart'; @@ -101,10 +103,7 @@ class FeedScreen extends StatelessWidget { flex: 1, child: CustomOutlinedButton( text: "+", - onPressed: () => Navigator.pushNamed( - context, - AppRoutes.blogPostCreateScreen, - ), + onPressed: () => GoRouter.of(context).goNamed('blogPostCreateScreen'), buttonStyle: CustomButtonStyles.outlinePrimaryTL15, ), ), @@ -169,10 +168,9 @@ class FeedScreen extends StatelessWidget { DateFormat('dd.MM.yyyy').format(DateTime.parse(post?['post']['updated_at'])), style: theme.textTheme.bodyMedium, ), - onTap: () => Navigator.pushNamed( - context, - AppRoutes.blogPostScreen, - arguments: post?['post']['id'].toString(), + onTap: () => GoRouter.of(context).goNamed( + 'blogPostScreen', + extra: post?['post']['id'].toString(), ), trailing: PopupMenuButton( onSelected: (value) => print("tap"), diff --git a/lib/presentation/glossary/glossary_screen/glossary_screen.dart b/lib/presentation/glossary/glossary_screen/glossary_screen.dart index 65dc65c..42b8477 100644 --- a/lib/presentation/glossary/glossary_screen/glossary_screen.dart +++ b/lib/presentation/glossary/glossary_screen/glossary_screen.dart @@ -12,12 +12,10 @@ import 'package:eatvio_app/presentation/glossary/glossary_screen/widgets/glossar class GlossaryScreen extends StatelessWidget { const GlossaryScreen({Key? key}) : super(key: key); + static Widget builder(BuildContext context) { return BlocProvider( - create: (context) => - GlossaryBloc(GlossaryState(glossaryModelObj: GlossaryModel())) - ..add(GlossaryInitialEvent()), - child: GlossaryScreen()); + create: (context) => GlossaryBloc(GlossaryState(glossaryModelObj: GlossaryModel()))..add(GlossaryInitialEvent()), child: GlossaryScreen()); } Widget build(BuildContext context) { @@ -43,32 +41,28 @@ class GlossaryScreen extends StatelessWidget { } _buildGlossary(BuildContext context, GlossaryLoadedState state) { - mediaQueryData = MediaQuery.of(context); - return SafeArea( - child: Scaffold( - backgroundColor: Colors.grey[200], - resizeToAvoidBottomInset: true, - body: SingleChildScrollView( - child: Container( - width: double.maxFinite, - decoration: BoxDecoration(color: Colors.grey[200]), - child: Padding( - padding: EdgeInsets.all(16), - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - SizedBox(height: 20), - _buildSearch(context), - SizedBox(height: 20), - _buildMenu(context), - SizedBox(height: 20), - _buildProducts(context, state) - ], - ), + return Scaffold( + backgroundColor: Colors.grey[200], + resizeToAvoidBottomInset: true, + body: SingleChildScrollView( + child: Container( + width: double.maxFinite, + decoration: BoxDecoration(color: Colors.grey[200]), + child: Padding( + padding: EdgeInsets.all(16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + SizedBox(height: 20), + _buildSearch(context), + SizedBox(height: 20), + _buildMenu(context), + SizedBox(height: 20), + _buildProducts(context, state) + ], ), ), ), - bottomNavigationBar: _buildBottomBar(context), ), ); } @@ -184,16 +178,12 @@ class GlossaryScreen extends StatelessWidget { vertical: 9, ), onChanged: _changeProductGroup(context, state), - width: MediaQuery.of(context) - .size - .width, // Set a percentage value as per your layout + width: MediaQuery.of(context).size.width, // Set a percentage value as per your layout ), SizedBox( height: 8, ), - Align( - alignment: Alignment.centerLeft, - child: Text("*КБЖУ указано за 100гр")), + Align(alignment: Alignment.centerLeft, child: Text("*КБЖУ указано за 100гр")), SizedBox( height: 8, ), @@ -268,8 +258,7 @@ class GlossaryScreen extends StatelessWidget { child: Column(children: [ Text("Жиры - ${product['fats_on_100gr'].toString()}"), SizedBox(height: 8), - Text( - "Углеводы - ${product['carbohydrates_on_100gr'].toString()}") + Text("Углеводы - ${product['carbohydrates_on_100gr'].toString()}") ]), ) ]) @@ -298,16 +287,6 @@ class GlossaryScreen extends StatelessWidget { return result; } - ///Handling route based on bottom click actions - String getCurrentRoute(BottomBarEnum type) { - switch (type) { - case BottomBarEnum.tf: - return AppRoutes.glossaryScreen; - default: - return "/"; - } - } - ///Handling page based on route Widget getCurrentPage( BuildContext context, @@ -321,10 +300,6 @@ class GlossaryScreen extends StatelessWidget { } } - _buildBottomBar(BuildContext context) { - return CustomBottomBar(onChanged: (BottomBarEnum type) {}); - } - _changeProductGroup(BuildContext context, GlossaryLoadedState state) { return (value) { context.read().add(ChangeProductGroup(value.id)); diff --git a/lib/presentation/plans/plan_create_screen/plan_create_screen.dart b/lib/presentation/plans/plan_create_screen/plan_create_screen.dart index af04abc..9ab5cad 100644 --- a/lib/presentation/plans/plan_create_screen/plan_create_screen.dart +++ b/lib/presentation/plans/plan_create_screen/plan_create_screen.dart @@ -6,12 +6,11 @@ import 'package:eatvio_app/widgets/custom_bottom_bar.dart'; class PlanCreateScreen extends StatelessWidget { const PlanCreateScreen({Key? key}) : super(key: key); + static Widget builder(BuildContext context) { final planID = ModalRoute.of(context)!.settings.arguments; return BlocProvider( - create: (context) => PlanCreateBloc(PlanCreateState( - planModelObj: PlanCreateModel(planID: planID.toString()))) - ..add(PlanCreateInitialEvent()), + create: (context) => PlanCreateBloc(PlanCreateState(planModelObj: PlanCreateModel(planID: planID.toString())))..add(PlanCreateInitialEvent()), child: PlanCreateScreen()); } @@ -40,58 +39,56 @@ class PlanCreateScreen extends StatelessWidget { _buildPlanCreate(BuildContext context, PlanCreateLoadedState state) { mediaQueryData = MediaQuery.of(context); return SafeArea( - child: Scaffold( - resizeToAvoidBottomInset: false, - body: Container( - width: double.maxFinite, - decoration: AppDecoration.fillGray, - child: ListView(children: [ - SizedBox(height: 30.v), - Container( - margin: EdgeInsets.only( - left: 16.h, - right: 20.h, - bottom: 10.h, - ), - padding: EdgeInsets.all(12.h), - 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: Column(mainAxisSize: MainAxisSize.min, children: [ - SizedBox(height: 16.0), - TextFormField( - controller: state.name, - decoration: InputDecoration(labelText: 'Заголовок'), + child: Scaffold( + resizeToAvoidBottomInset: false, + body: Container( + width: double.maxFinite, + decoration: AppDecoration.fillGray, + child: ListView( + children: [ + SizedBox(height: 30.v), + Container( + margin: EdgeInsets.only( + left: 16.h, + right: 20.h, + bottom: 10.h, + ), + padding: EdgeInsets.all(12.h), + 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), ), - SizedBox(height: 16.0), - TextFormField( - controller: state.details, - decoration: InputDecoration(labelText: 'Описание'), - ), - SizedBox(height: 16.0), - // Здесь нужно добавить виджет для загрузки картинки - ElevatedButton( - onPressed: () => - context.read().add(CreatePlan()), - child: Text('Создать'), - ) - ]), - ) - ]), - ), - bottomNavigationBar: _buildBottomBar(context))); + ], + ), + child: Column(mainAxisSize: MainAxisSize.min, children: [ + SizedBox(height: 16.0), + TextFormField( + controller: state.name, + decoration: InputDecoration(labelText: 'Заголовок'), + ), + SizedBox(height: 16.0), + TextFormField( + controller: state.details, + decoration: InputDecoration(labelText: 'Описание'), + ), + SizedBox(height: 16.0), + // Здесь нужно добавить виджет для загрузки картинки + ElevatedButton( + onPressed: () => context.read().add(CreatePlan()), + child: Text('Создать'), + ) + ]), + ) + ], + ), + ), + ), + ); } } - -_buildBottomBar(BuildContext context) { - return CustomBottomBar(onChanged: (BottomBarEnum type) {}); -} diff --git a/lib/presentation/plans/plan_edit_screen/plan_edit_screen.dart b/lib/presentation/plans/plan_edit_screen/plan_edit_screen.dart index 71ac12b..c163f2c 100644 --- a/lib/presentation/plans/plan_edit_screen/plan_edit_screen.dart +++ b/lib/presentation/plans/plan_edit_screen/plan_edit_screen.dart @@ -8,12 +8,11 @@ import 'package:flutter_dotenv/flutter_dotenv.dart'; class PlanEditScreen extends StatelessWidget { const PlanEditScreen({Key? key}) : super(key: key); + static Widget builder(BuildContext context) { final planID = ModalRoute.of(context)!.settings.arguments; return BlocProvider( - create: (context) => PlanEditBloc(PlanEditState( - planModelObj: PlanEditModel(planID: planID.toString()))) - ..add(PlanEditInitialEvent()), + create: (context) => PlanEditBloc(PlanEditState(planModelObj: PlanEditModel(planID: planID.toString())))..add(PlanEditInitialEvent()), child: PlanEditScreen()); } @@ -42,42 +41,43 @@ class PlanEditScreen extends StatelessWidget { _buildPlanEdit(BuildContext context, PlanEditLoadedState state) { mediaQueryData = MediaQuery.of(context); return SafeArea( - child: Scaffold( - resizeToAvoidBottomInset: false, - body: Container( - width: double.maxFinite, - decoration: AppDecoration.fillGray, - child: ListView(children: [ - SizedBox(height: 30.v), - Container( - margin: EdgeInsets.only( - left: 16.h, - right: 20.h, - bottom: 10.h, - ), - padding: EdgeInsets.all(12.h), - 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: Column(mainAxisSize: MainAxisSize.min, children: [ + child: Scaffold( + resizeToAvoidBottomInset: false, + body: Container( + width: double.maxFinite, + decoration: AppDecoration.fillGray, + child: ListView( + children: [ + SizedBox(height: 30.v), + Container( + margin: EdgeInsets.only( + left: 16.h, + right: 20.h, + bottom: 10.h, + ), + padding: EdgeInsets.all(12.h), + 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: Column( + mainAxisSize: MainAxisSize.min, + children: [ CachedNetworkImage( - imageUrl: dotenv.env['STORAGE_URL']! + - (state.plan?['image'] ?? ''), + imageUrl: dotenv.env['STORAGE_URL']! + (state.plan?['image'] ?? ''), imageBuilder: (context, imageProvider) => CircleAvatar( backgroundImage: imageProvider, radius: 25, ), - placeholder: (context, url) => - CircularProgressIndicator(), + placeholder: (context, url) => CircularProgressIndicator(), errorWidget: (context, url, error) => CircleAvatar( child: Icon(Icons.person), backgroundColor: Colors.white, @@ -97,18 +97,16 @@ class PlanEditScreen extends StatelessWidget { SizedBox(height: 16.0), // Здесь нужно добавить виджет для загрузки картинки ElevatedButton( - onPressed: () => - context.read().add(EditPlan()), + onPressed: () => context.read().add(EditPlan()), child: Text('Сохранить'), ) - ]), - ) - ]), - ), - bottomNavigationBar: _buildBottomBar(context))); + ], + ), + ) + ], + ), + ), + ), + ); } } - -_buildBottomBar(BuildContext context) { - return CustomBottomBar(onChanged: (BottomBarEnum type) {}); -} 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 7f3486a..a82a667 100644 --- a/lib/presentation/plans/plan_select_screen/plan_select_screen.dart +++ b/lib/presentation/plans/plan_select_screen/plan_select_screen.dart @@ -1,3 +1,5 @@ +import 'package:go_router/go_router.dart'; + import 'bloc/plan_select_bloc.dart'; import 'models/plan_select_model.dart'; import 'package:eatvio_app/core/app_export.dart'; @@ -39,75 +41,71 @@ class PlanSelectScreen extends StatelessWidget { } _buildSetingsScreen(BuildContext context, PlanSelectLoadedState state) { - mediaQueryData = MediaQuery.of(context); - return SafeArea( - child: Scaffold( - backgroundColor: Colors.grey[200], - resizeToAvoidBottomInset: true, - body: SingleChildScrollView( - child: Container( - width: double.maxFinite, - decoration: BoxDecoration(color: Colors.grey[200]), - child: Padding( - padding: EdgeInsets.all(16), - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - SizedBox(height: 10), - Container( - 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: CustomAppBar( - height: 54.v, - leadingWidth: 28.h, - leading: AppbarLeadingImage( - imagePath: ImageConstant.imgArrowLeft, - margin: EdgeInsets.only( - left: 16.h, top: 15.v, bottom: 15.v), - onTap: onTapBack(context), + return Scaffold( + backgroundColor: Colors.grey[200], + resizeToAvoidBottomInset: true, + body: SingleChildScrollView( + child: Container( + width: double.maxFinite, + decoration: BoxDecoration(color: Colors.grey[200]), + child: Padding( + padding: EdgeInsets.all(16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + SizedBox(height: 10), + Container( + 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), ), - title: Padding( - padding: EdgeInsets.only(left: 20.h), - child: Row( - children: [ - AppbarSubtitle( - text: "Планы", - 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)), - ) - ], - ), + ], + ), + child: CustomAppBar( + height: 54.v, + leadingWidth: 28.h, + leading: AppbarLeadingImage( + imagePath: ImageConstant.imgArrowLeft, + margin: EdgeInsets.only( + left: 16.h, top: 15.v, bottom: 15.v), + onTap: () => GoRouter.of(context).pop(), + ), + title: Padding( + padding: EdgeInsets.only(left: 20.h), + child: Row( + children: [ + AppbarSubtitle( + text: "Планы", + 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)), + ) + ], ), ), ), - SizedBox(height: 20), - _buildPlanList(context, state) - ], - ), + ), + SizedBox(height: 20), + _buildPlanList(context, state) + ], ), ), ), - bottomNavigationBar: _buildBottomBar(context), ), ); } @@ -174,10 +172,6 @@ class PlanSelectScreen extends StatelessWidget { }; } - _buildBottomBar(BuildContext context) { - return CustomBottomBar(onChanged: (BottomBarEnum type) {}); - } - onTapArrowLeft(BuildContext context) { NavigatorService.goBack(); } 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 d34e1a4..8e2f243 100644 --- a/lib/presentation/plans/plan_show_screen/plan_show_screen.dart +++ b/lib/presentation/plans/plan_show_screen/plan_show_screen.dart @@ -8,13 +8,11 @@ import 'package:flutter_dotenv/flutter_dotenv.dart'; class PlanScreen extends StatelessWidget { const PlanScreen({Key? key}) : super(key: key); + static Widget builder(BuildContext context) { final planID = ModalRoute.of(context)!.settings.arguments; return BlocProvider( - create: (context) => PlanBloc( - PlanState(planModelObj: PlanModel(planID: planID.toString()))) - ..add(PlanInitialEvent()), - child: PlanScreen()); + create: (context) => PlanBloc(PlanState(planModelObj: PlanModel(planID: planID.toString())))..add(PlanInitialEvent()), child: PlanScreen()); } Widget build(BuildContext context) { @@ -42,91 +40,76 @@ class PlanScreen extends StatelessWidget { _buildPlan(BuildContext context, PlanLoadedState state) { mediaQueryData = MediaQuery.of(context); return SafeArea( - child: Scaffold( - resizeToAvoidBottomInset: false, - body: Container( - width: double.maxFinite, - decoration: AppDecoration.fillGray, - child: ListView( - children: [ - SizedBox(height: 30.v), - Container( - margin: EdgeInsets.only( - left: 16.h, - right: 20.h, - bottom: 10.h, + child: Scaffold( + resizeToAvoidBottomInset: false, + body: Container( + width: double.maxFinite, + decoration: AppDecoration.fillGray, + child: ListView( + children: [ + SizedBox(height: 30.v), + Container( + margin: EdgeInsets.only( + left: 16.h, + right: 20.h, + bottom: 10.h, + ), + padding: EdgeInsets.all(12.h), + 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), ), - padding: EdgeInsets.all(12.h), - 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: Column(mainAxisSize: MainAxisSize.min, children: [ + CachedNetworkImage( + imageUrl: dotenv.env['STORAGE_URL']! + (state.plan?['image'] ?? ''), + imageBuilder: (context, imageProvider) => CircleAvatar( + backgroundImage: imageProvider, + radius: 25, ), - child: Column(mainAxisSize: MainAxisSize.min, children: [ - CachedNetworkImage( - imageUrl: dotenv.env['STORAGE_URL']! + - (state.plan?['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, - ), + placeholder: (context, url) => CircularProgressIndicator(), + errorWidget: (context, url, error) => CircleAvatar( + child: Icon(Icons.person), + backgroundColor: Colors.white, + radius: 25, + ), + ), + SizedBox(height: 16.0), + Text(state.plan?['name'], style: CustomTextStyles.titleMediumBlack), + SizedBox(height: 8.0), + Text( + state.plan?['details'], + ), + SizedBox(height: 16.0), + Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + ElevatedButton( + onPressed: () { + // Действие для редактирования + }, + child: Text('Редактировать'), ), - SizedBox(height: 16.0), - Text(state.plan?['name'], - style: CustomTextStyles.titleMediumBlack), - SizedBox(height: 8.0), - Text( - state.plan?['details'], + ElevatedButton( + onPressed: () => context.read().add(DeleteEntry(state.plan?['id'])), + child: Text('Удалить'), ), - SizedBox(height: 16.0), - Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: [ - ElevatedButton( - onPressed: () { - // Действие для редактирования - }, - child: Text('Редактировать'), - ), - ElevatedButton( - onPressed: () => context - .read() - .add(DeleteEntry(state.plan?['id'])), - child: Text('Удалить'), - ), - ], - ) - ]), + ], ) - ], - ), - ), - bottomNavigationBar: _buildBottomBar(context))); - } - - - ///Handling route based on bottom click actions - String getCurrentRoute(BottomBarEnum type) { - switch (type) { - case BottomBarEnum.tf: - return AppRoutes.planScreen; - default: - return "/"; - } + ]), + ) + ], + ), + ), + ), + ); } ///Handling page based on route @@ -142,10 +125,6 @@ class PlanScreen extends StatelessWidget { } } - _buildBottomBar(BuildContext context) { - return CustomBottomBar(onChanged: (BottomBarEnum type) {}); - } - /// Navigates to the previous screen. onTapArrowleftone(BuildContext context) { NavigatorService.goBack(); diff --git a/lib/presentation/profile/my_profile_screen/my_settings_screen.dart b/lib/presentation/profile/my_profile_screen/my_settings_screen.dart index 82ddc56..0f2ac43 100644 --- a/lib/presentation/profile/my_profile_screen/my_settings_screen.dart +++ b/lib/presentation/profile/my_profile_screen/my_settings_screen.dart @@ -1,3 +1,5 @@ +import 'package:go_router/go_router.dart'; + import 'bloc/my_profile_bloc.dart'; import 'models/my_profile_model.dart'; import 'package:eatvio_app/core/app_export.dart'; @@ -15,10 +17,7 @@ import 'package:flutter/material.dart'; class MySettingsScreen extends StatelessWidget { static Widget builder(BuildContext context) { return BlocProvider( - create: (context) => - MyProfileBloc(MyProfileState(myProfileModelObj: MyProfileModel())) - ..add(MyProfileInitialEvent()), - child: MySettingsScreen()); + create: (context) => MyProfileBloc(MyProfileState(myProfileModelObj: MyProfileModel()))..add(MyProfileInitialEvent()), child: MySettingsScreen()); } Widget build(BuildContext context) { @@ -42,136 +41,125 @@ class MySettingsScreen extends StatelessWidget { } _buildSetingsScreen(BuildContext context, MyProfileLoadedState state) { - mediaQueryData = MediaQuery.of(context); - - return SafeArea( - child: Scaffold( - backgroundColor: Colors.grey[200], - resizeToAvoidBottomInset: true, - body: SingleChildScrollView( - child: Container( - width: double.maxFinite, - decoration: BoxDecoration(color: Colors.grey[200]), - child: Padding( - padding: EdgeInsets.all(16), - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - SizedBox(height: 30), - Container( - 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), - ), - ], + return Scaffold( + backgroundColor: Colors.grey[200], + resizeToAvoidBottomInset: true, + body: SingleChildScrollView( + child: Container( + width: double.maxFinite, + decoration: BoxDecoration(color: Colors.grey[200]), + child: Padding( + padding: EdgeInsets.all(16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + SizedBox(height: 30), + Container( + 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: CustomAppBar( + height: 54.v, + leadingWidth: 28.h, + leading: AppbarLeadingImage( + imagePath: ImageConstant.imgArrowLeft, + margin: EdgeInsets.only(left: 16.h, top: 15.v, bottom: 15.v), + onTap: () => GoRouter.of(context).pop(), ), - child: CustomAppBar( - height: 54.v, - leadingWidth: 28.h, - leading: AppbarLeadingImage( - imagePath: ImageConstant.imgArrowLeft, - margin: EdgeInsets.only( - left: 16.h, top: 15.v, bottom: 15.v), - onTap: onTapBack(context)), - title: Padding( - padding: EdgeInsets.only(left: 20.h), - child: Row(children: [ - AppbarSubtitle( - text: state.user?['name'], - margin: EdgeInsets.only( - left: 80.h, top: 12.v, bottom: 9.v)) - ])), - )), - SizedBox(height: 20), - Container( - padding: EdgeInsets.symmetric( - horizontal: 24.h, - vertical: 12.v, - ), - 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: Column( - children: [ - SectionTitle('Язык'), - LanguageDropdown(), - ], - ), + title: Padding( + padding: EdgeInsets.only(left: 20.h), + child: Row(children: [AppbarSubtitle(text: state.user?['name'], margin: EdgeInsets.only(left: 80.h, top: 12.v, bottom: 9.v))])), + )), + SizedBox(height: 20), + Container( + padding: EdgeInsets.symmetric( + horizontal: 24.h, + vertical: 12.v, ), - SizedBox(height: 20), - Container( - padding: EdgeInsets.symmetric( - horizontal: 24.h, - vertical: 12.v, - ), - 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: Column( - children: [ - SectionTitle('Уведомления'), - NotificationSwitch('Уведомление об обновлениях'), - NotificationSwitch('Напоминания о заполнении'), - ], - ), + 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), + ), + ], ), - SizedBox(height: 20), - Container( - padding: EdgeInsets.symmetric( - horizontal: 24.h, - vertical: 12.v, - ), - 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: Column( - children: [ - SectionTitle('Дополнительная информация'), - ExpandableList('Персональные данные'), - AboutList('О нас', ['ООО Итвио', '2023-н.в.']), - ], - ), + child: Column( + children: [ + SectionTitle('Язык'), + LanguageDropdown(), + ], ), - ], - ), + ), + SizedBox(height: 20), + Container( + padding: EdgeInsets.symmetric( + horizontal: 24.h, + vertical: 12.v, + ), + 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: Column( + children: [ + SectionTitle('Уведомления'), + NotificationSwitch('Уведомление об обновлениях'), + NotificationSwitch('Напоминания о заполнении'), + ], + ), + ), + SizedBox(height: 20), + Container( + padding: EdgeInsets.symmetric( + horizontal: 24.h, + vertical: 12.v, + ), + 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: Column( + children: [ + SectionTitle('Дополнительная информация'), + ExpandableList('Персональные данные'), + AboutList('О нас', ['ООО Итвио', '2023-н.в.']), + ], + ), + ), + ], ), ), ), - bottomNavigationBar: _buildBottomBar(context), ), ); } @@ -182,10 +170,6 @@ class MySettingsScreen extends StatelessWidget { }; } - _buildBottomBar(BuildContext context) { - return CustomBottomBar(onChanged: (BottomBarEnum type) {}); - } - onTapArrowLeft(BuildContext context) { NavigatorService.goBack(); } diff --git a/lib/presentation/recipe/recipe_create_screen/recipe_create_screen.dart b/lib/presentation/recipe/recipe_create_screen/recipe_create_screen.dart index b663db2..84c484a 100644 --- a/lib/presentation/recipe/recipe_create_screen/recipe_create_screen.dart +++ b/lib/presentation/recipe/recipe_create_screen/recipe_create_screen.dart @@ -11,12 +11,12 @@ import 'package:eatvio_app/widgets/custom_outlined_button.dart'; class RecipeCreateScreen extends StatelessWidget { const RecipeCreateScreen({Key? key}) : super(key: key); + static Widget builder(BuildContext context) { final recipeID = ModalRoute.of(context)!.settings.arguments; return BlocProvider( - create: (context) => RecipeCreateBloc(RecipeCreateState( - recipeModelObj: RecipeCreateModel(recipeID: recipeID.toString()))) - ..add(RecipeCreateInitialEvent()), + create: (context) => + RecipeCreateBloc(RecipeCreateState(recipeModelObj: RecipeCreateModel(recipeID: recipeID.toString())))..add(RecipeCreateInitialEvent()), child: RecipeCreateScreen()); } @@ -52,25 +52,28 @@ class RecipeCreateScreen extends StatelessWidget { } return SafeArea( - child: Scaffold( - resizeToAvoidBottomInset: false, - body: Container( - width: double.maxFinite, - decoration: BoxDecoration(color: Colors.grey[200]), - child: ListView(children: [ - _buldAppBar(context), - SizedBox(height: 20.v), - _buildRecipeInfo(state, context), - SizedBox(height: 20.v), - Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: steps, - ), - SizedBox(height: 20.v), - _buildAdditional(context, state) - ]), - ), - bottomNavigationBar: _buildBottomBar(context))); + child: Scaffold( + resizeToAvoidBottomInset: false, + body: Container( + width: double.maxFinite, + decoration: BoxDecoration(color: Colors.grey[200]), + child: ListView( + children: [ + _buldAppBar(context), + SizedBox(height: 20.v), + _buildRecipeInfo(state, context), + SizedBox(height: 20.v), + Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: steps, + ), + SizedBox(height: 20.v), + _buildAdditional(context, state) + ], + ), + ), + ), + ); } _buldAppBar(BuildContext context) { @@ -337,9 +340,7 @@ _buildAdditional(BuildContext context, RecipeCreateLoadedState state) { ), ), SizedBox(height: 8.0), - Align( - alignment: Alignment.centerLeft, - child: Text("Ссылка на видео (необязательно)")), + Align(alignment: Alignment.centerLeft, child: Text("Ссылка на видео (необязательно)")), CustomTextFormField( controller: state.description, hintText: "YouTube", @@ -361,10 +362,6 @@ _buildAdditional(BuildContext context, RecipeCreateLoadedState state) { ); } -_buildBottomBar(BuildContext context) { - return CustomBottomBar(onChanged: (BottomBarEnum type) {}); -} - Function onTapBack(BuildContext context) { return () { onTapArrowLeft(context); diff --git a/lib/presentation/recipe/recipe_edit_screen/recipe_edit_screen.dart b/lib/presentation/recipe/recipe_edit_screen/recipe_edit_screen.dart index 31a723a..7785466 100644 --- a/lib/presentation/recipe/recipe_edit_screen/recipe_edit_screen.dart +++ b/lib/presentation/recipe/recipe_edit_screen/recipe_edit_screen.dart @@ -8,12 +8,11 @@ import 'package:flutter_dotenv/flutter_dotenv.dart'; class RecipeEditScreen extends StatelessWidget { const RecipeEditScreen({Key? key}) : super(key: key); + static Widget builder(BuildContext context) { final recipeID = ModalRoute.of(context)!.settings.arguments; return BlocProvider( - create: (context) => RecipeEditBloc(RecipeEditState( - recipeModelObj: RecipeEditModel(recipeID: recipeID.toString()))) - ..add(RecipeEditInitialEvent()), + create: (context) => RecipeEditBloc(RecipeEditState(recipeModelObj: RecipeEditModel(recipeID: recipeID.toString())))..add(RecipeEditInitialEvent()), child: RecipeEditScreen()); } @@ -42,42 +41,43 @@ class RecipeEditScreen extends StatelessWidget { _buildRecipeEdit(BuildContext context, RecipeEditLoadedState state) { mediaQueryData = MediaQuery.of(context); return SafeArea( - child: Scaffold( - resizeToAvoidBottomInset: false, - body: Container( - width: double.maxFinite, - decoration: AppDecoration.fillGray, - child: ListView(children: [ - SizedBox(height: 30.v), - Container( - margin: EdgeInsets.only( - left: 16.h, - right: 20.h, - bottom: 10.h, - ), - padding: EdgeInsets.all(12.h), - 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: Column(mainAxisSize: MainAxisSize.min, children: [ + child: Scaffold( + resizeToAvoidBottomInset: false, + body: Container( + width: double.maxFinite, + decoration: AppDecoration.fillGray, + child: ListView( + children: [ + SizedBox(height: 30.v), + Container( + margin: EdgeInsets.only( + left: 16.h, + right: 20.h, + bottom: 10.h, + ), + padding: EdgeInsets.all(12.h), + 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: Column( + mainAxisSize: MainAxisSize.min, + children: [ CachedNetworkImage( - imageUrl: dotenv.env['STORAGE_URL']! + - (state.recipe?['image'] ?? ''), + imageUrl: dotenv.env['STORAGE_URL']! + (state.recipe?['image'] ?? ''), imageBuilder: (context, imageProvider) => CircleAvatar( backgroundImage: imageProvider, radius: 25, ), - placeholder: (context, url) => - CircularProgressIndicator(), + placeholder: (context, url) => CircularProgressIndicator(), errorWidget: (context, url, error) => CircleAvatar( child: Icon(Icons.person), backgroundColor: Colors.white, @@ -102,18 +102,16 @@ class RecipeEditScreen extends StatelessWidget { SizedBox(height: 16.0), // Здесь нужно добавить виджет для загрузки картинки ElevatedButton( - onPressed: () => - context.read().add(EditRecipe()), + onPressed: () => context.read().add(EditRecipe()), child: Text('Сохранить'), ) - ]), - ) - ]), - ), - bottomNavigationBar: _buildBottomBar(context))); + ], + ), + ) + ], + ), + ), + ), + ); } } - -_buildBottomBar(BuildContext context) { - return CustomBottomBar(onChanged: (BottomBarEnum type) {}); -} 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 0623c05..0b45fda 100644 --- a/lib/presentation/recipe/recipe_select_screen/recipe_select_screen.dart +++ b/lib/presentation/recipe/recipe_select_screen/recipe_select_screen.dart @@ -1,3 +1,5 @@ +import 'package:go_router/go_router.dart'; + import 'bloc/recipe_select_bloc.dart'; import 'models/recipe_select_model.dart'; import 'package:eatvio_app/core/app_export.dart'; @@ -39,75 +41,71 @@ class RecipeSelectScreen extends StatelessWidget { } _buildRecipeScreen(BuildContext context, RecipeSelectLoadedState state) { - mediaQueryData = MediaQuery.of(context); - return SafeArea( - child: Scaffold( - backgroundColor: Colors.grey[200], - resizeToAvoidBottomInset: true, - body: SingleChildScrollView( - child: Container( - width: double.maxFinite, - decoration: BoxDecoration(color: Colors.grey[200]), - child: Padding( - padding: EdgeInsets.all(16), - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - SizedBox(height: 10), - Container( - 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: CustomAppBar( - height: 54.v, - leadingWidth: 28.h, - leading: AppbarLeadingImage( - imagePath: ImageConstant.imgArrowLeft, - margin: EdgeInsets.only( - left: 16.h, top: 15.v, bottom: 15.v), - onTap: onTapBack(context), + return Scaffold( + backgroundColor: Colors.grey[200], + resizeToAvoidBottomInset: true, + body: SingleChildScrollView( + child: Container( + width: double.maxFinite, + decoration: BoxDecoration(color: Colors.grey[200]), + child: Padding( + padding: EdgeInsets.all(16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + SizedBox(height: 10), + Container( + 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), ), - title: Padding( - padding: EdgeInsets.only(left: 20.h), - child: Row( - children: [ - AppbarSubtitle( - text: "Рецепты", - 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.recipeCreateScreen, - ), - child: Icon(Icons.create_outlined)), - ) - ], - ), + ], + ), + child: CustomAppBar( + height: 54.v, + leadingWidth: 28.h, + leading: AppbarLeadingImage( + imagePath: ImageConstant.imgArrowLeft, + margin: EdgeInsets.only( + left: 16.h, top: 15.v, bottom: 15.v), + onTap: () => GoRouter.of(context).pop(), + ), + title: Padding( + padding: EdgeInsets.only(left: 20.h), + child: Row( + children: [ + AppbarSubtitle( + text: "Рецепты", + 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.recipeCreateScreen, + ), + child: Icon(Icons.create_outlined)), + ) + ], ), ), ), - SizedBox(height: 20), - _buildRecipeList(context, state), - ], - ), + ), + SizedBox(height: 20), + _buildRecipeList(context, state), + ], ), ), ), - bottomNavigationBar: _buildBottomBar(context), ), ); } @@ -174,10 +172,6 @@ class RecipeSelectScreen extends StatelessWidget { }; } - _buildBottomBar(BuildContext context) { - return CustomBottomBar(onChanged: (BottomBarEnum type) {}); - } - onTapArrowLeft(BuildContext context) { NavigatorService.goBack(); } 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 ee75776..d250e1f 100644 --- a/lib/presentation/recipe/recipe_show_screen/recipe_show_screen.dart +++ b/lib/presentation/recipe/recipe_show_screen/recipe_show_screen.dart @@ -8,12 +8,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()); } @@ -42,90 +41,74 @@ class RecipeScreen extends StatelessWidget { _buildRecipe(BuildContext context, RecipeLoadedState state) { mediaQueryData = MediaQuery.of(context); return SafeArea( - child: Scaffold( - resizeToAvoidBottomInset: false, - body: Container( - width: double.maxFinite, - decoration: AppDecoration.fillGray, - child: ListView( - children: [ - SizedBox(height: 30.v), - Container( - margin: EdgeInsets.only( - left: 16.h, - right: 20.h, - bottom: 10.h, + child: Scaffold( + resizeToAvoidBottomInset: false, + body: Container( + width: double.maxFinite, + decoration: AppDecoration.fillGray, + child: ListView( + children: [ + SizedBox(height: 30.v), + Container( + margin: EdgeInsets.only( + left: 16.h, + right: 20.h, + bottom: 10.h, + ), + padding: EdgeInsets.all(12.h), + 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), ), - padding: EdgeInsets.all(12.h), - 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: Column(mainAxisSize: MainAxisSize.min, children: [ + CachedNetworkImage( + imageUrl: dotenv.env['STORAGE_URL']! + (state.recipe?['image'] ?? ''), + imageBuilder: (context, imageProvider) => CircleAvatar( + backgroundImage: imageProvider, + radius: 25, ), - child: Column(mainAxisSize: MainAxisSize.min, children: [ - CachedNetworkImage( - imageUrl: dotenv.env['STORAGE_URL']! + - (state.recipe?['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, - ), + placeholder: (context, url) => CircularProgressIndicator(), + errorWidget: (context, url, error) => CircleAvatar( + child: Icon(Icons.person), + backgroundColor: Colors.white, + radius: 25, + ), + ), + SizedBox(height: 16.0), + Text(state.recipe?['title'], style: CustomTextStyles.titleMediumBlack), + SizedBox(height: 8.0), + Text( + state.recipe?['description'], + ), + SizedBox(height: 16.0), + Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + ElevatedButton( + onPressed: () => Navigator.pushNamed(context, AppRoutes.recipeEditScreen, arguments: state.recipe?['id'].toString()), + child: Text('Редактировать'), ), - SizedBox(height: 16.0), - Text(state.recipe?['title'], - style: CustomTextStyles.titleMediumBlack), - SizedBox(height: 8.0), - Text( - state.recipe?['description'], + ElevatedButton( + onPressed: () => context.read().add(DeleteEntry(state.recipe?['id'])), + child: Text('Удалить'), ), - SizedBox(height: 16.0), - Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: [ - ElevatedButton( - onPressed: () => Navigator.pushNamed( - context, AppRoutes.recipeEditScreen, - arguments: state.recipe?['id'].toString()), - child: Text('Редактировать'), - ), - ElevatedButton( - onPressed: () => context - .read() - .add(DeleteEntry(state.recipe?['id'])), - child: Text('Удалить'), - ), - ], - ) - ]), + ], ) - ], - ), - ), - bottomNavigationBar: _buildBottomBar(context))); - } - - ///Handling route based on bottom click actions - String getCurrentRoute(BottomBarEnum type) { - switch (type) { - case BottomBarEnum.tf: - return AppRoutes.recipeScreen; - default: - return "/"; - } + ]), + ) + ], + ), + ), + ), + ); } ///Handling page based on route @@ -141,10 +124,6 @@ class RecipeScreen extends StatelessWidget { } } - _buildBottomBar(BuildContext context) { - return CustomBottomBar(onChanged: (BottomBarEnum type) {}); - } - /// Navigates to the previous screen. onTapArrowleftone(BuildContext context) { NavigatorService.goBack(); 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 56e644a..80b3a8b 100644 --- a/lib/presentation/registration/language_select_screen/language_select_screen.dart +++ b/lib/presentation/registration/language_select_screen/language_select_screen.dart @@ -9,97 +9,104 @@ import 'package:flutter/material.dart'; class LanguageSelectScreen extends StatelessWidget { const LanguageSelectScreen({Key? key}) : super(key: key); + static Widget builder(BuildContext context) { return BlocProvider( - create: (context) => LanguageSelectBloc( - LanguageSelectState(languageSelectModelObj: LanguageSelectModel())) - ..add(LanguageSelectInitialEvent()), - child: LanguageSelectScreen()); + create: (context) => LanguageSelectBloc( + LanguageSelectState( + languageSelectModelObj: LanguageSelectModel(), + ), + )..add(LanguageSelectInitialEvent()), + child: LanguageSelectScreen(), + ); } @override Widget build(BuildContext context) { - mediaQueryData = MediaQuery.of(context); - return SafeArea( - child: Scaffold( - body: Container( - width: double.maxFinite, - padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 5.v), - child: Column(children: [ - CustomImageView( - imagePath: ImageConstant.imgLogoEatvio, - height: 50.adaptSize, - width: 50.adaptSize), - SizedBox(height: 20.v), - Container( - height: 16.v, - width: 343.h, + return Scaffold( + body: Container( + width: double.maxFinite, + padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 5.v), + child: Column( + children: [ + CustomImageView(imagePath: ImageConstant.imgLogoEatvio, height: 50.adaptSize, width: 50.adaptSize), + 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, + backgroundColor: theme.colorScheme.onPrimary, + valueColor: AlwaysStoppedAnimation(appTheme.blueA400), + ), + ), + ), + SizedBox(height: 20.v), + Container( + width: 262.h, + margin: EdgeInsets.only(left: 41.h, right: 39.h), + child: Text( + "preferred_language".tr, + maxLines: 2, + overflow: TextOverflow.ellipsis, + textAlign: TextAlign.center, + style: theme.textTheme.headlineSmall, + ), + ), + Spacer(flex: 36), + BlocSelector( + selector: (state) => state.languageSelectModelObj, + builder: ( + context, + languageSelectModelObj, + ) { + return CustomDropDown( + icon: Container( + margin: EdgeInsets.fromLTRB(30.h, 11.v, 17.h, 11.v), 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, - backgroundColor: theme.colorScheme.onPrimary, - valueColor: AlwaysStoppedAnimation( - appTheme.blueA400)))), - SizedBox(height: 20.v), - Container( - width: 262.h, - margin: EdgeInsets.only(left: 41.h, right: 39.h), - child: Text("preferred_language".tr, - maxLines: 2, - overflow: TextOverflow.ellipsis, - textAlign: TextAlign.center, - style: theme.textTheme.headlineSmall)), - Spacer(flex: 36), - BlocSelector( - selector: (state) => state.languageSelectModelObj, - builder: ( - context, - languageSelectModelObj, - ) { - 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, - ), - ), - hintText: "Не выбрано".tr, - items: languageSelectModelObj?.dropdownItemList ?? [], - onChanged: (value) => - _onDropDownChanged(context, value), - ); - }), - Spacer(flex: 63), - ])), - bottomNavigationBar: - 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: _saveAndPush(state, context)); - }))); + borderRadius: BorderRadius.circular(1.h), + ), + child: CustomImageView( + imagePath: ImageConstant.imgFavorite, + height: 12.adaptSize, + width: 12.adaptSize, + ), + ), + hintText: "Не выбрано".tr, + items: languageSelectModelObj?.dropdownItemList ?? [], + onChanged: (value) => _onDropDownChanged(context, value), + ); + }), + Spacer(flex: 63), + ], + ), + ), + bottomNavigationBar: 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: _saveAndPush(state, context), + ); + }, + ), + ); } - void Function()? _saveAndPush( - LanguageSelectState state, BuildContext context) { + void Function()? _saveAndPush(LanguageSelectState state, BuildContext context) { return () { - UserRegistrationSheet sheet = - state.languageSelectModelObj!.userRegistrationSheet; + UserRegistrationSheet sheet = state.languageSelectModelObj!.userRegistrationSheet; Navigator.pushNamed( context, AppRoutes.credentialsScreen, diff --git a/lib/routes/app_routes.dart b/lib/routes/app_routes.dart index 16235b1..d870871 100644 --- a/lib/routes/app_routes.dart +++ b/lib/routes/app_routes.dart @@ -198,8 +198,8 @@ class AppRoutes { planCreateScreen: (context) => _buildFadeRoute(context, PlanCreateScreen.builder), feedScreen: (context) => _buildFadeRoute(context, FeedScreen.builder), - blogPostScreen: (context) => - _buildFadeRoute(context, BlogPostScreen.builder), + // blogPostScreen: (context) => + // _buildFadeRoute(context, BlogPostScreen.builder), blogPostEditScreen: (context) => _buildFadeRoute(context, BlogPostEditScreen.builder), blogPostCreateScreen: (context) => diff --git a/lib/widgets/custom_bottom_bar.dart b/lib/widgets/custom_bottom_bar.dart index b8e5460..f7ecba5 100644 --- a/lib/widgets/custom_bottom_bar.dart +++ b/lib/widgets/custom_bottom_bar.dart @@ -67,6 +67,7 @@ class _BottomNavigationBarWidgetState extends State { }, selectedFontSize: 12, unselectedFontSize: 12, + selectedItemColor: appTheme.blueA400, currentIndex: currentBottomNavBarIndex, items: [ BottomNavigationBarItem( @@ -76,18 +77,46 @@ class _BottomNavigationBarWidgetState extends State { BottomNavigationBarItem( label: 'Лента', icon: SvgPicture.asset(ImageConstant.imgFeed), + activeIcon: SvgPicture.asset( + ImageConstant.imgFeed, + colorFilter: ColorFilter.mode( + appTheme.blueA400, + BlendMode.srcIn, + ), + ), ), BottomNavigationBarItem( label: "diary".tr, icon: SvgPicture.asset(ImageConstant.imgDiary), + activeIcon: SvgPicture.asset( + ImageConstant.imgDiary, + colorFilter: ColorFilter.mode( + appTheme.blueA400, + BlendMode.srcIn, + ), + ), ), BottomNavigationBarItem( label: "chat".tr, icon: SvgPicture.asset(ImageConstant.imgChat), + activeIcon: SvgPicture.asset( + ImageConstant.imgChat, + colorFilter: ColorFilter.mode( + appTheme.blueA400, + BlendMode.srcIn, + ), + ), ), BottomNavigationBarItem( label: '', icon: SvgPicture.asset(ImageConstant.imgBell), + activeIcon: SvgPicture.asset( + ImageConstant.imgBell, + colorFilter: ColorFilter.mode( + appTheme.blueA400, + BlendMode.srcIn, + ), + ), ), BottomNavigationBarItem( label: '', @@ -102,223 +131,3 @@ class _BottomNavigationBarWidgetState extends State { ); } } - -// ignore: must_be_immutable -class CustomBottomBar extends StatefulWidget { - CustomBottomBar({this.onChanged}); - - Function(BottomBarEnum)? onChanged; - - @override - CustomBottomBarState createState() => CustomBottomBarState(); -} - -class CustomBottomBarState extends State { - int selectedIndex = 2; - - List bottomMenuList = [ - BottomMenuModel( - icon: ImageConstant.imgLogo, - activeIcon: ImageConstant.imgLogo, - type: BottomBarEnum.tf, - image: false, - ), - BottomMenuModel( - icon: ImageConstant.imgFeed, - activeIcon: ImageConstant.imgFeed, - title: "Лента", - type: BottomBarEnum.tf, - image: false, - ), - BottomMenuModel( - icon: ImageConstant.imgDiary, - activeIcon: ImageConstant.imgDiary, - title: "diary".tr, - type: BottomBarEnum.tf, - image: false, - ), - BottomMenuModel( - icon: ImageConstant.imgChat, - activeIcon: ImageConstant.imgChat, - title: "chat".tr, - type: BottomBarEnum.tf, - image: false, - ), - BottomMenuModel( - icon: ImageConstant.imgBell, - activeIcon: ImageConstant.imgBell, - type: BottomBarEnum.tf, - image: false, - ), - BottomMenuModel( - icon: ImageConstant.imgEllipse1, - activeIcon: ImageConstant.imgEllipse1, - type: BottomBarEnum.tf, - image: true, - ), - ]; - - @override - Widget build(BuildContext context) { - return Container( - height: 83.v, - decoration: BoxDecoration( - border: Border.all( - color: appTheme.whiteA700, - width: 1.h, - ), - ), - child: BottomNavigationBar( - backgroundColor: Colors.transparent, - showSelectedLabels: false, - showUnselectedLabels: false, - selectedFontSize: 0, - elevation: 0, - currentIndex: selectedIndex, - type: BottomNavigationBarType.fixed, - items: List.generate(bottomMenuList.length, bottomMenu), - onTap: changeMeny, - ), - ); - } - - void changeMeny(index) { - setState(() { - selectedIndex = index; - }); - - switch (index) { - case 0: - Navigator.pushReplacementNamed(context, AppRoutes.myProfile); - break; - case 1: - Navigator.pushReplacementNamed(context, AppRoutes.feedScreen); - break; - case 2: - Navigator.pushReplacementNamed(context, AppRoutes.diaryEdit); - break; - case 3: - Navigator.pushReplacementNamed(context, AppRoutes.chatSelectScreen); - break; - } - } - - BottomNavigationBarItem bottomMenu(index) { - bool isSelected = selectedIndex == index; - - double iconHeight; - double iconWidth; - - if (index == 0) { - // Для логотипа- - iconHeight = 52.v; // Увеличиваем высоту - iconWidth = 48.h; // Меняем ширину, чтобы сохранить пропорции - } else if (index == bottomMenuList.length - 2) { - // Для колокольчика - iconHeight = 20.v; // Уменьшаем высоту - iconWidth = 20.h; // Меняем ширину, чтобы сохранить пропорции - } else if (index == bottomMenuList.length - 1) { - // Для колокольчика - iconHeight = 40.v; // Уменьшаем высоту - iconWidth = 40.h; // Меняем ширину, чтобы сохранить пропорции - } else { - // Для остальных иконок - iconHeight = 24.v; // Стандартная высота - iconWidth = 19.h; // Стандартная ширина - } - - return BottomNavigationBarItem( - icon: Column( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - if (!bottomMenuList[index].image) - CustomImageView( - imagePath: bottomMenuList[index].icon, - height: iconHeight, - width: iconWidth, - color: isSelected ? theme.colorScheme.primary : appTheme.blueGray400, - ), - if (bottomMenuList[index].image) - GestureDetector( - onTap: () => showMenu( - context: context, - color: Colors.white, - shadowColor: Colors.white, - surfaceTintColor: Colors.white, - position: RelativeRect.fromLTRB( - // Указываем позицию справа по центру - MediaQuery.of(context).size.width - 50, // Расположение от правого края - kToolbarHeight + 340, // Расположение от верхнего края - 0, // Не смещаем по горизонтали - 0, // Не смещаем по вертикали - ), - items: [ - PopupMenuItem( - child: CustomNavigationMenu(), // Используйте ваше меню здесь - ) - ], - ), - child: AppbarTitleCircleimage( - imagePath: ImageConstant.imgEllipse1, - ), - ), - if (bottomMenuList[index].title != null) // Проверяем, существует ли title - Padding( - padding: EdgeInsets.only(top: 8.v), - child: Text( - bottomMenuList[index].title!, - style: CustomTextStyles.bodySmallMulishBluegray80012.copyWith( - color: isSelected ? theme.colorScheme.primary : appTheme.blueGray800, - ), - ), - ), - ], - ), - activeIcon: Column( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - CustomImageView( - imagePath: bottomMenuList[index].activeIcon, - height: iconHeight, // Используем тот же размер для активной иконки - width: iconWidth, // Используем тот же размер для активной иконки - color: theme.colorScheme.primary, - ), - Padding( - padding: EdgeInsets.only(top: 9.v), - child: Text( - bottomMenuList[index].title ?? "", - style: CustomTextStyles.bodySmallMulishPrimary.copyWith( - color: theme.colorScheme.primary, - ), - ), - ), - ], - ), - label: '', - ); - } -} - -enum BottomBarEnum { - tf, -} - -class BottomMenuModel { - BottomMenuModel({ - required this.icon, - required this.activeIcon, - this.title, - required this.type, - required this.image, - }); - - String icon; - - String activeIcon; - - String? title; - - BottomBarEnum type; - - bool image; -} diff --git a/lib/widgets/custom_navigation_menu.dart b/lib/widgets/custom_navigation_menu.dart index 4bbdc75..03d11a9 100644 --- a/lib/widgets/custom_navigation_menu.dart +++ b/lib/widgets/custom_navigation_menu.dart @@ -1,6 +1,7 @@ import 'package:eatvio_app/core/app_export.dart'; import 'package:flutter/material.dart'; import 'package:eatvio_app/widgets/custom_navigation_menu_item.dart'; +import 'package:go_router/go_router.dart'; import 'package:hive/hive.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:http/http.dart' as http; @@ -16,33 +17,30 @@ class CustomNavigationMenu extends StatelessWidget { MenuItem( icon: ImageConstant.imgSettings, text: 'Настройки профиля', - onTap: () => Navigator.pushNamed(context, AppRoutes.mySettings), + onTap: () => GoRouter.of(context).push('/my-settings-screen'), ), MenuItem( icon: ImageConstant.imgRecipes, text: 'Мои рецепты', - onTap: () => - Navigator.pushNamed(context, AppRoutes.recipeSelectScreen), + onTap: () => GoRouter.of(context).push('/recipe-select-screen'), // Действие при нажатии на "Мои рецепты" ), MenuItem( icon: ImageConstant.imgDiets, text: 'Мои диеты', - onTap: () => - Navigator.pushNamed(context, AppRoutes.dietSelectScreen), + onTap: () => GoRouter.of(context).push('/diet-select-screen'), // Действие при нажатии на "Мои рецепты" ), MenuItem( icon: ImageConstant.imgPlans, text: 'Мои планы', - onTap: () => - Navigator.pushNamed(context, AppRoutes.planSelectScreen), + onTap: () => GoRouter.of(context).push('/plan-select-screen'), // Действие при нажатии на "Мои рецепты" ), MenuItem( icon: ImageConstant.imgFinance, text: 'Глоссарий', - onTap: () => Navigator.pushNamed(context, AppRoutes.glossaryScreen), + onTap: () => GoRouter.of(context).push('/glossary-screen'), ), MenuItem( icon: ImageConstant.imgSupport, @@ -77,10 +75,7 @@ _onTapLogout(BuildContext context) { if (response.statusCode == 204) { print(response.statusCode); box.delete('token'); // Удаляем токен из Hive - Navigator.pushNamed( - context, - AppRoutes.authScreen, - ); + GoRouter.of(context).go('/auth-screen'); } }; } From 60c372fb4cca0539dad772290e6fa056ddb39ca6 Mon Sep 17 00:00:00 2001 From: mso7nueh Date: Wed, 5 Jun 2024 12:53:38 +0300 Subject: [PATCH 05/17] fix warnings --- lib/app_router.dart | 2 +- .../chat/chat_screen/chat_screen.dart | 57 ------------------- .../diet_create_screen.dart | 1 - .../diet_edit_screen/diet_edit_screen.dart | 1 - .../diet_select_screen.dart | 1 - .../diet_show_screen/diet_show_screen.dart | 1 - .../blog_post_edit_screen.dart | 1 - .../glossary_screen/glossary_screen.dart | 1 - .../plan_create_screen.dart | 1 - .../plan_edit_screen/plan_edit_screen.dart | 1 - .../plan_select_screen.dart | 1 - .../plan_show_screen/plan_show_screen.dart | 1 - .../my_profile_screen/my_settings_screen.dart | 1 - .../recipe_create_screen.dart | 1 - .../recipe_edit_screen.dart | 1 - .../recipe_select_screen.dart | 1 - .../recipe_show_screen.dart | 1 - lib/routes/app_routes.dart | 1 - ...dart => bottom_navigation_bar_widget.dart} | 1 - 19 files changed, 1 insertion(+), 75 deletions(-) rename lib/widgets/{custom_bottom_bar.dart => bottom_navigation_bar_widget.dart} (98%) diff --git a/lib/app_router.dart b/lib/app_router.dart index 255df7a..a7de988 100644 --- a/lib/app_router.dart +++ b/lib/app_router.dart @@ -11,7 +11,7 @@ import 'package:eatvio_app/presentation/profile/my_profile_screen/my_profile_scr import 'package:eatvio_app/presentation/profile/my_profile_screen/my_settings_screen.dart'; import 'package:eatvio_app/presentation/recipe/recipe_select_screen/recipe_select_screen.dart'; import 'package:eatvio_app/presentation/registration/language_select_screen/language_select_screen.dart'; -import 'package:eatvio_app/widgets/custom_bottom_bar.dart'; +import 'package:eatvio_app/widgets/bottom_navigation_bar_widget.dart'; import 'package:go_router/go_router.dart'; import 'package:hive_flutter/hive_flutter.dart'; diff --git a/lib/presentation/chat/chat_screen/chat_screen.dart b/lib/presentation/chat/chat_screen/chat_screen.dart index a132f88..7ec3ea6 100644 --- a/lib/presentation/chat/chat_screen/chat_screen.dart +++ b/lib/presentation/chat/chat_screen/chat_screen.dart @@ -6,8 +6,6 @@ import 'package:eatvio_app/widgets/app_bar/custom_app_bar.dart'; import 'package:eatvio_app/widgets/app_bar/appbar_subtitle.dart'; import 'package:eatvio_app/widgets/app_bar/appbar_leading_image.dart'; import 'package:eatvio_app/widgets/app_bar/appbar_title_image.dart'; -import 'package:eatvio_app/widgets/custom_bottom_bar.dart'; -import 'package:eatvio_app/widgets/custom_text_form_field.dart'; class ChatScreen extends StatelessWidget { const ChatScreen({Key? key}) : super(key: key); @@ -104,61 +102,6 @@ class ChatScreen extends StatelessWidget { ); } - /// Section Widget - _buildTextField(BuildContext context) { - return Container( - width: double.maxFinite, - padding: EdgeInsets.symmetric( - horizontal: 7.h, - vertical: 6.v, - ), - decoration: AppDecoration.outlineBlueGray, - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - CustomImageView( - imagePath: ImageConstant.imgAttach, - height: 29.adaptSize, - width: 29.adaptSize, - margin: EdgeInsets.only( - top: 1.v, - bottom: 6.v, - ), - ), - Expanded( - child: Padding( - padding: EdgeInsets.only( - left: 4.h, - bottom: 4.v, - ), - child: BlocSelector( - selector: (state) => TextEditingController(), - builder: (context, messageController) { - return CustomTextFormField( - controller: messageController, - hintText: "Напишите сообщение...", - textInputAction: TextInputAction.done, - ); - }, - ), - ), - ), - CustomImageView( - imagePath: ImageConstant.imgMic, - height: 24.v, - width: 18.h, - margin: EdgeInsets.only( - left: 11.h, - top: 4.v, - bottom: 8.v, - ), - ) - ], - ), - ); - } - ///Handling page based on route Widget getCurrentPage( BuildContext context, diff --git a/lib/presentation/diets/diet_create_screen/diet_create_screen.dart b/lib/presentation/diets/diet_create_screen/diet_create_screen.dart index eae238b..516a931 100644 --- a/lib/presentation/diets/diet_create_screen/diet_create_screen.dart +++ b/lib/presentation/diets/diet_create_screen/diet_create_screen.dart @@ -2,7 +2,6 @@ import 'bloc/diet_create_bloc.dart'; import 'models/diet_create_model.dart'; import 'package:eatvio_app/core/app_export.dart'; import 'package:flutter/material.dart'; -import 'package:eatvio_app/widgets/custom_bottom_bar.dart'; class DietCreateScreen extends StatelessWidget { const DietCreateScreen({Key? key}) : super(key: key); diff --git a/lib/presentation/diets/diet_edit_screen/diet_edit_screen.dart b/lib/presentation/diets/diet_edit_screen/diet_edit_screen.dart index 665927b..a0f988d 100644 --- a/lib/presentation/diets/diet_edit_screen/diet_edit_screen.dart +++ b/lib/presentation/diets/diet_edit_screen/diet_edit_screen.dart @@ -2,7 +2,6 @@ import 'bloc/diet_edit_bloc.dart'; import 'models/diet_edit_model.dart'; import 'package:eatvio_app/core/app_export.dart'; import 'package:flutter/material.dart'; -import 'package:eatvio_app/widgets/custom_bottom_bar.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter_dotenv/flutter_dotenv.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 207cbb6..e573be6 100644 --- a/lib/presentation/diets/diet_select_screen/diet_select_screen.dart +++ b/lib/presentation/diets/diet_select_screen/diet_select_screen.dart @@ -6,7 +6,6 @@ import 'package:eatvio_app/core/app_export.dart'; import 'package:eatvio_app/widgets/app_bar/appbar_subtitle.dart'; import 'package:eatvio_app/widgets/app_bar/appbar_leading_image.dart'; import 'package:eatvio_app/widgets/app_bar/custom_app_bar.dart'; -import 'package:eatvio_app/widgets/custom_bottom_bar.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:flutter/material.dart'; 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 d05a39a..a15c8f6 100644 --- a/lib/presentation/diets/diet_show_screen/diet_show_screen.dart +++ b/lib/presentation/diets/diet_show_screen/diet_show_screen.dart @@ -2,7 +2,6 @@ import 'bloc/diet_show_bloc.dart'; import 'models/diet_show_model.dart'; import 'package:eatvio_app/core/app_export.dart'; import 'package:flutter/material.dart'; -import 'package:eatvio_app/widgets/custom_bottom_bar.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; diff --git a/lib/presentation/feed/blog_post_edit_screen/blog_post_edit_screen.dart b/lib/presentation/feed/blog_post_edit_screen/blog_post_edit_screen.dart index ac5a833..cd3ad78 100644 --- a/lib/presentation/feed/blog_post_edit_screen/blog_post_edit_screen.dart +++ b/lib/presentation/feed/blog_post_edit_screen/blog_post_edit_screen.dart @@ -2,7 +2,6 @@ import 'bloc/blog_post_edit_bloc.dart'; import 'models/blog_post_edit_model.dart'; import 'package:eatvio_app/core/app_export.dart'; import 'package:flutter/material.dart'; -import 'package:eatvio_app/widgets/custom_bottom_bar.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; diff --git a/lib/presentation/glossary/glossary_screen/glossary_screen.dart b/lib/presentation/glossary/glossary_screen/glossary_screen.dart index 42b8477..ebfa70d 100644 --- a/lib/presentation/glossary/glossary_screen/glossary_screen.dart +++ b/lib/presentation/glossary/glossary_screen/glossary_screen.dart @@ -4,7 +4,6 @@ import 'package:eatvio_app/core/app_export.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; -import 'package:eatvio_app/widgets/custom_bottom_bar.dart'; import 'package:eatvio_app/widgets/custom_outlined_button.dart'; import 'package:eatvio_app/widgets/custom_drop_down.dart'; import 'package:eatvio_app/presentation/glossary/glossary_screen/widgets/glossary_search_widget.dart'; diff --git a/lib/presentation/plans/plan_create_screen/plan_create_screen.dart b/lib/presentation/plans/plan_create_screen/plan_create_screen.dart index 9ab5cad..bd354af 100644 --- a/lib/presentation/plans/plan_create_screen/plan_create_screen.dart +++ b/lib/presentation/plans/plan_create_screen/plan_create_screen.dart @@ -2,7 +2,6 @@ import 'bloc/plan_create_bloc.dart'; import 'models/plan_create_model.dart'; import 'package:eatvio_app/core/app_export.dart'; import 'package:flutter/material.dart'; -import 'package:eatvio_app/widgets/custom_bottom_bar.dart'; class PlanCreateScreen extends StatelessWidget { const PlanCreateScreen({Key? key}) : super(key: key); diff --git a/lib/presentation/plans/plan_edit_screen/plan_edit_screen.dart b/lib/presentation/plans/plan_edit_screen/plan_edit_screen.dart index c163f2c..7baa33d 100644 --- a/lib/presentation/plans/plan_edit_screen/plan_edit_screen.dart +++ b/lib/presentation/plans/plan_edit_screen/plan_edit_screen.dart @@ -2,7 +2,6 @@ import 'bloc/plan_edit_bloc.dart'; import 'models/plan_edit_model.dart'; import 'package:eatvio_app/core/app_export.dart'; import 'package:flutter/material.dart'; -import 'package:eatvio_app/widgets/custom_bottom_bar.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; 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 a82a667..78ac405 100644 --- a/lib/presentation/plans/plan_select_screen/plan_select_screen.dart +++ b/lib/presentation/plans/plan_select_screen/plan_select_screen.dart @@ -6,7 +6,6 @@ import 'package:eatvio_app/core/app_export.dart'; import 'package:eatvio_app/widgets/app_bar/appbar_subtitle.dart'; import 'package:eatvio_app/widgets/app_bar/appbar_leading_image.dart'; import 'package:eatvio_app/widgets/app_bar/custom_app_bar.dart'; -import 'package:eatvio_app/widgets/custom_bottom_bar.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:flutter/material.dart'; 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 8e2f243..262f876 100644 --- a/lib/presentation/plans/plan_show_screen/plan_show_screen.dart +++ b/lib/presentation/plans/plan_show_screen/plan_show_screen.dart @@ -2,7 +2,6 @@ import 'bloc/plan_show_bloc.dart'; import 'models/plan_show_model.dart'; import 'package:eatvio_app/core/app_export.dart'; import 'package:flutter/material.dart'; -import 'package:eatvio_app/widgets/custom_bottom_bar.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; diff --git a/lib/presentation/profile/my_profile_screen/my_settings_screen.dart b/lib/presentation/profile/my_profile_screen/my_settings_screen.dart index 0f2ac43..501ffca 100644 --- a/lib/presentation/profile/my_profile_screen/my_settings_screen.dart +++ b/lib/presentation/profile/my_profile_screen/my_settings_screen.dart @@ -6,7 +6,6 @@ import 'package:eatvio_app/core/app_export.dart'; import 'package:eatvio_app/widgets/app_bar/appbar_subtitle.dart'; import 'package:eatvio_app/widgets/app_bar/appbar_leading_image.dart'; import 'package:eatvio_app/widgets/app_bar/custom_app_bar.dart'; -import 'package:eatvio_app/widgets/custom_bottom_bar.dart'; import 'package:eatvio_app/widgets/custom_about_list.dart'; import 'package:eatvio_app/widgets/custom_expandable_list.dart'; import 'package:eatvio_app/widgets/custom_notification_screen.dart'; diff --git a/lib/presentation/recipe/recipe_create_screen/recipe_create_screen.dart b/lib/presentation/recipe/recipe_create_screen/recipe_create_screen.dart index 84c484a..8865407 100644 --- a/lib/presentation/recipe/recipe_create_screen/recipe_create_screen.dart +++ b/lib/presentation/recipe/recipe_create_screen/recipe_create_screen.dart @@ -5,7 +5,6 @@ import 'package:flutter/material.dart'; import 'package:eatvio_app/widgets/app_bar/custom_app_bar.dart'; import 'package:eatvio_app/widgets/app_bar/appbar_leading_image.dart'; import 'package:eatvio_app/widgets/app_bar/appbar_subtitle.dart'; -import 'package:eatvio_app/widgets/custom_bottom_bar.dart'; import 'package:eatvio_app/widgets/custom_text_form_field.dart'; import 'package:eatvio_app/widgets/custom_outlined_button.dart'; diff --git a/lib/presentation/recipe/recipe_edit_screen/recipe_edit_screen.dart b/lib/presentation/recipe/recipe_edit_screen/recipe_edit_screen.dart index 7785466..9ee0075 100644 --- a/lib/presentation/recipe/recipe_edit_screen/recipe_edit_screen.dart +++ b/lib/presentation/recipe/recipe_edit_screen/recipe_edit_screen.dart @@ -2,7 +2,6 @@ import 'bloc/recipe_edit_bloc.dart'; import 'models/recipe_edit_model.dart'; import 'package:eatvio_app/core/app_export.dart'; import 'package:flutter/material.dart'; -import 'package:eatvio_app/widgets/custom_bottom_bar.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; 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 0b45fda..f72ca51 100644 --- a/lib/presentation/recipe/recipe_select_screen/recipe_select_screen.dart +++ b/lib/presentation/recipe/recipe_select_screen/recipe_select_screen.dart @@ -6,7 +6,6 @@ import 'package:eatvio_app/core/app_export.dart'; import 'package:eatvio_app/widgets/app_bar/appbar_subtitle.dart'; import 'package:eatvio_app/widgets/app_bar/appbar_leading_image.dart'; import 'package:eatvio_app/widgets/app_bar/custom_app_bar.dart'; -import 'package:eatvio_app/widgets/custom_bottom_bar.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:flutter/material.dart'; 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 d250e1f..4bdea28 100644 --- a/lib/presentation/recipe/recipe_show_screen/recipe_show_screen.dart +++ b/lib/presentation/recipe/recipe_show_screen/recipe_show_screen.dart @@ -2,7 +2,6 @@ import 'bloc/recipe_show_bloc.dart'; import 'models/recipe_show_model.dart'; import 'package:eatvio_app/core/app_export.dart'; import 'package:flutter/material.dart'; -import 'package:eatvio_app/widgets/custom_bottom_bar.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; diff --git a/lib/routes/app_routes.dart b/lib/routes/app_routes.dart index d870871..fd65602 100644 --- a/lib/routes/app_routes.dart +++ b/lib/routes/app_routes.dart @@ -35,7 +35,6 @@ import 'package:eatvio_app/presentation/plans/plan_show_screen/plan_show_screen. 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_screen/blog_post_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'; diff --git a/lib/widgets/custom_bottom_bar.dart b/lib/widgets/bottom_navigation_bar_widget.dart similarity index 98% rename from lib/widgets/custom_bottom_bar.dart rename to lib/widgets/bottom_navigation_bar_widget.dart index f7ecba5..dbf9ba2 100644 --- a/lib/widgets/custom_bottom_bar.dart +++ b/lib/widgets/bottom_navigation_bar_widget.dart @@ -1,6 +1,5 @@ import 'package:eatvio_app/core/app_export.dart'; import 'package:flutter/material.dart'; -import 'package:eatvio_app/widgets/app_bar/appbar_title_circleimage.dart'; import 'package:eatvio_app/widgets/custom_navigation_menu.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:go_router/go_router.dart'; From bd88d8003481ee66f87df42423bc6c72b0e3722c Mon Sep 17 00:00:00 2001 From: mso7nueh Date: Wed, 5 Jun 2024 13:13:35 +0300 Subject: [PATCH 06/17] fix style warning --- lib/widgets/bottom_navigation_bar_widget.dart | 80 ++++++++++--------- 1 file changed, 41 insertions(+), 39 deletions(-) diff --git a/lib/widgets/bottom_navigation_bar_widget.dart b/lib/widgets/bottom_navigation_bar_widget.dart index dbf9ba2..6f29ef3 100644 --- a/lib/widgets/bottom_navigation_bar_widget.dart +++ b/lib/widgets/bottom_navigation_bar_widget.dart @@ -19,51 +19,53 @@ class BottomNavigationBarWidget extends StatefulWidget { } class _BottomNavigationBarWidgetState extends State { + void _onItemTapped(int index) { + if (currentBottomNavBarIndex != index) { + setState(() { + currentBottomNavBarIndex = index; + }); + } + switch (currentBottomNavBarIndex) { + case 0: + GoRouter.of(context).replace('/my-profile-screen'); + break; + case 1: + GoRouter.of(context).replace('/feed-screen'); + break; + case 2: + GoRouter.of(context).replace('/diary-screen'); + break; + case 3: + GoRouter.of(context).replace('/chat-select-screen'); + break; + case 4: + break; + case 5: + final RenderBox overlay = Overlay.of(context).context.findRenderObject() as RenderBox; + final size = overlay.size; + showMenu( + context: context, + color: Colors.white, + shadowColor: Colors.white, + surfaceTintColor: Colors.white, + items: [ + PopupMenuItem( + child: CustomNavigationMenu(), + ) + ], + position: RelativeRect.fromLTRB(size.width, size.height, 0, 0), + ); + break; + } + } + @override Widget build(BuildContext context) { return Scaffold( body: widget.child, bottomNavigationBar: BottomNavigationBar( type: BottomNavigationBarType.fixed, - onTap: (index) { - if (currentBottomNavBarIndex != index) { - setState(() { - currentBottomNavBarIndex = index; - }); - } - switch (currentBottomNavBarIndex) { - case 0: - GoRouter.of(context).replace('/my-profile-screen'); - break; - case 1: - GoRouter.of(context).replace('/feed-screen'); - break; - case 2: - GoRouter.of(context).replace('/diary-screen'); - break; - case 3: - GoRouter.of(context).replace('/chat-select-screen'); - break; - case 4: - break; - case 5: - final RenderBox overlay = Overlay.of(context).context.findRenderObject() as RenderBox; - final size = overlay.size; - showMenu( - context: context, - color: Colors.white, - shadowColor: Colors.white, - surfaceTintColor: Colors.white, - items: [ - PopupMenuItem( - child: CustomNavigationMenu(), - ) - ], - position: RelativeRect.fromLTRB(size.width, size.height, 0, 0), - ); - break; - } - }, + onTap: _onItemTapped, selectedFontSize: 12, unselectedFontSize: 12, selectedItemColor: appTheme.blueA400, From fc743727c2caac74baec4703dcfcfa0daae9b438 Mon Sep 17 00:00:00 2001 From: mso7nueh Date: Wed, 5 Jun 2024 13:23:02 +0300 Subject: [PATCH 07/17] fix style! warning --- .../my_profile_screen/my_profile_screen.dart | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) 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 3bfb6cc..5296917 100644 --- a/lib/presentation/profile/my_profile_screen/my_profile_screen.dart +++ b/lib/presentation/profile/my_profile_screen/my_profile_screen.dart @@ -70,23 +70,24 @@ class MyProfileScreen extends StatelessWidget { children: [ SizedBox(height: 30.v), Container( - padding: EdgeInsets.symmetric( - horizontal: 24.h, - vertical: 12.v, - ), - 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: _buildInfo(context, state)), + padding: EdgeInsets.symmetric( + horizontal: 24.h, + vertical: 12.v, + ), + 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: _buildInfo(context, state), + ), SizedBox(height: 15.v), Container( padding: EdgeInsets.symmetric( @@ -141,7 +142,7 @@ class MyProfileScreen extends StatelessWidget { } /// Section Widget - Widget _buildInfo(BuildContext context, MyProfileLoadedState state) { + _buildInfo(BuildContext context, MyProfileLoadedState state) { return Column( children: [ GestureDetector( From 6947b9bea0f22b2eb2fbd7e5e3f28464145e7f49 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Wed, 5 Jun 2024 16:20:14 +0300 Subject: [PATCH 08/17] feat(app): Recipe layouts --- .../bloc/recipe_create_bloc.dart | 82 ++- .../bloc/recipe_create_event.dart | 19 + .../bloc/recipe_create_state.dart | 35 +- .../recipe_create_screen.dart | 421 +++++++-------- .../bloc/recipe_edit_bloc.dart | 124 ++++- .../bloc/recipe_edit_event.dart | 19 + .../bloc/recipe_edit_state.dart | 22 +- .../recipe_edit_screen.dart | 455 ++++++++++++++--- .../bloc/recipe_show_bloc.dart | 130 ++++- .../bloc/recipe_show_event.dart | 7 + .../bloc/recipe_show_state.dart | 41 +- .../recipe_show_screen.dart | 479 +++++++++++++++--- .../widgets/comment_widget.dart | 107 ++++ lib/widgets/custom_text_form_field.dart | 7 + 14 files changed, 1574 insertions(+), 374 deletions(-) create mode 100644 lib/presentation/recipe/recipe_show_screen/widgets/comment_widget.dart 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 f637dbf..05535dd 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 @@ -16,6 +16,9 @@ class RecipeCreateBloc extends Bloc { RecipeCreateBloc(RecipeCreateState initialState) : super(initialState) { on(_onInitialize); on(_createRecipe); + on(_addStep); + on(_removeStep); + on(_reloadScreen); } _onInitialize( @@ -34,22 +37,65 @@ class RecipeCreateBloc extends Bloc { emit(currentState.copyWith( recipeModelObj: currentState.recipeModelObj, title: currentState.title, + token: currentState.token, description: currentState.description, video_url: currentState.video_url, - steps: currentState.steps)); + steps: currentState.steps, + stepDescriptions: currentState.stepDescriptions, + tags: currentState.tags)); } else { final Map step = { 'description': '', 'image': '', }; emit(RecipeCreateLoadedState( + token: token, title: TextEditingController(), description: TextEditingController(), video_url: TextEditingController(), + tags: TextEditingController(), + stepDescriptions: [TextEditingController()], steps: [step])); } } + FutureOr _addStep( + AddStep event, Emitter emit) async { + if (state is RecipeCreateLoadedState) { + var currentState = state as RecipeCreateLoadedState; + + List? updatedSteps = currentState.steps; + List? updatedStepDescriptions = + currentState.stepDescriptions; + + updatedSteps!.add({ + 'description': '', + 'image': '', + }); + updatedStepDescriptions!.add(TextEditingController()); + emit(currentState.copyWith( + steps: updatedSteps, stepDescriptions: updatedStepDescriptions)); + await _reloadScreen(event, emit); + } + } + + FutureOr _removeStep( + RemoveStep event, Emitter emit) async { + if (state is RecipeCreateLoadedState) { + var currentState = state as RecipeCreateLoadedState; + + List? updatedSteps = currentState.steps; + List? updatedStepDescriptions = + currentState.stepDescriptions; + + updatedSteps!.removeAt(event.id); + updatedStepDescriptions!.removeAt(event.id); + emit(currentState.copyWith( + steps: updatedSteps, stepDescriptions: updatedStepDescriptions)); + await _reloadScreen(event, emit); + } + } + FutureOr _createRecipe( CreateRecipe event, Emitter emit) async { if (state is RecipeCreateLoadedState) { @@ -59,6 +105,7 @@ class RecipeCreateBloc extends Bloc { currentState.title?.text, currentState.video_url?.text, currentState.description?.text, + currentState.steps, ); if (response.statusCode == 200) { @@ -70,17 +117,14 @@ class RecipeCreateBloc extends Bloc { } } - FutureOr sendRecipe( - String? title, - String? video_url, - String? description, - ) async { + FutureOr sendRecipe(String? title, String? video_url, + String? description, List? steps) async { String url = '${dotenv.env['SERVER_ROOT']!}/recipe/create'; - final Map credentials = { 'title': title, 'description': description, 'video_url': video_url, + 'steps': steps, 'status': 'active', }; @@ -95,4 +139,28 @@ class RecipeCreateBloc extends Bloc { return response; } + + FutureOr _reloadScreen( + RecipeCreateEvent? event, Emitter emit) async { + print('Reloading..'); + final box = await Hive.openBox('token'); + final token = box.get('token'); + if (token == null) { + NavigatorService.popAndPushNamed( + AppRoutes.authScreen, + ); + } + if (state is RecipeCreateLoadedState) { + var currentState = state as RecipeCreateLoadedState; + emit(currentState.copyWith( + recipeModelObj: currentState.recipeModelObj, + title: currentState.title, + token: currentState.token, + description: currentState.description, + video_url: currentState.video_url, + steps: currentState.steps, + stepDescriptions: currentState.stepDescriptions, + tags: currentState.tags)); + } + } } diff --git a/lib/presentation/recipe/recipe_create_screen/bloc/recipe_create_event.dart b/lib/presentation/recipe/recipe_create_screen/bloc/recipe_create_event.dart index fcea807..085045d 100644 --- a/lib/presentation/recipe/recipe_create_screen/bloc/recipe_create_event.dart +++ b/lib/presentation/recipe/recipe_create_screen/bloc/recipe_create_event.dart @@ -19,3 +19,22 @@ class CreateRecipe extends RecipeCreateEvent { @override List get props => []; } + +class AddStep extends RecipeCreateEvent { + AddStep(); + @override + List get props => []; +} + +class RemoveStep extends RecipeCreateEvent { + RemoveStep(this.id); + final int id; + @override + List get props => [id]; +} + +class ReloadScreen extends RecipeCreateEvent { + ReloadScreen(); + @override + List get props => []; +} diff --git a/lib/presentation/recipe/recipe_create_screen/bloc/recipe_create_state.dart b/lib/presentation/recipe/recipe_create_screen/bloc/recipe_create_state.dart index 2a331cb..8545b83 100644 --- a/lib/presentation/recipe/recipe_create_screen/bloc/recipe_create_state.dart +++ b/lib/presentation/recipe/recipe_create_screen/bloc/recipe_create_state.dart @@ -24,33 +24,52 @@ class RecipeCreateState extends Equatable { class RecipeCreateLoadedState extends RecipeCreateState { RecipeCreateLoadedState( {this.recipeModelObj, + this.token, this.title, this.description, this.video_url, + this.tags, + this.stepDescriptions, this.steps}); RecipeCreateModel? recipeModelObj; + String? token; TextEditingController? title; TextEditingController? description; TextEditingController? video_url; + TextEditingController? tags; List? steps; + List? stepDescriptions; @override - List get props => - [recipeModelObj, title, description, video_url, steps]; + List get props => [ + recipeModelObj, + title, + token, + description, + video_url, + steps, + tags, + stepDescriptions + ]; RecipeCreateLoadedState copyWith({ RecipeCreateModel? recipeModelObj, + String? token, TextEditingController? title, TextEditingController? description, TextEditingController? video_url, + TextEditingController? tags, List? steps, + List? stepDescriptions, }) { return RecipeCreateLoadedState( - recipeModelObj: recipeModelObj ?? this.recipeModelObj, - title: title ?? this.title, - description: description ?? this.description, - video_url: video_url ?? this.video_url, - steps: steps ?? this.steps, - ); + recipeModelObj: recipeModelObj ?? this.recipeModelObj, + title: title ?? this.title, + description: description ?? this.description, + video_url: video_url ?? this.video_url, + token: token ?? this.token, + steps: steps ?? this.steps, + tags: tags ?? this.tags, + stepDescriptions: stepDescriptions ?? this.stepDescriptions); } } diff --git a/lib/presentation/recipe/recipe_create_screen/recipe_create_screen.dart b/lib/presentation/recipe/recipe_create_screen/recipe_create_screen.dart index 8865407..2426879 100644 --- a/lib/presentation/recipe/recipe_create_screen/recipe_create_screen.dart +++ b/lib/presentation/recipe/recipe_create_screen/recipe_create_screen.dart @@ -10,12 +10,12 @@ import 'package:eatvio_app/widgets/custom_outlined_button.dart'; class RecipeCreateScreen extends StatelessWidget { const RecipeCreateScreen({Key? key}) : super(key: key); - static Widget builder(BuildContext context) { final recipeID = ModalRoute.of(context)!.settings.arguments; return BlocProvider( - create: (context) => - RecipeCreateBloc(RecipeCreateState(recipeModelObj: RecipeCreateModel(recipeID: recipeID.toString())))..add(RecipeCreateInitialEvent()), + create: (context) => RecipeCreateBloc(RecipeCreateState( + recipeModelObj: RecipeCreateModel(recipeID: recipeID.toString()))) + ..add(RecipeCreateInitialEvent()), child: RecipeCreateScreen()); } @@ -50,29 +50,27 @@ class RecipeCreateScreen extends StatelessWidget { } } - return SafeArea( - child: Scaffold( - resizeToAvoidBottomInset: false, - body: Container( - width: double.maxFinite, - decoration: BoxDecoration(color: Colors.grey[200]), - child: ListView( - children: [ - _buldAppBar(context), - SizedBox(height: 20.v), - _buildRecipeInfo(state, context), - SizedBox(height: 20.v), - Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: steps, - ), - SizedBox(height: 20.v), - _buildAdditional(context, state) - ], - ), - ), - ), - ); + return RefreshIndicator( + onRefresh: refreshPage(context), + child: SafeArea( + child: Scaffold( + resizeToAvoidBottomInset: false, + body: Container( + width: double.maxFinite, + decoration: BoxDecoration(color: Colors.grey[200]), + child: ListView(children: [ + _buldAppBar(context), + SizedBox(height: 20.v), + _buildRecipeInfo(state, context), + SizedBox(height: 20.v), + Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: steps, + ), + SizedBox(height: 20.v), + _buildAdditional(context, state) + ]), + )))); } _buldAppBar(BuildContext context) { @@ -164,45 +162,50 @@ class RecipeCreateScreen extends StatelessWidget { ]), ); } -} -_buildAddPhoto(BuildContext context, RecipeCreateLoadedState state) { - bool isLoading = false; - return GestureDetector( - child: Stack( - children: [ - if (!isLoading) - Container( - padding: EdgeInsets.symmetric( - horizontal: 40.h, - vertical: 80.v, - ), - decoration: AppDecoration.fillGray.copyWith( - borderRadius: BorderRadiusStyle.roundedBorder5, - ), - child: Row( - mainAxisAlignment: MainAxisAlignment.end, - mainAxisSize: MainAxisSize.min, - children: [ - Padding( - padding: EdgeInsets.only( - left: 7.h, - top: 5.v, + refreshPage(BuildContext context) { + return () async { + context.read().add(ReloadScreen()); + }; + } + + _buildAddPhoto(BuildContext context, RecipeCreateLoadedState state) { + bool isLoading = false; + return GestureDetector( + child: Stack( + children: [ + if (!isLoading) + Container( + padding: EdgeInsets.symmetric( + horizontal: 40.h, + vertical: 80.v, + ), + decoration: AppDecoration.fillGray.copyWith( + borderRadius: BorderRadiusStyle.roundedBorder5, + ), + child: Row( + mainAxisAlignment: MainAxisAlignment.end, + mainAxisSize: MainAxisSize.min, + children: [ + Padding( + padding: EdgeInsets.only( + left: 7.h, + top: 5.v, + ), + child: Text( + "Добавить фото", + selectionColor: appTheme.blueA400, + ), ), - child: Text( - "Добавить фото", - selectionColor: appTheme.blueA400, - ), - ), - Spacer(), - Icon( - Icons.photo_library, - color: appTheme.blueGray300, - ) - ], + Spacer(), + Icon( + Icons.photo_library, + color: appTheme.blueGray300, + ) + ], + ), ), - ), - /*if (isLoading) + /*if (isLoading) Container( margin: EdgeInsets.symmetric(horizontal: 10.h), padding: EdgeInsets.symmetric( @@ -218,155 +221,173 @@ _buildAddPhoto(BuildContext context, RecipeCreateLoadedState state) { .blueGray300), // Замените на свой прелоадер при необходимости ), ),*/ - ], - ), - ); -} - -_buildStep(BuildContext context, RecipeCreateLoadedState state, int i) { - bool isLastStep = i == state.steps!.length - 1; - bool isFirstStep = i == 0; - - return Container( - margin: EdgeInsets.only( - left: 16.h, - right: 16.h, - bottom: 10.h, - ), - padding: EdgeInsets.all(12.h), - 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: Column(mainAxisSize: MainAxisSize.min, children: [ - Align( - alignment: Alignment.centerLeft, - child: Text( - "Шаг ${i + 1}", - style: CustomTextStyles.titleMediumSemiBold, - ), + ], ), - SizedBox(height: 8.0), - CustomTextFormField( - controller: state.description, - hintText: "Введите описание шага", - maxLines: 4, - fillColor: appTheme.gray50, - borderDecoration: OutlineInputBorder( - borderRadius: BorderRadius.circular(5.h), - borderSide: BorderSide( - color: appTheme.gray50, - width: 1, + ); + } + + _buildStep(BuildContext context, RecipeCreateLoadedState state, int i) { + bool isLastStep = i == state.steps!.length - 1; + bool isFirstStep = i == 0; + + return Container( + margin: EdgeInsets.only( + left: 16.h, + right: 16.h, + bottom: 10.h, + ), + padding: EdgeInsets.all(12.h), + 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: Column(mainAxisSize: MainAxisSize.min, children: [ + Align( + alignment: Alignment.centerLeft, + child: Text( + "Шаг ${i + 1}", + style: CustomTextStyles.titleMediumSemiBold, ), ), - ), - SizedBox(height: 16.0), - _buildAddPhoto(context, state), - if (!isFirstStep) - Row( - children: [ - Flexible( - flex: 5, - child: CustomOutlinedButton( - text: "Добавить шаг", - buttonStyle: CustomButtonStyles.outlinePrimaryTL15, - ), + SizedBox(height: 8.0), + CustomTextFormField( + controller: state.stepDescriptions?[i], + hintText: "Введите описание шага", + maxLines: 4, + fillColor: appTheme.gray50, + borderDecoration: OutlineInputBorder( + borderRadius: BorderRadius.circular(5.h), + borderSide: BorderSide( + color: appTheme.gray50, + width: 1, ), - SizedBox(width: 8), // Add some spacing between the buttons - Flexible( - flex: 1, - child: CustomOutlinedButton( - text: "х", - onPressed: () => Navigator.pushNamed( - context, - AppRoutes.blogPostCreateScreen, - ), - buttonStyle: CustomButtonStyles.outlinePrimaryTL15, - ), - ), - ], + ), ), - if (isLastStep) // Добавляем кнопку "Добавить шаг" только для последнего шага SizedBox(height: 16.0), - CustomOutlinedButton( - text: "Добавить шаг", - buttonStyle: CustomButtonStyles.outlinePrimaryTL15, - ), - ]), - ); -} + _buildAddPhoto(context, state), + SizedBox(height: 16.0), + if (isFirstStep && isLastStep) + CustomOutlinedButton( + onPressed: () => context.read().add(AddStep()), + text: "Добавить шаг", + buttonStyle: CustomButtonStyles.outlinePrimaryTL15, + ), + if (isLastStep && + !isFirstStep) // Добавляем кнопку "Добавить шаг" только для последнего шага + Column( + children: [ + SizedBox(height: 16.0), + Row( + children: [ + Flexible( + flex: 5, + child: CustomOutlinedButton( + onPressed: () => + context.read().add(AddStep()), + text: "Добавить шаг", + buttonStyle: CustomButtonStyles.outlinePrimaryTL15, + ), + ), + SizedBox(width: 8), // Add some spacing between the buttons + Flexible( + flex: 1, + child: CustomOutlinedButton( + text: "х", + onPressed: () => + context.read().add(RemoveStep(i)), + buttonStyle: CustomButtonStyles.outlinePrimaryTL15, + ), + ), + ], + ), + ], + ), + if (!isLastStep && !isFirstStep) + CustomOutlinedButton( + onPressed: () => + context.read().add(RemoveStep(i)), + text: "x", + buttonStyle: CustomButtonStyles.outlinePrimaryTL15, + ), + ]), + ); + } -_buildAdditional(BuildContext context, RecipeCreateLoadedState state) { - return Container( - margin: EdgeInsets.only( - left: 16.h, - right: 16.h, - bottom: 10.h, - ), - padding: EdgeInsets.all(12.h), - 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: Column(mainAxisSize: MainAxisSize.min, children: [ - Align(alignment: Alignment.centerLeft, child: Text("Теги")), - CustomTextFormField( - controller: state.title, - hintText: "Введите теги, через запятую", - fillColor: appTheme.gray50, - borderDecoration: OutlineInputBorder( - borderRadius: BorderRadius.circular(5.h), - borderSide: BorderSide( - color: appTheme.gray50, - width: 1, + _buildAdditional(BuildContext context, RecipeCreateLoadedState state) { + return Container( + margin: EdgeInsets.only( + left: 16.h, + right: 16.h, + bottom: 10.h, + ), + padding: EdgeInsets.all(12.h), + 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: Column(mainAxisSize: MainAxisSize.min, children: [ + Align(alignment: Alignment.centerLeft, child: Text("Теги")), + CustomTextFormField( + controller: state.tags, + hintText: "Введите теги, через запятую", + fillColor: appTheme.gray50, + borderDecoration: OutlineInputBorder( + borderRadius: BorderRadius.circular(5.h), + borderSide: BorderSide( + color: appTheme.gray50, + width: 1, + ), ), ), - ), - SizedBox(height: 8.0), - Align(alignment: Alignment.centerLeft, child: Text("Ссылка на видео (необязательно)")), - CustomTextFormField( - controller: state.description, - hintText: "YouTube", - fillColor: appTheme.gray50, - borderDecoration: OutlineInputBorder( - borderRadius: BorderRadius.circular(5.h), - borderSide: BorderSide( - color: appTheme.gray50, - width: 1, + SizedBox(height: 8.0), + Align( + alignment: Alignment.centerLeft, + child: Text("Ссылка на видео (необязательно)")), + CustomTextFormField( + controller: state.video_url, + hintText: "YouTube", + fillColor: appTheme.gray50, + borderDecoration: OutlineInputBorder( + borderRadius: BorderRadius.circular(5.h), + borderSide: BorderSide( + color: appTheme.gray50, + width: 1, + ), ), ), - ), - SizedBox(height: 16.0), - CustomOutlinedButton( - text: "Добавить рецепт", - buttonStyle: CustomButtonStyles.outlinePrimaryTL15, - ), - ]), - ); -} + SizedBox(height: 16.0), + CustomOutlinedButton( + text: "Добавить рецепт", + buttonStyle: CustomButtonStyles.outlinePrimaryTL15, + ), + ]), + ); + } -Function onTapBack(BuildContext context) { - return () { - onTapArrowLeft(context); - }; -} -onTapArrowLeft(BuildContext context) { - NavigatorService.goBack(); + Function onTapBack(BuildContext context) { + return () { + onTapArrowLeft(context); + }; + } + + onTapArrowLeft(BuildContext context) { + NavigatorService.goBack(); + } } 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 8cafde3..1e971c2 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 @@ -16,6 +16,9 @@ class RecipeEditBloc extends Bloc { RecipeEditBloc(RecipeEditState initialState) : super(initialState) { on(_onInitialize); on(_editRecipe); + on(_addStep); + on(_removeStep); + on(_reloadScreen); } _onInitialize( @@ -44,16 +47,44 @@ class RecipeEditBloc extends Bloc { var currentState = state as RecipeEditLoadedState; emit(currentState.copyWith( recipeModelObj: currentState.recipeModelObj, - recipe: currentState.recipe, title: currentState.title, + token: currentState.token, + recipe: currentState.recipe, description: currentState.description, - video_url: currentState.video_url)); + video_url: currentState.video_url, + steps: currentState.steps, + stepDescriptions: currentState.stepDescriptions, + tags: currentState.tags)); } else { + final Map defaultStep = { + 'description': '', + 'image': '', + }; + + List steps = data['steps']; + List stepDescriptions = []; + + if (data['steps'] == null) { + stepDescriptions.add(TextEditingController()); + data['steps'].add(defaultStep); + } else { + for (var step in steps) { + stepDescriptions + .add(TextEditingController(text: step['description'])); + } + } + emit(RecipeEditLoadedState( - recipe: data, - title: TextEditingController(text: data['title']), - description: TextEditingController(text: data['description']), - video_url: TextEditingController(text: data['video_url']))); + token: token, + recipe: data, + title: TextEditingController(text: data['title']), + description: TextEditingController(text: data['description']), + video_url: TextEditingController(text: data['video_url']), + tagsController: TextEditingController(), + tags: await _fetchTags(data['id']), + stepDescriptions: stepDescriptions, + steps: steps, + )); } } else { // Один или несколько ключевых полей отсутствуют, обрабатываем ошибку @@ -92,6 +123,42 @@ class RecipeEditBloc extends Bloc { } } + FutureOr _addStep(AddStep event, Emitter emit) async { + if (state is RecipeEditLoadedState) { + var currentState = state as RecipeEditLoadedState; + + List? updatedSteps = currentState.steps; + List? updatedStepDescriptions = + currentState.stepDescriptions; + + updatedSteps!.add({ + 'description': '', + 'image': '', + }); + updatedStepDescriptions!.add(TextEditingController()); + emit(currentState.copyWith( + steps: updatedSteps, stepDescriptions: updatedStepDescriptions)); + await _reloadScreen(event, emit); + } + } + + FutureOr _removeStep( + RemoveStep event, Emitter emit) async { + if (state is RecipeEditLoadedState) { + var currentState = state as RecipeEditLoadedState; + + List? updatedSteps = currentState.steps; + List? updatedStepDescriptions = + currentState.stepDescriptions; + + updatedSteps!.removeAt(event.id); + updatedStepDescriptions!.removeAt(event.id); + emit(currentState.copyWith( + steps: updatedSteps, stepDescriptions: updatedStepDescriptions)); + await _reloadScreen(event, emit); + } + } + FutureOr sendRecipe( Map? recipe, String? title, @@ -123,4 +190,49 @@ class RecipeEditBloc extends Bloc { return response; } + + _fetchTags(int id) async { + final box = await Hive.openBox('token'); + final token = box.get('token'); + + if (token == null) { + NavigatorService.popAndPushNamed( + AppRoutes.authScreen, + ); + } + + final response = await http.get( + Uri.parse(dotenv.env['SERVER_ROOT']! + '/recipe/getTags/$id'), + headers: { + 'Authorization': 'Bearer $token', + }, + ); + final data = jsonDecode(response.body); + return data; + } + + FutureOr _reloadScreen( + RecipeEditEvent? event, Emitter emit) async { + print('Reloading..'); + final box = await Hive.openBox('token'); + final token = box.get('token'); + if (token == null) { + NavigatorService.popAndPushNamed( + AppRoutes.authScreen, + ); + } + if (state is RecipeEditLoadedState) { + var currentState = state as RecipeEditLoadedState; + emit(currentState.copyWith( + recipeModelObj: currentState.recipeModelObj, + recipe: currentState.recipe, + title: currentState.title, + token: currentState.token, + description: currentState.description, + video_url: currentState.video_url, + steps: currentState.steps, + stepDescriptions: currentState.stepDescriptions, + tags: currentState.tags)); + } + } } diff --git a/lib/presentation/recipe/recipe_edit_screen/bloc/recipe_edit_event.dart b/lib/presentation/recipe/recipe_edit_screen/bloc/recipe_edit_event.dart index bcbe219..c6d49d3 100644 --- a/lib/presentation/recipe/recipe_edit_screen/bloc/recipe_edit_event.dart +++ b/lib/presentation/recipe/recipe_edit_screen/bloc/recipe_edit_event.dart @@ -19,3 +19,22 @@ class EditRecipe extends RecipeEditEvent { @override List get props => []; } + +class AddStep extends RecipeEditEvent { + AddStep(); + @override + List get props => []; +} + +class RemoveStep extends RecipeEditEvent { + RemoveStep(this.id); + final int id; + @override + List get props => [id]; +} + +class ReloadScreen extends RecipeEditEvent { + ReloadScreen(); + @override + List get props => []; +} diff --git a/lib/presentation/recipe/recipe_edit_screen/bloc/recipe_edit_state.dart b/lib/presentation/recipe/recipe_edit_screen/bloc/recipe_edit_state.dart index ec00127..af03fcf 100644 --- a/lib/presentation/recipe/recipe_edit_screen/bloc/recipe_edit_state.dart +++ b/lib/presentation/recipe/recipe_edit_screen/bloc/recipe_edit_state.dart @@ -24,32 +24,52 @@ class RecipeEditState extends Equatable { class RecipeEditLoadedState extends RecipeEditState { RecipeEditLoadedState( {this.recipeModelObj, + this.token, this.recipe, this.title, this.description, - this.video_url}); + this.video_url, + this.tagsController, + this.stepDescriptions, + this.tags, + this.steps}); RecipeEditModel? recipeModelObj; Map? recipe; + String? token; TextEditingController? title; TextEditingController? description; TextEditingController? video_url; + TextEditingController? tagsController; + List? steps; + List? tags; + List? stepDescriptions; @override List get props => [recipeModelObj, recipe, title, description, video_url]; RecipeEditLoadedState copyWith({ RecipeEditModel? recipeModelObj, Map? recipe, + String? token, TextEditingController? title, TextEditingController? description, TextEditingController? video_url, + TextEditingController? tagsController, + List? steps, + List? tags, + List? stepDescriptions, }) { return RecipeEditLoadedState( recipeModelObj: recipeModelObj ?? this.recipeModelObj, + token: token ?? this.token, recipe: recipe ?? this.recipe, title: title ?? this.title, description: description ?? this.description, video_url: video_url ?? this.video_url, + tagsController: tagsController ?? this.tagsController, + steps: steps ?? this.steps, + tags: tags ?? this.tags, + stepDescriptions: stepDescriptions ?? this.stepDescriptions, ); } } diff --git a/lib/presentation/recipe/recipe_edit_screen/recipe_edit_screen.dart b/lib/presentation/recipe/recipe_edit_screen/recipe_edit_screen.dart index 9ee0075..c2344e1 100644 --- a/lib/presentation/recipe/recipe_edit_screen/recipe_edit_screen.dart +++ b/lib/presentation/recipe/recipe_edit_screen/recipe_edit_screen.dart @@ -1,17 +1,23 @@ import 'bloc/recipe_edit_bloc.dart'; import 'models/recipe_edit_model.dart'; -import 'package:eatvio_app/core/app_export.dart'; import 'package:flutter/material.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; +import 'package:eatvio_app/core/app_export.dart'; +import 'package:eatvio_app/widgets/app_bar/custom_app_bar.dart'; +import 'package:eatvio_app/widgets/app_bar/appbar_leading_image.dart'; +import 'package:eatvio_app/widgets/app_bar/appbar_subtitle.dart'; +import 'package:eatvio_app/widgets/custom_text_form_field.dart'; +import 'package:eatvio_app/widgets/custom_outlined_button.dart'; class RecipeEditScreen extends StatelessWidget { const RecipeEditScreen({Key? key}) : super(key: key); - static Widget builder(BuildContext context) { final recipeID = ModalRoute.of(context)!.settings.arguments; return BlocProvider( - create: (context) => RecipeEditBloc(RecipeEditState(recipeModelObj: RecipeEditModel(recipeID: recipeID.toString())))..add(RecipeEditInitialEvent()), + create: (context) => RecipeEditBloc(RecipeEditState( + recipeModelObj: RecipeEditModel(recipeID: recipeID.toString()))) + ..add(RecipeEditInitialEvent()), child: RecipeEditScreen()); } @@ -39,78 +45,385 @@ class RecipeEditScreen extends StatelessWidget { _buildRecipeEdit(BuildContext context, RecipeEditLoadedState state) { mediaQueryData = MediaQuery.of(context); - return SafeArea( - child: Scaffold( - resizeToAvoidBottomInset: false, - body: Container( - width: double.maxFinite, - decoration: AppDecoration.fillGray, - child: ListView( - children: [ - SizedBox(height: 30.v), - Container( - margin: EdgeInsets.only( - left: 16.h, - right: 20.h, - bottom: 10.h, - ), - padding: EdgeInsets.all(12.h), - 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), + List steps = []; + if (state.steps != null) { + for (int i = 0; i < state.steps!.length; i++) { + steps.add(_buildStep(context, state, i)); + } + } + + return RefreshIndicator( + onRefresh: refreshPage(context), + child: SafeArea( + child: Scaffold( + resizeToAvoidBottomInset: false, + body: Container( + width: double.maxFinite, + decoration: BoxDecoration(color: Colors.grey[200]), + child: ListView(children: [ + _buldAppBar(context), + SizedBox(height: 20.v), + _buildRecipeInfo(state, context), + SizedBox(height: 20.v), + Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: steps, ), - ], - ), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - CachedNetworkImage( - imageUrl: dotenv.env['STORAGE_URL']! + (state.recipe?['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, - ), - ), - SizedBox(height: 16.0), - TextFormField( - controller: state.title, - decoration: InputDecoration(labelText: 'Заголовок'), - ), - SizedBox(height: 16.0), - TextFormField( - controller: state.description, - decoration: InputDecoration(labelText: 'Описание'), - ), - SizedBox(height: 16.0), - TextFormField( - controller: state.video_url, - decoration: InputDecoration(labelText: 'Ссылка'), - ), - SizedBox(height: 16.0), - // Здесь нужно добавить виджет для загрузки картинки - ElevatedButton( - onPressed: () => context.read().add(EditRecipe()), - child: Text('Сохранить'), - ) - ], - ), - ) - ], + SizedBox(height: 20.v), + _buildAdditional(context, state) + ]), + )))); + } + + _buldAppBar(BuildContext context) { + return Container( + margin: EdgeInsets.all(16.h), + 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: CustomAppBar( + height: 54.v, + leadingWidth: 28.h, + leading: AppbarLeadingImage( + imagePath: ImageConstant.imgArrowLeft, + margin: EdgeInsets.only(left: 16.h, top: 15.v, bottom: 15.v), + onTap: onTapBack(context), ), + title: Align( + alignment: Alignment.center, + child: AppbarSubtitle( + text: "Редактирование рецепта", + )), ), ); } + + _buildRecipeInfo(RecipeEditLoadedState state, BuildContext context) { + return Container( + margin: EdgeInsets.only( + left: 16.h, + right: 16.h, + bottom: 10.h, + ), + padding: EdgeInsets.all(12.h), + 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: Column(mainAxisSize: MainAxisSize.min, children: [ + SizedBox(height: 16.0), + Align(alignment: Alignment.centerLeft, child: Text("Изображение")), + if (state.recipe?['image'] != null) + CachedNetworkImage( + imageUrl: dotenv.env['STORAGE_URL']! + (state.recipe?['image']), + width: double + .infinity, // Установите ширину равной ширине родительского элемента + height: 200.0, + fit: BoxFit.cover, + placeholder: (context, url) => CircularProgressIndicator(), + errorWidget: (context, url, error) => Icon(Icons.error), + ) + else + _buildAddPhoto(context, state), + SizedBox(height: 16.0), + Align(alignment: Alignment.centerLeft, child: Text("Название рецепта")), + CustomTextFormField( + controller: state.title, + hintText: "Введите название рецепта", + fillColor: appTheme.gray50, + borderDecoration: OutlineInputBorder( + borderRadius: BorderRadius.circular(5.h), + borderSide: BorderSide( + color: appTheme.gray50, + width: 1, + ), + ), + ), + SizedBox(height: 16.0), + Align(alignment: Alignment.centerLeft, child: Text("Описание")), + CustomTextFormField( + controller: state.description, + hintText: "Введите описание рецепта", + maxLines: 4, + fillColor: appTheme.gray50, + borderDecoration: OutlineInputBorder( + borderRadius: BorderRadius.circular(5.h), + borderSide: BorderSide( + color: appTheme.gray50, + width: 1, + ), + ), + ), + SizedBox(height: 16.0), + ]), + ); + } + + refreshPage(BuildContext context) { + return () async { + context.read().add(ReloadScreen()); + }; + } + + _buildAddPhoto(BuildContext context, RecipeEditLoadedState state) { + bool isLoading = false; + return GestureDetector( + child: Stack( + children: [ + if (!isLoading) + Container( + padding: EdgeInsets.symmetric( + horizontal: 40.h, + vertical: 80.v, + ), + decoration: AppDecoration.fillGray.copyWith( + borderRadius: BorderRadiusStyle.roundedBorder5, + ), + child: Row( + mainAxisAlignment: MainAxisAlignment.end, + mainAxisSize: MainAxisSize.min, + children: [ + Padding( + padding: EdgeInsets.only( + left: 7.h, + top: 5.v, + ), + child: Text( + "Добавить фото", + selectionColor: appTheme.blueA400, + ), + ), + Spacer(), + Icon( + Icons.photo_library, + color: appTheme.blueGray300, + ) + ], + ), + ), + /*if (isLoading) + Container( + margin: EdgeInsets.symmetric(horizontal: 10.h), + padding: EdgeInsets.symmetric( + horizontal: 40.h, + vertical: 80.v, + ), + decoration: AppDecoration.fillGray.copyWith( + borderRadius: BorderRadiusStyle.roundedBorder5, + ), + child: Center( + child: CircularProgressIndicator( + color: appTheme + .blueGray300), // Замените на свой прелоадер при необходимости + ), + ),*/ + ], + ), + ); + } + + _buildStep(BuildContext context, RecipeEditLoadedState state, int i) { + bool isLastStep = i == state.steps!.length - 1; + bool isFirstStep = i == 0; + + return Container( + margin: EdgeInsets.only( + left: 16.h, + right: 16.h, + bottom: 10.h, + ), + padding: EdgeInsets.all(12.h), + 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: Column(mainAxisSize: MainAxisSize.min, children: [ + Align( + alignment: Alignment.centerLeft, + child: Text( + "Шаг ${i + 1}", + style: CustomTextStyles.titleMediumSemiBold, + ), + ), + SizedBox(height: 8.0), + CustomTextFormField( + controller: state.stepDescriptions?[i], + hintText: "Введите описание шага", + maxLines: 4, + fillColor: appTheme.gray50, + borderDecoration: OutlineInputBorder( + borderRadius: BorderRadius.circular(5.h), + borderSide: BorderSide( + color: appTheme.gray50, + width: 1, + ), + ), + ), + SizedBox(height: 16.0), + if (state.steps?[i]['image'] != null) + CachedNetworkImage( + imageUrl: dotenv.env['STORAGE_URL']! + (state.steps?[i]['image']), + width: double + .infinity, // Установите ширину равной ширине родительского элемента + height: 200.0, // Задайте постоянную высоту элемента + fit: BoxFit.cover, + placeholder: (context, url) => CircularProgressIndicator(), + errorWidget: (context, url, error) => Icon(Icons.error), + ) + else + _buildAddPhoto(context, state), + SizedBox(height: 16.0), + if (isFirstStep && isLastStep) + CustomOutlinedButton( + onPressed: () => context.read().add(AddStep()), + text: "Добавить шаг", + buttonStyle: CustomButtonStyles.outlinePrimaryTL15, + ), + if (isLastStep && + !isFirstStep) // Добавляем кнопку "Добавить шаг" только для последнего шага + Column( + children: [ + SizedBox(height: 16.0), + Row( + children: [ + Flexible( + flex: 5, + child: CustomOutlinedButton( + onPressed: () => + context.read().add(AddStep()), + text: "Добавить шаг", + buttonStyle: CustomButtonStyles.outlinePrimaryTL15, + ), + ), + SizedBox(width: 8), // Add some spacing between the buttons + Flexible( + flex: 1, + child: CustomOutlinedButton( + text: "х", + onPressed: () => + context.read().add(RemoveStep(i)), + buttonStyle: CustomButtonStyles.outlinePrimaryTL15, + ), + ), + ], + ), + ], + ), + if (!isLastStep && !isFirstStep) + CustomOutlinedButton( + onPressed: () => context.read().add(RemoveStep(i)), + text: "x", + buttonStyle: CustomButtonStyles.outlinePrimaryTL15, + ), + ]), + ); + } + + _buildAdditional(BuildContext context, RecipeEditLoadedState state) { + return Container( + margin: EdgeInsets.only( + left: 16.h, + right: 16.h, + bottom: 10.h, + ), + padding: EdgeInsets.all(12.h), + 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: Column(mainAxisSize: MainAxisSize.min, children: [ + Align(alignment: Alignment.centerLeft, child: Text("Теги")), + _buildEditableTags(state.tags), + SizedBox(height: 8.0), + Align( + alignment: Alignment.centerLeft, + child: Text("Ссылка на видео (необязательно)")), + CustomTextFormField( + controller: state.video_url, + hintText: "YouTube", + fillColor: appTheme.gray50, + borderDecoration: OutlineInputBorder( + borderRadius: BorderRadius.circular(5.h), + borderSide: BorderSide( + color: appTheme.gray50, + width: 1, + ), + ), + ), + SizedBox(height: 16.0), + CustomOutlinedButton( + text: "Добавить рецепт", + buttonStyle: CustomButtonStyles.outlinePrimaryTL15, + ), + ]), + ); + } + + _buildEditableTags(List? tags) { + String initialText = tags!.map((tag) => tag['name']).join(', '); + + return CustomTextFormField( + initialValue: initialText, + fillColor: appTheme.gray50, + borderDecoration: OutlineInputBorder( + borderRadius: BorderRadius.circular(5.h), + borderSide: BorderSide( + color: appTheme.gray50, + width: 1, + ), + ), + onChanged: _trimTags, + ); + } + + void _trimTags(newValue) { + List newTagNames = + newValue!.split(',').map((tag) => tag.trim()).toList(); + List> newTags = + newTagNames.map((tagName) => {'name': tagName}).toList(); + print(newTags); + } + + Function onTapBack(BuildContext context) { + return () { + onTapArrowLeft(context); + }; + } + + onTapArrowLeft(BuildContext context) { + NavigatorService.goBack(); + } } 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 a65348e..982266c 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 @@ -5,9 +5,11 @@ import 'package:flutter/material.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:hive/hive.dart'; import 'package:http/http.dart' as http; +import 'package:intl/intl.dart'; import 'dart:convert'; 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'; part 'recipe_show_event.dart'; part 'recipe_show_state.dart'; @@ -16,6 +18,7 @@ class RecipeBloc extends Bloc { RecipeBloc(RecipeState initialState) : super(initialState) { on(_onInitialize); on(_deleteEntry); + on(_createComment); } _onInitialize( @@ -44,9 +47,21 @@ class RecipeBloc extends Bloc { var currentState = state as RecipeLoadedState; emit(currentState.copyWith( recipeModelObj: currentState.recipeModelObj, - recipe: currentState.recipe)); + recipe: currentState.recipe, + token: currentState.token, + commentController: currentState.commentController, + comments: currentState.comments, + steps: currentState.steps, + author: currentState.author)); } else { - emit(RecipeLoadedState(recipe: data)); + emit(RecipeLoadedState( + token: token, + recipe: data, + steps: data['steps'], + author: await _fetchAuthor(data['id']), + comments: fillCommentList(await _fetchComments(data['id'])), + tags: await _fetchTags(data['id']), + commentController: TextEditingController())); } } else { // Один или несколько ключевых полей отсутствуют, обрабатываем ошибку @@ -85,4 +100,115 @@ class RecipeBloc extends Bloc { emit(RecipeErrorState('Ошибка: ${response.statusCode}')); } } + + 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']); + if (response.statusCode == 200) { + var updatedComments = + fillCommentList(await _fetchComments(currentState.recipe?['id'])); + var updatedState = currentState.copyWith( + comments: updatedComments, + commentController: + TextEditingController(), // Clear the comment input field + ); + emit(updatedState); // Emit the updated state to trigger a screen update + } + } + } + + _fetchAuthor(int id) async { + final box = await Hive.openBox('token'); + final token = box.get('token'); + + if (token == null) { + NavigatorService.popAndPushNamed( + AppRoutes.authScreen, + ); + } + + final response = await http.get( + Uri.parse(dotenv.env['SERVER_ROOT']! + '/recipe/getAuthor/$id'), + headers: { + 'Authorization': 'Bearer $token', + }, + ); + final data = jsonDecode(response.body); + return data; + } + + Future _fetchComments(int id) async { + final box = await Hive.openBox('token'); + final token = box.get('token'); + if (token == null) { + NavigatorService.popAndPushNamed( + AppRoutes.authScreen, + ); + } + final response = await http.get( + Uri.parse(dotenv.env['SERVER_ROOT']! + '/recipe/getComments/$id'), + headers: { + 'Authorization': 'Bearer $token', + }, + ); + final data = jsonDecode(response.body); + return data; + } + + _fetchTags(int id) async { + final box = await Hive.openBox('token'); + final token = box.get('token'); + + if (token == null) { + NavigatorService.popAndPushNamed( + AppRoutes.authScreen, + ); + } + + final response = await http.get( + Uri.parse(dotenv.env['SERVER_ROOT']! + '/recipe/getTags/$id'), + headers: { + 'Authorization': 'Bearer $token', + }, + ); + final data = jsonDecode(response.body); + return data; + } + + List fillCommentList(List comments) { + List list = []; + for (int i = 0; i < comments.length; i++) { + list.add(CommentModel( + 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'])), + greetingText: comments[i]['body'])); + } + return list; + } + + Future _sendCommentData( + String? token, String body, int id) async { + String url = dotenv.env['SERVER_ROOT']! + '/recipe/createComment/$id'; + final Map credentials = { + 'id': id, + 'body': body, + }; + + var response = await http.post(Uri.parse(url), + headers: { + 'Content-Type': 'application/json', + 'Authorization': 'Bearer $token', + }, + body: json.encode(credentials), + encoding: utf8); + + return response; + } } diff --git a/lib/presentation/recipe/recipe_show_screen/bloc/recipe_show_event.dart b/lib/presentation/recipe/recipe_show_screen/bloc/recipe_show_event.dart index 6257e89..7510c3a 100644 --- a/lib/presentation/recipe/recipe_show_screen/bloc/recipe_show_event.dart +++ b/lib/presentation/recipe/recipe_show_screen/bloc/recipe_show_event.dart @@ -21,3 +21,10 @@ class DeleteEntry extends RecipeEvent { @override List get props => [id]; } + +class CreateComment extends RecipeEvent { + CreateComment(this.body); + final String body; + @override + List get props => [body]; +} diff --git a/lib/presentation/recipe/recipe_show_screen/bloc/recipe_show_state.dart b/lib/presentation/recipe/recipe_show_screen/bloc/recipe_show_state.dart index e8c1807..fc3a9f4 100644 --- a/lib/presentation/recipe/recipe_show_screen/bloc/recipe_show_state.dart +++ b/lib/presentation/recipe/recipe_show_screen/bloc/recipe_show_state.dart @@ -22,17 +22,52 @@ class RecipeState extends Equatable { } class RecipeLoadedState extends RecipeState { - RecipeLoadedState({this.recipeModelObj, this.recipe}); + RecipeLoadedState( + {this.recipeModelObj, + this.recipe, + this.author, + this.comments, + this.token, + this.commentController, + this.tags, + this.steps}); RecipeModel? recipeModelObj; Map? recipe; + Map? author; + List? comments; + TextEditingController? commentController; + List? steps; + List? tags; + String? token; @override - List get props => [recipeModelObj, recipe]; + List get props => [ + recipeModelObj, + recipe, + author, + comments, + token, + commentController, + steps + ]; RecipeLoadedState copyWith( - {RecipeModel? recipeModelObj, Map? recipe}) { + {RecipeModel? recipeModelObj, + Map? recipe, + Map? author, + TextEditingController? commentController, + String? token, + List? tags, + List? steps, + List? comments}) { return RecipeLoadedState( recipeModelObj: recipeModelObj ?? this.recipeModelObj, recipe: recipe ?? this.recipe, + author: author ?? this.author, + tags: tags ?? this.tags, + token: token ?? this.token, + commentController: commentController ?? this.commentController, + steps: steps ?? this.steps, + comments: comments ?? this.comments, ); } } 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 4bdea28..ef38aff 100644 --- a/lib/presentation/recipe/recipe_show_screen/recipe_show_screen.dart +++ b/lib/presentation/recipe/recipe_show_screen/recipe_show_screen.dart @@ -1,17 +1,22 @@ 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'; import 'package:eatvio_app/core/app_export.dart'; import 'package:flutter/material.dart'; +import 'package:intl/intl.dart'; +import 'package:eatvio_app/widgets/custom_edit_text_form_field.dart'; +import 'package:eatvio_app/widgets/custom_outlined_button.dart'; import 'package:cached_network_image/cached_network_image.dart'; 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()); } @@ -39,87 +44,365 @@ class RecipeScreen extends StatelessWidget { _buildRecipe(BuildContext context, RecipeLoadedState state) { mediaQueryData = MediaQuery.of(context); + List steps = []; + if (state.steps != null) { + for (int i = 0; i < state.steps!.length; i++) { + steps.add(_buildStep(context, state, i)); + } + } return SafeArea( - child: Scaffold( - resizeToAvoidBottomInset: false, - body: Container( - width: double.maxFinite, - decoration: AppDecoration.fillGray, - child: ListView( - children: [ - SizedBox(height: 30.v), - Container( - margin: EdgeInsets.only( - left: 16.h, - right: 20.h, - bottom: 10.h, - ), - padding: EdgeInsets.all(12.h), - 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: Column(mainAxisSize: MainAxisSize.min, children: [ - CachedNetworkImage( - imageUrl: dotenv.env['STORAGE_URL']! + (state.recipe?['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: Scaffold( + resizeToAvoidBottomInset: false, + body: Container( + width: double.maxFinite, + decoration: AppDecoration.fillGray, + child: ListView( + children: [ + SizedBox(height: 15.v), + _buildHeaderRow(context, state), + SizedBox(height: 15.v), + _buildRecipeData(context, state), + SizedBox(height: 15.v), + Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: steps, ), - SizedBox(height: 16.0), - Text(state.recipe?['title'], style: CustomTextStyles.titleMediumBlack), - SizedBox(height: 8.0), - Text( - state.recipe?['description'], - ), - SizedBox(height: 16.0), - Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: [ - ElevatedButton( - onPressed: () => Navigator.pushNamed(context, AppRoutes.recipeEditScreen, arguments: state.recipe?['id'].toString()), - child: Text('Редактировать'), - ), - ElevatedButton( - onPressed: () => context.read().add(DeleteEntry(state.recipe?['id'])), - child: Text('Удалить'), - ), - ], - ) - ]), - ) - ], + SizedBox(height: 15.v), + _buildTextField(context, state), + SizedBox(height: 15.v), + _buildCommentSection(context, state), + ], + ), + ))); + } + + _buildHeaderRow(BuildContext context, RecipeLoadedState state) { + final String name = state.author?['name']; + return Container( + margin: EdgeInsets.symmetric(horizontal: 16.h, vertical: 16.h), + padding: EdgeInsets.symmetric( + horizontal: 24.h, + vertical: 12.v, + ), + 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: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + CustomImageView( + imagePath: ImageConstant.imgArrowLeft, + onTap: () => NavigatorService.goBack()), + Padding( + padding: EdgeInsets.only(top: 1.v), + child: Row( + children: [ + Align( + alignment: Alignment.centerRight, + child: Text( + "$name", + style: CustomTextStyles.titleMediumBlack, + ), + ), + CachedNetworkImage( + imageUrl: dotenv.env['STORAGE_URL']! + + (state.author?['profile_photo_path'] ?? ''), + 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, + ), + ), + ], + ), + ), + ], ), ); } - ///Handling page based on route - Widget getCurrentPage( - BuildContext context, - String currentRoute, - ) { - switch (currentRoute) { - case AppRoutes.recipeScreen: - return RecipeScreen.builder(context); - default: - return RecipeScreen(); + _buildRecipeData(BuildContext context, RecipeLoadedState state) { + return Container( + margin: EdgeInsets.only( + left: 16.h, + right: 20.h, + bottom: 10.h, + ), + padding: EdgeInsets.all(12.h), + 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: Column(mainAxisSize: MainAxisSize.min, children: [ + Row( + children: [ + Text( + state.recipe?['title'], + style: CustomTextStyles.titleMediumBlack, + ), + Spacer(), + PopupMenuButton( + onSelected: (value) => tapMenu(value, context, state), + itemBuilder: (BuildContext context) => >[ + PopupMenuItem( + value: 'edit', + child: Text('Редактировать'), + ), + PopupMenuItem( + value: 'delete', + child: Text('Удалить'), + ), + ], + ), + ], + ), + SizedBox(height: 8.0), + _buildImage(state), + SizedBox(height: 16.0), + Text( + state.recipe?['description'], + style: CustomTextStyles.bodyMediumBluegray800, + ), + SizedBox(height: 16.0), + Align( + alignment: Alignment.topLeft, + child: Text( + DateFormat('dd.MM.yyyy') + .format(DateTime.parse(state.recipe?['updated_at'])), + style: theme.textTheme.bodyMedium, + )), + SizedBox(height: 16.0), + _buildTags(state.tags), + SizedBox(height: 16.0), + Row(children: [ + Padding( + padding: EdgeInsets.only(left: 24), + child: Row(children: [ + Padding( + padding: EdgeInsets.only(right: 8), + child: Icon(Icons.favorite_outline), + ), + Text( + "Нравится", + style: CustomTextStyles.titleMediumSemiBold, + ) + ]), + ), + Spacer(), + Padding( + padding: EdgeInsets.only(right: 24), + child: Row(children: [ + Padding( + padding: const EdgeInsets.only(right: 8), + child: Icon(Icons.share_outlined), + ), + Text( + "Поделиться", + style: CustomTextStyles.titleMediumSemiBold, + ) + ])) + ]), + ]), + ); + } + + _buildTags(List? tags) { + return Wrap( + spacing: 8.0, + runSpacing: 4.0, + children: tags!.map((tag) { + return Chip( + label: Text(tag['name']), + ); + }).toList(), + ); + } + + _buildImage(RecipeLoadedState state) { + return CachedNetworkImage( + imageUrl: dotenv.env['STORAGE_URL']! + (state.recipe?['image'] ?? ''), + imageBuilder: (context, imageProvider) => Stack( + children: [ + ClipRRect( + borderRadius: const BorderRadius.all(Radius.circular(8.0)), + child: Image( + image: imageProvider, + ), + ), + Positioned( + bottom: 0, + left: 0, + right: 0, + child: Container( + padding: EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Padding( + padding: const EdgeInsets.only(left: 48.0), + child: Row( + children: [ + Icon( + Icons.remove_red_eye, + color: Colors.white, + ), + SizedBox(width: 4.0), + Text( + '24', + style: TextStyle(color: Colors.white), + ), + ], + ), + ), + Row( + children: [ + Icon( + Icons.favorite, + color: Colors.white, + ), + SizedBox(width: 4.0), + Text( + '24', + style: TextStyle(color: Colors.white), + ), + ], + ), + Padding( + padding: const EdgeInsets.only(right: 48.0), + child: Row( + children: [ + Icon( + Icons.comment_outlined, + color: Colors.white, + ), + SizedBox(width: 4.0), + Text( + '${state.comments?.length}', + style: TextStyle(color: Colors.white), + ), + ], + ), + ), + ], + ), + ), + ), + ], + ), + placeholder: (context, url) => CircularProgressIndicator(), + ); + } + + void tapMenu(String value, BuildContext context, RecipeLoadedState state) { + if (value == 'edit') { + Navigator.pushNamed( + context, + AppRoutes.recipeEditScreen, + arguments: state.recipe?['id'].toString(), + ); + } else if (value == 'delete') { + context.read().add(DeleteEntry(state.recipe?['id'])); + } + } + + _buildTextField(BuildContext context, RecipeLoadedState state) { + return Container( + margin: EdgeInsets.only( + left: 16.h, + right: 20.h, + bottom: 10.h, + ), + padding: EdgeInsets.all(12.h), + 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: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Column( + children: [ + CustomTextFormField( + controller: state.commentController, + maxLines: 4, + ), + SizedBox(height: 15.h), + CustomOutlinedButton( + text: "Оставить отзыв", + margin: EdgeInsets.only(bottom: 5), + buttonStyle: CustomButtonStyles.outlinePrimaryTL15, + decoration: BoxDecoration( + color: Colors.transparent, + ), + onPressed: () => context + .read() + .add(CreateComment(state.commentController!.text)), + // Установите прозрачный фон + ) + ], + ), + ], + ), + ); + } + + _buildCommentSection(BuildContext context, RecipeLoadedState state) { + if (state.comments != null && state.comments!.isNotEmpty) { + return Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + for (int i = 0; i < state.comments!.length; i++) + Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + CommentWidget(state.comments![i]), + SizedBox(height: 10.0), // Separator + ], + ), + ], + ); + } else { + // Return a message or placeholder widget when there are no comments + return Column( + children: [ + Center( + child: Text('No comments available'), + ), + SizedBox( + height: 20, + ) + ], + ); } } @@ -127,4 +410,48 @@ class RecipeScreen extends StatelessWidget { onTapArrowleftone(BuildContext context) { NavigatorService.goBack(); } + + Widget _buildStep(BuildContext context, RecipeLoadedState state, int i) { + return Container( + margin: EdgeInsets.only( + left: 16.h, + right: 16.h, + bottom: 10.h, + ), + padding: EdgeInsets.all(12.h), + 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: Column(mainAxisSize: MainAxisSize.min, children: [ + Align( + alignment: Alignment.centerLeft, + child: Text( + "Шаг ${i + 1}", + style: CustomTextStyles.titleMediumSemiBold, + ), + ), + SizedBox(height: 16.0), + CachedNetworkImage( + imageUrl: dotenv.env['STORAGE_URL']! + (state.steps?[i]['image']), + width: double + .infinity, // Установите ширину равной ширине родительского элемента + height: 200.0, // Задайте постоянную высоту элемента + fit: BoxFit.cover, + placeholder: (context, url) => CircularProgressIndicator(), + errorWidget: (context, url, error) => Icon(Icons.error), + ), + SizedBox(height: 16.0), + Text(state.steps?[i]['description']) + ]), + ); + } } diff --git a/lib/presentation/recipe/recipe_show_screen/widgets/comment_widget.dart b/lib/presentation/recipe/recipe_show_screen/widgets/comment_widget.dart new file mode 100644 index 0000000..c224966 --- /dev/null +++ b/lib/presentation/recipe/recipe_show_screen/widgets/comment_widget.dart @@ -0,0 +1,107 @@ +// ignore_for_file: must_be_immutable + +import 'package:flutter/material.dart'; +import 'package:flutter_dotenv/flutter_dotenv.dart'; +import 'package:eatvio_app/core/app_export.dart'; +import 'package:eatvio_app/presentation/feed/blog_post_screen/models/comment_model.dart'; +import 'package:cached_network_image/cached_network_image.dart'; + +class CommentWidget extends StatelessWidget { + CommentWidget(this.commentModelObj, {Key? key}) + : super( + key: key, + ); + + CommentModel commentModelObj; + + @override + Widget build(BuildContext context) { + return Container( + margin: EdgeInsets.only( + left: 16.h, + right: 20.h, + bottom: 10.h, + ), + padding: EdgeInsets.all(12.h), + 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: Row( + mainAxisAlignment: MainAxisAlignment + .spaceBetween, // Move the main axis alignment to space between + crossAxisAlignment: + CrossAxisAlignment.center, // Center the items vertically + children: [ + CachedNetworkImage( + imageUrl: dotenv.env['STORAGE_URL']! + commentModelObj.userImage!, + 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, + ), + ), + Expanded( + child: Padding( + padding: EdgeInsets.only( + left: 12.h, + top: 2.v, + bottom: 11.v, + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SizedBox( + width: 227.h, + child: Row( + children: [ + Text( + commentModelObj.username!.length <= 15 + ? commentModelObj.username! + : commentModelObj.username!.substring(0, 15) + + '...', + style: theme.textTheme.titleMedium, + ), + Spacer(), + Padding( + padding: EdgeInsets.only(left: 6.h), + child: Text( + commentModelObj.dateText!, + style: theme.textTheme.bodyMedium, + ), + ) + ], + ), + ), + SizedBox(height: 6.v), + Text( + commentModelObj.greetingText!, + style: CustomTextStyles.bodyMediumBluegray800, + ), + ], + ), + ), + ), + CustomImageView( + imagePath: ImageConstant.imgSend, + height: 30.v, + width: 30.h, + margin: EdgeInsets.only(left: 5)), + ], + ), + ); + } +} diff --git a/lib/widgets/custom_text_form_field.dart b/lib/widgets/custom_text_form_field.dart index 86a2a23..6941627 100644 --- a/lib/widgets/custom_text_form_field.dart +++ b/lib/widgets/custom_text_form_field.dart @@ -30,6 +30,8 @@ class CustomTextFormField extends StatelessWidget { this.keyboardType, this.onFieldSubmitted, this.onSaved, + this.initialValue, + this.onChanged, }) : super( key: key, ); @@ -57,8 +59,10 @@ class CustomTextFormField extends StatelessWidget { final bool? filled; final TextInputType? keyboardType; final FormFieldValidator? validator; + final String? initialValue; final Function(String)? onFieldSubmitted; final void Function(String?)? onSaved; + final void Function(String?)? onChanged; @override Widget build(BuildContext context) { @@ -76,6 +80,7 @@ class CustomTextFormField extends StatelessWidget { textInputAction: textInputAction, maxLines: maxLines ?? 1, onFieldSubmitted: onFieldSubmitted, + onChanged: onChanged, decoration: InputDecoration( hintText: hintText ?? "", hintStyle: hintStyle ?? theme.textTheme.bodyLarge, @@ -116,6 +121,7 @@ class CustomTextFormField extends StatelessWidget { validator: validator, onSaved: onSaved, inputFormatters: inputFormatters, + initialValue: initialValue, ), ), ) @@ -129,6 +135,7 @@ class CustomTextFormField extends StatelessWidget { obscureText: obscureText!, textInputAction: textInputAction, maxLines: maxLines ?? 1, + initialValue: initialValue, decoration: InputDecoration( hintText: hintText ?? "", hintStyle: hintStyle ?? theme.textTheme.bodyLarge, From 2899c2220a5e7cbb5451b6a3b8dc91f0898e4aba Mon Sep 17 00:00:00 2001 From: maxxkim Date: Wed, 5 Jun 2024 16:41:26 +0300 Subject: [PATCH 09/17] feat(app): Keyboard dismisser and FocusNode fix --- lib/main.dart | 10 ++++++++-- lib/widgets/custom_text_form_field.dart | 4 ++-- pubspec.yaml | 1 + 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index e3ddb1f..3e4b3c8 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -14,6 +14,7 @@ import 'core/app_export.dart'; import 'package:hive_flutter/hive_flutter.dart'; import 'package:path_provider/path_provider.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; +import 'package:keyboard_dismisser/keyboard_dismisser.dart'; var globalMessengerKey = GlobalKey(); @@ -70,7 +71,12 @@ class MyApp extends StatelessWidget { ], child: BlocBuilder( builder: (context, state) { - return MaterialApp.router( + return KeyboardDismisser( + gestures: [ + GestureType.onTap, + GestureType.onPanUpdateDownDirection, + ], + child: MaterialApp.router( theme: theme, title: 'Eatvio', routerConfig: AppRouter.appRouter, @@ -87,7 +93,7 @@ class MyApp extends StatelessWidget { '', ), ], - ); + )); }, ), ); diff --git a/lib/widgets/custom_text_form_field.dart b/lib/widgets/custom_text_form_field.dart index 6941627..dcba88c 100644 --- a/lib/widgets/custom_text_form_field.dart +++ b/lib/widgets/custom_text_form_field.dart @@ -73,7 +73,7 @@ class CustomTextFormField extends StatelessWidget { width: width ?? double.maxFinite, child: TextFormField( controller: controller, - focusNode: focusNode ?? FocusNode(), + focusNode: focusNode ?? null, autofocus: autofocus!, style: textStyle ?? theme.textTheme.titleMedium, obscureText: obscureText!, @@ -129,7 +129,7 @@ class CustomTextFormField extends StatelessWidget { width: width ?? double.maxFinite, child: TextFormField( controller: controller, - focusNode: focusNode ?? FocusNode(), + focusNode: focusNode ?? null, autofocus: autofocus!, style: textStyle ?? theme.textTheme.titleMedium, obscureText: obscureText!, diff --git a/pubspec.yaml b/pubspec.yaml index 26be607..35f447c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -29,6 +29,7 @@ dependencies: bloc_test: ^9.1.6 # navigation go_router: ^14.1.4 + keyboard_dismisser: ^3.0.0 dev_dependencies: dart_code_metrics: ^5.7.6 From c9f825c37403b608fca65329bc147a986f26452b Mon Sep 17 00:00:00 2001 From: mso7nueh Date: Wed, 5 Jun 2024 17:39:53 +0300 Subject: [PATCH 10/17] fixes --- .../diary_edit_screen/diary_edit_screen.dart | 66 +++++++++---------- .../diet_select_screen.dart | 15 ++++- .../glossary_screen/glossary_screen.dart | 16 ++++- .../plan_select_screen.dart | 17 +++-- .../my_profile_screen/my_settings_screen.dart | 4 ++ .../recipe_create_screen.dart | 64 +++++++++--------- .../recipe_edit_screen.dart | 41 ++++++------ .../recipe_select_screen.dart | 4 ++ .../recipe_show_screen.dart | 49 +++++++------- lib/theme/theme_helper.dart | 8 +++ lib/widgets/app_bar/custom_app_bar.dart | 4 -- 11 files changed, 166 insertions(+), 122 deletions(-) diff --git a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart index 698d6e0..2b3e7ae 100644 --- a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart +++ b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart @@ -55,38 +55,40 @@ class DiaryEditScreen extends StatelessWidget { alignment: Alignment.bottomCenter, children: [ FormBuilder( - child: SafeArea( - child: Scaffold( - backgroundColor: Color.fromARGB(255, 240, 242, 245), - resizeToAvoidBottomInset: true, - body: SizedBox( - width: double.maxFinite, - child: Column( - children: [ - Expanded( - child: SingleChildScrollView( - child: Padding( - padding: EdgeInsets.only(bottom: 5.v), - child: Column( - children: [ - _buildHeaderRow(context, state), - SizedBox(height: 30.v), - _buildWakupRetire(context, state), - SizedBox(height: 30.v), - _buildMeal(context, state), - SizedBox(height: 20.v), - _buildMood(context, state), - SizedBox(height: 30.v), - _buildNutritionChart(context, state), - SizedBox(height: 30.v), - _buildComment(context, state), - ], - ), + child: Scaffold( + appBar: AppBar( + toolbarHeight: 0, + automaticallyImplyLeading: false, + ), + backgroundColor: Color.fromARGB(255, 240, 242, 245), + resizeToAvoidBottomInset: true, + body: SizedBox( + width: double.maxFinite, + child: Column( + children: [ + Expanded( + child: SingleChildScrollView( + child: Padding( + padding: EdgeInsets.only(bottom: 5.v), + child: Column( + children: [ + _buildHeaderRow(context, state), + SizedBox(height: 30.v), + _buildWakupRetire(context, state), + SizedBox(height: 30.v), + _buildMeal(context, state), + SizedBox(height: 20.v), + _buildMood(context, state), + SizedBox(height: 30.v), + _buildNutritionChart(context, state), + SizedBox(height: 30.v), + _buildComment(context, state), + ], ), ), ), - ], - ), + ), + ], ), ), ), @@ -142,12 +144,8 @@ class DiaryEditScreen extends StatelessWidget { ], ), child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, + mainAxisAlignment: MainAxisAlignment.center, children: [ - CustomImageView( - imagePath: ImageConstant.imgArrowLeft, - onTap: () => GoRouter.of(context).pop(), - ), Padding( padding: EdgeInsets.only(top: 1.v), child: Column( 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 e573be6..7bda468 100644 --- a/lib/presentation/diets/diet_select_screen/diet_select_screen.dart +++ b/lib/presentation/diets/diet_select_screen/diet_select_screen.dart @@ -24,6 +24,11 @@ class DietSelectScreen extends StatelessWidget { builder: (context, state) { if (state is DietSelectInitialState) { // Это начальное состояние, данные ещё не загружены. + return Scaffold( + body: Center( + child: CircularProgressIndicator(), + ), + ); return CircularProgressIndicator( color: Colors.white, backgroundColor: Colors.white, @@ -33,7 +38,11 @@ class DietSelectScreen extends StatelessWidget { return _buildSetingsScreen(context, state); } else { // Другие состояния, если они есть. - return Container(); // Пустой контейнер для необработанных состояний. + return Scaffold( + body: Center( + child: CircularProgressIndicator(), + ), + ); } }, ); @@ -41,6 +50,10 @@ class DietSelectScreen extends StatelessWidget { _buildSetingsScreen(BuildContext context, DietSelectLoadedState state) { return Scaffold( + appBar: AppBar( + toolbarHeight: 0, + automaticallyImplyLeading: false, + ), backgroundColor: Colors.grey[200], resizeToAvoidBottomInset: true, body: SingleChildScrollView( diff --git a/lib/presentation/glossary/glossary_screen/glossary_screen.dart b/lib/presentation/glossary/glossary_screen/glossary_screen.dart index ebfa70d..de262b3 100644 --- a/lib/presentation/glossary/glossary_screen/glossary_screen.dart +++ b/lib/presentation/glossary/glossary_screen/glossary_screen.dart @@ -22,8 +22,10 @@ class GlossaryScreen extends StatelessWidget { builder: (context, state) { if (state is GlossaryInitialState) { // Это начальное состояние, данные ещё не загружены. - return Container( - color: Colors.white, + return Scaffold( + body: Center( + child: CircularProgressIndicator(), + ), ); } else if (state is GlossaryLoadedState) { // Данные загружены, можно строить экран. @@ -33,7 +35,11 @@ class GlossaryScreen extends StatelessWidget { return Center(child: Text(state.errorMessage)); } else { // Другие состояния, если они есть. - return Container(); // Пустой контейнер для необработанных состояний. + return Scaffold( + body: Center( + child: CircularProgressIndicator(), + ), + ); } }, ); @@ -41,6 +47,10 @@ class GlossaryScreen extends StatelessWidget { _buildGlossary(BuildContext context, GlossaryLoadedState state) { return Scaffold( + appBar: AppBar( + toolbarHeight: 0, + automaticallyImplyLeading: false, + ), backgroundColor: Colors.grey[200], resizeToAvoidBottomInset: true, body: SingleChildScrollView( 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 78ac405..6dd7e33 100644 --- a/lib/presentation/plans/plan_select_screen/plan_select_screen.dart +++ b/lib/presentation/plans/plan_select_screen/plan_select_screen.dart @@ -24,16 +24,21 @@ class PlanSelectScreen extends StatelessWidget { builder: (context, state) { if (state is PlanSelectInitialState) { // Это начальное состояние, данные ещё не загружены. - return CircularProgressIndicator( - color: Colors.white, - backgroundColor: Colors.white, + return Scaffold( + body: Center( + child: CircularProgressIndicator(), + ), ); } else if (state is PlanSelectLoadedState) { // Данные загружены, можно строить экран. return _buildSetingsScreen(context, state); } else { // Другие состояния, если они есть. - return Container(); // Пустой контейнер для необработанных состояний. + return Scaffold( + body: Center( + child: CircularProgressIndicator(), + ), + ); } }, ); @@ -41,6 +46,10 @@ class PlanSelectScreen extends StatelessWidget { _buildSetingsScreen(BuildContext context, PlanSelectLoadedState state) { return Scaffold( + appBar: AppBar( + toolbarHeight: 0, + automaticallyImplyLeading: false, + ), backgroundColor: Colors.grey[200], resizeToAvoidBottomInset: true, body: SingleChildScrollView( diff --git a/lib/presentation/profile/my_profile_screen/my_settings_screen.dart b/lib/presentation/profile/my_profile_screen/my_settings_screen.dart index 501ffca..fe6de3c 100644 --- a/lib/presentation/profile/my_profile_screen/my_settings_screen.dart +++ b/lib/presentation/profile/my_profile_screen/my_settings_screen.dart @@ -41,6 +41,10 @@ class MySettingsScreen extends StatelessWidget { _buildSetingsScreen(BuildContext context, MyProfileLoadedState state) { return Scaffold( + appBar: AppBar( + toolbarHeight: 0, + automaticallyImplyLeading: false, + ), backgroundColor: Colors.grey[200], resizeToAvoidBottomInset: true, body: SingleChildScrollView( diff --git a/lib/presentation/recipe/recipe_create_screen/recipe_create_screen.dart b/lib/presentation/recipe/recipe_create_screen/recipe_create_screen.dart index 2426879..76e8a63 100644 --- a/lib/presentation/recipe/recipe_create_screen/recipe_create_screen.dart +++ b/lib/presentation/recipe/recipe_create_screen/recipe_create_screen.dart @@ -10,12 +10,12 @@ import 'package:eatvio_app/widgets/custom_outlined_button.dart'; class RecipeCreateScreen extends StatelessWidget { const RecipeCreateScreen({Key? key}) : super(key: key); + static Widget builder(BuildContext context) { final recipeID = ModalRoute.of(context)!.settings.arguments; return BlocProvider( - create: (context) => RecipeCreateBloc(RecipeCreateState( - recipeModelObj: RecipeCreateModel(recipeID: recipeID.toString()))) - ..add(RecipeCreateInitialEvent()), + create: (context) => + RecipeCreateBloc(RecipeCreateState(recipeModelObj: RecipeCreateModel(recipeID: recipeID.toString())))..add(RecipeCreateInitialEvent()), child: RecipeCreateScreen()); } @@ -52,25 +52,28 @@ class RecipeCreateScreen extends StatelessWidget { return RefreshIndicator( onRefresh: refreshPage(context), - child: SafeArea( - child: Scaffold( - resizeToAvoidBottomInset: false, - body: Container( - width: double.maxFinite, - decoration: BoxDecoration(color: Colors.grey[200]), - child: ListView(children: [ - _buldAppBar(context), - SizedBox(height: 20.v), - _buildRecipeInfo(state, context), - SizedBox(height: 20.v), - Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: steps, - ), - SizedBox(height: 20.v), - _buildAdditional(context, state) - ]), - )))); + child: Scaffold( + appBar: AppBar( + toolbarHeight: 0, + automaticallyImplyLeading: false, + ), + resizeToAvoidBottomInset: false, + body: Container( + width: double.maxFinite, + decoration: BoxDecoration(color: Colors.grey[200]), + child: ListView(children: [ + _buldAppBar(context), + SizedBox(height: 20.v), + _buildRecipeInfo(state, context), + SizedBox(height: 20.v), + Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: steps, + ), + SizedBox(height: 20.v), + _buildAdditional(context, state) + ]), + ))); } _buldAppBar(BuildContext context) { @@ -280,8 +283,7 @@ class RecipeCreateScreen extends StatelessWidget { text: "Добавить шаг", buttonStyle: CustomButtonStyles.outlinePrimaryTL15, ), - if (isLastStep && - !isFirstStep) // Добавляем кнопку "Добавить шаг" только для последнего шага + if (isLastStep && !isFirstStep) // Добавляем кнопку "Добавить шаг" только для последнего шага Column( children: [ SizedBox(height: 16.0), @@ -290,8 +292,7 @@ class RecipeCreateScreen extends StatelessWidget { Flexible( flex: 5, child: CustomOutlinedButton( - onPressed: () => - context.read().add(AddStep()), + onPressed: () => context.read().add(AddStep()), text: "Добавить шаг", buttonStyle: CustomButtonStyles.outlinePrimaryTL15, ), @@ -301,8 +302,7 @@ class RecipeCreateScreen extends StatelessWidget { flex: 1, child: CustomOutlinedButton( text: "х", - onPressed: () => - context.read().add(RemoveStep(i)), + onPressed: () => context.read().add(RemoveStep(i)), buttonStyle: CustomButtonStyles.outlinePrimaryTL15, ), ), @@ -312,8 +312,7 @@ class RecipeCreateScreen extends StatelessWidget { ), if (!isLastStep && !isFirstStep) CustomOutlinedButton( - onPressed: () => - context.read().add(RemoveStep(i)), + onPressed: () => context.read().add(RemoveStep(i)), text: "x", buttonStyle: CustomButtonStyles.outlinePrimaryTL15, ), @@ -356,9 +355,7 @@ class RecipeCreateScreen extends StatelessWidget { ), ), SizedBox(height: 8.0), - Align( - alignment: Alignment.centerLeft, - child: Text("Ссылка на видео (необязательно)")), + Align(alignment: Alignment.centerLeft, child: Text("Ссылка на видео (необязательно)")), CustomTextFormField( controller: state.video_url, hintText: "YouTube", @@ -380,7 +377,6 @@ class RecipeCreateScreen extends StatelessWidget { ); } - Function onTapBack(BuildContext context) { return () { onTapArrowLeft(context); diff --git a/lib/presentation/recipe/recipe_edit_screen/recipe_edit_screen.dart b/lib/presentation/recipe/recipe_edit_screen/recipe_edit_screen.dart index c2344e1..b204e6f 100644 --- a/lib/presentation/recipe/recipe_edit_screen/recipe_edit_screen.dart +++ b/lib/presentation/recipe/recipe_edit_screen/recipe_edit_screen.dart @@ -54,25 +54,28 @@ class RecipeEditScreen extends StatelessWidget { return RefreshIndicator( onRefresh: refreshPage(context), - child: SafeArea( - child: Scaffold( - resizeToAvoidBottomInset: false, - body: Container( - width: double.maxFinite, - decoration: BoxDecoration(color: Colors.grey[200]), - child: ListView(children: [ - _buldAppBar(context), - SizedBox(height: 20.v), - _buildRecipeInfo(state, context), - SizedBox(height: 20.v), - Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: steps, - ), - SizedBox(height: 20.v), - _buildAdditional(context, state) - ]), - )))); + child: Scaffold( + appBar: AppBar( + toolbarHeight: 0, + automaticallyImplyLeading: false, + ), + resizeToAvoidBottomInset: false, + body: Container( + width: double.maxFinite, + decoration: BoxDecoration(color: Colors.grey[200]), + child: ListView(children: [ + _buldAppBar(context), + SizedBox(height: 20.v), + _buildRecipeInfo(state, context), + SizedBox(height: 20.v), + Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: steps, + ), + SizedBox(height: 20.v), + _buildAdditional(context, state) + ]), + ))); } _buldAppBar(BuildContext context) { 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 f72ca51..1e0b1eb 100644 --- a/lib/presentation/recipe/recipe_select_screen/recipe_select_screen.dart +++ b/lib/presentation/recipe/recipe_select_screen/recipe_select_screen.dart @@ -41,6 +41,10 @@ class RecipeSelectScreen extends StatelessWidget { _buildRecipeScreen(BuildContext context, RecipeSelectLoadedState state) { return Scaffold( + appBar: AppBar( + toolbarHeight: 0, + automaticallyImplyLeading: false, + ), backgroundColor: Colors.grey[200], resizeToAvoidBottomInset: true, body: SingleChildScrollView( 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 ef38aff..195e3da 100644 --- a/lib/presentation/recipe/recipe_show_screen/recipe_show_screen.dart +++ b/lib/presentation/recipe/recipe_show_screen/recipe_show_screen.dart @@ -50,30 +50,33 @@ class RecipeScreen extends StatelessWidget { steps.add(_buildStep(context, state, i)); } } - return SafeArea( - child: Scaffold( - resizeToAvoidBottomInset: false, - body: Container( - width: double.maxFinite, - decoration: AppDecoration.fillGray, - child: ListView( - children: [ - SizedBox(height: 15.v), - _buildHeaderRow(context, state), - SizedBox(height: 15.v), - _buildRecipeData(context, state), - SizedBox(height: 15.v), - Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: steps, - ), - SizedBox(height: 15.v), - _buildTextField(context, state), - SizedBox(height: 15.v), - _buildCommentSection(context, state), - ], + return Scaffold( + appBar: AppBar( + toolbarHeight: 0, + automaticallyImplyLeading: false, + ), + resizeToAvoidBottomInset: false, + body: Container( + width: double.maxFinite, + decoration: AppDecoration.fillGray, + child: ListView( + children: [ + SizedBox(height: 15.v), + _buildHeaderRow(context, state), + SizedBox(height: 15.v), + _buildRecipeData(context, state), + SizedBox(height: 15.v), + Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: steps, ), - ))); + SizedBox(height: 15.v), + _buildTextField(context, state), + SizedBox(height: 15.v), + _buildCommentSection(context, state), + ], + ), + )); } _buildHeaderRow(BuildContext context, RecipeLoadedState state) { diff --git a/lib/theme/theme_helper.dart b/lib/theme/theme_helper.dart index 699e282..68aa928 100644 --- a/lib/theme/theme_helper.dart +++ b/lib/theme/theme_helper.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import '../../core/app_export.dart'; /// Helper class for managing themes and colors. @@ -50,6 +51,13 @@ class ThemeHelper { colorScheme: colorScheme, textTheme: TextThemes.textTheme(colorScheme), scaffoldBackgroundColor: colorScheme.onPrimary, + appBarTheme: AppBarTheme( + systemOverlayStyle: SystemUiOverlayStyle( + statusBarIconBrightness: Brightness.dark, + statusBarBrightness: Brightness.light, + systemNavigationBarColor: Colors.white, + ), + ), outlinedButtonTheme: OutlinedButtonThemeData( style: OutlinedButton.styleFrom( backgroundColor: Colors.transparent, diff --git a/lib/widgets/app_bar/custom_app_bar.dart b/lib/widgets/app_bar/custom_app_bar.dart index 0581170..63c7953 100644 --- a/lib/widgets/app_bar/custom_app_bar.dart +++ b/lib/widgets/app_bar/custom_app_bar.dart @@ -31,10 +31,6 @@ class CustomAppBar extends StatelessWidget implements PreferredSizeWidget { @override Widget build(BuildContext context) { return AppBar( - systemOverlayStyle: SystemUiOverlayStyle( - statusBarIconBrightness: Brightness.dark, - statusBarBrightness: Brightness.light, - ), toolbarHeight: height ?? 56.v, automaticallyImplyLeading: false, backgroundColor: Colors.transparent, From 8de91e6f7e2bd7b3bcc3350d0aac68deb219a298 Mon Sep 17 00:00:00 2001 From: mso7nueh Date: Wed, 5 Jun 2024 17:40:09 +0300 Subject: [PATCH 11/17] fixes warning --- .../diary/diary_edit_screen/diary_edit_screen.dart | 1 - .../diets/diet_select_screen/diet_select_screen.dart | 4 ---- lib/widgets/app_bar/custom_app_bar.dart | 1 - 3 files changed, 6 deletions(-) diff --git a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart index 2b3e7ae..68a70fa 100644 --- a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart +++ b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart @@ -1,6 +1,5 @@ // ignore_for_file: unused_local_variable -import 'package:go_router/go_router.dart'; import 'bloc/diary_edit_bloc.dart'; import 'models/diary_edit_model.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 7bda468..8b9e215 100644 --- a/lib/presentation/diets/diet_select_screen/diet_select_screen.dart +++ b/lib/presentation/diets/diet_select_screen/diet_select_screen.dart @@ -29,10 +29,6 @@ class DietSelectScreen extends StatelessWidget { child: CircularProgressIndicator(), ), ); - return CircularProgressIndicator( - color: Colors.white, - backgroundColor: Colors.white, - ); } else if (state is DietSelectLoadedState) { // Данные загружены, можно строить экран. return _buildSetingsScreen(context, state); diff --git a/lib/widgets/app_bar/custom_app_bar.dart b/lib/widgets/app_bar/custom_app_bar.dart index 63c7953..469e931 100644 --- a/lib/widgets/app_bar/custom_app_bar.dart +++ b/lib/widgets/app_bar/custom_app_bar.dart @@ -1,6 +1,5 @@ import 'package:eatvio_app/core/app_export.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; // ignore: must_be_immutable class CustomAppBar extends StatelessWidget implements PreferredSizeWidget { From d49030c3dd6b2bd5a73f51140349caf7852e8320 Mon Sep 17 00:00:00 2001 From: mso7nueh Date: Thu, 6 Jun 2024 13:42:46 +0300 Subject: [PATCH 12/17] go router 2 --- lib/app_router.dart | 4 + .../auth/auth_screen/auth_screen.dart | 32 ++--- .../chat/chat_screen/bloc/chat_bloc.dart | 5 +- .../bloc/chat_select_bloc.dart | 4 +- .../widgets/chat_entry_widget.dart | 130 +++++++++--------- .../bloc/diet_create_bloc.dart | 9 +- .../diet_edit_screen/bloc/diet_edit_bloc.dart | 20 +-- .../bloc/diet_select_bloc.dart | 4 +- .../diet_show_screen/bloc/diet_show_bloc.dart | 4 +- .../bloc/blog_post_create_bloc.dart | 4 +- .../bloc/blog_post_edit_bloc.dart | 4 +- .../blog_post_screen/bloc/blog_post_bloc.dart | 4 +- .../feed/feed_screen/bloc/feed_bloc.dart | 4 +- .../bloc/glossary_screen_bloc.dart | 4 +- .../bloc/plan_create_bloc.dart | 4 +- .../plan_edit_screen/bloc/plan_edit_bloc.dart | 4 +- .../bloc/plan_select_bloc.dart | 4 +- .../plan_show_screen/bloc/plan_show_bloc.dart | 4 +- .../my_profile_screen/my_profile_screen.dart | 30 ++-- .../my_profile_screen/my_settings_screen.dart | 13 +- .../bloc/recipe_create_bloc.dart | 4 +- .../bloc/recipe_edit_bloc.dart | 4 +- .../bloc/recipe_select_bloc.dart | 4 +- .../recipe_select_screen.dart | 25 ++-- .../bloc/recipe_show_bloc.dart | 4 +- lib/routes/app_routes.dart | 116 +++++----------- lib/widgets/bottom_navigation_bar_widget.dart | 36 ++++- lib/widgets/custom_expandable_list.dart | 6 +- 28 files changed, 219 insertions(+), 271 deletions(-) diff --git a/lib/app_router.dart b/lib/app_router.dart index a7de988..6f677a8 100644 --- a/lib/app_router.dart +++ b/lib/app_router.dart @@ -12,12 +12,16 @@ import 'package:eatvio_app/presentation/profile/my_profile_screen/my_settings_sc import 'package:eatvio_app/presentation/recipe/recipe_select_screen/recipe_select_screen.dart'; import 'package:eatvio_app/presentation/registration/language_select_screen/language_select_screen.dart'; import 'package:eatvio_app/widgets/bottom_navigation_bar_widget.dart'; +import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'package:hive_flutter/hive_flutter.dart'; class AppRouter { + static GlobalKey navigatorKey = GlobalKey(); + static GoRouter appRouter = GoRouter( initialLocation: '/auth-screen', + navigatorKey: navigatorKey, routes: [ GoRoute( path: '/auth-screen', diff --git a/lib/presentation/auth/auth_screen/auth_screen.dart b/lib/presentation/auth/auth_screen/auth_screen.dart index ff4408d..6b6c3a4 100644 --- a/lib/presentation/auth/auth_screen/auth_screen.dart +++ b/lib/presentation/auth/auth_screen/auth_screen.dart @@ -143,33 +143,23 @@ class AuthScreen extends StatelessWidget { }; } - onTapOk(BuildContext context) { - return () { - Navigator.pop(context); - }; - } + onTapOk(BuildContext context) => GoRouter.of(context).pop(context); - onTapDiaryTest(BuildContext context) { - return () { - Navigator.pushNamed(context, AppRoutes.diaryEdit); - }; - } + onTapDiaryTest(BuildContext context) => GoRouter.of(context).goNamed('diaryScreen'); - onTapProfileTest(BuildContext context) { - return () { - Navigator.pushNamed(context, AppRoutes.mySettings); - }; - } + onTapProfileTest(BuildContext context) => GoRouter.of(context).goNamed('mySettingsScreen'); - onTapNoAccount(BuildContext context) { - return () { - GoRouter.of(context).goNamed('languageSelectScreen'); - }; - } + onTapNoAccount(BuildContext context) => GoRouter.of(context).goNamed('languageSelectScreen'); /// Section Widget _buildAppBar(BuildContext context) { - return CustomAppBar(leadingWidth: 29.h, centerTitle: true, title: AppbarTitleImage(imagePath: ImageConstant.imgLogoEatvio)); + return CustomAppBar( + leadingWidth: 29.h, + centerTitle: true, + title: AppbarTitleImage( + imagePath: ImageConstant.imgLogoEatvio, + ), + ); } List validateFields(String email, String password) { diff --git a/lib/presentation/chat/chat_screen/bloc/chat_bloc.dart b/lib/presentation/chat/chat_screen/bloc/chat_bloc.dart index 52cf81d..3d8f73a 100644 --- a/lib/presentation/chat/chat_screen/bloc/chat_bloc.dart +++ b/lib/presentation/chat/chat_screen/bloc/chat_bloc.dart @@ -1,6 +1,7 @@ import 'package:equatable/equatable.dart'; import 'package:flutter/material.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; +import 'package:go_router/go_router.dart'; import 'package:hive/hive.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; @@ -24,9 +25,7 @@ class ChatBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - NavigatorService.popAndPushNamed( - AppRoutes.authScreen, - ); + // go to auth screen } final String? chatID = state.chatModelObj?.chatID; final response = await http.get( diff --git a/lib/presentation/chat/chat_select_screen/bloc/chat_select_bloc.dart b/lib/presentation/chat/chat_select_screen/bloc/chat_select_bloc.dart index f543c5a..fe6d0a7 100644 --- a/lib/presentation/chat/chat_select_screen/bloc/chat_select_bloc.dart +++ b/lib/presentation/chat/chat_select_screen/bloc/chat_select_bloc.dart @@ -47,9 +47,7 @@ class ChatSelectBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - NavigatorService.popAndPushNamed( - AppRoutes.authScreen, - ); + // go to auth screen } final response = await http.get( Uri.parse(dotenv.env['SERVER_ROOT']! + '/chat/index'), 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 52f9de3..55f5ee4 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 @@ -28,23 +28,23 @@ class ChatEntryWidget extends StatelessWidget { borderRadius: BorderRadiusStyle.circleBorder8, ), child: Row( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - CachedNetworkImage( - imageUrl: dotenv.env['STORAGE_URL']! + chatEntryObj.userImage!, - 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, - ), + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + CachedNetworkImage( + imageUrl: dotenv.env['STORAGE_URL']! + chatEntryObj.userImage!, + imageBuilder: (context, imageProvider) => CircleAvatar( + backgroundImage: imageProvider, + radius: 25, ), - /*CustomImageView( + placeholder: (context, url) => CircularProgressIndicator(), + errorWidget: (context, url, error) => CircleAvatar( + child: Icon(Icons.person), + backgroundColor: Colors.white, + radius: 25, + ), + ), + /*CustomImageView( imagePath: dotenv.env['STORAGE_URL']! + chatEntryObj.userImage!, height: 60.adaptSize, @@ -53,57 +53,55 @@ class ChatEntryWidget extends StatelessWidget { 30.h, ), ),*/ - Expanded( - child: Padding( - padding: EdgeInsets.only( - left: 12.h, - top: 2.v, - bottom: 11.v, - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - SizedBox( - width: 227.h, - child: Row( - children: [ - Text( - chatEntryObj.username!.length <= 15 - ? chatEntryObj.username! - : chatEntryObj.username!.substring(0, 15) + - '...', - style: theme.textTheme.titleMedium, - ), - Spacer(), - CustomImageView( - imagePath: ImageConstant.imageNotFound, - height: 9.v, - width: 16.h, - margin: EdgeInsets.only( - top: 4.v, - bottom: 6.v, - ), - ), - Padding( - padding: EdgeInsets.only(left: 6.h), - child: Text( - chatEntryObj.dateText!, - style: theme.textTheme.bodyMedium, - ), - ) - ], - ), - ), - SizedBox(height: 6.v), - Text( - chatEntryObj.greetingText!, - style: CustomTextStyles.bodyMediumBluegray800, - ) - ], - ), + Expanded( + child: Padding( + padding: EdgeInsets.only( + left: 12.h, + top: 2.v, + bottom: 11.v, ), - ) - ]), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SizedBox( + width: 227.h, + child: Row( + children: [ + Text( + chatEntryObj.username!.length <= 15 ? chatEntryObj.username! : chatEntryObj.username!.substring(0, 15) + '...', + style: theme.textTheme.titleMedium, + ), + Spacer(), + CustomImageView( + imagePath: ImageConstant.imageNotFound, + height: 9.v, + width: 16.h, + margin: EdgeInsets.only( + top: 4.v, + bottom: 6.v, + ), + ), + Padding( + padding: EdgeInsets.only(left: 6.h), + child: Text( + chatEntryObj.dateText!, + style: theme.textTheme.bodyMedium, + ), + ) + ], + ), + ), + SizedBox(height: 6.v), + Text( + chatEntryObj.greetingText!, + style: CustomTextStyles.bodyMediumBluegray800, + ) + ], + ), + ), + ) + ], + ), ), ); } diff --git a/lib/presentation/diets/diet_create_screen/bloc/diet_create_bloc.dart b/lib/presentation/diets/diet_create_screen/bloc/diet_create_bloc.dart index e517c1a..e4e0cbc 100644 --- a/lib/presentation/diets/diet_create_screen/bloc/diet_create_bloc.dart +++ b/lib/presentation/diets/diet_create_screen/bloc/diet_create_bloc.dart @@ -1,13 +1,16 @@ 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'; +import 'package:go_router/go_router.dart'; import 'package:hive/hive.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; import '/core/app_export.dart'; import 'package:eatvio_app/presentation/diets/diet_create_screen/models/diet_create_model.dart'; + part 'diet_create_event.dart'; part 'diet_create_state.dart'; @@ -25,9 +28,7 @@ class DietCreateBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - NavigatorService.popAndPushNamed( - AppRoutes.authScreen, - ); + AppRouter.navigatorKey.currentContext?.goNamed('authScreen'); } if (state is DietCreateLoadedState) { var currentState = state as DietCreateLoadedState; @@ -55,7 +56,7 @@ class DietCreateBloc extends Bloc { ); if (response.statusCode == 200) { - NavigatorService.pushNamed(AppRoutes.dietSelectScreen); + AppRouter.navigatorKey.currentContext?.goNamed('dietSelectScreen'); } else { print( 'Failed to create blog post. Status Code: ${response.statusCode} ${response.body}'); diff --git a/lib/presentation/diets/diet_edit_screen/bloc/diet_edit_bloc.dart b/lib/presentation/diets/diet_edit_screen/bloc/diet_edit_bloc.dart index d816779..e69101c 100644 --- a/lib/presentation/diets/diet_edit_screen/bloc/diet_edit_bloc.dart +++ b/lib/presentation/diets/diet_edit_screen/bloc/diet_edit_bloc.dart @@ -1,14 +1,18 @@ 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'; +import 'package:go_router/go_router.dart'; import 'package:hive/hive.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; import '/core/app_export.dart'; import 'package:eatvio_app/presentation/diets/diet_edit_screen/models/diet_edit_model.dart'; + part 'diet_edit_event.dart'; + part 'diet_edit_state.dart'; /// A bloc that manages the state of a DietEdit according to the event that is dispatched to it. @@ -26,9 +30,7 @@ class DietEditBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - NavigatorService.popAndPushNamed( - AppRoutes.authScreen, - ); + AppRouter.navigatorKey.currentContext?.goNamed('authScreen'); } final String? dietID = state.dietModelObj?.dietID; final response = await http.get( @@ -74,15 +76,15 @@ class DietEditBloc extends Bloc { var currentState = state as DietEditLoadedState; int duration = int.parse(currentState.duration!.text) * 7; print(duration); - var response = await sendDiet(currentState.diet, currentState.name?.text, - currentState.details?.text, duration.toString()); + var response = await sendDiet(currentState.diet, currentState.name?.text, currentState.details?.text, duration.toString()); if (response.statusCode == 200) { - NavigatorService.pushNamed(AppRoutes.dietScreen, - arguments: currentState.diet?['id'].toString()); + AppRouter.navigatorKey.currentContext?.goNamed( + 'dietScreen', + extra: currentState.diet?['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/diets/diet_select_screen/bloc/diet_select_bloc.dart b/lib/presentation/diets/diet_select_screen/bloc/diet_select_bloc.dart index 49def2d..21e7dbd 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 @@ -28,9 +28,7 @@ class DietSelectBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - NavigatorService.popAndPushNamed( - AppRoutes.authScreen, - ); // Если токен есть, запускаем приложение + // go to auth screen } final response = await http.get( Uri.parse(dotenv.env['SERVER_ROOT']! + '/diets/index'), 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 a1216bd..7c11ea6 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 @@ -26,9 +26,7 @@ class DietBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - NavigatorService.popAndPushNamed( - AppRoutes.authScreen, - ); + // go to auth screen } final String? dietID = state.dietModelObj?.dietID; final response = await http.get( 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 e07d2dc..5fb90f4 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 @@ -26,9 +26,7 @@ class BlogPostCreateBloc final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - NavigatorService.popAndPushNamed( - AppRoutes.authScreen, - ); + // go to auth screen } if (state is BlogPostCreateLoadedState) { var currentState = state as BlogPostCreateLoadedState; 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 f3b193e..9783704 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 @@ -26,9 +26,7 @@ class BlogPostEditBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - NavigatorService.popAndPushNamed( - AppRoutes.authScreen, - ); + // go to auth screen } final String? blog_postID = state.blog_postModelObj?.blog_postID; final response = await http.get( 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 d065533..d26638d 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 @@ -29,9 +29,7 @@ class BlogPostBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - NavigatorService.popAndPushNamed( - AppRoutes.authScreen, - ); + // go to auth screen } final String? blog_postID = state.blog_postModelObj?.blog_postID; final response = await http.get( diff --git a/lib/presentation/feed/feed_screen/bloc/feed_bloc.dart b/lib/presentation/feed/feed_screen/bloc/feed_bloc.dart index 3932f49..0040ad2 100644 --- a/lib/presentation/feed/feed_screen/bloc/feed_bloc.dart +++ b/lib/presentation/feed/feed_screen/bloc/feed_bloc.dart @@ -28,9 +28,7 @@ class FeedBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - NavigatorService.popAndPushNamed( - AppRoutes.authScreen, - ); // Если токен есть, запускаем приложение + // go to auth screen } final response = await http.get( Uri.parse(dotenv.env['SERVER_ROOT']! + '/feed/index'), diff --git a/lib/presentation/glossary/glossary_screen/bloc/glossary_screen_bloc.dart b/lib/presentation/glossary/glossary_screen/bloc/glossary_screen_bloc.dart index d106526..c40fd21 100644 --- a/lib/presentation/glossary/glossary_screen/bloc/glossary_screen_bloc.dart +++ b/lib/presentation/glossary/glossary_screen/bloc/glossary_screen_bloc.dart @@ -26,9 +26,7 @@ class GlossaryBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - NavigatorService.popAndPushNamed( - AppRoutes.authScreen, - ); + // go to auth screen } final responseProductGroups = await http.get( Uri.parse(dotenv.env['SERVER_ROOT']! + '/glossary/getProductGroups'), 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 b06092c..5569bae 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 @@ -25,9 +25,7 @@ class PlanCreateBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - NavigatorService.popAndPushNamed( - AppRoutes.authScreen, - ); + // go to auth screen } if (state is PlanCreateLoadedState) { var currentState = state as PlanCreateLoadedState; 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 e8fa9ea..a8051c1 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 @@ -26,9 +26,7 @@ class PlanEditBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - NavigatorService.popAndPushNamed( - AppRoutes.authScreen, - ); + // go to auth screen } final String? planID = state.planModelObj?.planID; final response = await http.get( diff --git a/lib/presentation/plans/plan_select_screen/bloc/plan_select_bloc.dart b/lib/presentation/plans/plan_select_screen/bloc/plan_select_bloc.dart index 40d5f6f..e53e658 100644 --- a/lib/presentation/plans/plan_select_screen/bloc/plan_select_bloc.dart +++ b/lib/presentation/plans/plan_select_screen/bloc/plan_select_bloc.dart @@ -28,9 +28,7 @@ class PlanSelectBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - NavigatorService.popAndPushNamed( - AppRoutes.authScreen, - ); // Если токен есть, запускаем приложение + // go to auth screen } final response = await http.get( Uri.parse(dotenv.env['SERVER_ROOT']! + '/plans/index'), 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 616b521..654f3ec 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 @@ -26,9 +26,7 @@ class PlanBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - NavigatorService.popAndPushNamed( - AppRoutes.authScreen, - ); + // go to auth screen } final String? planID = state.planModelObj?.planID; final response = await http.get( 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 5296917..804bab6 100644 --- a/lib/presentation/profile/my_profile_screen/my_profile_screen.dart +++ b/lib/presentation/profile/my_profile_screen/my_profile_screen.dart @@ -1,4 +1,4 @@ -import 'package:eatvio_app/widgets/app_bar/custom_app_bar.dart'; +import 'package:go_router/go_router.dart'; import 'bloc/my_profile_bloc.dart'; import 'models/my_profile_model.dart'; @@ -34,9 +34,10 @@ class MyProfileScreen extends StatelessWidget { builder: (context, state) { if (state is MyProfileInitialState) { // Это начальное состояние, данные ещё не загружены. - return CircularProgressIndicator( - color: Colors.white, - backgroundColor: Colors.white, + return Scaffold( + body: Center( + child: CircularProgressIndicator(), + ), ); } else if (state is MyProfileLoadedState) { // Данные загружены, можно строить экран. @@ -46,7 +47,11 @@ class MyProfileScreen extends StatelessWidget { return Center(child: Text(state.errorMessage)); } else { // Другие состояния, если они есть. - return Container(); // Пустой контейнер для необработанных состояний. + return Scaffold( + body: Center( + child: CircularProgressIndicator(), + ), + ); } }, ); @@ -55,8 +60,9 @@ class MyProfileScreen extends StatelessWidget { _buildMyProfileScreen(BuildContext context, MyProfileLoadedState state) { mediaQueryData = MediaQuery.of(context); return Scaffold( - appBar: CustomAppBar( - height: 0, + appBar: AppBar( + toolbarHeight: 0, + automaticallyImplyLeading: false, ), backgroundColor: Colors.grey[200], resizeToAvoidBottomInset: true, @@ -811,10 +817,7 @@ class MyProfileScreen extends StatelessWidget { ); if (response.statusCode == 201) { - Navigator.pushNamed( - context, - AppRoutes.myProfile, - ); + GoRouter.of(context).go('/my-profile-screen'); } else { // Ошибка от сервера print("Ошибка при отправке данных. Код ответа: ${response.statusCode}"); @@ -903,10 +906,7 @@ class MyProfileScreen extends StatelessWidget { ); if (response.statusCode == 201) { - Navigator.pushNamed( - context, - AppRoutes.myProfile, - ); + GoRouter.of(context).go('/my-profile-screen'); } else { // Ошибка от сервера print("Ошибка при отправке данных. Код ответа: ${response.statusCode}"); diff --git a/lib/presentation/profile/my_profile_screen/my_settings_screen.dart b/lib/presentation/profile/my_profile_screen/my_settings_screen.dart index fe6de3c..5d3682a 100644 --- a/lib/presentation/profile/my_profile_screen/my_settings_screen.dart +++ b/lib/presentation/profile/my_profile_screen/my_settings_screen.dart @@ -24,16 +24,21 @@ class MySettingsScreen extends StatelessWidget { builder: (context, state) { if (state is MyProfileInitialState) { // Это начальное состояние, данные ещё не загружены. - return CircularProgressIndicator( - color: Colors.white, - backgroundColor: Colors.white, + return Scaffold( + body: Center( + child: CircularProgressIndicator(), + ), ); } else if (state is MyProfileLoadedState) { // Данные загружены, можно строить экран. return _buildSetingsScreen(context, state); } else { // Другие состояния, если они есть. - return Container(); // Пустой контейнер для необработанных состояний. + return Scaffold( + body: Center( + child: CircularProgressIndicator(), + ), + ); } }, ); 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 05535dd..483dcd3 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 @@ -28,9 +28,7 @@ class RecipeCreateBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - NavigatorService.popAndPushNamed( - AppRoutes.authScreen, - ); + // go to auth screen } if (state is RecipeCreateLoadedState) { var currentState = state as RecipeCreateLoadedState; 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 1e971c2..eb87a14 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 @@ -29,9 +29,7 @@ class RecipeEditBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - NavigatorService.popAndPushNamed( - AppRoutes.authScreen, - ); + // go to auth screen } final String? recipeID = state.recipeModelObj?.recipeID; final response = await http.get( diff --git a/lib/presentation/recipe/recipe_select_screen/bloc/recipe_select_bloc.dart b/lib/presentation/recipe/recipe_select_screen/bloc/recipe_select_bloc.dart index fc9a96f..b597cbb 100644 --- a/lib/presentation/recipe/recipe_select_screen/bloc/recipe_select_bloc.dart +++ b/lib/presentation/recipe/recipe_select_screen/bloc/recipe_select_bloc.dart @@ -28,9 +28,7 @@ class RecipeSelectBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - NavigatorService.popAndPushNamed( - AppRoutes.authScreen, - ); // Если токен есть, запускаем приложение + // go to auth screen } final response = await http.get( Uri.parse(dotenv.env['SERVER_ROOT']! + '/recipe/index'), 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 1e0b1eb..195fab7 100644 --- a/lib/presentation/recipe/recipe_select_screen/recipe_select_screen.dart +++ b/lib/presentation/recipe/recipe_select_screen/recipe_select_screen.dart @@ -13,9 +13,7 @@ import 'package:flutter/material.dart'; class RecipeSelectScreen extends StatelessWidget { static Widget builder(BuildContext context) { return BlocProvider( - create: (context) => RecipeSelectBloc( - RecipeSelectState(myProfileModelObj: RecipeSelectModel())) - ..add(RecipeSelectInitialEvent()), + create: (context) => RecipeSelectBloc(RecipeSelectState(myProfileModelObj: RecipeSelectModel()))..add(RecipeSelectInitialEvent()), child: RecipeSelectScreen()); } @@ -23,17 +21,20 @@ class RecipeSelectScreen extends StatelessWidget { return BlocBuilder( builder: (context, state) { if (state is RecipeSelectInitialState) { - // Это начальное состояние, данные ещё не загружены. - return CircularProgressIndicator( - color: Colors.white, - backgroundColor: Colors.white, + return Scaffold( + body: Center( + child: CircularProgressIndicator(), + ), ); } else if (state is RecipeSelectLoadedState) { // Данные загружены, можно строить экран. return _buildRecipeScreen(context, state); } else { - // Другие состояния, если они есть. - return Container(); // Пустой контейнер для необработанных состояний. + return Scaffold( + body: Center( + child: CircularProgressIndicator(), + ), + ); } }, ); @@ -75,8 +76,7 @@ class RecipeSelectScreen 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( @@ -85,8 +85,7 @@ class RecipeSelectScreen 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( 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 982266c..b431b04 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 @@ -29,9 +29,7 @@ class RecipeBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - NavigatorService.popAndPushNamed( - AppRoutes.authScreen, - ); + // go to auth screen } final String? recipeID = state.recipeModelObj?.recipeID; final response = await http.get( diff --git a/lib/routes/app_routes.dart b/lib/routes/app_routes.dart index fd65602..2cbe9aa 100644 --- a/lib/routes/app_routes.dart +++ b/lib/routes/app_routes.dart @@ -68,8 +68,7 @@ class AppRoutes { static const String scheduleScreen = '/schedule_screen'; - static const String additionalInformationScreen = - '/additional_information_screen'; + static const String additionalInformationScreen = '/additional_information_screen'; static const String languageSelectScreen = '/language_select_screen'; @@ -129,82 +128,45 @@ class AppRoutes { 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), + 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), - authScreen: (context) => _buildFadeRoute(context, AuthScreen.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), + 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), + 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), + 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), + planEditScreen: (context) => _buildFadeRoute(context, PlanEditScreen.builder), + planCreateScreen: (context) => _buildFadeRoute(context, PlanCreateScreen.builder), feedScreen: (context) => _buildFadeRoute(context, FeedScreen.builder), - // blogPostScreen: (context) => - // _buildFadeRoute(context, BlogPostScreen.builder), - blogPostEditScreen: (context) => - _buildFadeRoute(context, BlogPostEditScreen.builder), - blogPostCreateScreen: (context) => - _buildFadeRoute(context, BlogPostCreateScreen.builder), - glossaryScreen: (context) => - _buildFadeRoute(context, GlossaryScreen.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) { @@ -220,14 +182,10 @@ class FadeTransitionPage extends PageRouteBuilder { FadeTransitionPage({required this.builder}) : super( - pageBuilder: (BuildContext context, Animation animation, - Animation secondaryAnimation) { + pageBuilder: (BuildContext context, Animation animation, Animation secondaryAnimation) { return builder(context); }, - transitionsBuilder: (BuildContext context, - Animation animation, - Animation secondaryAnimation, - Widget child) { + transitionsBuilder: (BuildContext context, Animation animation, Animation secondaryAnimation, Widget child) { return FadeTransition(opacity: animation, child: child); }, ); diff --git a/lib/widgets/bottom_navigation_bar_widget.dart b/lib/widgets/bottom_navigation_bar_widget.dart index 6f29ef3..68197c1 100644 --- a/lib/widgets/bottom_navigation_bar_widget.dart +++ b/lib/widgets/bottom_navigation_bar_widget.dart @@ -73,13 +73,21 @@ class _BottomNavigationBarWidgetState extends State { items: [ BottomNavigationBarItem( label: '', - icon: SvgPicture.asset(ImageConstant.imgLogo), + icon: SvgPicture.asset( + ImageConstant.imgLogo, + ), ), BottomNavigationBarItem( label: 'Лента', - icon: SvgPicture.asset(ImageConstant.imgFeed), + icon: SvgPicture.asset( + width: 24, + height: 24, + ImageConstant.imgFeed, + ), activeIcon: SvgPicture.asset( ImageConstant.imgFeed, + width: 24, + height: 24, colorFilter: ColorFilter.mode( appTheme.blueA400, BlendMode.srcIn, @@ -88,9 +96,15 @@ class _BottomNavigationBarWidgetState extends State { ), BottomNavigationBarItem( label: "diary".tr, - icon: SvgPicture.asset(ImageConstant.imgDiary), + icon: SvgPicture.asset( + ImageConstant.imgDiary, + width: 24, + height: 24, + ), activeIcon: SvgPicture.asset( ImageConstant.imgDiary, + width: 24, + height: 24, colorFilter: ColorFilter.mode( appTheme.blueA400, BlendMode.srcIn, @@ -99,9 +113,15 @@ class _BottomNavigationBarWidgetState extends State { ), BottomNavigationBarItem( label: "chat".tr, - icon: SvgPicture.asset(ImageConstant.imgChat), + icon: SvgPicture.asset( + ImageConstant.imgChat, + width: 24, + height: 24, + ), activeIcon: SvgPicture.asset( ImageConstant.imgChat, + width: 24, + height: 24, colorFilter: ColorFilter.mode( appTheme.blueA400, BlendMode.srcIn, @@ -110,9 +130,15 @@ class _BottomNavigationBarWidgetState extends State { ), BottomNavigationBarItem( label: '', - icon: SvgPicture.asset(ImageConstant.imgBell), + icon: SvgPicture.asset( + ImageConstant.imgBell, + width: 24, + height: 24, + ), activeIcon: SvgPicture.asset( ImageConstant.imgBell, + width: 24, + height: 24, colorFilter: ColorFilter.mode( appTheme.blueA400, BlendMode.srcIn, diff --git a/lib/widgets/custom_expandable_list.dart b/lib/widgets/custom_expandable_list.dart index 00d66ce..c3d552b 100644 --- a/lib/widgets/custom_expandable_list.dart +++ b/lib/widgets/custom_expandable_list.dart @@ -3,6 +3,7 @@ import 'package:eatvio_app/core/app_export.dart'; import 'package:eatvio_app/presentation/profile/my_profile_screen/bloc/my_profile_bloc.dart'; import 'package:eatvio_app/widgets/custom_hyper_switch.dart'; import 'package:eatvio_app/widgets/custom_hypo_switch.dart'; +import 'package:go_router/go_router.dart'; import 'package:intl/intl.dart'; import 'package:eatvio_app/widgets/next_step_button.dart'; import 'dart:convert'; @@ -395,10 +396,7 @@ class _ExpandableListState extends State { } void _navigateToProfilePage() { - Navigator.pushNamed( - context, - AppRoutes.myProfile, - ); + GoRouter.of(context).go('/my-profile-screen'); } String _getErrorMessage(http.Response response) { From 4e62ebe60d3198125ea5a8ea6593c3bf02c069da Mon Sep 17 00:00:00 2001 From: mso7nueh Date: Thu, 6 Jun 2024 13:42:56 +0300 Subject: [PATCH 13/17] go router 2 --- lib/presentation/chat/chat_screen/bloc/chat_bloc.dart | 1 - lib/routes/app_routes.dart | 1 - 2 files changed, 2 deletions(-) diff --git a/lib/presentation/chat/chat_screen/bloc/chat_bloc.dart b/lib/presentation/chat/chat_screen/bloc/chat_bloc.dart index 3d8f73a..15319c2 100644 --- a/lib/presentation/chat/chat_screen/bloc/chat_bloc.dart +++ b/lib/presentation/chat/chat_screen/bloc/chat_bloc.dart @@ -1,7 +1,6 @@ import 'package:equatable/equatable.dart'; import 'package:flutter/material.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; -import 'package:go_router/go_router.dart'; import 'package:hive/hive.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; diff --git a/lib/routes/app_routes.dart b/lib/routes/app_routes.dart index 2cbe9aa..f763336 100644 --- a/lib/routes/app_routes.dart +++ b/lib/routes/app_routes.dart @@ -17,7 +17,6 @@ import 'package:eatvio_app/presentation/registration/height_screen/height_screen 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/auth/auth_screen/auth_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'; From 7b552046591f16cd7773b8ec840a32bf791456ac Mon Sep 17 00:00:00 2001 From: mso7nueh Date: Thu, 6 Jun 2024 13:50:00 +0300 Subject: [PATCH 14/17] go router 3 --- .../chat/chat_screen/bloc/chat_bloc.dart | 4 +++- .../bloc/chat_select_bloc.dart | 7 +++++-- .../bloc/diet_select_bloc.dart | 2 +- .../diet_show_screen/bloc/diet_show_bloc.dart | 6 ++---- .../bloc/blog_post_create_bloc.dart | 4 +++- .../bloc/blog_post_edit_bloc.dart | 4 +++- .../blog_post_screen/bloc/blog_post_bloc.dart | 16 ++++++--------- .../feed/feed_screen/bloc/feed_bloc.dart | 4 +++- .../bloc/glossary_screen_bloc.dart | 4 +++- .../bloc/plan_create_bloc.dart | 4 +++- .../plan_edit_screen/bloc/plan_edit_bloc.dart | 4 +++- .../bloc/plan_select_bloc.dart | 4 +++- .../plan_show_screen/bloc/plan_show_bloc.dart | 8 ++++---- .../bloc/my_profile_bloc.dart | 6 +++--- .../bloc/recipe_create_bloc.dart | 8 ++++---- .../bloc/recipe_edit_bloc.dart | 12 +++++------ .../bloc/recipe_select_bloc.dart | 5 +++-- .../bloc/recipe_show_bloc.dart | 20 +++++++------------ lib/routes/app_routes.dart | 2 +- 19 files changed, 65 insertions(+), 59 deletions(-) diff --git a/lib/presentation/chat/chat_screen/bloc/chat_bloc.dart b/lib/presentation/chat/chat_screen/bloc/chat_bloc.dart index 15319c2..8c33f02 100644 --- a/lib/presentation/chat/chat_screen/bloc/chat_bloc.dart +++ b/lib/presentation/chat/chat_screen/bloc/chat_bloc.dart @@ -1,8 +1,10 @@ +import 'package:eatvio_app/app_router.dart'; import 'package:equatable/equatable.dart'; import 'package:flutter/material.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:hive/hive.dart'; import 'package:http/http.dart' as http; +import 'package:go_router/go_router.dart'; import 'dart:convert'; import '/core/app_export.dart'; import 'package:eatvio_app/presentation/chat/chat_screen/models/chat_model.dart'; @@ -24,7 +26,7 @@ class ChatBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - // go to auth screen + AppRouter.navigatorKey.currentContext?.goNamed('authScreen'); } final String? chatID = state.chatModelObj?.chatID; final response = await http.get( diff --git a/lib/presentation/chat/chat_select_screen/bloc/chat_select_bloc.dart b/lib/presentation/chat/chat_select_screen/bloc/chat_select_bloc.dart index fe6d0a7..b71f87c 100644 --- a/lib/presentation/chat/chat_select_screen/bloc/chat_select_bloc.dart +++ b/lib/presentation/chat/chat_select_screen/bloc/chat_select_bloc.dart @@ -1,3 +1,4 @@ +import 'package:eatvio_app/app_router.dart'; import 'package:equatable/equatable.dart'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; @@ -8,7 +9,9 @@ import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'dart:convert'; import '/core/app_export.dart'; import 'package:eatvio_app/presentation/chat/chat_select_screen/models/chat_select_model.dart'; -import 'package:eatvio_app/presentation/chat/chat_select_screen/models/chat_entry.dart'; // ignore: must_be_immutable +import 'package:eatvio_app/presentation/chat/chat_select_screen/models/chat_entry.dart'; +import 'package:go_router/go_router.dart'; + part 'chat_select_event.dart'; part 'chat_select_state.dart'; @@ -47,7 +50,7 @@ class ChatSelectBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - // go to auth screen + AppRouter.navigatorKey.currentContext?.goNamed('authScreen'); } final response = await http.get( Uri.parse(dotenv.env['SERVER_ROOT']! + '/chat/index'), 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 21e7dbd..5776d70 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 @@ -28,7 +28,7 @@ class DietSelectBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - // go to auth screen + AppRouter.navigatorKey.currentContext?.goNamed('authScreen'); } final response = await http.get( Uri.parse(dotenv.env['SERVER_ROOT']! + '/diets/index'), 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 7c11ea6..5c60a1d 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 @@ -26,7 +26,7 @@ class DietBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - // go to auth screen + AppRouter.navigatorKey.currentContext?.goNamed('authScreen'); } final String? dietID = state.dietModelObj?.dietID; final response = await http.get( @@ -65,9 +65,7 @@ class DietBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - NavigatorService.popAndPushNamed( - AppRoutes.authScreen, - ); + AppRouter.navigatorKey.currentContext?.goNamed('authScreen'); } final int id = event.id; final response = await http.post( 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 5fb90f4..3f5d95e 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 @@ -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,6 +9,7 @@ import 'package:http/http.dart' as http; import 'dart:convert'; import '/core/app_export.dart'; import 'package:eatvio_app/presentation/feed/blog_post_create_screen/models/blog_post_create_model.dart'; +import 'package:go_router/go_router.dart'; part 'blog_post_create_event.dart'; part 'blog_post_create_state.dart'; @@ -26,7 +28,7 @@ class BlogPostCreateBloc final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - // go to auth screen + AppRouter.navigatorKey.currentContext?.goNamed('authScreen'); } if (state is BlogPostCreateLoadedState) { var currentState = state as BlogPostCreateLoadedState; 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 9783704..1810faf 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 @@ -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,6 +9,7 @@ import 'package:http/http.dart' as http; 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'; @@ -26,7 +28,7 @@ class BlogPostEditBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - // go to auth screen + AppRouter.navigatorKey.currentContext?.goNamed('authScreen'); } final String? blog_postID = state.blog_postModelObj?.blog_postID; final response = await http.get( 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 d26638d..19f0c70 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 @@ -1,5 +1,6 @@ import 'dart:async'; +import 'package:eatvio_app/app_router.dart'; import 'package:eatvio_app/presentation/feed/blog_post_screen/models/comment_model.dart'; import 'package:equatable/equatable.dart'; import 'package:flutter/material.dart'; @@ -10,6 +11,7 @@ import 'package:intl/intl.dart'; import 'dart:convert'; import '/core/app_export.dart'; import 'package:eatvio_app/presentation/feed/blog_post_screen/models/blog_post_model.dart'; +import 'package:go_router/go_router.dart'; part 'blog_post_event.dart'; part 'blog_post_state.dart'; @@ -29,7 +31,7 @@ class BlogPostBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - // go to auth screen + AppRouter.navigatorKey.currentContext?.goNamed('authScreen'); } final String? blog_postID = state.blog_postModelObj?.blog_postID; final response = await http.get( @@ -96,9 +98,7 @@ class BlogPostBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - NavigatorService.popAndPushNamed( - AppRoutes.authScreen, - ); + AppRouter.navigatorKey.currentContext?.goNamed('authScreen'); } final int id = event.id; final response = await http.post( @@ -120,9 +120,7 @@ class BlogPostBloc extends Bloc { final token = box.get('token'); if (token == null) { - NavigatorService.popAndPushNamed( - AppRoutes.authScreen, - ); + AppRouter.navigatorKey.currentContext?.goNamed('authScreen'); } final response = await http.get( @@ -139,9 +137,7 @@ class BlogPostBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - NavigatorService.popAndPushNamed( - AppRoutes.authScreen, - ); + AppRouter.navigatorKey.currentContext?.goNamed('authScreen'); } final response = await http.get( Uri.parse(dotenv.env['SERVER_ROOT']! + '/feed/getComments/$id'), diff --git a/lib/presentation/feed/feed_screen/bloc/feed_bloc.dart b/lib/presentation/feed/feed_screen/bloc/feed_bloc.dart index 0040ad2..1eda1fe 100644 --- a/lib/presentation/feed/feed_screen/bloc/feed_bloc.dart +++ b/lib/presentation/feed/feed_screen/bloc/feed_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 'feed_event.dart'; part 'feed_state.dart'; @@ -28,7 +30,7 @@ class FeedBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - // go to auth screen + AppRouter.navigatorKey.currentContext?.goNamed('authScreen'); } final response = await http.get( Uri.parse(dotenv.env['SERVER_ROOT']! + '/feed/index'), diff --git a/lib/presentation/glossary/glossary_screen/bloc/glossary_screen_bloc.dart b/lib/presentation/glossary/glossary_screen/bloc/glossary_screen_bloc.dart index c40fd21..5f63f29 100644 --- a/lib/presentation/glossary/glossary_screen/bloc/glossary_screen_bloc.dart +++ b/lib/presentation/glossary/glossary_screen/bloc/glossary_screen_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,6 +9,7 @@ import 'package:http/http.dart' as http; import 'dart:convert'; import '/core/app_export.dart'; import 'package:eatvio_app/presentation/glossary/glossary_screen/models/glossary_screen_model.dart'; +import 'package:go_router/go_router.dart'; part 'glossary_screen_event.dart'; part 'glossary_screen_state.dart'; @@ -26,7 +28,7 @@ class GlossaryBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - // go to auth screen + AppRouter.navigatorKey.currentContext?.goNamed('authScreen'); } final responseProductGroups = await http.get( Uri.parse(dotenv.env['SERVER_ROOT']! + '/glossary/getProductGroups'), 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 5569bae..a74e40e 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 @@ -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,6 +9,7 @@ import 'package:http/http.dart' as http; import 'dart:convert'; import '/core/app_export.dart'; import 'package:eatvio_app/presentation/plans/plan_create_screen/models/plan_create_model.dart'; +import 'package:go_router/go_router.dart'; part 'plan_create_event.dart'; part 'plan_create_state.dart'; @@ -25,7 +27,7 @@ class PlanCreateBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - // go to auth screen + AppRouter.navigatorKey.currentContext?.goNamed('authScreen'); } if (state is PlanCreateLoadedState) { var currentState = state as PlanCreateLoadedState; 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 a8051c1..584f9d2 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 @@ -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,6 +9,7 @@ import 'package:http/http.dart' as http; 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'; @@ -26,7 +28,7 @@ class PlanEditBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - // go to auth screen + AppRouter.navigatorKey.currentContext?.goNamed('authScreen'); } final String? planID = state.planModelObj?.planID; final response = await http.get( diff --git a/lib/presentation/plans/plan_select_screen/bloc/plan_select_bloc.dart b/lib/presentation/plans/plan_select_screen/bloc/plan_select_bloc.dart index e53e658..b74c0ed 100644 --- a/lib/presentation/plans/plan_select_screen/bloc/plan_select_bloc.dart +++ b/lib/presentation/plans/plan_select_screen/bloc/plan_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 'plan_select_event.dart'; part 'plan_select_state.dart'; @@ -28,7 +30,7 @@ class PlanSelectBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - // go to auth screen + AppRouter.navigatorKey.currentContext?.goNamed('authScreen'); } final response = await http.get( Uri.parse(dotenv.env['SERVER_ROOT']! + '/plans/index'), 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 654f3ec..1c29624 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 @@ -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,6 +9,7 @@ import 'package:http/http.dart' as http; 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'; @@ -26,7 +28,7 @@ class PlanBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - // go to auth screen + AppRouter.navigatorKey.currentContext?.goNamed('authScreen'); } final String? planID = state.planModelObj?.planID; final response = await http.get( @@ -65,9 +67,7 @@ class PlanBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - NavigatorService.popAndPushNamed( - AppRoutes.authScreen, - ); + AppRouter.navigatorKey.currentContext?.goNamed('authScreen'); } final int id = event.id; final response = await http.post( diff --git a/lib/presentation/profile/my_profile_screen/bloc/my_profile_bloc.dart b/lib/presentation/profile/my_profile_screen/bloc/my_profile_bloc.dart index b0359fd..af5fb77 100644 --- a/lib/presentation/profile/my_profile_screen/bloc/my_profile_bloc.dart +++ b/lib/presentation/profile/my_profile_screen/bloc/my_profile_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 'my_profile_event.dart'; part 'my_profile_state.dart'; @@ -29,9 +31,7 @@ class MyProfileBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - NavigatorService.popAndPushNamed( - AppRoutes.authScreen, - ); // Если токен есть, запускаем приложение + AppRouter.navigatorKey.currentContext?.goNamed('authScreen'); } //final token = // "9|laravel_sanctum_KFXbccDcWEvTPfJmV99EQv1ne AggmpR2TidVGDPN34fa201a"; 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 483dcd3..1b28e10 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 @@ -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,6 +9,7 @@ import 'package:http/http.dart' as http; import 'dart:convert'; import '/core/app_export.dart'; import 'package:eatvio_app/presentation/recipe/recipe_create_screen/models/recipe_create_model.dart'; +import 'package:go_router/go_router.dart'; part 'recipe_create_event.dart'; part 'recipe_create_state.dart'; @@ -28,7 +30,7 @@ class RecipeCreateBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - // go to auth screen + AppRouter.navigatorKey.currentContext?.goNamed('authScreen'); } if (state is RecipeCreateLoadedState) { var currentState = state as RecipeCreateLoadedState; @@ -144,9 +146,7 @@ class RecipeCreateBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - NavigatorService.popAndPushNamed( - AppRoutes.authScreen, - ); + AppRouter.navigatorKey.currentContext?.goNamed('authScreen'); } if (state is RecipeCreateLoadedState) { var currentState = state as RecipeCreateLoadedState; 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 eb87a14..4a5fce4 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 @@ -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,6 +9,7 @@ import 'package:http/http.dart' as http; 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'; @@ -29,7 +31,7 @@ class RecipeEditBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - // go to auth screen + AppRouter.navigatorKey.currentContext?.goNamed('authScreen'); } final String? recipeID = state.recipeModelObj?.recipeID; final response = await http.get( @@ -194,9 +196,7 @@ class RecipeEditBloc extends Bloc { final token = box.get('token'); if (token == null) { - NavigatorService.popAndPushNamed( - AppRoutes.authScreen, - ); + AppRouter.navigatorKey.currentContext?.goNamed('authScreen'); } final response = await http.get( @@ -215,9 +215,7 @@ class RecipeEditBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - NavigatorService.popAndPushNamed( - AppRoutes.authScreen, - ); + AppRouter.navigatorKey.currentContext?.goNamed('authScreen'); } if (state is RecipeEditLoadedState) { var currentState = state as RecipeEditLoadedState; diff --git a/lib/presentation/recipe/recipe_select_screen/bloc/recipe_select_bloc.dart b/lib/presentation/recipe/recipe_select_screen/bloc/recipe_select_bloc.dart index b597cbb..a7b0d37 100644 --- a/lib/presentation/recipe/recipe_select_screen/bloc/recipe_select_bloc.dart +++ b/lib/presentation/recipe/recipe_select_screen/bloc/recipe_select_bloc.dart @@ -1,6 +1,6 @@ -//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 +10,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 'recipe_select_event.dart'; part 'recipe_select_state.dart'; @@ -28,7 +29,7 @@ class RecipeSelectBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - // go to auth screen + AppRouter.navigatorKey.currentContext?.goNamed('authScreen'); } final response = await http.get( Uri.parse(dotenv.env['SERVER_ROOT']! + '/recipe/index'), 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 b431b04..aaf8c62 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 @@ -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'; @@ -10,6 +11,7 @@ import 'dart:convert'; 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'; @@ -29,7 +31,7 @@ class RecipeBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - // go to auth screen + AppRouter.navigatorKey.currentContext?.goNamed('authScreen'); } final String? recipeID = state.recipeModelObj?.recipeID; final response = await http.get( @@ -80,9 +82,7 @@ class RecipeBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - NavigatorService.popAndPushNamed( - AppRoutes.authScreen, - ); + AppRouter.navigatorKey.currentContext?.goNamed('authScreen'); } final int id = event.id; final response = await http.post( @@ -124,9 +124,7 @@ class RecipeBloc extends Bloc { final token = box.get('token'); if (token == null) { - NavigatorService.popAndPushNamed( - AppRoutes.authScreen, - ); + AppRouter.navigatorKey.currentContext?.goNamed('authScreen'); } final response = await http.get( @@ -143,9 +141,7 @@ class RecipeBloc extends Bloc { final box = await Hive.openBox('token'); final token = box.get('token'); if (token == null) { - NavigatorService.popAndPushNamed( - AppRoutes.authScreen, - ); + AppRouter.navigatorKey.currentContext?.goNamed('authScreen'); } final response = await http.get( Uri.parse(dotenv.env['SERVER_ROOT']! + '/recipe/getComments/$id'), @@ -162,9 +158,7 @@ class RecipeBloc extends Bloc { final token = box.get('token'); if (token == null) { - NavigatorService.popAndPushNamed( - AppRoutes.authScreen, - ); + AppRouter.navigatorKey.currentContext?.goNamed('authScreen'); } final response = await http.get( diff --git a/lib/routes/app_routes.dart b/lib/routes/app_routes.dart index f763336..d3183f0 100644 --- a/lib/routes/app_routes.dart +++ b/lib/routes/app_routes.dart @@ -38,7 +38,7 @@ import 'package:eatvio_app/presentation/feed/blog_post_edit_screen/blog_post_edi 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 AppRoutes { +class AppRoutesq { // REGISTRATION static const String dateOfBirthScreen = '/date_of_birth_screen'; From 647e9e9133dcbbf3234f156193aea4ed691886e0 Mon Sep 17 00:00:00 2001 From: mso7nueh Date: Thu, 6 Jun 2024 16:02:39 +0300 Subject: [PATCH 15/17] go router full --- lib/core/app_export.dart | 1 - lib/main.dart | 44 ++-- .../chat/chat_screen/chat_screen.dart | 2 +- .../widgets/chat_entry_widget.dart | 8 +- .../bloc/diet_select_bloc.dart | 2 + .../diet_select_screen.dart | 38 ++-- .../diet_show_screen/bloc/diet_show_bloc.dart | 13 +- .../diet_show_screen/diet_show_screen.dart | 11 +- .../bloc/blog_post_create_bloc.dart | 2 +- .../bloc/blog_post_edit_bloc.dart | 14 +- .../blog_post_screen/bloc/blog_post_bloc.dart | 2 +- .../blog_post_screen/blog_post_screen.dart | 7 +- .../glossary_screen/glossary_screen.dart | 2 +- .../bloc/plan_create_bloc.dart | 2 +- .../plan_edit_screen/bloc/plan_edit_bloc.dart | 17 +- .../plan_select_screen.dart | 105 +++++----- .../plan_show_screen/bloc/plan_show_bloc.dart | 11 +- .../plan_show_screen/plan_show_screen.dart | 3 +- .../my_profile_screen/my_profile_screen.dart | 2 +- .../bloc/recipe_create_bloc.dart | 2 +- .../bloc/recipe_edit_bloc.dart | 38 ++-- .../recipe_select_screen.dart | 27 ++- .../bloc/recipe_show_bloc.dart | 25 +-- .../recipe_show_screen.dart | 35 ++-- .../additional_information_screen.dart | 7 +- .../allergies_screen/allergies_screen.dart | 61 ++---- .../app_navigation_screen.dart | 55 ++--- .../blood_pressure_screen.dart | 134 ++++-------- .../body_circumferences_screen.dart | 93 +++------ .../city_of_living_screen.dart | 76 +++---- .../credentials_screen.dart | 8 +- .../date_of_birth_screen.dart | 83 +++----- .../favorite_foods_screen.dart | 77 ++----- .../favorite_sports_screen.dart | 115 ++++------- .../gender_screen/gender_screen.dart | 46 ++--- .../height_screen/height_screen.dart | 24 +-- .../language_select_screen.dart | 8 +- .../medicine_intake_screen.dart | 68 +++---- .../registration/name_screen/name_screen.dart | 10 +- .../splash_screen/bloc/splash_bloc.dart | 8 +- .../weight_screen/weight_screen.dart | 24 +-- lib/routes/app_routes.dart | 191 ------------------ 42 files changed, 483 insertions(+), 1018 deletions(-) delete mode 100644 lib/routes/app_routes.dart 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); - }, - ); -} From ddc908da5745a457e747f70c42230976f07174e4 Mon Sep 17 00:00:00 2001 From: mso7nueh Date: Tue, 11 Jun 2024 05:13:30 +0300 Subject: [PATCH 16/17] go router fix --- lib/app_router.dart | 104 ++++++++ lib/core/app_export.dart | 1 - lib/core/utils/navigator_service.dart | 28 --- lib/core/utils/progress_dialog_utils.dart | 13 +- lib/localization/app_localization.dart | 4 +- .../auth/auth_screen/auth_screen.dart | 37 ++- .../auth/auth_screen/bloc/auth_bloc.dart | 9 +- .../chat/chat_screen/chat_screen.dart | 5 +- .../diet_select_screen.dart | 2 +- .../diet_show_screen/diet_show_screen.dart | 2 +- .../feed/feed_screen/feed_screen.dart | 2 +- .../plan_select_screen.dart | 2 +- .../plan_show_screen/plan_show_screen.dart | 4 +- .../my_profile_screen/my_settings_screen.dart | 2 +- .../recipe_create_screen.dart | 4 +- .../recipe_edit_screen.dart | 4 +- .../recipe_select_screen.dart | 2 +- .../recipe_show_screen.dart | 7 +- .../additional_information_screen.dart | 62 ++--- .../allergies_screen/allergies_screen.dart | 83 ++++--- .../blood_pressure_screen.dart | 225 +++++++++--------- .../body_circumferences_screen.dart | 125 +++++----- .../city_of_living_screen.dart | 200 ++++++++-------- .../credentials_screen.dart | 69 ++---- .../date_of_birth_screen.dart | 78 +++--- .../favorite_foods_screen.dart | 95 ++++---- .../favorite_sports_screen.dart | 83 ++++--- .../gender_screen/gender_screen.dart | 121 +++++----- .../height_screen/height_screen.dart | 149 ++++++------ .../medicine_intake_screen.dart | 2 +- .../registration/name_screen/name_screen.dart | 117 ++++----- .../weight_screen/weight_screen.dart | 150 ++++++------ 32 files changed, 907 insertions(+), 884 deletions(-) delete mode 100644 lib/core/utils/navigator_service.dart diff --git a/lib/app_router.dart b/lib/app_router.dart index 6f677a8..aeed36c 100644 --- a/lib/app_router.dart +++ b/lib/app_router.dart @@ -10,7 +10,20 @@ import 'package:eatvio_app/presentation/plans/plan_select_screen/plan_select_scr 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/recipe/recipe_select_screen/recipe_select_screen.dart'; +import 'package:eatvio_app/presentation/registration/additional_information_screen/additional_information_screen.dart'; +import 'package:eatvio_app/presentation/registration/allergies_screen/allergies_screen.dart'; +import 'package:eatvio_app/presentation/registration/blood_pressure_screen/blood_pressure_screen.dart'; +import 'package:eatvio_app/presentation/registration/body_circumferences_screen/body_circumferences_screen.dart'; +import 'package:eatvio_app/presentation/registration/city_of_living_screen/city_of_living_screen.dart'; +import 'package:eatvio_app/presentation/registration/credentials_screen/credentials_screen.dart'; +import 'package:eatvio_app/presentation/registration/date_of_birth_screen/date_of_birth_screen.dart'; +import 'package:eatvio_app/presentation/registration/favorite_foods_screen/favorite_foods_screen.dart'; +import 'package:eatvio_app/presentation/registration/favorite_sports_screen/favorite_sports_screen.dart'; +import 'package:eatvio_app/presentation/registration/gender_screen/gender_screen.dart'; +import 'package:eatvio_app/presentation/registration/height_screen/height_screen.dart'; import 'package:eatvio_app/presentation/registration/language_select_screen/language_select_screen.dart'; +import 'package:eatvio_app/presentation/registration/name_screen/name_screen.dart'; +import 'package:eatvio_app/presentation/registration/weight_screen/weight_screen.dart'; import 'package:eatvio_app/widgets/bottom_navigation_bar_widget.dart'; import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; @@ -40,6 +53,97 @@ class AppRouter { path: 'language-select-screen', name: 'languageSelectScreen', builder: (context, state) => LanguageSelectScreen.builder(context), + routes: [ + GoRoute( + path: 'credentials-screen', + name: 'credentialsScreen', + builder: (context, state) => CredentialsScreen.builder(context, state.extra), + routes: [ + GoRoute( + path: 'name-screen', + name: 'nameScreen', + builder: (context, state) => NameScreen.builder(context, state.extra), + routes: [ + GoRoute( + path: 'gender-screen', + name: 'genderScreen', + builder: (context, state) => GenderScreen.builder(context, state.extra), + routes: [ + GoRoute( + path: 'date-of-birth-screen', + name: 'dateOfBirthScreen', + builder: (context, state) => DateOfBirthScreen.builder(context, state.extra), + routes: [ + GoRoute( + path: 'city-of-living-screen', + name: 'cityOfLivingScreen', + builder: (context, state) => CityOfLivingScreen.builder(context, state.extra), + routes: [ + GoRoute( + path: 'body-circumferences-screen', + name: 'bodyCircumferencesScreen', + builder: (context, state) => BodyCircumferencesScreen.builder(context, state.extra), + routes: [ + GoRoute( + path: 'weight-screen', + name: 'weightScreen', + builder: (context, state) => WeightScreen.builder(context, state.extra), + routes: [ + GoRoute( + path: 'height-screen', + name: 'heightScreen', + builder: (context, state) => HeightScreen.builder(context, state.extra), + routes: [ + GoRoute( + path: 'blood-pressure-screen', + name: 'bloodPressureScreen', + builder: (context, state) => BloodPressureScreen.builder(context, state.extra), + routes: [ + GoRoute( + path: 'favorite-sports-screen', + name: 'favoriteSportsScreen', + builder: (context, state) => FavoriteSportsScreen.builder(context, state.extra), + routes: [ + GoRoute( + name: 'allergiesScreen', + path: 'allergiesScreen', + builder: (context, state) => AllergiesScreen.builder(context, state.extra), + routes: [ + GoRoute( + name: 'favoriteFoodsScreen', + path: 'favorite-foods-screen', + builder: (context, state) => FavoriteFoodsScreen.builder(context, state.extra), + routes: [ + GoRoute( + path: 'additional-information-screen', + name: 'additionalInformationScreen', + builder: (context, state) => AdditionalInformationScreen.builder(context, state.extra), + ), + ], + ), + ], + ), + ], + ), + ], + ), + ], + ), + ], + ), + ], + ), + ], + ), + ], + ), + ], + ), + ], + ), + ], + ), + ], ), ], ), diff --git a/lib/core/app_export.dart b/lib/core/app_export.dart index fe2ac98..926e7cb 100644 --- a/lib/core/app_export.dart +++ b/lib/core/app_export.dart @@ -5,7 +5,6 @@ export 'package:eatvio_app/core/errors/exceptions.dart'; export 'package:eatvio_app/core/network/network_info.dart'; export 'package:eatvio_app/core/utils/image_constant.dart'; export 'package:eatvio_app/core/utils/logger.dart'; -export 'package:eatvio_app/core/utils/navigator_service.dart'; 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'; diff --git a/lib/core/utils/navigator_service.dart b/lib/core/utils/navigator_service.dart deleted file mode 100644 index e5ea835..0000000 --- a/lib/core/utils/navigator_service.dart +++ /dev/null @@ -1,28 +0,0 @@ -import 'package:flutter/material.dart'; - -class NavigatorService { - static GlobalKey navigatorKey = GlobalKey(); - - static Future pushNamed(String routeName, - {dynamic arguments}) async { - return navigatorKey.currentState - ?.pushNamed(routeName, arguments: arguments); - } - - static void goBack() { - return navigatorKey.currentState?.pop(); - } - - static Future pushNamedAndRemoveUntil(String routeName, - {bool routePredicate = false, dynamic arguments}) async { - return navigatorKey.currentState?.pushNamedAndRemoveUntil( - routeName, (route) => routePredicate, - arguments: arguments); - } - - static Future popAndPushNamed(String routeName, - {dynamic arguments}) async { - return navigatorKey.currentState - ?.popAndPushNamed(routeName, arguments: arguments); - } -} diff --git a/lib/core/utils/progress_dialog_utils.dart b/lib/core/utils/progress_dialog_utils.dart index b111e96..7ac6ed7 100644 --- a/lib/core/utils/progress_dialog_utils.dart +++ b/lib/core/utils/progress_dialog_utils.dart @@ -1,3 +1,4 @@ +import 'package:eatvio_app/app_router.dart'; import 'package:flutter/material.dart'; import 'package:eatvio_app/core/app_export.dart'; @@ -5,13 +6,11 @@ class ProgressDialogUtils { static bool isProgressVisible = false; ///common method for showing progress dialog - static void showProgressDialog( - {BuildContext? context, isCancellable = false}) async { - if (!isProgressVisible && - NavigatorService.navigatorKey.currentState?.overlay?.context != null) { + static void showProgressDialog({BuildContext? context, isCancellable = false}) async { + if (!isProgressVisible && AppRouter.navigatorKey.currentState?.overlay?.context != null) { showDialog( barrierDismissible: isCancellable, - context: NavigatorService.navigatorKey.currentState!.overlay!.context, + context: AppRouter.navigatorKey.currentState!.overlay!.context, builder: (BuildContext context) { return Center( child: CircularProgressIndicator.adaptive( @@ -28,9 +27,7 @@ class ProgressDialogUtils { ///common method for hiding progress dialog static void hideProgressDialog() { - if (isProgressVisible) - Navigator.pop( - NavigatorService.navigatorKey.currentState!.overlay!.context); + if (isProgressVisible) Navigator.pop(AppRouter.navigatorKey.currentState!.overlay!.context); isProgressVisible = false; } } diff --git a/lib/localization/app_localization.dart b/lib/localization/app_localization.dart index 4701a67..98ee1eb 100644 --- a/lib/localization/app_localization.dart +++ b/lib/localization/app_localization.dart @@ -1,3 +1,5 @@ +import 'package:eatvio_app/app_router.dart'; + import 'ru/ru_translations.dart'; //import 'en_us/en_us_translations.dart'; import 'package:flutter/foundation.dart'; @@ -17,7 +19,7 @@ class AppLocalization { };*/ static AppLocalization of() { - final context = NavigatorService.navigatorKey.currentContext; + final context = AppRouter.navigatorKey.currentContext; if (context != null) { return Localizations.of(context, AppLocalization)!; } else { diff --git a/lib/presentation/auth/auth_screen/auth_screen.dart b/lib/presentation/auth/auth_screen/auth_screen.dart index 6b6c3a4..7235372 100644 --- a/lib/presentation/auth/auth_screen/auth_screen.dart +++ b/lib/presentation/auth/auth_screen/auth_screen.dart @@ -21,7 +21,9 @@ class AuthScreen extends StatelessWidget { AuthState( authModelObj: AuthModel(), ), - )..add(AuthInitialEvent()), + )..add( + AuthInitialEvent(), + ), child: AuthScreen(), ); } @@ -61,10 +63,11 @@ class AuthScreen extends StatelessWidget { }), SizedBox(height: 50.v), NextStepButton( - text: "no_account".tr.toUpperCase(), - margin: EdgeInsets.only(left: 16.h, right: 16.h, bottom: 50.v), - buttonStyle: CustomButtonStyles.outlinePrimaryTL15, - onPressed: onTapNoAccount(context)), + text: "no_account".tr.toUpperCase(), + margin: EdgeInsets.only(left: 16.h, right: 16.h, bottom: 50.v), + buttonStyle: CustomButtonStyles.outlinePrimaryTL15, + onPressed: onTapNoAccount(context), + ), /*NextStepButton( text: "Тест дневника".toUpperCase(), margin: @@ -143,13 +146,29 @@ class AuthScreen extends StatelessWidget { }; } - onTapOk(BuildContext context) => GoRouter.of(context).pop(context); + onTapOk(BuildContext context) { + return () { + GoRouter.of(context).pop(context); + }; + } - onTapDiaryTest(BuildContext context) => GoRouter.of(context).goNamed('diaryScreen'); + onTapDiaryTest(BuildContext context) { + return () { + GoRouter.of(context).goNamed('diaryScreen'); + }; + } - onTapProfileTest(BuildContext context) => GoRouter.of(context).goNamed('mySettingsScreen'); + onTapProfileTest(BuildContext context) { + return () { + GoRouter.of(context).goNamed('mySettingsScreen'); + }; + } - onTapNoAccount(BuildContext context) => GoRouter.of(context).goNamed('languageSelectScreen'); + onTapNoAccount(BuildContext context) { + return () { + GoRouter.of(context).goNamed('languageSelectScreen'); + }; + } /// Section Widget _buildAppBar(BuildContext context) { diff --git a/lib/presentation/auth/auth_screen/bloc/auth_bloc.dart b/lib/presentation/auth/auth_screen/bloc/auth_bloc.dart index cd0203a..6622981 100644 --- a/lib/presentation/auth/auth_screen/bloc/auth_bloc.dart +++ b/lib/presentation/auth/auth_screen/bloc/auth_bloc.dart @@ -2,7 +2,9 @@ import 'package:equatable/equatable.dart'; import 'package:flutter/material.dart'; import '/core/app_export.dart'; import 'package:eatvio_app/presentation/auth/auth_screen/models/auth_model.dart'; + part 'auth_event.dart'; + part 'auth_state.dart'; /// A bloc that manages the state of a Auth according to the event that is dispatched to it. @@ -15,8 +17,11 @@ class AuthBloc extends Bloc { AuthInitialEvent event, Emitter emit, ) async { - emit(state.copyWith( + emit( + state.copyWith( emailController: TextEditingController(), - passwordController: TextEditingController())); + passwordController: TextEditingController(), + ), + ); } } diff --git a/lib/presentation/chat/chat_screen/chat_screen.dart b/lib/presentation/chat/chat_screen/chat_screen.dart index 48169f5..b69a0ec 100644 --- a/lib/presentation/chat/chat_screen/chat_screen.dart +++ b/lib/presentation/chat/chat_screen/chat_screen.dart @@ -1,3 +1,6 @@ +import 'package:eatvio_app/app_router.dart'; +import 'package:go_router/go_router.dart'; + import 'bloc/chat_bloc.dart'; import 'models/chat_model.dart'; import 'package:eatvio_app/core/app_export.dart'; @@ -117,6 +120,6 @@ class ChatScreen extends StatelessWidget { /// Navigates to the previous screen. onTapArrowleftone(BuildContext context) { - NavigatorService.goBack(); + GoRouter.of(context).pop(); } } 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 ef058bd..68834d0 100644 --- a/lib/presentation/diets/diet_select_screen/diet_select_screen.dart +++ b/lib/presentation/diets/diet_select_screen/diet_select_screen.dart @@ -173,6 +173,6 @@ class DietSelectScreen extends StatelessWidget { } onTapArrowLeft(BuildContext context) { - NavigatorService.goBack(); + GoRouter.of(context).pop(); } } 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 f6af548..0c06f5d 100644 --- a/lib/presentation/diets/diet_show_screen/diet_show_screen.dart +++ b/lib/presentation/diets/diet_show_screen/diet_show_screen.dart @@ -129,6 +129,6 @@ class DietScreen extends StatelessWidget { /// Navigates to the previous screen. onTapArrowleftone(BuildContext context) { - NavigatorService.goBack(); + GoRouter.of(context).pop(); } } diff --git a/lib/presentation/feed/feed_screen/feed_screen.dart b/lib/presentation/feed/feed_screen/feed_screen.dart index cddb9cc..1af8a84 100644 --- a/lib/presentation/feed/feed_screen/feed_screen.dart +++ b/lib/presentation/feed/feed_screen/feed_screen.dart @@ -267,7 +267,7 @@ class FeedScreen extends StatelessWidget { } onTapArrowLeft(BuildContext context) { - NavigatorService.goBack(); + GoRouter.of(context).pop(); } _buildMenu(BuildContext context, FeedLoadedState state) { 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 519ff0d..810bd3a 100644 --- a/lib/presentation/plans/plan_select_screen/plan_select_screen.dart +++ b/lib/presentation/plans/plan_select_screen/plan_select_screen.dart @@ -174,6 +174,6 @@ class PlanSelectScreen extends StatelessWidget { } onTapArrowLeft(BuildContext context) { - NavigatorService.goBack(); + GoRouter.of(context).pop(); } } 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 287cf85..a19f6da 100644 --- a/lib/presentation/plans/plan_show_screen/plan_show_screen.dart +++ b/lib/presentation/plans/plan_show_screen/plan_show_screen.dart @@ -1,4 +1,6 @@ +import 'package:go_router/go_router.dart'; + import 'bloc/plan_show_bloc.dart'; import 'models/plan_show_model.dart'; import 'package:eatvio_app/core/app_export.dart'; @@ -127,6 +129,6 @@ class PlanScreen extends StatelessWidget { /// Navigates to the previous screen. onTapArrowleftone(BuildContext context) { - NavigatorService.goBack(); + GoRouter.of(context).pop(); } } diff --git a/lib/presentation/profile/my_profile_screen/my_settings_screen.dart b/lib/presentation/profile/my_profile_screen/my_settings_screen.dart index 5d3682a..ea56a75 100644 --- a/lib/presentation/profile/my_profile_screen/my_settings_screen.dart +++ b/lib/presentation/profile/my_profile_screen/my_settings_screen.dart @@ -179,6 +179,6 @@ class MySettingsScreen extends StatelessWidget { } onTapArrowLeft(BuildContext context) { - NavigatorService.goBack(); + GoRouter.of(context).pop(); } } diff --git a/lib/presentation/recipe/recipe_create_screen/recipe_create_screen.dart b/lib/presentation/recipe/recipe_create_screen/recipe_create_screen.dart index 76e8a63..3a81754 100644 --- a/lib/presentation/recipe/recipe_create_screen/recipe_create_screen.dart +++ b/lib/presentation/recipe/recipe_create_screen/recipe_create_screen.dart @@ -1,3 +1,5 @@ +import 'package:go_router/go_router.dart'; + import 'bloc/recipe_create_bloc.dart'; import 'models/recipe_create_model.dart'; import 'package:eatvio_app/core/app_export.dart'; @@ -384,6 +386,6 @@ class RecipeCreateScreen extends StatelessWidget { } onTapArrowLeft(BuildContext context) { - NavigatorService.goBack(); + GoRouter.of(context).pop(); } } diff --git a/lib/presentation/recipe/recipe_edit_screen/recipe_edit_screen.dart b/lib/presentation/recipe/recipe_edit_screen/recipe_edit_screen.dart index b204e6f..8e16144 100644 --- a/lib/presentation/recipe/recipe_edit_screen/recipe_edit_screen.dart +++ b/lib/presentation/recipe/recipe_edit_screen/recipe_edit_screen.dart @@ -1,3 +1,5 @@ +import 'package:go_router/go_router.dart'; + import 'bloc/recipe_edit_bloc.dart'; import 'models/recipe_edit_model.dart'; import 'package:flutter/material.dart'; @@ -427,6 +429,6 @@ class RecipeEditScreen extends StatelessWidget { } onTapArrowLeft(BuildContext context) { - NavigatorService.goBack(); + GoRouter.of(context).pop(); } } 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 8ac9416..2a3a108 100644 --- a/lib/presentation/recipe/recipe_select_screen/recipe_select_screen.dart +++ b/lib/presentation/recipe/recipe_select_screen/recipe_select_screen.dart @@ -172,6 +172,6 @@ class RecipeSelectScreen extends StatelessWidget { } onTapArrowLeft(BuildContext context) { - NavigatorService.goBack(); + GoRouter.of(context).pop(); } } 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 a51d7f9..f1835f8 100644 --- a/lib/presentation/recipe/recipe_show_screen/recipe_show_screen.dart +++ b/lib/presentation/recipe/recipe_show_screen/recipe_show_screen.dart @@ -103,7 +103,10 @@ class RecipeScreen extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - CustomImageView(imagePath: ImageConstant.imgArrowLeft, onTap: () => NavigatorService.goBack()), + CustomImageView( + imagePath: ImageConstant.imgArrowLeft, + onTap: () => GoRouter.of(context).pop(), + ), Padding( padding: EdgeInsets.only(top: 1.v), child: Row( @@ -405,7 +408,7 @@ class RecipeScreen extends StatelessWidget { /// Navigates to the previous screen. onTapArrowleftone(BuildContext context) { - NavigatorService.goBack(); + GoRouter.of(context).pop(); } Widget _buildStep(BuildContext context, RecipeLoadedState state, int i) { 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 47c01b3..0a695a5 100644 --- a/lib/presentation/registration/additional_information_screen/additional_information_screen.dart +++ b/lib/presentation/registration/additional_information_screen/additional_information_screen.dart @@ -18,15 +18,11 @@ import 'package:http/http.dart' as http; class AdditionalInformationScreen extends StatelessWidget { const AdditionalInformationScreen({Key? key}) : super(key: key); - static Widget builder(BuildContext context) { - final sheet = - ModalRoute.of(context)!.settings.arguments as UserRegistrationSheet; + static Widget builder(BuildContext context, sheet) { return BlocProvider( - create: (context) => AdditionalInformationBloc( - AdditionalInformationState( - additionalInformationModelObj: - AdditionalInformationModel(userRegistrationSheet: sheet))) - ..add(AdditionalInformationInitialEvent()), + create: (context) => + AdditionalInformationBloc(AdditionalInformationState(additionalInformationModelObj: AdditionalInformationModel(userRegistrationSheet: sheet))) + ..add(AdditionalInformationInitialEvent()), child: AdditionalInformationScreen()); } @@ -48,25 +44,19 @@ class AdditionalInformationScreen 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: 1, - backgroundColor: theme.colorScheme.onPrimary, - valueColor: AlwaysStoppedAnimation( - appTheme.blueA400)))), + value: 1, backgroundColor: theme.colorScheme.onPrimary, valueColor: AlwaysStoppedAnimation(appTheme.blueA400)))), SizedBox(height: 20.v), SizedBox(height: 73.v), _buildTextFormField(context), Spacer(), - BlocBuilder(builder: (context, state) { + BlocBuilder(builder: (context, state) { return NextStepButton( text: "finish".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: onTapFinish(state, context)); }), @@ -75,18 +65,11 @@ class AdditionalInformationScreen extends StatelessWidget { onTapFinish(AdditionalInformationState state, BuildContext context) { return () async { - UserRegistrationSheet sheet = - state.additionalInformationModelObj!.userRegistrationSheet; + UserRegistrationSheet sheet = state.additionalInformationModelObj!.userRegistrationSheet; sheet.additionalInfo = state.editTextController!.text; - final response = await http.post( - Uri.parse(dotenv.env['SERVER_ROOT']! + '/register'), - headers: { - 'Content-Type': 'application/json', - 'Accept': 'application/json' - }, - body: jsonEncode(sheet.toJson()), - encoding: utf8); + final response = await http.post(Uri.parse(dotenv.env['SERVER_ROOT']! + '/register'), + headers: {'Content-Type': 'application/json', 'Accept': 'application/json'}, body: jsonEncode(sheet.toJson()), encoding: utf8); var res = await jsonDecode(response.body); if (response.statusCode == 200) { @@ -104,10 +87,8 @@ class AdditionalInformationScreen extends StatelessWidget { _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)); } @@ -131,19 +112,14 @@ class AdditionalInformationScreen extends StatelessWidget { width: 294.h, margin: EdgeInsets.only(left: 24.h, right: 23.h), child: Text("enter_additional_information".tr, - maxLines: 2, - overflow: TextOverflow.ellipsis, - textAlign: TextAlign.center, - style: CustomTextStyles.titleMediumSegoeUI)), + maxLines: 2, overflow: TextOverflow.ellipsis, textAlign: TextAlign.center, style: CustomTextStyles.titleMediumSegoeUI)), SizedBox(height: 10.v), - BlocSelector( + BlocSelector( selector: (state) => state.editTextController, builder: (context, editTextController) { return CustomTextFormField( controller: editTextController, - hintText: - "У меня крепкое здоровье, но последнее время часто утомляюсь, однако, это мне не мешает радоваться жизни", + hintText: "У меня крепкое здоровье, но последнее время часто утомляюсь, однако, это мне не мешает радоваться жизни", textInputAction: TextInputAction.done, maxLines: 8); }) @@ -153,7 +129,7 @@ class AdditionalInformationScreen extends StatelessWidget { /// Navigates to the previous screen. onTapArrowLeft(BuildContext context) { - NavigatorService.goBack(); + GoRouter.of(context).pop(); } /// Displays an alert dialog when the action is triggered. @@ -164,9 +140,7 @@ class AdditionalInformationScreen extends StatelessWidget { builder: (_) => AlertDialog( title: const Text('Ошибка'), content: Text(text), - actions: [ - TextButton(onPressed: onTapOk(context), child: const Text('Ok')) - ], + actions: [TextButton(onPressed: onTapOk(context), child: const Text('Ok'))], )); } diff --git a/lib/presentation/registration/allergies_screen/allergies_screen.dart b/lib/presentation/registration/allergies_screen/allergies_screen.dart index 75528b6..50d056b 100644 --- a/lib/presentation/registration/allergies_screen/allergies_screen.dart +++ b/lib/presentation/registration/allergies_screen/allergies_screen.dart @@ -14,8 +14,7 @@ import 'package:flutter/material.dart'; 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; + static Widget builder(BuildContext context, sheet) { return BlocProvider( create: (context) => AllergiesBloc(AllergiesState(allergiesModelObj: AllergiesModel(userRegistrationSheet: sheet)))..add(AllergiesInitialEvent()), child: AllergiesScreen()); @@ -28,46 +27,44 @@ class AllergiesScreen extends StatefulWidget { class _AllergiesScreenState extends State { @override Widget build(BuildContext context) { - mediaQueryData = MediaQuery.of(context); - return SafeArea( - child: Scaffold( - resizeToAvoidBottomInset: false, - appBar: _buildAppBar(context), - body: Container( - width: double.maxFinite, - padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v), - child: Column(children: [ - SizedBox(height: 7.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.76, backgroundColor: theme.colorScheme.onPrimary, valueColor: AlwaysStoppedAnimation(appTheme.blueA400)))), - SizedBox(height: 22.v), - Text("allergies_presence".tr, style: theme.textTheme.headlineSmall), - Spacer(flex: 36), - _buildTextFormField(context), - Spacer(flex: 54), - 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), - ); - }), - ])))); + return Scaffold( + resizeToAvoidBottomInset: false, + appBar: _buildAppBar(context), + body: Container( + width: double.maxFinite, + padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v), + child: Column(children: [ + SizedBox(height: 7.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.76, backgroundColor: theme.colorScheme.onPrimary, valueColor: AlwaysStoppedAnimation(appTheme.blueA400)))), + SizedBox(height: 22.v), + Text("allergies_presence".tr, style: theme.textTheme.headlineSmall), + Spacer(flex: 36), + _buildTextFormField(context), + Spacer(flex: 54), + 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(AllergiesState state, BuildContext context) { @@ -117,6 +114,6 @@ class _AllergiesScreenState extends State { /// Navigates to the previous screen. onTapArrowLeft(BuildContext context) { - NavigatorService.goBack(); + GoRouter.of(context).pop(); } } 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 681d5ce..5d4d8cc 100644 --- a/lib/presentation/registration/blood_pressure_screen/blood_pressure_screen.dart +++ b/lib/presentation/registration/blood_pressure_screen/blood_pressure_screen.dart @@ -17,8 +17,7 @@ import 'package:flutter/material.dart'; 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; + static Widget builder(BuildContext context, sheet) { return BlocProvider( create: (context) => BloodPressureBloc(BloodPressureState(bloodPressureModelObj: BloodPressureModel(userRegistrationSheet: sheet)))..add(BloodPressureInitialEvent()), @@ -33,118 +32,116 @@ class _BloodPressureScreenState extends State { @override Widget build(BuildContext context) { final digitsOnly = FilteringTextInputFormatter.digitsOnly; - mediaQueryData = MediaQuery.of(context); - return SafeArea( - child: Scaffold( - resizeToAvoidBottomInset: false, - appBar: _buildAppBar(context), - body: Container( - width: double.maxFinite, - padding: EdgeInsets.symmetric(horizontal: 12.h, vertical: 9.v), - child: Column(children: [ - SizedBox(height: 7.v), - Container( - height: 16.v, - width: 343.h, - padding: EdgeInsets.symmetric(horizontal: 4.h), - // Apply padding directly to the Container - 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.62, - backgroundColor: theme.colorScheme.onPrimary, - valueColor: AlwaysStoppedAnimation(appTheme.blueA400), - ), - ), + return Scaffold( + resizeToAvoidBottomInset: false, + appBar: _buildAppBar(context), + body: Container( + width: double.maxFinite, + padding: EdgeInsets.symmetric(horizontal: 12.h, vertical: 9.v), + child: Column(children: [ + SizedBox(height: 7.v), + Container( + height: 16.v, + width: 343.h, + padding: EdgeInsets.symmetric(horizontal: 4.h), + // Apply padding directly to the Container + decoration: BoxDecoration( + color: theme.colorScheme.onPrimary, + borderRadius: BorderRadius.circular(8.h), + border: Border.all( + color: theme.colorScheme.primary, + width: 1.h, ), - SizedBox(height: 21.v), - SizedBox( - width: 224.h, - child: Text("your_blood_pressure".tr, - 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), - SizedBox(height: 2.v), - BlocSelector( - selector: (state) => state.upPressureController, - builder: (context, upPressureController) { - return CustomTextFormField(inputFormatters: [digitsOnly], controller: upPressureController, hintText: "90".tr); - }) - ])), - SizedBox(height: 21.v), - Container( - margin: EdgeInsets.only(right: 1.h), - padding: EdgeInsets.symmetric(horizontal: 3.h), - child: Column(children: [ - Text("down_pressure".tr, style: theme.textTheme.bodyLarge), - SizedBox(height: 2.v), - BlocSelector( - selector: (state) => state.downPressureController, - builder: (context, downPressureController) { - return CustomTextFormField(inputFormatters: [digitsOnly], controller: downPressureController, hintText: "90".tr); - }) - ])), - SizedBox(height: 22.v), - Text("do_you_have_hypotension_tendency".tr, style: theme.textTheme.bodyLarge), - SizedBox(height: 2.v), - Padding( - padding: EdgeInsets.symmetric(horizontal: 4.h), - 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)), - hintText: "Не выбрано".tr, - items: bloodPressureModelObj?.dropdownItemList ?? [], - onChanged: onChangeHyper(context)); - })), - SizedBox(height: 22.v), - Text("do_you_have_hypertension_tendency".tr, style: theme.textTheme.bodyLarge), - SizedBox(height: 2.v), - Padding( - padding: EdgeInsets.symmetric(horizontal: 4.h), - 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)), - hintText: "Не выбрано".tr, - items: bloodPressureModelObj?.dropdownItemList ?? [], - onChanged: onChangeHypo(context)); - })), - Spacer(), - 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: ClipRRect( + borderRadius: BorderRadius.circular(8.h), + child: LinearProgressIndicator( + value: 0.62, + backgroundColor: theme.colorScheme.onPrimary, + valueColor: AlwaysStoppedAnimation(appTheme.blueA400), + ), + ), + ), + SizedBox(height: 21.v), + SizedBox( + width: 224.h, + child: Text("your_blood_pressure".tr, + 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), + SizedBox(height: 2.v), + BlocSelector( + selector: (state) => state.upPressureController, + builder: (context, upPressureController) { + return CustomTextFormField(inputFormatters: [digitsOnly], controller: upPressureController, hintText: "90".tr); + }) + ])), + SizedBox(height: 21.v), + Container( + margin: EdgeInsets.only(right: 1.h), + padding: EdgeInsets.symmetric(horizontal: 3.h), + child: Column(children: [ + Text("down_pressure".tr, style: theme.textTheme.bodyLarge), + SizedBox(height: 2.v), + BlocSelector( + selector: (state) => state.downPressureController, + builder: (context, downPressureController) { + return CustomTextFormField(inputFormatters: [digitsOnly], controller: downPressureController, hintText: "90".tr); + }) + ])), + SizedBox(height: 22.v), + Text("do_you_have_hypotension_tendency".tr, style: theme.textTheme.bodyLarge), + SizedBox(height: 2.v), + Padding( + padding: EdgeInsets.symmetric(horizontal: 4.h), + 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)), + hintText: "Не выбрано".tr, + items: bloodPressureModelObj?.dropdownItemList ?? [], + onChanged: onChangeHyper(context)); + })), + SizedBox(height: 22.v), + Text("do_you_have_hypertension_tendency".tr, style: theme.textTheme.bodyLarge), + SizedBox(height: 2.v), + Padding( + padding: EdgeInsets.symmetric(horizontal: 4.h), + 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)), + hintText: "Не выбрано".tr, + items: bloodPressureModelObj?.dropdownItemList ?? [], + onChanged: onChangeHypo(context)); + })), + Spacer(), + 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(BloodPressureState state, BuildContext context) { @@ -222,7 +219,7 @@ class _BloodPressureScreenState extends State { /// Navigates to the previous screen. onTapArrowLeft(BuildContext context) { - NavigatorService.goBack(); + GoRouter.of(context).pop(); } List validateFields( 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 2df67fc..3610697 100644 --- a/lib/presentation/registration/body_circumferences_screen/body_circumferences_screen.dart +++ b/lib/presentation/registration/body_circumferences_screen/body_circumferences_screen.dart @@ -15,76 +15,75 @@ import 'package:flutter/material.dart'; 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; + static Widget builder(BuildContext context, sheet) { return BlocProvider( - create: (context) => BodyCircumferencesBloc(BodyCircumferencesState(bodyCircumferencesModelObj: BodyCircumferencesModel(userRegistrationSheet: sheet))) - ..add(BodyCircumferencesInitialEvent()), - child: BodyCircumferencesScreen()); + create: (context) => BodyCircumferencesBloc(BodyCircumferencesState(bodyCircumferencesModelObj: BodyCircumferencesModel(userRegistrationSheet: sheet))) + ..add(BodyCircumferencesInitialEvent()), + child: BodyCircumferencesScreen(), + ); } @override Widget build(BuildContext context) { final digitsOnly = FilteringTextInputFormatter.digitsOnly; mediaQueryData = MediaQuery.of(context); - return SafeArea( - child: Scaffold( - resizeToAvoidBottomInset: false, - appBar: _buildAppBar(context), - body: Container( - width: double.maxFinite, - padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v), - child: Column(children: [ - SizedBox(height: 7.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.40, backgroundColor: theme.colorScheme.onPrimary, valueColor: AlwaysStoppedAnimation(appTheme.blueA400)))), - SizedBox(height: 39.v), - Text("initial_measurements".tr, style: theme.textTheme.headlineSmall), - SizedBox(height: 93.v), - Column(children: [ - Text("chest_circumference".tr, style: theme.textTheme.bodyLarge), - SizedBox(height: 3.v), - BlocSelector( - selector: (state) => state.chestCircumferenceController, - builder: (context, chestCircumferenceController) { - return CustomTextFormField(inputFormatters: [digitsOnly], controller: chestCircumferenceController, hintText: "90".tr); - }) - ]), - SizedBox(height: 19.v), - Text("waist_circumference".tr, style: theme.textTheme.bodyLarge), - SizedBox(height: 5.v), - BlocSelector( - selector: (state) => state.waistCircumferenceController, - builder: (context, waistCircumferenceController) { - return CustomTextFormField(inputFormatters: [digitsOnly], controller: waistCircumferenceController, hintText: "60".tr); - }), - SizedBox(height: 21.v), - Text("hip_circumference".tr, style: theme.textTheme.bodyLarge), - SizedBox(height: 3.v), - BlocSelector( - selector: (state) => state.hipCircumferenceController, - builder: (context, hipCircumferenceController) { - return CustomTextFormField( - inputFormatters: [digitsOnly], controller: hipCircumferenceController, hintText: "90".tr, textInputAction: TextInputAction.done); - }), - Spacer(), - 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)); + return Scaffold( + resizeToAvoidBottomInset: false, + appBar: _buildAppBar(context), + body: Container( + width: double.maxFinite, + padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v), + child: Column(children: [ + SizedBox(height: 7.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.40, backgroundColor: theme.colorScheme.onPrimary, valueColor: AlwaysStoppedAnimation(appTheme.blueA400)))), + SizedBox(height: 39.v), + Text("initial_measurements".tr, style: theme.textTheme.headlineSmall), + SizedBox(height: 93.v), + Column(children: [ + Text("chest_circumference".tr, style: theme.textTheme.bodyLarge), + SizedBox(height: 3.v), + BlocSelector( + selector: (state) => state.chestCircumferenceController, + builder: (context, chestCircumferenceController) { + return CustomTextFormField(inputFormatters: [digitsOnly], controller: chestCircumferenceController, hintText: "90".tr); + }) + ]), + SizedBox(height: 19.v), + Text("waist_circumference".tr, style: theme.textTheme.bodyLarge), + SizedBox(height: 5.v), + BlocSelector( + selector: (state) => state.waistCircumferenceController, + builder: (context, waistCircumferenceController) { + return CustomTextFormField(inputFormatters: [digitsOnly], controller: waistCircumferenceController, hintText: "60".tr); }), - ])))); + SizedBox(height: 21.v), + Text("hip_circumference".tr, style: theme.textTheme.bodyLarge), + SizedBox(height: 3.v), + BlocSelector( + selector: (state) => state.hipCircumferenceController, + builder: (context, hipCircumferenceController) { + return CustomTextFormField( + inputFormatters: [digitsOnly], controller: hipCircumferenceController, hintText: "90".tr, textInputAction: TextInputAction.done); + }), + Spacer(), + 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)); + }), + ]))); } onTapContinue(BodyCircumferencesState state, BuildContext context) { @@ -145,7 +144,7 @@ class BodyCircumferencesScreen extends StatelessWidget { /// Navigates to the previous screen. onTapArrowLeft(BuildContext context) { - NavigatorService.goBack(); + GoRouter.of(context).pop(); } /// Navigates to the weightScreen when the action is triggered. 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 3e78a1f..5ce9150 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 @@ -15,12 +15,12 @@ import 'package:flutter/material.dart'; 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; + static Widget builder(BuildContext context, sheet) { return BlocProvider( - create: (context) => - CityOfLivingBloc(CityOfLivingState(cityOfLivingModelObj: CityOfLivingModel(userRegistrationSheet: sheet)))..add(CityOfLivingInitialEvent()), - child: CityOfLivingScreen()); + create: (context) => + CityOfLivingBloc(CityOfLivingState(cityOfLivingModelObj: CityOfLivingModel(userRegistrationSheet: sheet)))..add(CityOfLivingInitialEvent()), + child: CityOfLivingScreen(), + ); } @override @@ -1144,102 +1144,100 @@ class CityOfLivingScreen extends StatelessWidget { "Ясный", "Яхрома" ]; - mediaQueryData = MediaQuery.of(context); - return SafeArea( - child: Scaffold( - appBar: _buildAppBar(context), - body: Container( - width: double.maxFinite, - padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v), - child: Column(children: [ - SizedBox(height: 7.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.32, backgroundColor: theme.colorScheme.onPrimary, valueColor: AlwaysStoppedAnimation(appTheme.blueA400)))), - SizedBox(height: 39.v), - Text("place_of_living".tr, style: theme.textTheme.headlineSmall), - Spacer(flex: 34), - Text("country".tr, style: theme.textTheme.bodyLarge), - SizedBox(height: 2.v), - 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)), - hintText: "Не выбрано".tr, - items: cityOfLivingModelObj?.dropdownItemList ?? [], - onChanged: onDropDownChange(context)); - }), - SizedBox(height: 22.v), - Text("Населенный пункт", style: theme.textTheme.bodyLarge), - SizedBox(height: 2.v), - BlocBuilder(builder: (context, state) { - return RawAutocomplete( - optionsBuilder: (TextEditingValue textEditingValue) => _options.where((String option) { - return option.toLowerCase().startsWith(textEditingValue.text.toLowerCase()); - }), - fieldViewBuilder: ( - BuildContext context, - TextEditingController textEditingController, - FocusNode focusNode, - VoidCallback onFieldSubmitted, - ) { - return CustomTextFormField( - controller: textEditingController, - focusNode: focusNode, - onFieldSubmitted: (String value) => onFieldSubmitted(), - ); - }, - optionsViewBuilder: ( - BuildContext context, - AutocompleteOnSelected onSelected, - Iterable options, - ) { - return Align( - alignment: Alignment.topLeft, - child: Material( - elevation: 4.0, - child: SizedBox( - height: 200.0, - child: ListView.builder( - padding: const EdgeInsets.all(8.0), - itemCount: options.length, - itemBuilder: (BuildContext context, int index) { - final String option = options.elementAt(index); - return GestureDetector( - onTap: () => onSelected(option), - child: ListTile( - title: Text(option), - ), - ); - }, - ), - ), - ), - ); - }, + return Scaffold( + appBar: _buildAppBar(context), + body: Container( + width: double.maxFinite, + padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v), + child: Column(children: [ + SizedBox(height: 7.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.32, backgroundColor: theme.colorScheme.onPrimary, valueColor: AlwaysStoppedAnimation(appTheme.blueA400)))), + SizedBox(height: 39.v), + Text("place_of_living".tr, style: theme.textTheme.headlineSmall), + Spacer(flex: 34), + Text("country".tr, style: theme.textTheme.bodyLarge), + SizedBox(height: 2.v), + 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)), + hintText: "Не выбрано".tr, + items: cityOfLivingModelObj?.dropdownItemList ?? [], + onChanged: onDropDownChange(context)); + }), + SizedBox(height: 22.v), + Text("Населенный пункт", style: theme.textTheme.bodyLarge), + SizedBox(height: 2.v), + BlocBuilder(builder: (context, state) { + return RawAutocomplete( + optionsBuilder: (TextEditingValue textEditingValue) => _options.where((String option) { + return option.toLowerCase().startsWith(textEditingValue.text.toLowerCase()); + }), + fieldViewBuilder: ( + BuildContext context, + TextEditingController textEditingController, + FocusNode focusNode, + VoidCallback onFieldSubmitted, + ) { + return CustomTextFormField( + controller: textEditingController, + focusNode: focusNode, + onFieldSubmitted: (String value) => onFieldSubmitted(), ); - }), - Spacer(flex: 65), - 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)); - }), - ])))); + }, + optionsViewBuilder: ( + BuildContext context, + AutocompleteOnSelected onSelected, + Iterable options, + ) { + return Align( + alignment: Alignment.topLeft, + child: Material( + elevation: 4.0, + child: SizedBox( + height: 200.0, + child: ListView.builder( + padding: const EdgeInsets.all(8.0), + itemCount: options.length, + itemBuilder: (BuildContext context, int index) { + final String option = options.elementAt(index); + return GestureDetector( + onTap: () => onSelected(option), + child: ListTile( + title: Text(option), + ), + ); + }, + ), + ), + ), + ); + }, + ); + }), + Spacer(flex: 65), + 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)); + }), + ]))); } onTapContinue(CityOfLivingState state, BuildContext context) { @@ -1273,7 +1271,7 @@ class CityOfLivingScreen extends StatelessWidget { /// Navigates to the previous screen. onTapArrowLeft(BuildContext context) { - NavigatorService.goBack(); + GoRouter.of(context).pop(); } } diff --git a/lib/presentation/registration/credentials_screen/credentials_screen.dart b/lib/presentation/registration/credentials_screen/credentials_screen.dart index ba51783..90723f6 100644 --- a/lib/presentation/registration/credentials_screen/credentials_screen.dart +++ b/lib/presentation/registration/credentials_screen/credentials_screen.dart @@ -12,9 +12,7 @@ import 'package:eatvio_app/widgets/custom_text_form_field.dart'; import 'package:flutter/material.dart'; class CredentialsScreen extends StatelessWidget { - static Widget builder(BuildContext context) { - final sheet = - ModalRoute.of(context)!.settings.arguments as UserRegistrationSheet; + static Widget builder(BuildContext context, sheet) { return BlocProvider( create: (context) => CredentialsBloc( CredentialsState( @@ -42,45 +40,33 @@ class CredentialsScreen 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.05, - backgroundColor: theme.colorScheme.onPrimary, - valueColor: AlwaysStoppedAnimation( - appTheme.blueA400)))), + value: 0.05, backgroundColor: theme.colorScheme.onPrimary, valueColor: AlwaysStoppedAnimation(appTheme.blueA400)))), SizedBox(height: 39.v), - Text("user_registration".tr, - style: theme.textTheme.headlineSmall), + Text("user_registration".tr, style: theme.textTheme.headlineSmall), SizedBox(height: 16.v), Text("email".tr, style: theme.textTheme.bodyLarge), SizedBox(height: 3.v), - BlocSelector( + BlocSelector( selector: (state) => state.emailController, builder: (context, emailController) { - return CustomTextFormField( - controller: emailController, - textInputAction: TextInputAction.done); + return CustomTextFormField(controller: emailController, textInputAction: TextInputAction.done); }), SizedBox(height: 22.v), Text("username".tr, style: theme.textTheme.bodyLarge), SizedBox(height: 3.v), - BlocSelector( + BlocSelector( selector: (state) => state.nameController, builder: (context, nameController) { - return CustomTextFormField( - controller: nameController, - textInputAction: TextInputAction.done); + return CustomTextFormField(controller: nameController, textInputAction: TextInputAction.done); }), SizedBox(height: 19.v), Text("password".tr, style: theme.textTheme.bodyLarge), SizedBox(height: 5.v), - BlocSelector( + BlocSelector( selector: (state) => state.passwordController, builder: (context, passwordController) { return CustomTextFormField( @@ -89,25 +75,18 @@ class CredentialsScreen extends StatelessWidget { ); }), SizedBox(height: 21.v), - Text("password_confirmation".tr, - style: theme.textTheme.bodyLarge), + Text("password_confirmation".tr, style: theme.textTheme.bodyLarge), SizedBox(height: 3.v), - BlocSelector( + BlocSelector( selector: (state) => state.passwordConfirmationController, builder: (context, passwordConfirmationController) { - return CustomTextFormField( - obscureText: true, - controller: passwordConfirmationController, - textInputAction: TextInputAction.done); + return CustomTextFormField(obscureText: true, controller: passwordConfirmationController, 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)); }), @@ -116,19 +95,15 @@ class CredentialsScreen extends StatelessWidget { onTapContinue(CredentialsState state, BuildContext context) { return () { - List errors = validateFields( - state.emailController!.text, - state.nameController!.text, - state.passwordController!.text, - state.passwordConfirmationController!.text); + List errors = + validateFields(state.emailController!.text, state.nameController!.text, state.passwordController!.text, state.passwordConfirmationController!.text); if (errors.isEmpty) { - UserRegistrationSheet sheet = - state.credentialsModelObj!.userRegistrationSheet; + UserRegistrationSheet sheet = state.credentialsModelObj!.userRegistrationSheet; sheet.email = state.emailController!.text; sheet.name = state.nameController!.text; sheet.password = state.passwordController!.text; sheet.passwordConfirmation = state.passwordConfirmationController!.text; - GoRouter.of(context).goNamed('nameScreen'); + GoRouter.of(context).goNamed('nameScreen', extra: sheet); } else { String errorMessage = ''; @@ -161,14 +136,10 @@ class CredentialsScreen extends StatelessWidget { /// Section Widget _buildAppBar(BuildContext context) { - return CustomAppBar( - leadingWidth: 29.h, - centerTitle: true, - title: AppbarTitleImage(imagePath: ImageConstant.imgLogoEatvio)); + return CustomAppBar(leadingWidth: 29.h, centerTitle: true, title: AppbarTitleImage(imagePath: ImageConstant.imgLogoEatvio)); } - List validateFields( - String email, String name, String password, String passwordConfirmation) { + List validateFields(String email, String name, String password, String passwordConfirmation) { List errors = []; if (!isEmail(email)) { 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 7f86075..5f68a3d 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 @@ -13,12 +13,17 @@ import 'package:flutter/material.dart'; 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; + static Widget builder(BuildContext context, sheet) { return BlocProvider( - create: (context) => - DateOfBirthBloc(DateOfBirthState(dateOfBirthModelObj: DateOfBirthModel(userRegistrationSheet: sheet)))..add(DateOfBirthInitialEvent()), - child: DateOfBirthScreen()); + create: (context) => DateOfBirthBloc( + DateOfBirthState( + dateOfBirthModelObj: DateOfBirthModel( + userRegistrationSheet: sheet, + ), + ), + )..add(DateOfBirthInitialEvent()), + child: DateOfBirthScreen(), + ); } @override @@ -32,37 +37,36 @@ class _DateOfBirthScreenState extends State { Widget build(BuildContext context) { mediaQueryData = MediaQuery.of(context); 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), - child: Column(children: [ - 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.24, backgroundColor: theme.colorScheme.onPrimary, valueColor: AlwaysStoppedAnimation(appTheme.blueA400)))), - SizedBox(height: 38.v), - Text("date_of_birth".tr, style: theme.textTheme.headlineSmall), - Spacer(flex: 39), - _buildDateInput(context), - Spacer(flex: 60), - 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)); - }), - ])))); + return Scaffold( + appBar: _buildAppBar(context), + body: Container( + width: double.maxFinite, + padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v), + child: Column(children: [ + 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.24, backgroundColor: theme.colorScheme.onPrimary, valueColor: AlwaysStoppedAnimation(appTheme.blueA400)))), + SizedBox(height: 38.v), + Text("date_of_birth".tr, style: theme.textTheme.headlineSmall), + Spacer(flex: 39), + _buildDateInput(context), + Spacer(flex: 60), + 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)); + }), + ]))); }); } @@ -116,7 +120,7 @@ class _DateOfBirthScreenState extends State { /// Navigates to the previous screen. onTapArrowLeft(BuildContext context) { - NavigatorService.goBack(); + GoRouter.of(context).pop(); } /// Displays a date picker dialog to update the selected date 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 a0c35dd..94771a1 100644 --- a/lib/presentation/registration/favorite_foods_screen/favorite_foods_screen.dart +++ b/lib/presentation/registration/favorite_foods_screen/favorite_foods_screen.dart @@ -14,8 +14,7 @@ import 'package:flutter/material.dart'; 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; + static Widget builder(BuildContext context, sheet) { return BlocProvider( create: (context) => FavoriteFoodsBloc(FavoriteFoodsState(favoriteFoodsModelObj: FavoriteFoodsModel(userRegistrationSheet: sheet)))..add(FavoriteFoodsInitialEvent()), @@ -29,52 +28,50 @@ class FavoriteFoodsScreen extends StatefulWidget { class _FavoriteFoodsScreenState extends State { @override Widget build(BuildContext context) { - mediaQueryData = MediaQuery.of(context); - return SafeArea( - child: Scaffold( - resizeToAvoidBottomInset: false, - appBar: _buildAppBar(context), - body: Container( - width: double.maxFinite, - padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v), - child: Column(children: [ - SizedBox(height: 7.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.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)), - SizedBox(height: 13.v), - _buildTextFormFieldFav(context), - SizedBox(height: 12.v), - _buildTextFormFieldUnfav(context), - Spacer(), - BlocBuilder(builder: (context, state) { - return NextStepButton( - text: "continue".tr.toUpperCase(), - margin: EdgeInsets.only(left: 16.h, right: 16.h, bottom: 40.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), - ); - }), - ])))); + return Scaffold( + resizeToAvoidBottomInset: false, + appBar: _buildAppBar(context), + body: Container( + width: double.maxFinite, + padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v), + child: Column(children: [ + SizedBox(height: 7.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.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)), + SizedBox(height: 13.v), + _buildTextFormFieldFav(context), + SizedBox(height: 12.v), + _buildTextFormFieldUnfav(context), + Spacer(), + BlocBuilder(builder: (context, state) { + return NextStepButton( + text: "continue".tr.toUpperCase(), + margin: EdgeInsets.only(left: 16.h, right: 16.h, bottom: 40.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(FavoriteFoodsState state, BuildContext context) { @@ -138,7 +135,7 @@ class _FavoriteFoodsScreenState extends State { /// Navigates to the previous screen. onTapArrowLeft(BuildContext context) { - NavigatorService.goBack(); + GoRouter.of(context).pop(); } /// Navigates to the scheduleScreen when the action is triggered. 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 a9217ec..66f98d2 100644 --- a/lib/presentation/registration/favorite_sports_screen/favorite_sports_screen.dart +++ b/lib/presentation/registration/favorite_sports_screen/favorite_sports_screen.dart @@ -14,8 +14,7 @@ import 'package:flutter/material.dart'; 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; + static Widget builder(BuildContext context, sheet) { return BlocProvider( create: (context) => FavoriteSportsBloc(FavoriteSportsState(favoriteSportsModelObj: FavoriteSportsModel(userRegistrationSheet: sheet))) ..add(FavoriteSportsInitialEvent()), @@ -29,46 +28,44 @@ class FavoriteSportsScreen extends StatefulWidget { class _FavoriteSportsScreenState extends State { @override Widget build(BuildContext context) { - mediaQueryData = MediaQuery.of(context); - return SafeArea( - child: Scaffold( - resizeToAvoidBottomInset: false, - appBar: _buildAppBar(context), - 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), - ); - }), - ])))); + return Scaffold( + resizeToAvoidBottomInset: false, + appBar: _buildAppBar(context), + 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), + ); + }), + ]))); } onTapSkip(FavoriteSportsState state, BuildContext context) { @@ -120,6 +117,6 @@ class _FavoriteSportsScreenState extends State { } onTapArrowLeft(BuildContext context) { - NavigatorService.goBack(); + GoRouter.of(context).pop(); } } diff --git a/lib/presentation/registration/gender_screen/gender_screen.dart b/lib/presentation/registration/gender_screen/gender_screen.dart index 4e90621..68909d7 100644 --- a/lib/presentation/registration/gender_screen/gender_screen.dart +++ b/lib/presentation/registration/gender_screen/gender_screen.dart @@ -13,8 +13,7 @@ import 'package:flutter/material.dart'; 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; + static Widget builder(BuildContext context, sheet) { return BlocProvider( create: (context) => GenderBloc( GenderState( @@ -33,58 +32,57 @@ class _GenderScreenState extends State { Widget build(BuildContext context) { mediaQueryData = MediaQuery.of(context); 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), - child: Column(children: [ - SizedBox(height: 7.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.16, backgroundColor: theme.colorScheme.onPrimary, valueColor: AlwaysStoppedAnimation(appTheme.blueA400)))), - SizedBox(height: 36.v), - Text("your_gender".tr, style: theme.textTheme.headlineSmall), - RadioListTile( - title: Text('Мужской'), - value: 'male', - groupValue: state.selectedRadioValue, - onChanged: onMale(context), - secondary: Image.asset( - 'assets/images/img_male.png', - width: 40, - height: 40, - ), - ), - RadioListTile( - title: Text('Женский'), - value: 'female', - groupValue: state.selectedRadioValue, - onChanged: onFemale(context), - secondary: Image.asset( - 'assets/images/img_female.png', - width: 40, - height: 40, - ), - ), - Spacer(flex: 66), - 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: onTapNext(state, context)); - }), - ])))); + return Scaffold( + appBar: _buildAppBar(context), + body: Container( + width: double.maxFinite, + padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v), + child: Column(children: [ + SizedBox(height: 7.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.16, backgroundColor: theme.colorScheme.onPrimary, valueColor: AlwaysStoppedAnimation(appTheme.blueA400)))), + SizedBox(height: 36.v), + Text("your_gender".tr, style: theme.textTheme.headlineSmall), + RadioListTile( + title: Text('Мужской'), + value: 'male', + groupValue: state.selectedRadioValue, + onChanged: onMale(context), + secondary: Image.asset( + 'assets/images/img_male.png', + width: 40, + height: 40, + ), + ), + RadioListTile( + title: Text('Женский'), + value: 'female', + groupValue: state.selectedRadioValue, + onChanged: onFemale(context), + secondary: Image.asset( + 'assets/images/img_female.png', + width: 40, + height: 40, + ), + ), + Spacer(flex: 66), + 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: onTapNext(state, context)); + }), + ]))); }); } @@ -111,20 +109,23 @@ class _GenderScreenState extends State { /// Section Widget _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()), - centerTitle: true, - title: AppbarTitleImage(imagePath: ImageConstant.imgLogoEatvio)); + leadingWidth: 29.h, + 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 () { - GoRouter.of(context).goNamed('dateOfBirthScreen'); + GoRouter.of(context).pop(); }; } /// Navigates to the previous screen. onTapArrowLeft(BuildContext context) { - NavigatorService.goBack(); + GoRouter.of(context).pop(); } } diff --git a/lib/presentation/registration/height_screen/height_screen.dart b/lib/presentation/registration/height_screen/height_screen.dart index 243fe89..071285f 100644 --- a/lib/presentation/registration/height_screen/height_screen.dart +++ b/lib/presentation/registration/height_screen/height_screen.dart @@ -15,8 +15,7 @@ import 'package:flutter/material.dart'; 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; + static Widget builder(BuildContext context, sheet) { return BlocProvider( create: (context) => HeightBloc(HeightState(heightModelObj: HeightModel(userRegistrationSheet: sheet)))..add(HeightInitialEvent()), child: HeightScreen()); @@ -25,84 +24,82 @@ class HeightScreen extends StatelessWidget { @override Widget build(BuildContext context) { mediaQueryData = MediaQuery.of(context); - return SafeArea( - child: Scaffold( - appBar: _buildAppBar(context), - body: Container( - width: double.maxFinite, - padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v), - child: Column( - children: [ - SizedBox(height: 7.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, - ), + return Scaffold( + appBar: _buildAppBar(context), + body: Container( + width: double.maxFinite, + padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v), + child: Column( + children: [ + SizedBox(height: 7.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.55, - backgroundColor: theme.colorScheme.onPrimary, - valueColor: AlwaysStoppedAnimation( - appTheme.blueA400, - ), + ), + child: ClipRRect( + borderRadius: BorderRadius.circular(8.h), + child: LinearProgressIndicator( + value: 0.55, + backgroundColor: theme.colorScheme.onPrimary, + valueColor: AlwaysStoppedAnimation( + appTheme.blueA400, ), ), ), - SizedBox(height: 39.v), - Column( - children: [ - Text( - "height_measurements".tr, - style: theme.textTheme.headlineSmall, - ), - SizedBox(height: 174.v), - Column( - children: [ - Text( - "your_height".tr, - style: theme.textTheme.bodyLarge, - ), - SizedBox(height: 4.v), - BlocBuilder(builder: (context, state) { - return CustomTextFormField( - width: 150.h, - textInputAction: TextInputAction.done, - controller: state.heightController, - keyboardType: TextInputType.number, - inputFormatters: [ - FilteringTextInputFormatter.digitsOnly, - ], - ); - }) - ], - ), - ], - ), - Spacer(), - BlocBuilder( - builder: (context, state) { - return NextStepButton( - text: "continue".tr.toUpperCase(), - margin: EdgeInsets.only( - left: 16.h, - right: 16.h, - bottom: 50.v, + ), + SizedBox(height: 39.v), + Column( + children: [ + Text( + "height_measurements".tr, + style: theme.textTheme.headlineSmall, + ), + SizedBox(height: 174.v), + Column( + children: [ + Text( + "your_height".tr, + style: theme.textTheme.bodyLarge, ), - buttonStyle: CustomButtonStyles.outlinePrimaryTL15, - onPressed: onTapNext(state, context), - ); - }, - ), - ], - ), + SizedBox(height: 4.v), + BlocBuilder(builder: (context, state) { + return CustomTextFormField( + width: 150.h, + textInputAction: TextInputAction.done, + controller: state.heightController, + keyboardType: TextInputType.number, + inputFormatters: [ + FilteringTextInputFormatter.digitsOnly, + ], + ); + }) + ], + ), + ], + ), + Spacer(), + 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: onTapNext(state, context), + ); + }, + ), + ], ), ), ); @@ -133,6 +130,6 @@ class HeightScreen extends StatelessWidget { /// Navigates to the previous screen. onTapArrowLeft(BuildContext context) { - NavigatorService.goBack(); + GoRouter.of(context).pop(); } } 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 a3cc105..bfd4085 100644 --- a/lib/presentation/registration/medicine_intake_screen/medicine_intake_screen.dart +++ b/lib/presentation/registration/medicine_intake_screen/medicine_intake_screen.dart @@ -128,6 +128,6 @@ class _MedicineIntakeScreenState extends State { /// Navigates to the previous screen. onTapArrowLeft(BuildContext context) { - NavigatorService.goBack(); + GoRouter.of(context).pop(); } } diff --git a/lib/presentation/registration/name_screen/name_screen.dart b/lib/presentation/registration/name_screen/name_screen.dart index 6501c00..e1f0327 100644 --- a/lib/presentation/registration/name_screen/name_screen.dart +++ b/lib/presentation/registration/name_screen/name_screen.dart @@ -14,10 +14,8 @@ import 'package:flutter/material.dart'; class NameScreen extends StatelessWidget { const NameScreen({Key? key}) : super(key: key); - static Widget builder(BuildContext context) { - final sheet = - ModalRoute.of(context)!.settings.arguments as UserRegistrationSheet; + static Widget builder(BuildContext context, sheet) { return BlocProvider( create: (context) => NameBloc( NameState( @@ -30,65 +28,55 @@ class NameScreen extends StatelessWidget { @override Widget build(BuildContext context) { mediaQueryData = MediaQuery.of(context); - return SafeArea( - child: Scaffold( - resizeToAvoidBottomInset: false, - appBar: _buildAppBar(context), - body: Container( - width: double.maxFinite, - padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v), - child: Column(children: [ - SizedBox(height: 7.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.1, - backgroundColor: theme.colorScheme.onPrimary, - valueColor: AlwaysStoppedAnimation( - appTheme.blueA400)))), - SizedBox(height: 39.v), - Text("what_is_your_name".tr, - style: theme.textTheme.headlineSmall), - SizedBox(height: 93.v), - Text("first_name".tr, style: theme.textTheme.bodyLarge), - SizedBox(height: 3.v), - BlocSelector( - selector: (state) => state.firstNameController, - builder: (context, firstNameController) { - return CustomTextFormField( - controller: firstNameController, - textInputAction: TextInputAction.done); - }), - SizedBox(height: 19.v), - Text("last_name".tr, style: theme.textTheme.bodyLarge), - SizedBox(height: 5.v), - BlocSelector( - selector: (state) => state.lastNameController, - builder: (context, lastNameController) { - return CustomTextFormField( - controller: lastNameController, - ); - }), - Spacer(), - 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: () => _onTapNext( - context, state), // Assign callback function here + return Scaffold( + resizeToAvoidBottomInset: false, + appBar: _buildAppBar(context), + body: Container( + width: double.maxFinite, + padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v), + child: Column(children: [ + SizedBox(height: 7.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.1, backgroundColor: theme.colorScheme.onPrimary, valueColor: AlwaysStoppedAnimation(appTheme.blueA400)))), + SizedBox(height: 39.v), + Text("what_is_your_name".tr, style: theme.textTheme.headlineSmall), + SizedBox(height: 93.v), + Text("first_name".tr, style: theme.textTheme.bodyLarge), + SizedBox(height: 3.v), + BlocSelector( + selector: (state) => state.firstNameController, + builder: (context, firstNameController) { + return CustomTextFormField(controller: firstNameController, textInputAction: TextInputAction.done); + }), + SizedBox(height: 19.v), + Text("last_name".tr, style: theme.textTheme.bodyLarge), + SizedBox(height: 5.v), + BlocSelector( + selector: (state) => state.lastNameController, + builder: (context, lastNameController) { + return CustomTextFormField( + controller: lastNameController, ); }), - ])))); + Spacer(), + 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: () => _onTapNext(context, state), // Assign callback function here + ); + }), + ]))); } /// Section Widget @@ -96,22 +84,19 @@ class NameScreen extends StatelessWidget { return CustomAppBar( leadingWidth: 29.h, leading: AppbarLeadingImage( - imagePath: ImageConstant.imgArrowLeft, - margin: EdgeInsets.only(left: 16.h, top: 15.v, bottom: 15.v), - onTap: () => onTapArrowLeft(context)), + imagePath: ImageConstant.imgArrowLeft, margin: EdgeInsets.only(left: 16.h, top: 15.v, bottom: 15.v), onTap: () => onTapArrowLeft(context)), centerTitle: true, title: AppbarTitleImage(imagePath: ImageConstant.imgLogoEatvio)); } /// Navigates to the previous screen. onTapArrowLeft(BuildContext context) { - NavigatorService.goBack(); + GoRouter.of(context).pop(); } _onTapNext(BuildContext context, NameState state) { if (state.firstNameController != null && state.lastNameController != null) { - List errors = validateFields( - state.firstNameController!.text, state.lastNameController!.text); + List errors = validateFields(state.firstNameController!.text, state.lastNameController!.text); if (errors.isEmpty) { UserRegistrationSheet sheet = state.nameModelObj!.userRegistrationSheet; diff --git a/lib/presentation/registration/weight_screen/weight_screen.dart b/lib/presentation/registration/weight_screen/weight_screen.dart index 28b0913..7bf28f1 100644 --- a/lib/presentation/registration/weight_screen/weight_screen.dart +++ b/lib/presentation/registration/weight_screen/weight_screen.dart @@ -15,8 +15,7 @@ import 'package:flutter/material.dart'; 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; + static Widget builder(BuildContext context, sheet) { return BlocProvider( create: (context) => WeightBloc(WeightState(weightModelObj: WeightModel(userRegistrationSheet: sheet)))..add(WeightInitialEvent()), child: WeightScreen()); @@ -24,85 +23,82 @@ class WeightScreen extends StatelessWidget { @override Widget build(BuildContext context) { - mediaQueryData = MediaQuery.of(context); - return SafeArea( - child: Scaffold( - appBar: _buildAppBar(context), - body: Container( - width: double.maxFinite, - padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v), - child: Column( - children: [ - SizedBox(height: 7.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, - ), + return Scaffold( + appBar: _buildAppBar(context), + body: Container( + width: double.maxFinite, + padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v), + child: Column( + children: [ + SizedBox(height: 7.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.55, - backgroundColor: theme.colorScheme.onPrimary, - valueColor: AlwaysStoppedAnimation( - appTheme.blueA400, - ), + ), + child: ClipRRect( + borderRadius: BorderRadius.circular(8.h), + child: LinearProgressIndicator( + value: 0.55, + backgroundColor: theme.colorScheme.onPrimary, + valueColor: AlwaysStoppedAnimation( + appTheme.blueA400, ), ), ), - SizedBox(height: 39.v), - Column( - children: [ - Text( - "weight_measurements".tr, - style: theme.textTheme.headlineSmall, - ), - SizedBox(height: 174.v), - Column( - children: [ - Text( - "your_weight".tr, - style: theme.textTheme.bodyLarge, - ), - SizedBox(height: 4.v), - BlocBuilder(builder: (context, state) { - return CustomTextFormField( - width: 150.h, - textInputAction: TextInputAction.done, - controller: state.weightController, - keyboardType: TextInputType.number, - inputFormatters: [ - FilteringTextInputFormatter.digitsOnly, - ], - ); - }) - ], - ), - ], - ), - Spacer(), - BlocBuilder( - builder: (context, state) { - return NextStepButton( - text: "continue".tr.toUpperCase(), - margin: EdgeInsets.only( - left: 16.h, - right: 16.h, - bottom: 50.v, + ), + SizedBox(height: 39.v), + Column( + children: [ + Text( + "weight_measurements".tr, + style: theme.textTheme.headlineSmall, + ), + SizedBox(height: 174.v), + Column( + children: [ + Text( + "your_weight".tr, + style: theme.textTheme.bodyLarge, ), - buttonStyle: CustomButtonStyles.outlinePrimaryTL15, - onPressed: onTapNext(state, context), - ); - }, - ), - ], - ), + SizedBox(height: 4.v), + BlocBuilder(builder: (context, state) { + return CustomTextFormField( + width: 150.h, + textInputAction: TextInputAction.done, + controller: state.weightController, + keyboardType: TextInputType.number, + inputFormatters: [ + FilteringTextInputFormatter.digitsOnly, + ], + ); + }) + ], + ), + ], + ), + Spacer(), + 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: onTapNext(state, context), + ); + }, + ), + ], ), ), ); @@ -133,6 +129,6 @@ class WeightScreen extends StatelessWidget { /// Navigates to the previous screen. onTapArrowLeft(BuildContext context) { - NavigatorService.goBack(); + GoRouter.of(context).pop(); } } From 1d47e282023556c595a67f3e62df7e75a4a875b1 Mon Sep 17 00:00:00 2001 From: mso7nueh Date: Tue, 11 Jun 2024 11:57:45 +0300 Subject: [PATCH 17/17] refactor(go_router): add pages to go router, fix screens --- lib/app_router.dart | 31 ++++ lib/core/utils/progress_dialog_utils.dart | 1 - lib/localization/app_localization.dart | 1 - .../chat/chat_screen/bloc/chat_bloc.dart | 13 +- .../chat/chat_screen/chat_screen.dart | 34 +--- .../chat_select_screen.dart | 124 +++++++------- .../blog_post_edit_screen.dart | 151 +++++++++--------- .../additional_information_screen.dart | 64 ++++---- .../medicine_intake_screen.dart | 88 +++++----- 9 files changed, 257 insertions(+), 250 deletions(-) diff --git a/lib/app_router.dart b/lib/app_router.dart index aeed36c..c6de2d5 100644 --- a/lib/app_router.dart +++ b/lib/app_router.dart @@ -1,8 +1,11 @@ import 'package:eatvio_app/presentation/auth/auth_screen/auth_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/diary/diary_edit_screen/diary_edit_screen.dart'; +import 'package:eatvio_app/presentation/diets/diet_create_screen/diet_create_screen.dart'; import 'package:eatvio_app/presentation/diets/diet_select_screen/diet_select_screen.dart'; import 'package:eatvio_app/presentation/feed/blog_post_create_screen/blog_post_create_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_screen/blog_post_screen.dart'; import 'package:eatvio_app/presentation/feed/feed_screen/feed_screen.dart'; import 'package:eatvio_app/presentation/glossary/glossary_screen/glossary_screen.dart'; @@ -22,6 +25,7 @@ import 'package:eatvio_app/presentation/registration/favorite_sports_screen/favo import 'package:eatvio_app/presentation/registration/gender_screen/gender_screen.dart'; import 'package:eatvio_app/presentation/registration/height_screen/height_screen.dart'; import 'package:eatvio_app/presentation/registration/language_select_screen/language_select_screen.dart'; +import 'package:eatvio_app/presentation/registration/medicine_intake_screen/medicine_intake_screen.dart'; import 'package:eatvio_app/presentation/registration/name_screen/name_screen.dart'; import 'package:eatvio_app/presentation/registration/weight_screen/weight_screen.dart'; import 'package:eatvio_app/widgets/bottom_navigation_bar_widget.dart'; @@ -109,6 +113,11 @@ class AppRouter { path: 'allergiesScreen', builder: (context, state) => AllergiesScreen.builder(context, state.extra), routes: [ + GoRoute( + name: 'medicineIntakeScreen', + path: 'medicine-intake-screen', + builder: (context, state) => MedicineIntakeScreen.builder(context, state.extra), + ), GoRoute( name: 'favoriteFoodsScreen', path: 'favorite-foods-screen', @@ -174,6 +183,16 @@ class AppRouter { context, state.extra.toString(), ), + routes: [ + GoRoute( + path: 'blog-post-edit-screen', + name: 'blogPostEditScreen', + builder: (context, state) => BlogPostEditScreen.builder( + context, + state.extra, + ), + ), + ], ), ], ), @@ -186,6 +205,13 @@ class AppRouter { path: '/chat-select-screen', name: 'chatSelectScreen', builder: (context, state) => ChatSelectScreen(), + routes: [ + GoRoute( + path: 'chat-screen', + name: 'chatScreen', + builder: (context, state) => ChatScreen.builder(context, state.extra), + ), + ], ), ], ), @@ -204,6 +230,11 @@ class AppRouter { name: 'dietSelectScreen', builder: (context, state) => DietSelectScreen.builder(context), ), + GoRoute( + path: '/diet-create-screen', + name: 'dietCreateScreen', + builder: (context, state) => DietCreateScreen.builder(context), + ), GoRoute( path: '/plan-select-screen', name: 'planSelectScreen', diff --git a/lib/core/utils/progress_dialog_utils.dart b/lib/core/utils/progress_dialog_utils.dart index 7ac6ed7..ce4da75 100644 --- a/lib/core/utils/progress_dialog_utils.dart +++ b/lib/core/utils/progress_dialog_utils.dart @@ -1,6 +1,5 @@ import 'package:eatvio_app/app_router.dart'; import 'package:flutter/material.dart'; -import 'package:eatvio_app/core/app_export.dart'; class ProgressDialogUtils { static bool isProgressVisible = false; diff --git a/lib/localization/app_localization.dart b/lib/localization/app_localization.dart index 98ee1eb..2fc106d 100644 --- a/lib/localization/app_localization.dart +++ b/lib/localization/app_localization.dart @@ -4,7 +4,6 @@ import 'ru/ru_translations.dart'; //import 'en_us/en_us_translations.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/cupertino.dart'; -import '../core/app_export.dart'; class AppLocalization { AppLocalization(this.locale); diff --git a/lib/presentation/chat/chat_screen/bloc/chat_bloc.dart b/lib/presentation/chat/chat_screen/bloc/chat_bloc.dart index 8c33f02..caaa4c1 100644 --- a/lib/presentation/chat/chat_screen/bloc/chat_bloc.dart +++ b/lib/presentation/chat/chat_screen/bloc/chat_bloc.dart @@ -9,7 +9,9 @@ import 'dart:convert'; import '/core/app_export.dart'; import 'package:eatvio_app/presentation/chat/chat_screen/models/chat_model.dart'; import 'package:eatvio_app/presentation/chat/chat_screen/models/chat_message_model.dart'; + part 'chat_event.dart'; + part 'chat_state.dart'; /// A bloc that manages the state of a Chat according to the event that is dispatched to it. @@ -37,17 +39,12 @@ class ChatBloc extends Bloc { ); if (response.statusCode == 200) { final data = jsonDecode(response.body); - if (data is Map && - data.containsKey('chatRoom') && - data['chatRoom'].containsKey('messages')) { + if (data is Map && data.containsKey('chatRoom') && data['chatRoom'].containsKey('messages')) { if (state is ChatLoadedState) { var currentState = state as ChatLoadedState; - emit(currentState.copyWith( - chatModelObj: currentState.chatModelObj, - messages: currentState.messages)); + emit(currentState.copyWith(chatModelObj: currentState.chatModelObj, messages: currentState.messages)); } else { - emit(ChatLoadedState( - messages: fillMessages(data['chatRoom']['messages']))); + emit(ChatLoadedState(messages: fillMessages(data['chatRoom']['messages']))); } } else { // Один или несколько ключевых полей отсутствуют, обрабатываем ошибку diff --git a/lib/presentation/chat/chat_screen/chat_screen.dart b/lib/presentation/chat/chat_screen/chat_screen.dart index b69a0ec..8e34fc4 100644 --- a/lib/presentation/chat/chat_screen/chat_screen.dart +++ b/lib/presentation/chat/chat_screen/chat_screen.dart @@ -1,4 +1,3 @@ -import 'package:eatvio_app/app_router.dart'; import 'package:go_router/go_router.dart'; import 'bloc/chat_bloc.dart'; @@ -8,12 +7,11 @@ import 'package:flutter/material.dart'; import 'package:eatvio_app/widgets/app_bar/custom_app_bar.dart'; import 'package:eatvio_app/widgets/app_bar/appbar_subtitle.dart'; import 'package:eatvio_app/widgets/app_bar/appbar_leading_image.dart'; -import 'package:eatvio_app/widgets/app_bar/appbar_title_image.dart'; class ChatScreen extends StatelessWidget { const ChatScreen({Key? key}) : super(key: key); - static Widget builder(BuildContext context) { - final chatID = ModalRoute.of(context)!.settings.arguments; + + static Widget builder(BuildContext context, chatID) { return BlocProvider( create: (context) => ChatBloc( ChatState(chatModelObj: ChatModel(chatID: chatID.toString()))) @@ -25,9 +23,8 @@ class ChatScreen extends StatelessWidget { return BlocBuilder( builder: (context, state) { if (state is ChatInitialState) { - // Это начальное состояние, данные ещё не загружены. - return Container( - color: Colors.white, + return Scaffold( + body: Center(child: CircularProgressIndicator(),), ); } else if (state is ChatLoadedState) { // Данные загружены, можно строить экран. @@ -36,8 +33,9 @@ class ChatScreen extends StatelessWidget { // Произошла ошибка при загрузке данных. return Center(child: Text(state.errorMessage)); } else { - // Другие состояния, если они есть. - return Container(); // Пустой контейнер для необработанных состояний. + return Scaffold( + body: Center(child: CircularProgressIndicator(),), + ); } }, ); @@ -80,16 +78,13 @@ class ChatScreen extends StatelessWidget { padding: EdgeInsets.only(left: 12.h), child: Row( children: [ - AppbarTitleImage( - imagePath: ImageConstant.imgIconMoreHorizontal, - margin: EdgeInsets.only(bottom: 3.v), - ), Padding( padding: EdgeInsets.only( left: 12.h, top: 2.v, ), child: Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ AppbarSubtitle( text: "Валерий Леонтьев", @@ -105,19 +100,6 @@ class ChatScreen extends StatelessWidget { ); } - ///Handling page based on route - Widget getCurrentPage( - BuildContext context, - String currentRoute, - ) { - switch (currentRoute) { - case '/chat': - return ChatScreen.builder(context); - default: - return ChatScreen(); - } - } - /// Navigates to the previous screen. onTapArrowleftone(BuildContext context) { GoRouter.of(context).pop(); diff --git a/lib/presentation/chat/chat_select_screen/chat_select_screen.dart b/lib/presentation/chat/chat_select_screen/chat_select_screen.dart index e59e215..ba6c886 100644 --- a/lib/presentation/chat/chat_select_screen/chat_select_screen.dart +++ b/lib/presentation/chat/chat_select_screen/chat_select_screen.dart @@ -11,75 +11,77 @@ class ChatSelectScreen extends StatelessWidget { static Widget builder(BuildContext context) { return BlocProvider( - create: (context) => ChatSelectBloc(ChatSelectState(chatSelectModelObj: ChatSelectModel()))..add(ChatSelectInitialEvent()), child: ChatSelectScreen()); + create: (context) => ChatSelectBloc(ChatSelectState(chatSelectModelObj: ChatSelectModel())) + ..add( + ChatSelectInitialEvent(), + ), + child: ChatSelectScreen(), + ); } Widget build(BuildContext context) { return BlocBuilder( - builder: (context, state) { - if (state is ChatSelectInitialState) { - // Это начальное состояние, данные ещё не загружены. - return Container( - color: Colors.white, - ); - } else if (state is ChatSelectLoadedState) { - // Данные загружены, можно строить экран. - return _buildScreen(context, state); - } else if (state is ChatSelectErrorState) { - // Произошла ошибка при загрузке данных. - return Center(child: Text(state.errorMessage)); - } else { - // Другие состояния, если они есть. - return Container(); // Пустой контейнер для необработанных состояний. - } - }, + builder: (context, state) { + if (state is ChatSelectInitialState) { + // Это начальное состояние, данные ещё не загружены. + return Container( + color: Colors.white, + ); + } else if (state is ChatSelectLoadedState) { + // Данные загружены, можно строить экран. + return _buildScreen(context, state); + } else if (state is ChatSelectErrorState) { + // Произошла ошибка при загрузке данных. + return Center(child: Text(state.errorMessage)); + } else { + // Другие состояния, если они есть. + return Container(); // Пустой контейнер для необработанных состояний. + } + }, ); } _buildScreen(BuildContext context, ChatSelectLoadedState state) { - mediaQueryData = MediaQuery.of(context); - return SafeArea( - child: Scaffold( - resizeToAvoidBottomInset: false, - body: Container( - width: double.maxFinite, - decoration: AppDecoration.fillGray, - child: ListView( - children: [ - SizedBox(height: 30.v), - Container( - margin: EdgeInsets.only( - left: 16.h, - right: 20.h, - bottom: 10.h, - ), - padding: EdgeInsets.all(12.h), - 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: Column( - mainAxisSize: MainAxisSize.min, - children: [ - CustomSearchView( - controller: state.searchController, - hintText: "Поиск", - ), - SizedBox(height: 20.v), - _buildChatList(context, state), - ], - ), - ) - ], - ), + return Scaffold( + resizeToAvoidBottomInset: false, + body: Container( + width: double.maxFinite, + decoration: AppDecoration.fillGray, + child: ListView( + children: [ + SizedBox(height: 30.v), + Container( + margin: EdgeInsets.only( + left: 16.h, + right: 20.h, + bottom: 10.h, + ), + padding: EdgeInsets.all(12.h), + 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: Column( + mainAxisSize: MainAxisSize.min, + children: [ + CustomSearchView( + controller: state.searchController, + hintText: "Поиск", + ), + SizedBox(height: 20.v), + _buildChatList(context, state), + ], + ), + ) + ], ), ), ); diff --git a/lib/presentation/feed/blog_post_edit_screen/blog_post_edit_screen.dart b/lib/presentation/feed/blog_post_edit_screen/blog_post_edit_screen.dart index cd3ad78..5c38ffb 100644 --- a/lib/presentation/feed/blog_post_edit_screen/blog_post_edit_screen.dart +++ b/lib/presentation/feed/blog_post_edit_screen/blog_post_edit_screen.dart @@ -8,8 +8,7 @@ import 'package:flutter_dotenv/flutter_dotenv.dart'; class BlogPostEditScreen extends StatelessWidget { const BlogPostEditScreen({Key? key}) : super(key: key); - static Widget builder(BuildContext context) { - final blog_postID = ModalRoute.of(context)!.settings.arguments; + static Widget builder(BuildContext context, blog_postID) { return BlocProvider( create: (context) => BlogPostEditBloc(BlogPostEditState(blog_postModelObj: BlogPostEditModel(blog_postID: blog_postID.toString())))..add(BlogPostEditInitialEvent()), @@ -20,9 +19,10 @@ class BlogPostEditScreen extends StatelessWidget { return BlocBuilder( builder: (context, state) { if (state is BlogPostEditInitialState) { - // Это начальное состояние, данные ещё не загружены. - return Container( - color: Colors.white, + return Scaffold( + body: Center( + child: CircularProgressIndicator(), + ), ); } else if (state is BlogPostEditLoadedState) { // Данные загружены, можно строить экран. @@ -31,8 +31,11 @@ class BlogPostEditScreen extends StatelessWidget { // Произошла ошибка при загрузке данных. return Center(child: Text(state.errorMessage)); } else { - // Другие состояния, если они есть. - return Container(); // Пустой контейнер для необработанных состояний. + return Scaffold( + body: Center( + child: CircularProgressIndicator(), + ), + ); } }, ); @@ -40,76 +43,74 @@ class BlogPostEditScreen extends StatelessWidget { _buildBlogPostEdit(BuildContext context, BlogPostEditLoadedState state) { mediaQueryData = MediaQuery.of(context); - return SafeArea( - child: Scaffold( - resizeToAvoidBottomInset: false, - body: Container( - width: double.maxFinite, - decoration: AppDecoration.fillGray, - child: ListView( - children: [ - SizedBox(height: 30.v), - Container( - margin: EdgeInsets.only( - left: 16.h, - right: 20.h, - bottom: 10.h, - ), - padding: EdgeInsets.all(12.h), - 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), + return Scaffold( + resizeToAvoidBottomInset: false, + body: Container( + width: double.maxFinite, + decoration: AppDecoration.fillGray, + child: ListView( + children: [ + SizedBox(height: 30.v), + Container( + margin: EdgeInsets.only( + left: 16.h, + right: 20.h, + bottom: 10.h, + ), + padding: EdgeInsets.all(12.h), + 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: Column( + mainAxisSize: MainAxisSize.min, + children: [ + CachedNetworkImage( + imageUrl: dotenv.env['STORAGE_URL']! + (state.blog_post?['image'] ?? ''), + imageBuilder: (context, imageProvider) => CircleAvatar( + backgroundImage: imageProvider, + radius: 25, ), - ], - ), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - CachedNetworkImage( - imageUrl: dotenv.env['STORAGE_URL']! + (state.blog_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, - ), + placeholder: (context, url) => CircularProgressIndicator(), + errorWidget: (context, url, error) => CircleAvatar( + child: Icon(Icons.person), + backgroundColor: Colors.white, + radius: 25, ), - SizedBox(height: 16.0), - TextFormField( - controller: state.title, - decoration: InputDecoration(labelText: 'Заголовок'), - ), - SizedBox(height: 16.0), - TextFormField( - controller: state.description, - decoration: InputDecoration(labelText: 'Описание'), - ), - SizedBox(height: 16.0), - TextFormField( - controller: state.youtube_url, - decoration: InputDecoration(labelText: 'Ссылка'), - ), - SizedBox(height: 16.0), - // Здесь нужно добавить виджет для загрузки картинки - ElevatedButton( - onPressed: () => context.read().add(EditBlogPost()), - child: Text('Сохранить'), - ) - ], - ), - ) - ], - ), + ), + SizedBox(height: 16.0), + TextFormField( + controller: state.title, + decoration: InputDecoration(labelText: 'Заголовок'), + ), + SizedBox(height: 16.0), + TextFormField( + controller: state.description, + decoration: InputDecoration(labelText: 'Описание'), + ), + SizedBox(height: 16.0), + TextFormField( + controller: state.youtube_url, + decoration: InputDecoration(labelText: 'Ссылка'), + ), + SizedBox(height: 16.0), + // Здесь нужно добавить виджет для загрузки картинки + ElevatedButton( + onPressed: () => context.read().add(EditBlogPost()), + child: Text('Сохранить'), + ) + ], + ), + ) + ], ), ), ); 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 0a695a5..c855fb4 100644 --- a/lib/presentation/registration/additional_information_screen/additional_information_screen.dart +++ b/lib/presentation/registration/additional_information_screen/additional_information_screen.dart @@ -28,39 +28,37 @@ class AdditionalInformationScreen extends StatelessWidget { @override Widget build(BuildContext context) { - mediaQueryData = MediaQuery.of(context); - return SafeArea( - child: Scaffold( - resizeToAvoidBottomInset: false, - appBar: _buildAppBar(context), - body: Container( - width: double.maxFinite, - padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v), - child: Column(children: [ - SizedBox(height: 7.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: 1, backgroundColor: theme.colorScheme.onPrimary, valueColor: AlwaysStoppedAnimation(appTheme.blueA400)))), - SizedBox(height: 20.v), - SizedBox(height: 73.v), - _buildTextFormField(context), - Spacer(), - BlocBuilder(builder: (context, state) { - return NextStepButton( - text: "finish".tr.toUpperCase(), - margin: EdgeInsets.only(left: 16.h, right: 16.h, bottom: 50.v), - buttonStyle: CustomButtonStyles.outlinePrimaryTL15, - onPressed: onTapFinish(state, context)); - }), - ])))); + return Scaffold( + resizeToAvoidBottomInset: false, + appBar: _buildAppBar(context), + body: Container( + width: double.maxFinite, + padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v), + child: Column(children: [ + SizedBox(height: 7.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: 1, backgroundColor: theme.colorScheme.onPrimary, valueColor: AlwaysStoppedAnimation(appTheme.blueA400)))), + SizedBox(height: 20.v), + SizedBox(height: 73.v), + _buildTextFormField(context), + Spacer(), + BlocBuilder(builder: (context, state) { + return NextStepButton( + text: "finish".tr.toUpperCase(), + margin: EdgeInsets.only(left: 16.h, right: 16.h, bottom: 50.v), + buttonStyle: CustomButtonStyles.outlinePrimaryTL15, + onPressed: onTapFinish(state, context)); + }), + ]))); } onTapFinish(AdditionalInformationState state, BuildContext context) { 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 bfd4085..9f01f6f 100644 --- a/lib/presentation/registration/medicine_intake_screen/medicine_intake_screen.dart +++ b/lib/presentation/registration/medicine_intake_screen/medicine_intake_screen.dart @@ -14,8 +14,7 @@ import 'package:flutter/material.dart'; 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; + static Widget builder(BuildContext context, sheet) { return BlocProvider( create: (context) => MedicineIntakeBloc(MedicineIntakeState(medicineIntakeModelObj: MedicineIntakeModel(userRegistrationSheet: sheet))) ..add(MedicineIntakeInitialEvent()), @@ -30,49 +29,48 @@ class _MedicineIntakeScreenState extends State { @override Widget build(BuildContext context) { mediaQueryData = MediaQuery.of(context); - return SafeArea( - child: Scaffold( - resizeToAvoidBottomInset: false, - appBar: _buildAppBar(context), - body: Container( - width: double.maxFinite, - padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v), - child: Column(children: [ - SizedBox(height: 7.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.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)), - SizedBox(height: 86.v), - _buildTextFormField(context), - Spacer(), - 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: onTapNext(state, context)); - }), - BlocBuilder(builder: (context, state) { - return GestureDetector( - onTap: onTapSkip(state, context), - child: Text("skip".tr, style: theme.textTheme.bodyLarge), - ); - }), - ])))); + return Scaffold( + resizeToAvoidBottomInset: false, + appBar: _buildAppBar(context), + body: Container( + width: double.maxFinite, + padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v), + child: Column(children: [ + SizedBox(height: 7.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.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)), + SizedBox(height: 86.v), + _buildTextFormField(context), + Spacer(), + 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: onTapNext(state, context)); + }), + BlocBuilder(builder: (context, state) { + return GestureDetector( + onTap: onTapSkip(state, context), + child: Text("skip".tr, style: theme.textTheme.bodyLarge), + ); + }), + ]))); } onTapSkip(MedicineIntakeState state, BuildContext context) {