108 lines
3.4 KiB
Dart
108 lines
3.4 KiB
Dart
import 'package:cloud_firestore/cloud_firestore.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class FavoritesScreen extends StatefulWidget {
|
|
const FavoritesScreen({super.key});
|
|
|
|
@override
|
|
// ignore: library_private_types_in_public_api
|
|
_FavoritesScreenState createState() => _FavoritesScreenState();
|
|
}
|
|
|
|
class _FavoritesScreenState extends State<FavoritesScreen> {
|
|
List<dynamic> favoriteRecipes = [];
|
|
|
|
final db = FirebaseFirestore.instance;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
getFavoriteRecipes();
|
|
}
|
|
|
|
Future<void> getFavoriteRecipes() async {
|
|
final recipesRef = db.collection('recipes');
|
|
final snapshot = await recipesRef.get();
|
|
final List<QueryDocumentSnapshot> documents = snapshot.docs;
|
|
final List<dynamic> recipes =
|
|
documents.map((doc) => doc.data()).toList();
|
|
setState(() {
|
|
favoriteRecipes = recipes;
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text(
|
|
'Favorites',
|
|
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: favoriteRecipes.length,
|
|
itemBuilder: (BuildContext context, int index) {
|
|
final recipe = favoriteRecipes[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),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
);
|
|
}
|
|
} |