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

View File

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