112 lines
3.5 KiB
Dart
112 lines
3.5 KiB
Dart
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
||
|
import 'package:flutter/material.dart';
|
||
|
|
||
|
class MyRecipesScreen extends StatefulWidget {
|
||
|
const MyRecipesScreen({super.key});
|
||
|
|
||
|
@override
|
||
|
// ignore: library_private_types_in_public_api
|
||
|
_MyRecipesState createState() => _MyRecipesState();
|
||
|
}
|
||
|
|
||
|
class _MyRecipesState extends State<MyRecipesScreen> {
|
||
|
List<dynamic> myRecipes = [];
|
||
|
|
||
|
final db = FirebaseFirestore.instance;
|
||
|
|
||
|
@override
|
||
|
void initState() {
|
||
|
super.initState();
|
||
|
getMyRecipes();
|
||
|
}
|
||
|
|
||
|
Future<void> getMyRecipes() async {
|
||
|
try {
|
||
|
final recipesRef = db.collection('myRecipes');
|
||
|
final snapshot = await recipesRef.get();
|
||
|
final List<QueryDocumentSnapshot> documents = snapshot.docs;
|
||
|
final List<dynamic> recipes =
|
||
|
documents.map((doc) => doc.data()).toList();
|
||
|
setState(() {
|
||
|
myRecipes = recipes;
|
||
|
});
|
||
|
} catch (e) {
|
||
|
print('Error getting favorite recipes: $e');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
return Scaffold(
|
||
|
appBar: AppBar(
|
||
|
title: const Text(
|
||
|
'My Recipes',
|
||
|
style: TextStyle(color: Colors.white),
|
||
|
),
|
||
|
iconTheme: const IconThemeData(color: Colors.white),
|
||
|
),
|
||
|
body: Container(
|
||
|
decoration: const BoxDecoration(
|
||
|
image: DecorationImage(
|
||
|
image: AssetImage('img/background.jpg'),
|
||
|
fit: BoxFit.cover,
|
||
|
),
|
||
|
),
|
||
|
child: ListView.builder(
|
||
|
itemCount: myRecipes.length,
|
||
|
itemBuilder: (BuildContext context, int index) {
|
||
|
final recipe = myRecipes[index];
|
||
|
return Card(
|
||
|
margin: const EdgeInsets.all(10),
|
||
|
color: Colors.orange,
|
||
|
shape: RoundedRectangleBorder(
|
||
|
borderRadius: BorderRadius.circular(10),
|
||
|
),
|
||
|
child: Column(
|
||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||
|
children: [
|
||
|
ClipRRect(
|
||
|
borderRadius: const BorderRadius.only(
|
||
|
topLeft: Radius.circular(10),
|
||
|
topRight: Radius.circular(10),
|
||
|
),
|
||
|
child: Image.network(
|
||
|
recipe['imageUrl'],
|
||
|
height: 200,
|
||
|
width: double.infinity,
|
||
|
fit: BoxFit.cover,
|
||
|
),
|
||
|
),
|
||
|
Padding(
|
||
|
padding: const EdgeInsets.all(8.0),
|
||
|
child: Text(
|
||
|
recipe['label'],
|
||
|
style: const TextStyle(
|
||
|
fontWeight: FontWeight.bold,
|
||
|
fontSize: 16,
|
||
|
color: Colors.white),
|
||
|
),
|
||
|
),
|
||
|
Padding(
|
||
|
padding: const EdgeInsets.all(8.0),
|
||
|
child: Column(
|
||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||
|
children: [
|
||
|
for (var i = 0; i < recipe['ingredientLines'].length; i++)
|
||
|
Text(
|
||
|
'${i + 1}. ${recipe['ingredientLines'][i]}',
|
||
|
style: const TextStyle(
|
||
|
fontSize: 14, color: Colors.white),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
);
|
||
|
},
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
}
|