From 818721a993fc36491e38ba3831fa4b990a32b073 Mon Sep 17 00:00:00 2001 From: mso7nueh Date: Sun, 28 Jul 2024 18:39:36 +0300 Subject: [PATCH] feature(registration): add location endpoint with debounce --- .../user_registration_model.dart | 5 +- .../user_registration_model.freezed.dart | 75 +++---- .../user_registration_model.g.dart | 8 +- .../registration/models/location_model.dart | 15 ++ .../models/location_model.freezed.dart | 189 ++++++++++++++++++ .../registration/models/location_model.g.dart | 19 ++ .../registration_cubit.dart | 14 +- .../pages/city_of_living_screen.dart | 61 ++---- .../pages/registration_screen.dart | 2 +- .../repositories/registration_repository.dart | 9 + .../services/registration_service.dart | 6 + .../services/registration_service.g.dart | 27 +++ .../bloc/blog_post_create_bloc.dart | 6 +- 13 files changed, 345 insertions(+), 91 deletions(-) create mode 100644 lib/features/registration/models/location_model.dart create mode 100644 lib/features/registration/models/location_model.freezed.dart create mode 100644 lib/features/registration/models/location_model.g.dart diff --git a/lib/data/models/userRegistrationModel/user_registration_model.dart b/lib/data/models/userRegistrationModel/user_registration_model.dart index 5e308189..a86d0648 100644 --- a/lib/data/models/userRegistrationModel/user_registration_model.dart +++ b/lib/data/models/userRegistrationModel/user_registration_model.dart @@ -15,8 +15,9 @@ class UserRegistrationSheet with _$UserRegistrationSheet { @Default('accepted') @JsonKey(name: 'terms') String termsAccepted, required String birthdate, required String gender, - required String country, - required String city, + required String location, + @JsonKey(name: 'response_body') + required String responseBody, required String lang, required int weight, required int height, diff --git a/lib/data/models/userRegistrationModel/user_registration_model.freezed.dart b/lib/data/models/userRegistrationModel/user_registration_model.freezed.dart index 4aa91df8..70f656fe 100644 --- a/lib/data/models/userRegistrationModel/user_registration_model.freezed.dart +++ b/lib/data/models/userRegistrationModel/user_registration_model.freezed.dart @@ -34,8 +34,9 @@ mixin _$UserRegistrationSheet { String get termsAccepted => throw _privateConstructorUsedError; String get birthdate => throw _privateConstructorUsedError; String get gender => throw _privateConstructorUsedError; - String get country => throw _privateConstructorUsedError; - String get city => throw _privateConstructorUsedError; + String get location => throw _privateConstructorUsedError; + @JsonKey(name: 'response_body') + String get responseBody => throw _privateConstructorUsedError; String get lang => throw _privateConstructorUsedError; int get weight => throw _privateConstructorUsedError; int get height => throw _privateConstructorUsedError; @@ -90,8 +91,8 @@ abstract class $UserRegistrationSheetCopyWith<$Res> { @JsonKey(name: 'terms') String termsAccepted, String birthdate, String gender, - String country, - String city, + String location, + @JsonKey(name: 'response_body') String responseBody, String lang, int weight, int height, @@ -134,8 +135,8 @@ class _$UserRegistrationSheetCopyWithImpl<$Res, Object? termsAccepted = null, Object? birthdate = null, Object? gender = null, - Object? country = null, - Object? city = null, + Object? location = null, + Object? responseBody = null, Object? lang = null, Object? weight = null, Object? height = null, @@ -191,13 +192,13 @@ class _$UserRegistrationSheetCopyWithImpl<$Res, ? _value.gender : gender // ignore: cast_nullable_to_non_nullable as String, - country: null == country - ? _value.country - : country // ignore: cast_nullable_to_non_nullable + location: null == location + ? _value.location + : location // ignore: cast_nullable_to_non_nullable as String, - city: null == city - ? _value.city - : city // ignore: cast_nullable_to_non_nullable + responseBody: null == responseBody + ? _value.responseBody + : responseBody // ignore: cast_nullable_to_non_nullable as String, lang: null == lang ? _value.lang @@ -290,8 +291,8 @@ abstract class _$$UserRegistrationSheetImplCopyWith<$Res> @JsonKey(name: 'terms') String termsAccepted, String birthdate, String gender, - String country, - String city, + String location, + @JsonKey(name: 'response_body') String responseBody, String lang, int weight, int height, @@ -332,8 +333,8 @@ class __$$UserRegistrationSheetImplCopyWithImpl<$Res> Object? termsAccepted = null, Object? birthdate = null, Object? gender = null, - Object? country = null, - Object? city = null, + Object? location = null, + Object? responseBody = null, Object? lang = null, Object? weight = null, Object? height = null, @@ -389,13 +390,13 @@ class __$$UserRegistrationSheetImplCopyWithImpl<$Res> ? _value.gender : gender // ignore: cast_nullable_to_non_nullable as String, - country: null == country - ? _value.country - : country // ignore: cast_nullable_to_non_nullable + location: null == location + ? _value.location + : location // ignore: cast_nullable_to_non_nullable as String, - city: null == city - ? _value.city - : city // ignore: cast_nullable_to_non_nullable + responseBody: null == responseBody + ? _value.responseBody + : responseBody // ignore: cast_nullable_to_non_nullable as String, lang: null == lang ? _value.lang @@ -483,8 +484,8 @@ class _$UserRegistrationSheetImpl implements _UserRegistrationSheet { @JsonKey(name: 'terms') this.termsAccepted = 'accepted', required this.birthdate, required this.gender, - required this.country, - required this.city, + required this.location, + @JsonKey(name: 'response_body') required this.responseBody, required this.lang, required this.weight, required this.height, @@ -529,9 +530,10 @@ class _$UserRegistrationSheetImpl implements _UserRegistrationSheet { @override final String gender; @override - final String country; + final String location; @override - final String city; + @JsonKey(name: 'response_body') + final String responseBody; @override final String lang; @override @@ -583,7 +585,7 @@ class _$UserRegistrationSheetImpl implements _UserRegistrationSheet { @override String toString() { - return 'UserRegistrationSheet(name: $name, firstName: $firstName, lastName: $lastName, email: $email, password: $password, passwordConfirmation: $passwordConfirmation, termsAccepted: $termsAccepted, birthdate: $birthdate, gender: $gender, country: $country, city: $city, lang: $lang, weight: $weight, height: $height, chestCircumference: $chestCircumference, waistCircumference: $waistCircumference, hipCircumference: $hipCircumference, bloodPressureUp: $bloodPressureUp, bloodPressureDown: $bloodPressureDown, hasHypo: $hasHypo, hasHyper: $hasHyper, aboutAllergy: $aboutAllergy, aboutTakingPils: $aboutTakingPils, aboutSportHobbies: $aboutSportHobbies, favoriteFoods: $favoriteFoods, unfavoriteFoods: $unfavoriteFoods, additionalInfo: $additionalInfo, activityCoefficient: $activityCoefficient)'; + return 'UserRegistrationSheet(name: $name, firstName: $firstName, lastName: $lastName, email: $email, password: $password, passwordConfirmation: $passwordConfirmation, termsAccepted: $termsAccepted, birthdate: $birthdate, gender: $gender, location: $location, responseBody: $responseBody, lang: $lang, weight: $weight, height: $height, chestCircumference: $chestCircumference, waistCircumference: $waistCircumference, hipCircumference: $hipCircumference, bloodPressureUp: $bloodPressureUp, bloodPressureDown: $bloodPressureDown, hasHypo: $hasHypo, hasHyper: $hasHyper, aboutAllergy: $aboutAllergy, aboutTakingPils: $aboutTakingPils, aboutSportHobbies: $aboutSportHobbies, favoriteFoods: $favoriteFoods, unfavoriteFoods: $unfavoriteFoods, additionalInfo: $additionalInfo, activityCoefficient: $activityCoefficient)'; } @override @@ -606,8 +608,10 @@ class _$UserRegistrationSheetImpl implements _UserRegistrationSheet { (identical(other.birthdate, birthdate) || other.birthdate == birthdate) && (identical(other.gender, gender) || other.gender == gender) && - (identical(other.country, country) || other.country == country) && - (identical(other.city, city) || other.city == city) && + (identical(other.location, location) || + other.location == location) && + (identical(other.responseBody, responseBody) || + other.responseBody == responseBody) && (identical(other.lang, lang) || other.lang == lang) && (identical(other.weight, weight) || other.weight == weight) && (identical(other.height, height) || other.height == height) && @@ -653,8 +657,8 @@ class _$UserRegistrationSheetImpl implements _UserRegistrationSheet { termsAccepted, birthdate, gender, - country, - city, + location, + responseBody, lang, weight, height, @@ -701,8 +705,8 @@ abstract class _UserRegistrationSheet implements UserRegistrationSheet { @JsonKey(name: 'terms') final String termsAccepted, required final String birthdate, required final String gender, - required final String country, - required final String city, + required final String location, + @JsonKey(name: 'response_body') required final String responseBody, required final String lang, required final int weight, required final int height, @@ -752,9 +756,10 @@ abstract class _UserRegistrationSheet implements UserRegistrationSheet { @override String get gender; @override - String get country; + String get location; @override - String get city; + @JsonKey(name: 'response_body') + String get responseBody; @override String get lang; @override diff --git a/lib/data/models/userRegistrationModel/user_registration_model.g.dart b/lib/data/models/userRegistrationModel/user_registration_model.g.dart index 132240b7..6ca8a1cf 100644 --- a/lib/data/models/userRegistrationModel/user_registration_model.g.dart +++ b/lib/data/models/userRegistrationModel/user_registration_model.g.dart @@ -18,8 +18,8 @@ _$UserRegistrationSheetImpl _$$UserRegistrationSheetImplFromJson( termsAccepted: json['terms'] as String? ?? 'accepted', birthdate: json['birthdate'] as String, gender: json['gender'] as String, - country: json['country'] as String, - city: json['city'] as String, + location: json['location'] as String, + responseBody: json['response_body'] as String, lang: json['lang'] as String, weight: (json['weight'] as num).toInt(), height: (json['height'] as num).toInt(), @@ -52,8 +52,8 @@ Map _$$UserRegistrationSheetImplToJson( 'terms': instance.termsAccepted, 'birthdate': instance.birthdate, 'gender': instance.gender, - 'country': instance.country, - 'city': instance.city, + 'location': instance.location, + 'response_body': instance.responseBody, 'lang': instance.lang, 'weight': instance.weight, 'height': instance.height, diff --git a/lib/features/registration/models/location_model.dart b/lib/features/registration/models/location_model.dart new file mode 100644 index 00000000..3632a3e4 --- /dev/null +++ b/lib/features/registration/models/location_model.dart @@ -0,0 +1,15 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'location_model.g.dart'; +part 'location_model.freezed.dart'; + +@freezed +class LocationModel with _$LocationModel { + const factory LocationModel({ + required Map locations, + @JsonKey(name: 'response_body') + required String responseBody, +}) = _LocationModel; + + factory LocationModel.fromJson(Map json) => _$LocationModelFromJson(json); +} \ No newline at end of file diff --git a/lib/features/registration/models/location_model.freezed.dart b/lib/features/registration/models/location_model.freezed.dart new file mode 100644 index 00000000..71cbcb49 --- /dev/null +++ b/lib/features/registration/models/location_model.freezed.dart @@ -0,0 +1,189 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'location_model.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); + +LocationModel _$LocationModelFromJson(Map json) { + return _LocationModel.fromJson(json); +} + +/// @nodoc +mixin _$LocationModel { + Map get locations => throw _privateConstructorUsedError; + @JsonKey(name: 'response_body') + String get responseBody => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $LocationModelCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $LocationModelCopyWith<$Res> { + factory $LocationModelCopyWith( + LocationModel value, $Res Function(LocationModel) then) = + _$LocationModelCopyWithImpl<$Res, LocationModel>; + @useResult + $Res call( + {Map locations, + @JsonKey(name: 'response_body') String responseBody}); +} + +/// @nodoc +class _$LocationModelCopyWithImpl<$Res, $Val extends LocationModel> + implements $LocationModelCopyWith<$Res> { + _$LocationModelCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? locations = null, + Object? responseBody = null, + }) { + return _then(_value.copyWith( + locations: null == locations + ? _value.locations + : locations // ignore: cast_nullable_to_non_nullable + as Map, + responseBody: null == responseBody + ? _value.responseBody + : responseBody // ignore: cast_nullable_to_non_nullable + as String, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$LocationModelImplCopyWith<$Res> + implements $LocationModelCopyWith<$Res> { + factory _$$LocationModelImplCopyWith( + _$LocationModelImpl value, $Res Function(_$LocationModelImpl) then) = + __$$LocationModelImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {Map locations, + @JsonKey(name: 'response_body') String responseBody}); +} + +/// @nodoc +class __$$LocationModelImplCopyWithImpl<$Res> + extends _$LocationModelCopyWithImpl<$Res, _$LocationModelImpl> + implements _$$LocationModelImplCopyWith<$Res> { + __$$LocationModelImplCopyWithImpl( + _$LocationModelImpl _value, $Res Function(_$LocationModelImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? locations = null, + Object? responseBody = null, + }) { + return _then(_$LocationModelImpl( + locations: null == locations + ? _value._locations + : locations // ignore: cast_nullable_to_non_nullable + as Map, + responseBody: null == responseBody + ? _value.responseBody + : responseBody // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$LocationModelImpl implements _LocationModel { + const _$LocationModelImpl( + {required final Map locations, + @JsonKey(name: 'response_body') required this.responseBody}) + : _locations = locations; + + factory _$LocationModelImpl.fromJson(Map json) => + _$$LocationModelImplFromJson(json); + + final Map _locations; + @override + Map get locations { + if (_locations is EqualUnmodifiableMapView) return _locations; + // ignore: implicit_dynamic_type + return EqualUnmodifiableMapView(_locations); + } + + @override + @JsonKey(name: 'response_body') + final String responseBody; + + @override + String toString() { + return 'LocationModel(locations: $locations, responseBody: $responseBody)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$LocationModelImpl && + const DeepCollectionEquality() + .equals(other._locations, _locations) && + (identical(other.responseBody, responseBody) || + other.responseBody == responseBody)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash(runtimeType, + const DeepCollectionEquality().hash(_locations), responseBody); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$LocationModelImplCopyWith<_$LocationModelImpl> get copyWith => + __$$LocationModelImplCopyWithImpl<_$LocationModelImpl>(this, _$identity); + + @override + Map toJson() { + return _$$LocationModelImplToJson( + this, + ); + } +} + +abstract class _LocationModel implements LocationModel { + const factory _LocationModel( + {required final Map locations, + @JsonKey(name: 'response_body') required final String responseBody}) = + _$LocationModelImpl; + + factory _LocationModel.fromJson(Map json) = + _$LocationModelImpl.fromJson; + + @override + Map get locations; + @override + @JsonKey(name: 'response_body') + String get responseBody; + @override + @JsonKey(ignore: true) + _$$LocationModelImplCopyWith<_$LocationModelImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/features/registration/models/location_model.g.dart b/lib/features/registration/models/location_model.g.dart new file mode 100644 index 00000000..04a199fb --- /dev/null +++ b/lib/features/registration/models/location_model.g.dart @@ -0,0 +1,19 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'location_model.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$LocationModelImpl _$$LocationModelImplFromJson(Map json) => + _$LocationModelImpl( + locations: json['locations'] as Map, + responseBody: json['response_body'] as String, + ); + +Map _$$LocationModelImplToJson(_$LocationModelImpl instance) => + { + 'locations': instance.locations, + 'response_body': instance.responseBody, + }; diff --git a/lib/features/registration/presentation/bloc/registration_cubit/registration_cubit.dart b/lib/features/registration/presentation/bloc/registration_cubit/registration_cubit.dart index f9e767fc..af81fda8 100644 --- a/lib/features/registration/presentation/bloc/registration_cubit/registration_cubit.dart +++ b/lib/features/registration/presentation/bloc/registration_cubit/registration_cubit.dart @@ -21,8 +21,8 @@ class RegistrationCubit extends Cubit { passwordConfirmation: '', birthdate: '', gender: '', - country: '', - city: '', + location: '', + responseBody: '', lang: '', weight: 0, height: 0, @@ -54,4 +54,14 @@ class RegistrationCubit extends Cubit { rethrow; } } + + Future> getLocationsByQuery(String query) async { + try { + final location = (await registrationRepository.getLocationsListByQuery(query)); + emit(RegistrationState(sheet: state.sheet.copyWith(responseBody: location.responseBody))); + return location.locations.values.toList().map((e) => e.toString()).toList(); + } catch (e) { + rethrow; + } + } } diff --git a/lib/features/registration/presentation/pages/city_of_living_screen.dart b/lib/features/registration/presentation/pages/city_of_living_screen.dart index 02e5c65e..0a3dd291 100644 --- a/lib/features/registration/presentation/pages/city_of_living_screen.dart +++ b/lib/features/registration/presentation/pages/city_of_living_screen.dart @@ -1,8 +1,6 @@ import 'package:eatvio_app/core/app_export.dart'; import 'package:eatvio_app/data/models/userRegistrationModel/user_registration_model.dart'; -import 'package:eatvio_app/features/registration/consts/cities_list.dart'; import 'package:eatvio_app/features/registration/presentation/bloc/registration_cubit/registration_cubit.dart'; -import 'package:eatvio_app/widgets/custom_drop_down.dart'; import 'package:eatvio_app/widgets/custom_edit_text_form_field.dart'; import 'package:flutter/material.dart'; import 'package:flutter_typeahead/flutter_typeahead.dart'; @@ -27,15 +25,8 @@ class _CityOfLivingScreenState extends State { @override void initState() { super.initState(); - if (widget.sheet.country.isNotEmpty) { - selectedItem = dropdownItemList.firstWhere((item) => item.title == widget.sheet.country); - } else { - selectedItem = dropdownItemList.first; - final registrationCubit = context.read(); - registrationCubit.updateSheet(registrationCubit.state.sheet.copyWith(country: selectedItem.title)); - } - if (widget.sheet.city.isNotEmpty) { - cityController.text = widget.sheet.city; + if (widget.sheet.location.isNotEmpty) { + cityController.text = widget.sheet.location; } } @@ -46,39 +37,19 @@ class _CityOfLivingScreenState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text("country".tr), - SizedBox(height: 4), - 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: dropdownItemList, - value: selectedItem, - onChanged: (newValue) { - setState(() { - selectedItem = newValue; - }); - final registrationCubit = context.read(); - registrationCubit.updateSheet(registrationCubit.state.sheet.copyWith(country: newValue.title)); - }, - ), - SizedBox(height: 16), - Text("Населенный пункт"), + Text("Местоположение"), SizedBox(height: 4), TypeAheadField( - debounceDuration: Duration.zero, + debounceDuration: Duration(milliseconds: 300), controller: cityController, builder: (context, controller, focus) => CustomTextFormField( - controller: cityController, - focusNode: focus, - textStyle: TextStyle( - fontSize: 16, - color: Colors.black, - ) - ), + controller: cityController, + focusNode: focus, + autofocus: true, + textStyle: TextStyle( + fontSize: 16, + color: Colors.black, + )), itemBuilder: (BuildContext context, String item) { return Padding( padding: const EdgeInsets.all(8.0), @@ -96,10 +67,14 @@ class _CityOfLivingScreenState extends State { cityController.text = item; }); final registrationCubit = context.read(); - registrationCubit.updateSheet(registrationCubit.state.sheet.copyWith(city: item)); + registrationCubit.updateSheet(registrationCubit.state.sheet.copyWith(location: item)); }, - suggestionsCallback: (query) { - return citiesList.where((country) => country.toLowerCase().contains(query.toLowerCase())).toList(); + suggestionsCallback: (query) async { + if (query.length >= 3) { + final registrationCubit = context.read(); + return (await registrationCubit.getLocationsByQuery(query)); + } + return null; }, ), ], diff --git a/lib/features/registration/presentation/pages/registration_screen.dart b/lib/features/registration/presentation/pages/registration_screen.dart index 1688ef2c..08562908 100644 --- a/lib/features/registration/presentation/pages/registration_screen.dart +++ b/lib/features/registration/presentation/pages/registration_screen.dart @@ -244,7 +244,7 @@ class _RegistrationScreenState extends State { return false; } case 6: - if (state.sheet.country.isNotEmpty && state.sheet.city.isNotEmpty) + if (state.sheet.location.isNotEmpty) return true; else { showDialog( diff --git a/lib/features/registration/repositories/registration_repository.dart b/lib/features/registration/repositories/registration_repository.dart index aa388801..31a1ff11 100644 --- a/lib/features/registration/repositories/registration_repository.dart +++ b/lib/features/registration/repositories/registration_repository.dart @@ -1,4 +1,5 @@ import 'package:eatvio_app/data/models/userRegistrationModel/user_registration_model.dart'; +import 'package:eatvio_app/features/registration/models/location_model.dart'; import 'package:eatvio_app/features/registration/services/registration_service.dart'; class RegistrationRepository { @@ -13,4 +14,12 @@ class RegistrationRepository { rethrow; } } + + Future getLocationsListByQuery(String query) async { + try { + return (await registrationService.getLocations(query: query)); + } catch (e) { + rethrow; + } + } } diff --git a/lib/features/registration/services/registration_service.dart b/lib/features/registration/services/registration_service.dart index fefca6ad..af4bd836 100644 --- a/lib/features/registration/services/registration_service.dart +++ b/lib/features/registration/services/registration_service.dart @@ -1,4 +1,5 @@ import 'package:dio/dio.dart'; +import 'package:eatvio_app/features/registration/models/location_model.dart'; import 'package:retrofit/retrofit.dart'; part 'registration_service.g.dart'; @@ -11,4 +12,9 @@ abstract class RegistrationService { Future> register({ @Body() required Map sheet, }); + + @GET('/api/locations') + Future getLocations({ + @Query('user_address') required String query, + }); } diff --git a/lib/features/registration/services/registration_service.g.dart b/lib/features/registration/services/registration_service.g.dart index 269d16cc..6c9ce5bc 100644 --- a/lib/features/registration/services/registration_service.g.dart +++ b/lib/features/registration/services/registration_service.g.dart @@ -47,6 +47,33 @@ class _RegistrationService implements RegistrationService { return _value; } + @override + Future getLocations({required String query}) async { + final _extra = {}; + final queryParameters = {r'user_address': query}; + final _headers = {}; + const Map? _data = null; + final _result = await _dio + .fetch>(_setStreamType(Options( + method: 'GET', + headers: _headers, + extra: _extra, + ) + .compose( + _dio.options, + '/api/locations', + queryParameters: queryParameters, + data: _data, + ) + .copyWith( + baseUrl: _combineBaseUrls( + _dio.options.baseUrl, + baseUrl, + )))); + final _value = LocationModel.fromJson(_result.data!); + return _value; + } + RequestOptions _setStreamType(RequestOptions requestOptions) { if (T != dynamic && !(requestOptions.responseType == ResponseType.bytes || 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 654e963e..184938ad 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 @@ -72,9 +72,7 @@ class BlogPostCreateBloc extends Bloc if (response.statusCode == 200 || response.statusCode == 201) { AppRouter.navigatorKey.currentContext?.goNamed('feedScreen'); } else { - print( - 'Failed to create blog post. Status Code: ${response.statusCode} ${response.data}', - ); + print('Failed to create blog post. Status Code: ${response.statusCode} ${response.data}'); } } } @@ -85,7 +83,7 @@ class BlogPostCreateBloc extends Bloc FormData formData = FormData.fromMap({ 'title': title, 'description': description, - 'videoUrl': youtubeURL, + 'youtube_url': youtubeURL, 'state': 'active', 'image': await MultipartFile.fromFile(image!.path, filename: image.name), });