From 52c62988e6f091980baac86428e23bc38dfa6f17 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Thu, 14 Mar 2024 15:46:08 +0300 Subject: [PATCH 1/4] refactor(registration) Fixing issues in registration after refactoring Run Code Metrics --- .../registration/name_screen/name_screen.dart | 16 +++++++++------- .../weight_screen/weight_screen.dart | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/presentation/registration/name_screen/name_screen.dart b/lib/presentation/registration/name_screen/name_screen.dart index 83dafefe..f8335561 100644 --- a/lib/presentation/registration/name_screen/name_screen.dart +++ b/lib/presentation/registration/name_screen/name_screen.dart @@ -11,10 +11,10 @@ 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; + return BlocProvider( create: (context) => NameBloc( NameState( @@ -77,11 +77,13 @@ class NameScreen extends StatelessWidget { SizedBox(height: 21.v), 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)); + 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 + ); }), ])))); } @@ -93,7 +95,7 @@ class NameScreen extends StatelessWidget { leading: AppbarLeadingImage( imagePath: ImageConstant.imgArrowLeft, margin: EdgeInsets.only(left: 16.h, top: 15.v, bottom: 15.v), - onTap: onTapArrowLeft(context)), + onTap: () => onTapArrowLeft(context)), centerTitle: true, title: AppbarTitleImage(imagePath: ImageConstant.imgLogoEatvio)); } diff --git a/lib/presentation/registration/weight_screen/weight_screen.dart b/lib/presentation/registration/weight_screen/weight_screen.dart index 3a14fd0a..a874e728 100644 --- a/lib/presentation/registration/weight_screen/weight_screen.dart +++ b/lib/presentation/registration/weight_screen/weight_screen.dart @@ -100,7 +100,7 @@ class _WeightScreenState extends State { leading: AppbarLeadingImage( imagePath: ImageConstant.imgArrowLeft, margin: EdgeInsets.only(left: 16.h, top: 15.v, bottom: 15.v), - onTap: onTapArrowLeft(context)), + onTap: () => onTapArrowLeft(context)), centerTitle: true, title: AppbarTitleImage(imagePath: ImageConstant.imgLogoEatvio)); } From 77dadba8fc7bf844b30a1953b2d30553b32a3a18 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Thu, 14 Mar 2024 15:54:19 +0300 Subject: [PATCH 2/4] Fixed broken layouts after refactoring. Fixed a bug (onTapNext() is called on screen build --- lib/presentation/registration/name_screen/name_screen.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/presentation/registration/name_screen/name_screen.dart b/lib/presentation/registration/name_screen/name_screen.dart index f8335561..23612d72 100644 --- a/lib/presentation/registration/name_screen/name_screen.dart +++ b/lib/presentation/registration/name_screen/name_screen.dart @@ -34,7 +34,7 @@ class NameScreen extends StatelessWidget { body: Container( width: double.maxFinite, padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v), - child: ListView(children: [ + child: Column(children: [ SizedBox(height: 7.v), Container( height: 16.v, @@ -74,7 +74,7 @@ class NameScreen extends StatelessWidget { controller: lastNameController, ); }), - SizedBox(height: 21.v), + Spacer(), BlocBuilder(builder: (context, state) { return NextStepButton( text: "continue".tr.toUpperCase(), From e4637d54e8948329089a268ef337cbfed3b5f103 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Thu, 14 Mar 2024 15:59:28 +0300 Subject: [PATCH 3/4] fix(registration) Broken layouts fixed for weight screen --- lib/presentation/registration/weight_screen/weight_screen.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/presentation/registration/weight_screen/weight_screen.dart b/lib/presentation/registration/weight_screen/weight_screen.dart index a874e728..f26fe3de 100644 --- a/lib/presentation/registration/weight_screen/weight_screen.dart +++ b/lib/presentation/registration/weight_screen/weight_screen.dart @@ -36,7 +36,7 @@ class _WeightScreenState extends State { body: Container( width: double.maxFinite, padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v), - child: ListView(children: [ + child: Column(children: [ SizedBox(height: 7.v), Container( height: 16.v, @@ -81,6 +81,7 @@ class _WeightScreenState extends State { }) ]) ]), + Spacer(), BlocBuilder( builder: (context, state) { return NextStepButton( From 4a5fa3dd5c6deae04068905d98b58abd134ed52f Mon Sep 17 00:00:00 2001 From: maxxkim Date: Thu, 14 Mar 2024 16:24:33 +0300 Subject: [PATCH 4/4] fix(registration) Finished fixing registration after code refactoring --- .env | 4 ++-- .../auth/auth_screen/auth_screen.dart | 2 +- .../additional_information_screen.dart | 23 +++++++++++-------- .../favorite_foods_screen.dart | 4 ++-- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/.env b/.env index 98d26074..e223a359 100644 --- a/.env +++ b/.env @@ -1,2 +1,2 @@ -SERVER_ROOT='https://ohngeeri3ien-dev3.eatvio.ru/api' -STORAGE_URL='https://ohngeeri3ien-dev3.eatvio.ru/storage/' \ No newline at end of file +SERVER_ROOT='https://mobile-stage.eatvio.ru/api' +STORAGE_URL='https://mobile-stage.eatvio.ru/storage/' \ No newline at end of file diff --git a/lib/presentation/auth/auth_screen/auth_screen.dart b/lib/presentation/auth/auth_screen/auth_screen.dart index 483e0ff5..93d38b46 100644 --- a/lib/presentation/auth/auth_screen/auth_screen.dart +++ b/lib/presentation/auth/auth_screen/auth_screen.dart @@ -77,7 +77,7 @@ class AuthScreen extends StatelessWidget { margin: EdgeInsets.only(left: 16.h, right: 16.h, bottom: 50.v), buttonStyle: CustomButtonStyles.outlinePrimaryTL15, - onPressed: onTapAuth(state, context)); + onPressed: () => onTapAuth(state, context)); }), ]))); } 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 345af298..08ad6dd6 100644 --- a/lib/presentation/registration/additional_information_screen/additional_information_screen.dart +++ b/lib/presentation/registration/additional_information_screen/additional_information_screen.dart @@ -76,19 +76,24 @@ class AdditionalInformationScreen extends StatelessWidget { UserRegistrationSheet sheet = state.additionalInformationModelObj!.userRegistrationSheet; sheet.additionalInfo = state.editTextController!.text; + //print(json.encode(sheet.toJson())); final response = await http.post( Uri.parse(dotenv.env['SERVER_ROOT']! + '/register'), headers: {'Content-Type': 'application/json'}, - body: json.encode(sheet), - ); - var res = await jsonDecode(response.body); - final box = await Hive.openBox('token'); - final token = res['token']; - box.put('token', token); - Navigator.pushNamed( - context, - AppRoutes.myProfile, + body: jsonEncode(sheet.toJson()), ); + print(response.statusCode); + print(response.body); + if (response.statusCode == 200) { + var res = await jsonDecode(response.body); + final box = await Hive.openBox('token'); + final token = res['token']; + box.put('token', token); + Navigator.pushNamed( + context, + AppRoutes.myProfile, + ); + } }; } 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 8a576af0..dac3ebd0 100644 --- a/lib/presentation/registration/favorite_foods_screen/favorite_foods_screen.dart +++ b/lib/presentation/registration/favorite_foods_screen/favorite_foods_screen.dart @@ -38,7 +38,7 @@ class _FavoriteFoodsScreenState extends State { body: Container( width: double.maxFinite, padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v), - child: ListView(children: [ + child: Column(children: [ SizedBox(height: 7.v), Container( height: 16.v, @@ -68,7 +68,7 @@ class _FavoriteFoodsScreenState extends State { _buildTextFormFieldFav(context), SizedBox(height: 12.v), _buildTextFormFieldUnfav(context), - SizedBox(height: 17.v), + Spacer(), BlocBuilder( builder: (context, state) { return NextStepButton(