implemented provider in screens

This commit is contained in:
SomnusVeritas
2023-10-17 22:43:38 +02:00
parent f05d582ff8
commit 3e094bf8f0
2 changed files with 21 additions and 15 deletions

View File

@@ -1,6 +1,8 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:rezepte/widgets/ingredients_bottomsheet.dart'; import 'package:rezepte/widgets/ingredients_bottomsheet.dart';
import '../models/difficulty.dart'; import '../models/difficulty.dart';
import '../services/providers/recipe_provider.dart';
class CreateRecipe extends StatefulWidget { class CreateRecipe extends StatefulWidget {
const CreateRecipe({super.key}); const CreateRecipe({super.key});
@@ -11,14 +13,11 @@ class CreateRecipe extends StatefulWidget {
} }
class _CreateRecipeState extends State<CreateRecipe> { class _CreateRecipeState extends State<CreateRecipe> {
Difficulty? _recipeDifficulty; late RecipeProvider recipeProvider;
TextEditingController titleText = TextEditingController();
TextEditingController descriptionText = TextEditingController();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final width = MediaQuery.of(context).size.width; recipeProvider = Provider.of<RecipeProvider>(context);
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: const Text('Create Recipe'), title: const Text('Create Recipe'),
@@ -27,20 +26,20 @@ class _CreateRecipeState extends State<CreateRecipe> {
child: Column( child: Column(
children: [ children: [
TextFormField( TextFormField(
controller: titleText, onChanged: (value) => recipeProvider.title = value,
decoration: const InputDecoration( decoration: const InputDecoration(
label: Text('Title'), label: Text('Title'),
), ),
), ),
TextFormField( TextFormField(
controller: descriptionText, onChanged: (value) => recipeProvider.description = value,
decoration: const InputDecoration( decoration: const InputDecoration(
label: Text('Description'), label: Text('Description'),
), ),
), ),
DropdownMenu<Difficulty?>( DropdownMenu<Difficulty?>(
dropdownMenuEntries: DifficultyUtil.getDropdownList(), dropdownMenuEntries: DifficultyUtil.getDropdownList(),
onSelected: (value) {}, onSelected: (value) => recipeProvider.difficulty = value,
), ),
ElevatedButton( ElevatedButton(
onPressed: _openIngredientBottomSheet, onPressed: _openIngredientBottomSheet,
@@ -52,10 +51,6 @@ class _CreateRecipeState extends State<CreateRecipe> {
); );
} }
void _onChanged(int index) {
_recipeDifficulty = Difficulty.values.elementAt(index);
}
void _openIngredientBottomSheet() { void _openIngredientBottomSheet() {
showModalBottomSheet( showModalBottomSheet(
context: context, context: context,

View File

@@ -1,8 +1,10 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../constants.dart' as constants; import '../constants.dart' as constants;
import '../models/ingredient.dart'; import '../models/ingredient.dart';
import '../models/unit.dart'; import '../models/unit.dart';
import '../example_data.dart' as ea; import '../example_data.dart' as ea;
import '../services/providers/recipe_provider.dart';
class IngredientsBottomsheet extends StatefulWidget { class IngredientsBottomsheet extends StatefulWidget {
const IngredientsBottomsheet({super.key}); const IngredientsBottomsheet({super.key});
@@ -15,6 +17,7 @@ class _IngredientsBottomsheetState extends State<IngredientsBottomsheet> {
final List<DropdownMenuEntry<Ingredient>> ingredientEntries = []; final List<DropdownMenuEntry<Ingredient>> ingredientEntries = [];
final List<DropdownMenuEntry<Unit>> unitEntries = []; final List<DropdownMenuEntry<Unit>> unitEntries = [];
Unit? selectedUnit; Unit? selectedUnit;
late RecipeProvider recipeProvider;
bool _isOptional = false; bool _isOptional = false;
TextEditingController _ingredientController = TextEditingController(); TextEditingController _ingredientController = TextEditingController();
@@ -136,6 +139,7 @@ class _IngredientsBottomsheetState extends State<IngredientsBottomsheet> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
recipeProvider = Provider.of<RecipeProvider>(context);
return BottomSheet( return BottomSheet(
onClosing: onClosing, onClosing: onClosing,
builder: _bottomSheetContent, builder: _bottomSheetContent,
@@ -143,6 +147,7 @@ class _IngredientsBottomsheetState extends State<IngredientsBottomsheet> {
} }
void _nextTapped() { void _nextTapped() {
_submit();
setState(() { setState(() {
_ingredientController.value = TextEditingValue.empty; _ingredientController.value = TextEditingValue.empty;
_unitController.value = TextEditingValue.empty; _unitController.value = TextEditingValue.empty;
@@ -151,7 +156,13 @@ class _IngredientsBottomsheetState extends State<IngredientsBottomsheet> {
}); });
} }
void _finishTapped() {} void _finishTapped() {
// TODO implement}
void _cancelTapped() {} }
void _cancelTapped() {
// TODO implement}
}
void _submit() {
// TODO implement
}
} }