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 a8ad156..1629dd1 100644 --- a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart +++ b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart @@ -281,72 +281,58 @@ class DiaryEditScreen extends StatelessWidget { vertical: 9.v, ), defaultValue: diaryEditModelObj?.mealList[0], - onChanged: (value) { - context.read().add( - ChangeMeal(meals: state.meals, value: value)); - }, + onChanged: changeMeal(context, state), ); })), SizedBox(height: 20.v), Padding( padding: EdgeInsets.symmetric(horizontal: 10.h), child: RawAutocomplete( - 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 > 2) { - context.read().add(ProductInput(value)); - } - }, - /*onFieldSubmitted: (String value) { + optionsBuilder: buildOptions(_options), + fieldViewBuilder: ( + BuildContext context, + TextEditingController textEditingController, + FocusNode focusNode, + VoidCallback onFieldSubmitted, + ) { + return CustomTextFormField( + hintText: "Введите название продукта", + controller: textEditingController, + focusNode: focusNode, + onChanged: getAutocomplete(context), + /*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); + ); + }, + 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: selectProduct(onSelected, option), + child: ListTile( + title: Text(option), + ), + ); }, - child: ListTile( - title: Text(option), - ), - ); - }, + ), + ), ), - ), - ), - ); - }), + ); + }), ), SizedBox(height: 20.v), Padding( @@ -395,44 +381,32 @@ class DiaryEditScreen extends StatelessWidget { ScaleElement( color: Colors.red, isSelected: state.selectedSatiety == 0, - onTap: () { - context.read().add(ChangeSatiety(0)); - }, + onTap: changeSatiety(context, 0), ), ScaleElement( color: Colors.orange, isSelected: state.selectedSatiety == 1, - onTap: () { - context.read().add(ChangeSatiety(1)); - }, + onTap: changeSatiety(context, 1), ), ScaleElement( color: Colors.yellow, isSelected: state.selectedSatiety == 2, - onTap: () { - context.read().add(ChangeSatiety(2)); - }, + onTap: changeSatiety(context, 2), ), ScaleElement( color: Colors.lime, isSelected: state.selectedSatiety == 3, - onTap: () { - context.read().add(ChangeSatiety(3)); - }, + onTap: changeSatiety(context, 3), ), ScaleElement( color: Colors.lightGreen, isSelected: state.selectedSatiety == 4, - onTap: () { - context.read().add(ChangeSatiety(4)); - }, + onTap: changeSatiety(context, 4), ), ScaleElement( color: Colors.green, isSelected: state.selectedSatiety == 5, - onTap: () { - context.read().add(ChangeSatiety(5)); - }, + onTap: changeSatiety(context, 5), ), Text("😊"), // Остальные элементы шкалы @@ -447,6 +421,45 @@ class DiaryEditScreen extends StatelessWidget { )); } + changeSatiety(BuildContext context, int satiety) { + return () { + context.read().add(ChangeSatiety(satiety)); + }; + } + + selectProduct(AutocompleteOnSelected onSelected, String option) { + return () { + onSelected(option); + }; + } + + getAutocomplete(BuildContext context) { + return (value) { + /*print(state.autocompleteList + ?.map((dynamic item) => item as String) + .toList());*/ + if (value.length > 2) { + context.read().add(ProductInput(value)); + } + }; + } + + buildOptions(List _options) { + return (TextEditingValue textEditingValue) { + return _options.where((String option) { + return true; + }); + }; + } + + changeMeal(BuildContext context, DiaryEditLoadedState state) { + return (value) { + context + .read() + .add(ChangeMeal(meals: state.meals, value: value)); + }; + } + _buildProduct(BuildContext context, Map portion) { return Container( margin: EdgeInsets.symmetric(horizontal: 10.h), @@ -485,11 +498,7 @@ class DiaryEditScreen extends StatelessWidget { ), Spacer(), GestureDetector( - onTap: () { - context - .read() - .add(RemovePortionEvent(portion['id'])); - }, + onTap: removePortion(context, portion), child: Padding( padding: const EdgeInsets.only(right: 10), child: Icon( @@ -502,6 +511,12 @@ class DiaryEditScreen extends StatelessWidget { ); } + removePortion(BuildContext context, Map portion) { + return () { + context.read().add(RemovePortionEvent(portion['id'])); + }; + } + _buildNutritionChart(BuildContext context) { return Container( margin: EdgeInsets.symmetric(horizontal: 16.h), @@ -808,10 +823,7 @@ class DiaryEditScreen extends StatelessWidget { child: Column( children: [ GestureDetector( - onTap: () { - BlocProvider.of(context) - .add(ToggleWakeupExpandedEvent()); - }, + onTap: toggleWakeup(context), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ @@ -863,6 +875,12 @@ class DiaryEditScreen extends StatelessWidget { ); } + toggleWakeup(BuildContext context) { + return () { + BlocProvider.of(context).add(ToggleWakeupExpandedEvent()); + }; + } + /// Section Widget _buildEndDay(BuildContext context) { return CustomOutlinedButton( @@ -900,10 +918,7 @@ class DiaryEditScreen extends StatelessWidget { ), child: Column(children: [ GestureDetector( - onTap: () { - BlocProvider.of(context) - .add(ToggleMoodExpandedEvent()); - }, + onTap: toggleMood(context), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ @@ -925,44 +940,32 @@ class DiaryEditScreen extends StatelessWidget { ScaleElement( color: Colors.red, isSelected: state.selectedMood == 0, - onTap: () { - context.read().add(ChangeMood(0)); - }, + onTap: changeMood(context, 0), ), ScaleElement( color: Colors.orange, isSelected: state.selectedMood == 1, - onTap: () { - context.read().add(ChangeMood(1)); - }, + onTap: changeMood(context, 1), ), ScaleElement( color: Colors.yellow, isSelected: state.selectedMood == 2, - onTap: () { - context.read().add(ChangeMood(2)); - }, + onTap: changeMood(context, 2), ), ScaleElement( color: Colors.lime, isSelected: state.selectedMood == 3, - onTap: () { - context.read().add(ChangeMood(3)); - }, + onTap: changeMood(context, 3), ), ScaleElement( color: Colors.lightGreen, isSelected: state.selectedMood == 4, - onTap: () { - context.read().add(ChangeMood(4)); - }, + onTap: changeMood(context, 4), ), ScaleElement( color: Colors.green, isSelected: state.selectedMood == 5, - onTap: () { - context.read().add(ChangeMood(5)); - }, + onTap: changeMood(context, 5), ), Text("😊"), // Остальные элементы шкалы @@ -971,6 +974,18 @@ class DiaryEditScreen extends StatelessWidget { ])); } + changeMood(BuildContext context, int satiety) { + return () { + context.read().add(ChangeMood(satiety)); + }; + } + + toggleMood(BuildContext context) { + return () { + BlocProvider.of(context).add(ToggleMoodExpandedEvent()); + }; + } + Future _selectWakeupTime( BuildContext context, DiaryEditLoadedState state) async { final TimeOfDay? pickedTime = await showTimePicker( diff --git a/lib/presentation/profile/my_profile_screen/my_profile_screen.dart b/lib/presentation/profile/my_profile_screen/my_profile_screen.dart index cb11557..77929fd 100644 --- a/lib/presentation/profile/my_profile_screen/my_profile_screen.dart +++ b/lib/presentation/profile/my_profile_screen/my_profile_screen.dart @@ -677,7 +677,6 @@ class MyProfileScreen extends StatelessWidget { Align( alignment: Alignment.topCenter, child: ListView.builder( - shrinkWrap: true, itemCount: plans?.length ?? 0, itemBuilder: (context, i) { String state = states?[i];