142 lines
4.8 KiB
Dart
142 lines
4.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../../services/providers/recipe_provider.dart';
|
|
import '../../src/enums.dart';
|
|
import '../../services/tools.dart' show getEnumValueName;
|
|
import '../../widgets/clearing_dropdown_menu.dart';
|
|
import '../../widgets/cooking_duration_button.dart';
|
|
|
|
class MetadataPage extends StatefulWidget {
|
|
const MetadataPage({super.key});
|
|
|
|
@override
|
|
State<MetadataPage> createState() => _MetadataPageState();
|
|
}
|
|
|
|
class _MetadataPageState extends State<MetadataPage> {
|
|
late RecipeProvider _recipeProvider;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
_recipeProvider = context.watch<RecipeProvider>();
|
|
return Padding(
|
|
padding: const EdgeInsets.fromLTRB(20, 10, 20, 0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
TextField(
|
|
onChanged: (value) => _recipeProvider.updateTitle(value),
|
|
decoration: InputDecoration(
|
|
label: Text('Title'),
|
|
border: OutlineInputBorder(),
|
|
enabledBorder: _recipeProvider.recipe.title.isEmpty
|
|
? OutlineInputBorder(
|
|
borderSide: BorderSide(
|
|
color: Theme.of(context).colorScheme.tertiary,
|
|
),
|
|
)
|
|
: null,
|
|
),
|
|
onSubmitted: (value) => TextInputAction.next,
|
|
),
|
|
Padding(padding: EdgeInsets.only(top: 10)),
|
|
TextField(
|
|
onChanged: (value) => _recipeProvider.updateDescription(value),
|
|
decoration: InputDecoration(
|
|
label: Text('Description'),
|
|
border: OutlineInputBorder(),
|
|
),
|
|
onSubmitted: (value) => TextInputAction.next,
|
|
),
|
|
Padding(padding: EdgeInsets.only(top: 10)),
|
|
TextField(
|
|
onChanged: (value) =>
|
|
_recipeProvider.updateServingSize(int.parse(value)),
|
|
keyboardType: TextInputType.number,
|
|
inputFormatters: [
|
|
FilteringTextInputFormatter.allow(RegExp(r'\d')),
|
|
],
|
|
maxLength: 2,
|
|
decoration: InputDecoration(
|
|
label: Text('Serving Size'),
|
|
border: OutlineInputBorder(),
|
|
enabledBorder: _recipeProvider.recipe.servingSize == 0
|
|
? OutlineInputBorder(
|
|
borderSide: BorderSide(
|
|
color: Theme.of(context).colorScheme.tertiary,
|
|
),
|
|
)
|
|
: null,
|
|
),
|
|
onSubmitted: (value) => TextInputAction.next,
|
|
),
|
|
Padding(padding: EdgeInsets.only(top: 10)),
|
|
DropdownMenu(
|
|
enableFilter: false,
|
|
enableSearch: false,
|
|
requestFocusOnTap: false,
|
|
label: Text('Difficulty'),
|
|
dropdownMenuEntries:
|
|
getDropdownMenuEntriesFromEnum(Difficulty.values),
|
|
onSelected: _recipeProvider.updateDifficulty,
|
|
),
|
|
Padding(padding: EdgeInsets.only(top: 10)),
|
|
ClearingDropdownMenu(
|
|
entries: getDropdownMenuEntriesFromEnum(MealCategory.values),
|
|
label: 'Category',
|
|
onSelected: _recipeProvider.updateMealCategory,
|
|
),
|
|
Padding(padding: EdgeInsets.only(top: 10)),
|
|
ClearingDropdownMenu(
|
|
entries: getDropdownMenuEntriesFromEnum(Cuisine.values),
|
|
label: 'Cuisine',
|
|
onSelected: _recipeProvider.updateCuisine,
|
|
),
|
|
Padding(padding: EdgeInsets.only(top: 10)),
|
|
Row(
|
|
children: [
|
|
Text(
|
|
'Prep Time',
|
|
style: Theme.of(context).textTheme.titleMedium,
|
|
),
|
|
Padding(padding: EdgeInsets.only(left: 10)),
|
|
CookingDurationButton(
|
|
selectedDuration: _recipeProvider.recipe.prepTime,
|
|
onDurationChanged: _recipeProvider.updatePrepTime,
|
|
),
|
|
],
|
|
),
|
|
Padding(padding: EdgeInsets.only(top: 10)),
|
|
Row(
|
|
children: [
|
|
Text(
|
|
'Cooking Time',
|
|
style: Theme.of(context).textTheme.titleMedium,
|
|
),
|
|
Padding(padding: EdgeInsets.only(left: 10)),
|
|
CookingDurationButton(
|
|
selectedDuration: _recipeProvider.recipe.cookTime,
|
|
onDurationChanged: _recipeProvider.updateCookTime,
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
List<DropdownMenuEntry<T>> getDropdownMenuEntriesFromEnum<T extends Enum>(
|
|
List<T> values) {
|
|
return values
|
|
.map(
|
|
(e) => DropdownMenuEntry(
|
|
value: e,
|
|
label: getEnumValueName(e),
|
|
),
|
|
)
|
|
.toList();
|
|
}
|
|
}
|