From a8ed8b75b1bd9886b8df5d34da689580967468cd Mon Sep 17 00:00:00 2001 From: maxxkim Date: Tue, 26 Dec 2023 16:06:24 +0300 Subject: [PATCH] Send JSON to server --- .../user_registration_model.dart | 24 +++++++++---------- .../additional_information_screen.dart | 23 ++++++++---------- .../bloc/blood_pressure_bloc.dart | 8 +++---- .../blood_pressure_screen.dart | 4 ++-- .../body_circumferences_screen.dart | 12 +++++----- .../date_of_birth_screen.dart | 2 +- .../height_screen/bloc/height_bloc.dart | 3 +-- .../models/language_select_model.dart | 22 ++++++++--------- .../weight_screen/bloc/weight_bloc.dart | 3 +-- 9 files changed, 48 insertions(+), 53 deletions(-) diff --git a/lib/data/models/userRegistrationModel/user_registration_model.dart b/lib/data/models/userRegistrationModel/user_registration_model.dart index 7f32d56c..6ce27ca5 100644 --- a/lib/data/models/userRegistrationModel/user_registration_model.dart +++ b/lib/data/models/userRegistrationModel/user_registration_model.dart @@ -7,21 +7,21 @@ class UserRegistrationSheet { String email; String password; String passwordConfirmation; - bool termsAccepted; - DateTime birthdate; + String termsAccepted; + String birthdate; String gender; String country; String city; String lang; - int weight; - int height; - int chestCircumference; - int waistCircumference; - int hipCircumference; - int bloodPressureUp; - int bloodPressureDown; - bool hasHypo = false; - bool hasHyper = false; + String weight; + String height; + String chestCircumference; + String waistCircumference; + String hipCircumference; + String bloodPressureUp; + String bloodPressureDown; + String hasHypo = ''; + String hasHyper = ''; String aboutAllergy = ''; String aboutTakingPils = ''; String aboutSportHobbies = ''; @@ -66,7 +66,7 @@ class UserRegistrationSheet { 'password': password, 'password_confirmation': passwordConfirmation, 'terms': termsAccepted, - 'birthdate': birthdate.toIso8601String(), + 'birthdate': birthdate.toString(), 'gender': gender, 'country': country, 'city': city, diff --git a/lib/presentation/additional_information_screen/additional_information_screen.dart b/lib/presentation/additional_information_screen/additional_information_screen.dart index 4ee525de..76b53580 100644 --- a/lib/presentation/additional_information_screen/additional_information_screen.dart +++ b/lib/presentation/additional_information_screen/additional_information_screen.dart @@ -9,8 +9,9 @@ import 'package:eatvio_app/data/models/userRegistrationModel/user_registration_m import 'package:eatvio_app/widgets/custom_text_form_field.dart'; import 'package:flutter/material.dart'; import 'dart:convert'; +import 'package:http/http.dart' as http; -class AdditionalInformationScreen extends StatefulWidget { +class AdditionalInformationScreen extends StatelessWidget { const AdditionalInformationScreen({Key? key}) : super(key: key); static Widget builder(BuildContext context) { @@ -25,13 +26,6 @@ class AdditionalInformationScreen extends StatefulWidget { child: AdditionalInformationScreen()); } - @override - State createState() => - _AdditionalInformationScreenState(); -} - -class _AdditionalInformationScreenState - extends State { @override Widget build(BuildContext context) { mediaQueryData = MediaQuery.of(context); @@ -70,14 +64,17 @@ class _AdditionalInformationScreenState margin: EdgeInsets.only( left: 16.h, right: 16.h, bottom: 50.v), buttonStyle: CustomButtonStyles.outlinePrimaryTL15, - onPressed: () { - var message; + onPressed: () async { UserRegistrationSheet sheet = state .additionalInformationModelObj! .userRegistrationSheet; sheet.additionalInfo = state.editTextController!.text; - message = sheet.toJson(); - print(message); + final response = await http.post( + Uri.parse('http://10.55.5.126:1092/api/register'), + headers: {'Content-Type': 'application/json'}, + body: json.encode(sheet), + ); + print(response.body); }); }), SizedBox(height: 17.v), @@ -140,7 +137,7 @@ class _AdditionalInformationScreenState context: context, builder: (_) => AlertDialog( title: const Text('Регистрация завершена!'), - content: const Text(text), + content: const Text('1'), actions: [ TextButton( onPressed: () { diff --git a/lib/presentation/blood_pressure_screen/bloc/blood_pressure_bloc.dart b/lib/presentation/blood_pressure_screen/bloc/blood_pressure_bloc.dart index c2c3632c..9ff02aeb 100644 --- a/lib/presentation/blood_pressure_screen/bloc/blood_pressure_bloc.dart +++ b/lib/presentation/blood_pressure_screen/bloc/blood_pressure_bloc.dart @@ -18,9 +18,9 @@ class BloodPressureBloc extends Bloc { Emitter emit, ) { if (event.value.id == 1) { - state.bloodPressureModelObj!.userRegistrationSheet.hasHyper = true; + state.bloodPressureModelObj!.userRegistrationSheet.hasHyper = '1'; } else { - state.bloodPressureModelObj!.userRegistrationSheet.hasHyper = false; + state.bloodPressureModelObj!.userRegistrationSheet.hasHyper = '0'; } emit(state.copyWith(selectedHyperValue: event.value)); } @@ -30,9 +30,9 @@ class BloodPressureBloc extends Bloc { Emitter emit, ) { if (event.value.id == 1) { - state.bloodPressureModelObj!.userRegistrationSheet.hasHypo = true; + state.bloodPressureModelObj!.userRegistrationSheet.hasHypo = '1'; } else { - state.bloodPressureModelObj!.userRegistrationSheet.hasHypo = false; + state.bloodPressureModelObj!.userRegistrationSheet.hasHypo = '0'; } emit(state.copyWith(selectedHypoValue: event.value)); } diff --git a/lib/presentation/blood_pressure_screen/blood_pressure_screen.dart b/lib/presentation/blood_pressure_screen/blood_pressure_screen.dart index f5c10e1d..0ecd9b61 100644 --- a/lib/presentation/blood_pressure_screen/blood_pressure_screen.dart +++ b/lib/presentation/blood_pressure_screen/blood_pressure_screen.dart @@ -178,9 +178,9 @@ class _BloodPressureScreenState extends State { UserRegistrationSheet sheet = state .bloodPressureModelObj!.userRegistrationSheet; sheet.bloodPressureUp = - int.tryParse(state.upPressureController!.text)!; + state.upPressureController!.text; sheet.bloodPressureDown = - int.tryParse(state.downPressureController!.text)!; + state.downPressureController!.text; Navigator.pushNamed( context, AppRoutes.favoriteSportsScreen, diff --git a/lib/presentation/body_circumferences_screen/body_circumferences_screen.dart b/lib/presentation/body_circumferences_screen/body_circumferences_screen.dart index c6e75bce..7aa3490b 100644 --- a/lib/presentation/body_circumferences_screen/body_circumferences_screen.dart +++ b/lib/presentation/body_circumferences_screen/body_circumferences_screen.dart @@ -109,12 +109,12 @@ class BodyCircumferencesScreen extends StatelessWidget { UserRegistrationSheet sheet = state .bodyCircumferencesModelObj! .userRegistrationSheet; - sheet.chestCircumference = int.tryParse( - state.chestCircumferenceController!.text)!; - sheet.waistCircumference = int.tryParse( - state.waistCircumferenceController!.text)!; - sheet.hipCircumference = int.tryParse( - state.hipCircumferenceController!.text)!; + sheet.chestCircumference = + state.chestCircumferenceController!.text!; + sheet.waistCircumference = + state.waistCircumferenceController!.text!; + sheet.hipCircumference = + state.hipCircumferenceController!.text!; Navigator.pushNamed( context, AppRoutes.weightScreen, diff --git a/lib/presentation/date_of_birth_screen/date_of_birth_screen.dart b/lib/presentation/date_of_birth_screen/date_of_birth_screen.dart index 5c3dcb6e..8b7c6d89 100644 --- a/lib/presentation/date_of_birth_screen/date_of_birth_screen.dart +++ b/lib/presentation/date_of_birth_screen/date_of_birth_screen.dart @@ -72,7 +72,7 @@ class _DateOfBirthScreenState extends State { onPressed: () { UserRegistrationSheet sheet = state .dateOfBirthModelObj!.userRegistrationSheet; - sheet.birthdate = selectedDate; + sheet.birthdate = selectedDate.toString(); Navigator.pushNamed( context, AppRoutes.cityOfLivingScreen, diff --git a/lib/presentation/height_screen/bloc/height_bloc.dart b/lib/presentation/height_screen/bloc/height_bloc.dart index 629778fe..7136a21a 100644 --- a/lib/presentation/height_screen/bloc/height_bloc.dart +++ b/lib/presentation/height_screen/bloc/height_bloc.dart @@ -26,8 +26,7 @@ class HeightBloc extends Bloc { Emitter emit, ) { emit(state.copyWith(selectedDropDownValue: event.value)); - state.heightModelObj?.userRegistrationSheet.height = - int.tryParse(event.value.title)!; + state.heightModelObj?.userRegistrationSheet.height = event.value.title; } List fillDropdownItemList() { diff --git a/lib/presentation/language_select_screen/models/language_select_model.dart b/lib/presentation/language_select_screen/models/language_select_model.dart index 1df7f8aa..d26e0391 100644 --- a/lib/presentation/language_select_screen/models/language_select_model.dart +++ b/lib/presentation/language_select_screen/models/language_select_model.dart @@ -14,21 +14,21 @@ class LanguageSelectModel extends Equatable { email: '', password: '', passwordConfirmation: '', - termsAccepted: false, - birthdate: DateTime.now(), + termsAccepted: 'accepted', + birthdate: DateTime.now().toString(), gender: '', country: '', city: '', lang: '', - weight: 0, - height: 0, - chestCircumference: 0, - waistCircumference: 0, - hipCircumference: 0, - bloodPressureUp: 0, - bloodPressureDown: 0, - hasHypo: false, - hasHyper: false, + weight: '', + height: '', + chestCircumference: '', + waistCircumference: '', + hipCircumference: '', + bloodPressureUp: '', + bloodPressureDown: '', + hasHypo: '', + hasHyper: '', aboutAllergy: '', aboutTakingPils: '', aboutSportHobbies: '', diff --git a/lib/presentation/weight_screen/bloc/weight_bloc.dart b/lib/presentation/weight_screen/bloc/weight_bloc.dart index 94091376..507220a4 100644 --- a/lib/presentation/weight_screen/bloc/weight_bloc.dart +++ b/lib/presentation/weight_screen/bloc/weight_bloc.dart @@ -26,8 +26,7 @@ class WeightBloc extends Bloc { Emitter emit, ) { emit(state.copyWith(selectedDropDownValue: event.value)); - state.weightModelObj?.userRegistrationSheet.weight = - int.tryParse(event.value.title)!; + state.weightModelObj?.userRegistrationSheet.weight = event.value.title; } List fillDropdownItemList() {