From 1fa05eae5fa3d32cc4d170f4cdf539bf9cec56a0 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Mon, 4 Mar 2024 14:04:09 +0300 Subject: [PATCH] Impoved autocomplete and partial encoding error fix --- .../bloc/diary_edit_bloc.dart | 6 +- .../diary_edit_screen/diary_edit_screen.dart | 171 ++++++------------ 2 files changed, 58 insertions(+), 119 deletions(-) diff --git a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_bloc.dart b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_bloc.dart index da42241b..81e7f5dc 100644 --- a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_bloc.dart +++ b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_bloc.dart @@ -170,7 +170,6 @@ class DiaryEditBloc extends Bloc { final credentials = { 'satiety': selectedSatiety, }; - print(json.encode(credentials)); var response = await http.post(Uri.parse(url), headers: { 'Authorization': 'Bearer $token', @@ -465,8 +464,9 @@ class DiaryEditBloc extends Bloc { AddComment event, Emitter emit) async { if (state is DiaryEditLoadedState) { var currentState = state as DiaryEditLoadedState; - var updatedState = - currentState.copyWith(commentController: event.comment); + var updatedState = currentState.copyWith( + commentController: TextEditingController(text: event.comment), + ); // Отправляем данные по HTTP маршруту и ждем ответ var response = await sendCommentData( 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 e4cb6f56..5bf9881c 100644 --- a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart +++ b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart @@ -205,11 +205,9 @@ class DiaryEditScreen extends StatelessWidget { Padding _buildMeal(BuildContext context, DiaryEditLoadedState state) { final digitsOnly = FilteringTextInputFormatter.digitsOnly; - const List _options = [ - 'aardvark', - 'bobcat', - 'chameleon', - ]; + List _options = + state.autocompleteList!.map((dynamic item) => item as String).toList(); + print(_options); return Padding( padding: EdgeInsets.symmetric(horizontal: 16.h), child: Container( @@ -288,123 +286,64 @@ class DiaryEditScreen extends StatelessWidget { Padding( padding: EdgeInsets.symmetric(horizontal: 10.h), child: RawAutocomplete( - optionsBuilder: (TextEditingValue textEditingValue) { - if (textEditingValue.text == '') { - return const Iterable.empty(); - } - return Future>.value(state.autocompleteList - ?.map((dynamic item) => item as String) - .toList() - .where((String option) { - return true; - })); - }, - fieldViewBuilder: ( - BuildContext context, - TextEditingController textEditingController, - FocusNode focusNode, - VoidCallback onFieldSubmitted, - ) { - return CustomTextFormField( - hintText: "Введите название продукта", - controller: state.productNameController, - onChanged: (value) { - /*print(state.autocompleteList + optionsBuilder: (TextEditingValue textEditingValue) { + return _options.where((String option) { + return true; + }); + }, fieldViewBuilder: ( + BuildContext context, + TextEditingController textEditingController, + FocusNode focusNode, + VoidCallback onFieldSubmitted, + ) { + return CustomTextFormField( + hintText: "Введите название продукта", + controller: textEditingController, + focusNode: focusNode, + onChanged: (value) { + /*print(state.autocompleteList ?.map((dynamic item) => item as String) .toList());*/ - if (value.length > 3) { - context - .read() - .add(ProductInput(value)); - } - }, - ); - }, - 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), - ), - ); - }, - ), + if (value.length > 3) { + context.read().add(ProductInput(value)); + } + }, + /*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), + ), + ); + }, ), ), - ); - }, - onSelected: (String selection) { - // Обработка выбранного варианта автозаполнения - }, - ), + ), + ); + }), ), SizedBox(height: 20.v), - RawAutocomplete( - optionsBuilder: (TextEditingValue textEditingValue) { - return _options.where((String option) { - return option.contains( - state.productNameController!.text.toLowerCase()); - }); - }, fieldViewBuilder: ( - BuildContext context, - TextEditingController textEditingController, - FocusNode focusNode, - VoidCallback onFieldSubmitted, - ) { - return TextFormField( - 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), - ), - ); - }, - ), - ), - ), - ); - }), Padding( padding: EdgeInsets.symmetric(horizontal: 10.h), child: Row(