Refactoring diary finished
This commit is contained in:
@@ -281,72 +281,58 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
vertical: 9.v,
|
||||
),
|
||||
defaultValue: diaryEditModelObj?.mealList[0],
|
||||
onChanged: (value) {
|
||||
context.read<DiaryEditBloc>().add(
|
||||
ChangeMeal(meals: state.meals, value: value));
|
||||
},
|
||||
onChanged: changeMeal(context, state),
|
||||
);
|
||||
})),
|
||||
SizedBox(height: 20.v),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 10.h),
|
||||
child: RawAutocomplete<String>(
|
||||
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<DiaryEditBloc>().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<String> onSelected,
|
||||
Iterable<String> 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<String> onSelected,
|
||||
Iterable<String> 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<DiaryEditBloc>().add(ChangeSatiety(0));
|
||||
},
|
||||
onTap: changeSatiety(context, 0),
|
||||
),
|
||||
ScaleElement(
|
||||
color: Colors.orange,
|
||||
isSelected: state.selectedSatiety == 1,
|
||||
onTap: () {
|
||||
context.read<DiaryEditBloc>().add(ChangeSatiety(1));
|
||||
},
|
||||
onTap: changeSatiety(context, 1),
|
||||
),
|
||||
ScaleElement(
|
||||
color: Colors.yellow,
|
||||
isSelected: state.selectedSatiety == 2,
|
||||
onTap: () {
|
||||
context.read<DiaryEditBloc>().add(ChangeSatiety(2));
|
||||
},
|
||||
onTap: changeSatiety(context, 2),
|
||||
),
|
||||
ScaleElement(
|
||||
color: Colors.lime,
|
||||
isSelected: state.selectedSatiety == 3,
|
||||
onTap: () {
|
||||
context.read<DiaryEditBloc>().add(ChangeSatiety(3));
|
||||
},
|
||||
onTap: changeSatiety(context, 3),
|
||||
),
|
||||
ScaleElement(
|
||||
color: Colors.lightGreen,
|
||||
isSelected: state.selectedSatiety == 4,
|
||||
onTap: () {
|
||||
context.read<DiaryEditBloc>().add(ChangeSatiety(4));
|
||||
},
|
||||
onTap: changeSatiety(context, 4),
|
||||
),
|
||||
ScaleElement(
|
||||
color: Colors.green,
|
||||
isSelected: state.selectedSatiety == 5,
|
||||
onTap: () {
|
||||
context.read<DiaryEditBloc>().add(ChangeSatiety(5));
|
||||
},
|
||||
onTap: changeSatiety(context, 5),
|
||||
),
|
||||
Text("😊"),
|
||||
// Остальные элементы шкалы
|
||||
@@ -447,6 +421,45 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
));
|
||||
}
|
||||
|
||||
changeSatiety(BuildContext context, int satiety) {
|
||||
return () {
|
||||
context.read<DiaryEditBloc>().add(ChangeSatiety(satiety));
|
||||
};
|
||||
}
|
||||
|
||||
selectProduct(AutocompleteOnSelected<String> 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<DiaryEditBloc>().add(ProductInput(value));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
buildOptions(List<String> _options) {
|
||||
return (TextEditingValue textEditingValue) {
|
||||
return _options.where((String option) {
|
||||
return true;
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
changeMeal(BuildContext context, DiaryEditLoadedState state) {
|
||||
return (value) {
|
||||
context
|
||||
.read<DiaryEditBloc>()
|
||||
.add(ChangeMeal(meals: state.meals, value: value));
|
||||
};
|
||||
}
|
||||
|
||||
_buildProduct(BuildContext context, Map<String, dynamic> portion) {
|
||||
return Container(
|
||||
margin: EdgeInsets.symmetric(horizontal: 10.h),
|
||||
@@ -485,11 +498,7 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
),
|
||||
Spacer(),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
context
|
||||
.read<DiaryEditBloc>()
|
||||
.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<String, dynamic> portion) {
|
||||
return () {
|
||||
context.read<DiaryEditBloc>().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<DiaryEditBloc>(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<DiaryEditBloc>(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<DiaryEditBloc>(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<DiaryEditBloc>().add(ChangeMood(0));
|
||||
},
|
||||
onTap: changeMood(context, 0),
|
||||
),
|
||||
ScaleElement(
|
||||
color: Colors.orange,
|
||||
isSelected: state.selectedMood == 1,
|
||||
onTap: () {
|
||||
context.read<DiaryEditBloc>().add(ChangeMood(1));
|
||||
},
|
||||
onTap: changeMood(context, 1),
|
||||
),
|
||||
ScaleElement(
|
||||
color: Colors.yellow,
|
||||
isSelected: state.selectedMood == 2,
|
||||
onTap: () {
|
||||
context.read<DiaryEditBloc>().add(ChangeMood(2));
|
||||
},
|
||||
onTap: changeMood(context, 2),
|
||||
),
|
||||
ScaleElement(
|
||||
color: Colors.lime,
|
||||
isSelected: state.selectedMood == 3,
|
||||
onTap: () {
|
||||
context.read<DiaryEditBloc>().add(ChangeMood(3));
|
||||
},
|
||||
onTap: changeMood(context, 3),
|
||||
),
|
||||
ScaleElement(
|
||||
color: Colors.lightGreen,
|
||||
isSelected: state.selectedMood == 4,
|
||||
onTap: () {
|
||||
context.read<DiaryEditBloc>().add(ChangeMood(4));
|
||||
},
|
||||
onTap: changeMood(context, 4),
|
||||
),
|
||||
ScaleElement(
|
||||
color: Colors.green,
|
||||
isSelected: state.selectedMood == 5,
|
||||
onTap: () {
|
||||
context.read<DiaryEditBloc>().add(ChangeMood(5));
|
||||
},
|
||||
onTap: changeMood(context, 5),
|
||||
),
|
||||
Text("😊"),
|
||||
// Остальные элементы шкалы
|
||||
@@ -971,6 +974,18 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
]));
|
||||
}
|
||||
|
||||
changeMood(BuildContext context, int satiety) {
|
||||
return () {
|
||||
context.read<DiaryEditBloc>().add(ChangeMood(satiety));
|
||||
};
|
||||
}
|
||||
|
||||
toggleMood(BuildContext context) {
|
||||
return () {
|
||||
BlocProvider.of<DiaryEditBloc>(context).add(ToggleMoodExpandedEvent());
|
||||
};
|
||||
}
|
||||
|
||||
Future<void> _selectWakeupTime(
|
||||
BuildContext context, DiaryEditLoadedState state) async {
|
||||
final TimeOfDay? pickedTime = await showTimePicker(
|
||||
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user