Skip to content

Commit

Permalink
Added Navigation to new Edit Recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
Teifun2 committed Aug 14, 2020
1 parent 91aac1f commit 68f4dd9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
3 changes: 1 addition & 2 deletions lib/src/screens/login_page.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';

import 'package:flutter_bloc/flutter_bloc.dart';

import '../blocs/authentication/authentication_bloc.dart';
Expand All @@ -13,7 +12,7 @@ class LoginPage extends StatelessWidget {
appBar: AppBar(
title: Text('Login'),
),
body: BlocProvider(
body: BlocProvider<LoginBloc>(
create: (context) {
return LoginBloc(
authenticationBloc: BlocProvider.of<AuthenticationBloc>(context),
Expand Down
47 changes: 36 additions & 11 deletions lib/src/screens/recipe_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:nextcloud_cookbook_flutter/src/blocs/recipe/recipe.dart';
import 'package:nextcloud_cookbook_flutter/src/models/recipe.dart';
import 'package:nextcloud_cookbook_flutter/src/models/recipe_short.dart';
import 'package:nextcloud_cookbook_flutter/src/screens/recipe_edit_screen.dart';
import 'package:nextcloud_cookbook_flutter/src/widget/authentication_cached_network_image.dart';
import 'package:nextcloud_cookbook_flutter/src/widget/duration_indicator.dart';

Expand All @@ -28,13 +29,34 @@ class RecipeScreenState extends State<RecipeScreen> {

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Recipe"),
),
body: BlocBuilder<RecipeBloc, RecipeState>(
bloc: RecipeBloc()..add(RecipeLoaded(recipeId: recipeShort.recipeId)),
return BlocProvider<RecipeBloc>(
create: (context) =>
RecipeBloc()..add(RecipeLoaded(recipeId: recipeShort.recipeId)),
child: BlocBuilder<RecipeBloc, RecipeState>(
builder: (BuildContext context, RecipeState state) {
final recipeBloc = BlocProvider.of<RecipeBloc>(context);
return Scaffold(
appBar: AppBar(
title: Text("Recipe"),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
if (state is RecipeLoadSuccess) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return BlocProvider.value(
value: recipeBloc,
child: RecipeEditScreen(state.recipe));
},
),
);
}
},
child: Icon(Icons.edit),
),
body: () {
if (state is RecipeLoadSuccess) {
return _buildRecipeScreen(state.recipe);
} else if (state is RecipeLoadInProgress) {
Expand All @@ -50,8 +72,10 @@ class RecipeScreenState extends State<RecipeScreen> {
child: Text("FAILED"),
);
}
},
));
}(),
);
}),
);
}

Widget _buildRecipeScreen(Recipe recipe) {
Expand Down Expand Up @@ -116,19 +140,20 @@ class RecipeScreenState extends State<RecipeScreen> {
),
Padding(
padding: const EdgeInsets.only(bottom: 10.0),
child: Column(
child: Wrap(
alignment: WrapAlignment.center,
runSpacing: 10,
spacing: 10,
children: <Widget>[
(recipe.prepTime != null)
? DurationIndicator(
duration: recipe.prepTime,
name: "Preparation time")
: SizedBox(height: 0),
SizedBox(height: 10),
(recipe.cookTime != null)
? DurationIndicator(
duration: recipe.cookTime, name: "Cooking time")
: SizedBox(height: 0),
SizedBox(height: 10),
(recipe.totalTime != null)
? DurationIndicator(
duration: recipe.totalTime, name: "Total time")
Expand Down

0 comments on commit 68f4dd9

Please sign in to comment.