kochkomplize/lib/recipesoverview.dart

48 lines
1.7 KiB
Dart
Raw Permalink Normal View History

import 'package:flutter/material.dart';
import 'package:firebase_database/firebase_database.dart';
import 'menu_content.dart';
import 'recipedetailpage.dart';
class RecipesOverview implements MenuContent {
@override
Widget build(BuildContext context) {
return StreamBuilder(
stream: FirebaseDatabase.instance.ref('rezepte').onValue,
builder: (context, AsyncSnapshot<DatabaseEvent> snapshot) {
if (snapshot.hasData && !snapshot.hasError && snapshot.data!.snapshot.value != null) {
Map<dynamic, dynamic> recipes = snapshot.data!.snapshot.value as Map<dynamic, dynamic>;
return ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: recipes.length,
itemBuilder: (BuildContext context, int index) {
String key = recipes.keys.elementAt(index);
var value = recipes[key];
return GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => RecipeDetailPage(recipeId: key, recipe: const {},),
),
);
},
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Image.network(value["bild1"], width: 100, height: 100),
Text(value["titel"]),
],
),
),
);
},
);
} else {
return const Center(child: CircularProgressIndicator());
}
},
);
}
}