@@ -21,6 +21,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
21
21
import 'package:intl/intl.dart' ;
22
22
import 'package:wger/providers/nutrition.dart' ;
23
23
import 'package:wger/screens/nutritional_plan_screen.dart' ;
24
+ import 'package:wger/widgets/core/text_prompt.dart' ;
24
25
25
26
class NutritionalPlansList extends StatelessWidget {
26
27
final NutritionPlansProvider _nutritionProvider;
@@ -31,87 +32,89 @@ class NutritionalPlansList extends StatelessWidget {
31
32
Widget build (BuildContext context) {
32
33
return RefreshIndicator (
33
34
onRefresh: () => _nutritionProvider.fetchAndSetAllPlansSparse (),
34
- child: ListView .builder (
35
- padding: const EdgeInsets .all (10.0 ),
36
- itemCount: _nutritionProvider.items.length,
37
- itemBuilder: (context, index) {
38
- final currentPlan = _nutritionProvider.items[index];
39
- return Dismissible (
40
- key: Key (currentPlan.id.toString ()),
41
- confirmDismiss: (direction) async {
42
- // Delete workout from DB
43
- final bool ? res = await showDialog (
44
- context: context,
45
- builder: (BuildContext contextDialog) {
46
- return AlertDialog (
47
- content: Text (
48
- AppLocalizations .of (context).confirmDelete (currentPlan.description),
49
- ),
50
- actions: [
51
- TextButton (
52
- child: Text (MaterialLocalizations .of (context).cancelButtonLabel),
53
- onPressed: () => Navigator .of (contextDialog).pop (),
54
- ),
55
- TextButton (
56
- child: Text (
57
- AppLocalizations .of (context).delete,
58
- style: TextStyle (color: Theme .of (context).errorColor),
59
- ),
60
- onPressed: () {
61
- // Confirmed, delete the workout
62
- _nutritionProvider.deletePlan (currentPlan.id! );
35
+ child: _nutritionProvider.items.length == 0
36
+ ? TextPrompt ()
37
+ : ListView .builder (
38
+ padding: const EdgeInsets .all (10.0 ),
39
+ itemCount: _nutritionProvider.items.length,
40
+ itemBuilder: (context, index) {
41
+ final currentPlan = _nutritionProvider.items[index];
42
+ return Dismissible (
43
+ key: Key (currentPlan.id.toString ()),
44
+ confirmDismiss: (direction) async {
45
+ // Delete workout from DB
46
+ final bool ? res = await showDialog (
47
+ context: context,
48
+ builder: (BuildContext contextDialog) {
49
+ return AlertDialog (
50
+ content: Text (
51
+ AppLocalizations .of (context).confirmDelete (currentPlan.description),
52
+ ),
53
+ actions: [
54
+ TextButton (
55
+ child: Text (MaterialLocalizations .of (context).cancelButtonLabel),
56
+ onPressed: () => Navigator .of (contextDialog).pop (),
57
+ ),
58
+ TextButton (
59
+ child: Text (
60
+ AppLocalizations .of (context).delete,
61
+ style: TextStyle (color: Theme .of (context).errorColor),
62
+ ),
63
+ onPressed: () {
64
+ // Confirmed, delete the workout
65
+ _nutritionProvider.deletePlan (currentPlan.id! );
63
66
64
- // Close the popup
65
- Navigator .of (contextDialog).pop ();
67
+ // Close the popup
68
+ Navigator .of (contextDialog).pop ();
66
69
67
- // and inform the user
68
- ScaffoldMessenger .of (context).showSnackBar (
69
- SnackBar (
70
- content: Text (
71
- AppLocalizations .of (context).successfullyDeleted,
72
- textAlign: TextAlign .center,
73
- ),
70
+ // and inform the user
71
+ ScaffoldMessenger .of (context).showSnackBar (
72
+ SnackBar (
73
+ content: Text (
74
+ AppLocalizations .of (context).successfullyDeleted,
75
+ textAlign: TextAlign .center,
76
+ ),
77
+ ),
78
+ );
79
+ },
74
80
),
75
- );
76
- },
77
- ),
78
- ],
79
- );
80
- });
81
- return res;
82
- } ,
83
- background : Container (
84
- color : Theme . of (context).errorColor,
85
- alignment : Alignment .centerRight ,
86
- padding : const EdgeInsets . only (right : 20 ) ,
87
- margin : const EdgeInsets . symmetric (
88
- horizontal : 4 ,
89
- vertical : 4 ,
90
- ) ,
91
- child : const Icon (
92
- Icons .delete ,
93
- color : Colors .white ,
94
- ),
95
- ),
96
- direction : DismissDirection .endToStart,
97
- child : Card (
98
- child : ListTile (
99
- onTap : () {
100
- Navigator . of (context). pushNamed (
101
- NutritionalPlanScreen .routeName ,
102
- arguments : currentPlan,
103
- );
104
- },
105
- title : Text (currentPlan.getLabel (context) ),
106
- subtitle : Text (
107
- DateFormat . yMd ( Localizations . localeOf (context).languageCode)
108
- . format (currentPlan.creationDate ),
109
- ),
110
- ) ,
81
+ ],
82
+ );
83
+ });
84
+ return res;
85
+ },
86
+ background : Container (
87
+ color : Theme . of (context).errorColor,
88
+ alignment : Alignment .centerRight ,
89
+ padding : const EdgeInsets . only (right : 20 ),
90
+ margin : const EdgeInsets . symmetric (
91
+ horizontal : 4 ,
92
+ vertical : 4 ,
93
+ ),
94
+ child : const Icon (
95
+ Icons .delete ,
96
+ color : Colors .white ,
97
+ ),
98
+ ) ,
99
+ direction : DismissDirection .endToStart ,
100
+ child : Card (
101
+ child : ListTile (
102
+ onTap : () {
103
+ Navigator . of (context). pushNamed (
104
+ NutritionalPlanScreen .routeName,
105
+ arguments : currentPlan,
106
+ );
107
+ } ,
108
+ title : Text ( currentPlan. getLabel (context)) ,
109
+ subtitle : Text (
110
+ DateFormat . yMd ( Localizations . localeOf (context).languageCode)
111
+ . format (currentPlan.creationDate ),
112
+ ),
113
+ ),
114
+ ),
115
+ );
116
+ } ,
111
117
),
112
- );
113
- },
114
- ),
115
118
);
116
119
}
117
120
}
0 commit comments