refactor(diary): Even more refactoring

This commit is contained in:
2024-03-05 17:35:48 +03:00
parent 3cf61ce5ca
commit 3019a5a264
3 changed files with 75 additions and 57 deletions

View File

@@ -66,29 +66,32 @@ class AdditionalInformationScreen extends StatelessWidget {
margin: EdgeInsets.only(
left: 16.h, right: 16.h, bottom: 50.v),
buttonStyle: CustomButtonStyles.outlinePrimaryTL15,
onPressed: () async {
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'},
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,
);
});
onPressed: onTapFinish(state, context));
}),
]))));
}
onTapFinish(AdditionalInformationState state, BuildContext context) {
return () async {
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'},
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,
);
};
}
/// Section Widget
_buildAppBar(BuildContext context) {
return CustomAppBar(
@@ -96,15 +99,19 @@ class AdditionalInformationScreen extends StatelessWidget {
leading: AppbarLeadingImage(
imagePath: ImageConstant.imgArrowLeft,
margin: EdgeInsets.only(left: 18.h, top: 15.v, bottom: 15.v),
onTap: () {
onTapArrowLeft(context);
}),
onTap: onTapBack(context)),
centerTitle: true,
title: AppbarTitleImage(imagePath: ImageConstant.imgLogoEatvio));
}
onTapBack(BuildContext context) {
return () {
onTapArrowLeft(context);
};
}
/// Section Widget
Widget _buildTextFormField(BuildContext context) {
_buildTextFormField(BuildContext context) {
return SizedBox(
height: 257.v,
width: 343.h,
@@ -147,12 +154,14 @@ class AdditionalInformationScreen extends StatelessWidget {
title: const Text('Регистрация завершена!'),
content: const Text('1'),
actions: [
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: const Text('Ok'))
TextButton(onPressed: onTapOk(context), child: const Text('Ok'))
],
));
}
onTapOk(BuildContext context) {
return () {
Navigator.pop(context);
};
}
}

View File

@@ -67,36 +67,43 @@ class _AllergiesScreenState extends State<AllergiesScreen> {
margin: EdgeInsets.only(
left: 16.h, right: 16.h, bottom: 50.v),
buttonStyle: CustomButtonStyles.outlinePrimaryTL15,
onPressed: () {
UserRegistrationSheet sheet =
state.allergiesModelObj!.userRegistrationSheet;
sheet.aboutAllergy =
state.enterInformationController!.text;
Navigator.pushNamed(
context,
AppRoutes.medicineIntakeScreen,
arguments: sheet,
);
});
onPressed: onTapContinue(state, context));
}),
BlocBuilder<AllergiesBloc, AllergiesState>(
builder: (context, state) {
return GestureDetector(
onTap: () {
UserRegistrationSheet sheet =
state.allergiesModelObj!.userRegistrationSheet;
Navigator.pushNamed(
context,
AppRoutes.medicineIntakeScreen,
arguments: sheet,
);
},
onTap: onTapSkip(state, context),
child: Text("skip".tr, style: theme.textTheme.bodyLarge),
);
}),
]))));
}
onTapSkip(AllergiesState state, BuildContext context) {
return () {
UserRegistrationSheet sheet =
state.allergiesModelObj!.userRegistrationSheet;
Navigator.pushNamed(
context,
AppRoutes.medicineIntakeScreen,
arguments: sheet,
);
};
}
onTapContinue(AllergiesState state, BuildContext context) {
return () {
UserRegistrationSheet sheet =
state.allergiesModelObj!.userRegistrationSheet;
sheet.aboutAllergy = state.enterInformationController!.text;
Navigator.pushNamed(
context,
AppRoutes.medicineIntakeScreen,
arguments: sheet,
);
};
}
/// Section Widget
_buildAppBar(BuildContext context) {
return CustomAppBar(
@@ -104,15 +111,19 @@ class _AllergiesScreenState extends State<AllergiesScreen> {
leading: AppbarLeadingImage(
imagePath: ImageConstant.imgArrowLeft,
margin: EdgeInsets.only(left: 18.h, top: 15.v, bottom: 15.v),
onTap: () {
onTapArrowLeft(context);
}),
onTap: onTapBack(context)),
centerTitle: true,
title: AppbarTitleImage(imagePath: ImageConstant.imgLogoEatvio));
}
onTapBack(BuildContext context) {
return () {
onTapArrowLeft(context);
};
}
/// Section Widget
Widget _buildTextFormField(BuildContext context) {
_buildTextFormField(BuildContext context) {
return Column(children: [
Text("fill_in_information".tr,
style: CustomTextStyles.titleMediumSegoeUI),

View File

@@ -151,7 +151,7 @@ class _AppNavigationScreenState extends State<AppNavigationScreen> {
}
/// Section Widget
Widget _buildAppNavigation(BuildContext context) {
_buildAppNavigation(BuildContext context) {
return Container(
decoration: BoxDecoration(
color: Color(0XFFFFFFFF),
@@ -205,15 +205,13 @@ class _AppNavigationScreenState extends State<AppNavigationScreen> {
}
/// Common widget
Widget _buildScreenTitle(
_buildScreenTitle(
BuildContext context, {
required String screenTitle,
Function? onTapScreenTitle,
}) {
return GestureDetector(
onTap: () {
onTapScreenTitle!.call();
},
onTap: onTapScreenTitle!.call(),
child: Container(
decoration: BoxDecoration(
color: Color(0XFFFFFFFF),