forked from eatvio/eatvio_app
internet connection handling
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import 'package:eatvio_app/core/widgets/custom_text_form_field.dart';
|
||||
import 'package:eatvio_app/features/create_diet/presentation/widgets/error_widget.dart';
|
||||
import 'package:eatvio_app/features/recipes/presentation/bloc/create_recipe_cubit/create_recipe_cubit.dart';
|
||||
import 'package:eatvio_app/features/recipes/presentation/bloc/create_recipe_cubit/create_recipe_state.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
@@ -12,7 +14,6 @@ class PortionWidget extends StatefulWidget {
|
||||
|
||||
class _PortionWidgetState extends State<PortionWidget> {
|
||||
late final CreateRecipeCubit createRecipeCubit;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -21,49 +22,86 @@ class _PortionWidgetState extends State<PortionWidget> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Row(
|
||||
return BlocBuilder<CreateRecipeCubit, CreateRecipeState>(
|
||||
buildWhen: (previous, current) =>
|
||||
previous.servingsValidationError != current.servingsValidationError ||
|
||||
previous.energyPerServingValidationError != current.energyPerServingValidationError,
|
||||
builder: (context, state) {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Кол-во порций'),
|
||||
SizedBox(height: 4),
|
||||
CustomTextFormField(
|
||||
hintText: '1',
|
||||
onChanged: (value) {
|
||||
createRecipeCubit.replacePortionsCount(int.parse(value));
|
||||
},
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Кол-во порций'),
|
||||
SizedBox(height: 4),
|
||||
Column(
|
||||
children: [
|
||||
CustomTextFormField(
|
||||
hintText: '1',
|
||||
hasError: state.servingsValidationError != null,
|
||||
textInputType: TextInputType.number,
|
||||
onChanged: (value) {
|
||||
createRecipeCubit.replacePortionsCount(int.parse(value));
|
||||
if (state.servingsValidationError != null) {
|
||||
createRecipeCubit.validateServings();
|
||||
}
|
||||
},
|
||||
),
|
||||
if (state.servingsValidationError != null) ...[
|
||||
SizedBox(height: 4),
|
||||
CustomErrorWidget(
|
||||
error: state.servingsValidationError!,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Ккал в одной порции'),
|
||||
SizedBox(height: 4),
|
||||
CustomTextFormField(
|
||||
hintText: '100',
|
||||
suffixText: 'Ккал',
|
||||
onChanged: (value) {
|
||||
createRecipeCubit.replaceEnegryInPortion(double.parse(value));
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Ккал в одной порции'),
|
||||
SizedBox(height: 4),
|
||||
Column(
|
||||
children: [
|
||||
CustomTextFormField(
|
||||
hintText: '100',
|
||||
hasError: state.energyPerServingValidationError != null,
|
||||
suffixText: 'Ккал',
|
||||
textInputType: TextInputType.numberWithOptions(decimal: true),
|
||||
onChanged: (value) {
|
||||
createRecipeCubit.replaceEnegryInPortion(double.parse(value));
|
||||
if (state.energyPerServingValidationError != null) {
|
||||
createRecipeCubit.validateEnergyPerServing();
|
||||
}
|
||||
},
|
||||
),
|
||||
if (state.energyPerServingValidationError != null) ...[
|
||||
SizedBox(height: 4),
|
||||
CustomErrorWidget(
|
||||
error: state.energyPerServingValidationError!,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user