Added fields to metadata page
This commit is contained in:
@@ -1,12 +1,182 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
class MetadataPage extends StatelessWidget {
|
import '../../services/providers/recipe_provider.dart';
|
||||||
|
import '../../src/enums.dart';
|
||||||
|
import '../../services/tools.dart'
|
||||||
|
show getEnumValueName, durationToFormattedString;
|
||||||
|
import '../../widgets/duration_picker.dart';
|
||||||
|
|
||||||
|
class MetadataPage extends StatefulWidget {
|
||||||
const MetadataPage({super.key});
|
const MetadataPage({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<MetadataPage> createState() => _MetadataPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _MetadataPageState extends State<MetadataPage> {
|
||||||
|
late RecipeProvider _recipeProvider;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return const Center(
|
_recipeProvider = context.watch<RecipeProvider>();
|
||||||
child: Text('Metadata'),
|
return Center(
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
TextField(
|
||||||
|
decoration: InputDecoration(
|
||||||
|
label: Text('Title'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
TextField(
|
||||||
|
decoration: InputDecoration(
|
||||||
|
label: Text('Description'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
DropdownButton(
|
||||||
|
value: _recipeProvider.recipe.difficulty,
|
||||||
|
items: Difficulty.values
|
||||||
|
.map(
|
||||||
|
(e) => DropdownMenuItem<Difficulty>(
|
||||||
|
value: e,
|
||||||
|
child: Text(getEnumValueName(e)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.toList(),
|
||||||
|
onChanged: (value) => setState(() {
|
||||||
|
_recipeProvider.updateDifficulty(value ?? Difficulty.notSelected);
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
DropdownMenu(
|
||||||
|
dropdownMenuEntries:
|
||||||
|
getDropdownMenuEntriesFromEnum(MealCategory.values),
|
||||||
|
enableFilter: true,
|
||||||
|
label: Text('Category'),
|
||||||
|
),
|
||||||
|
DropdownMenu(
|
||||||
|
dropdownMenuEntries: getDropdownMenuEntriesFromEnum(Cuisine.values),
|
||||||
|
enableFilter: true,
|
||||||
|
label: Text('Cuisine'),
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Text('Preparation time'),
|
||||||
|
_recipeProvider.recipe.prepTime.inMinutes == 0
|
||||||
|
? IconButton(
|
||||||
|
onPressed: () => showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) => _getDurationDialog(
|
||||||
|
context,
|
||||||
|
_recipeProvider.updatePrepTime,
|
||||||
|
_recipeProvider.recipe.prepTime),
|
||||||
|
),
|
||||||
|
icon: Icon(Icons.add),
|
||||||
|
)
|
||||||
|
: TextButton(
|
||||||
|
onPressed: () => showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) => _getDurationDialog(
|
||||||
|
context,
|
||||||
|
_recipeProvider.updatePrepTime,
|
||||||
|
_recipeProvider.recipe.prepTime),
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
durationToFormattedString(
|
||||||
|
_recipeProvider.recipe.prepTime),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Text('Cooking time'),
|
||||||
|
_recipeProvider.recipe.prepTime.inMinutes == 0
|
||||||
|
? IconButton(
|
||||||
|
onPressed: () => showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) => _getDurationDialog(
|
||||||
|
context,
|
||||||
|
_recipeProvider.updateCookTime,
|
||||||
|
_recipeProvider.recipe.cookTime),
|
||||||
|
),
|
||||||
|
icon: Icon(Icons.add),
|
||||||
|
)
|
||||||
|
: TextButton(
|
||||||
|
onPressed: () => showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) => _getDurationDialog(
|
||||||
|
context,
|
||||||
|
_recipeProvider.updateCookTime,
|
||||||
|
_recipeProvider.recipe.cookTime),
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
durationToFormattedString(
|
||||||
|
_recipeProvider.recipe.cookTime),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Text('Total Time'),
|
||||||
|
Padding(padding: EdgeInsets.only(left: 10)),
|
||||||
|
Text(durationToFormattedString(_recipeProvider.recipe.totalTime)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<DropdownMenuEntry<T>> getDropdownMenuEntriesFromEnum<T extends Enum>(
|
||||||
|
List<T> values) {
|
||||||
|
return values
|
||||||
|
.map(
|
||||||
|
(e) => DropdownMenuEntry(
|
||||||
|
value: e,
|
||||||
|
label: getEnumValueName(e),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
Dialog _getDurationDialog(
|
||||||
|
BuildContext context,
|
||||||
|
void Function(Duration duration) update,
|
||||||
|
Duration initialDuration,
|
||||||
|
) {
|
||||||
|
final width = MediaQuery.of(context).size.width * 0.8;
|
||||||
|
final height = MediaQuery.of(context).size.height * 0.6;
|
||||||
|
Duration selectedTime = initialDuration;
|
||||||
|
return Dialog(
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
DurationPicker(
|
||||||
|
initialDuration: initialDuration,
|
||||||
|
onChangedCallback: (duration) => selectedTime = duration,
|
||||||
|
height: width * 1.25 > height ? height : width * 1.25,
|
||||||
|
width: width,
|
||||||
|
),
|
||||||
|
Align(
|
||||||
|
alignment: Alignment.bottomRight,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(0, 20, 20, 20),
|
||||||
|
child: FloatingActionButton.extended(
|
||||||
|
label: Text('Save'),
|
||||||
|
icon: Icon(Icons.save),
|
||||||
|
onPressed: () {
|
||||||
|
update(selectedTime);
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user