1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
import 'package:flutter/material.dart';
import 'package:kulinar_app/models/recipe_class.dart';
import 'package:kulinar_app/widgets/error_widgets.dart';
import 'package:kulinar_app/widgets/toastbar_widget.dart';
import 'package:kulinar_app/widgets/recipe_card_widget.dart';
import 'package:kulinar_app/widgets/custom_drawer_widget.dart';
import 'package:kulinar_app/models/data/recipe_data_class.dart';
import 'package:kulinar_app/widgets/recipe_search_delegate.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
class FavoritesView extends StatefulWidget {
const FavoritesView({Key? key}) : super(key: key);
@override
FavoritesViewState createState() => FavoritesViewState();
}
class FavoritesViewState extends State<FavoritesView> {
BuildContext? _toastyContext;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: _buildAppBar(context),
drawer: const CustomDrawer(initialIndex: 1),
body: SizedBox(
width: double.infinity,
child: Builder(
builder: (BuildContext context) {
_toastyContext = context;
return _buildListView();
},
),
),
);
}
void redrawFavoritesView() {
setState(() {});
}
void showToastCallback(String content, String actionLabel, Function actionCallback) {
ToastBar.showToastBar(_toastyContext!, content, actionLabel: actionLabel, actionCallback: actionCallback);
}
PreferredSizeWidget _buildAppBar(BuildContext context) {
return AppBar(
title: Text(AppLocalizations.of(context)!.category4),
actions: [
IconButton(
icon: const Icon(Icons.search),
onPressed: () async {
await showSearch(
context: context,
delegate: FavoriteRecipeSearch(),
);
setState(() {});
},
),
],
);
}
Widget _buildListView() {
List<Recipe> filteredRecipeList = RecipeData.recipeList.where((element) => element.favorite).toList();
if (filteredRecipeList.isEmpty) return const NoContentError();
return ListView.builder(
itemCount: filteredRecipeList.length,
itemBuilder: (context, index) => RecipeCard(
recipe: filteredRecipeList[index],
redrawCallback: redrawFavoritesView,
showToastCallback: showToastCallback,
),
);
}
}
|