mirror of
https://github.com/wger-project/flutter.git
synced 2026-12-02 10:09:11 +01:00
Add dropdown menu to nutrition detail page
This commit is contained in:
@@ -21,8 +21,16 @@ import 'package:provider/provider.dart';
|
||||
import 'package:wger/locale/locales.dart';
|
||||
import 'package:wger/models/nutrition/nutritional_plan.dart';
|
||||
import 'package:wger/providers/nutrition.dart';
|
||||
import 'package:wger/widgets/core/bottom_sheet.dart';
|
||||
import 'package:wger/widgets/nutrition/forms.dart';
|
||||
import 'package:wger/widgets/nutrition/nutritional_plan_detail.dart';
|
||||
|
||||
enum NutritionalPlanOptions {
|
||||
edit,
|
||||
delete,
|
||||
toggleMode,
|
||||
}
|
||||
|
||||
class NutritionalPlanScreen extends StatefulWidget {
|
||||
static const routeName = '/nutritional-plan-detail';
|
||||
|
||||
@@ -38,27 +46,39 @@ class _NutritionalPlanScreenState extends State<NutritionalPlanScreen> {
|
||||
return plan;
|
||||
}
|
||||
|
||||
Widget getAppBar() {
|
||||
Widget getAppBar(NutritionalPlan plan) {
|
||||
return AppBar(
|
||||
title: Text(AppLocalizations.of(context).nutritionalPlan),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: Icon(Icons.menu),
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
content: Text("Would open options"),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text(
|
||||
"Cancel",
|
||||
),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
],
|
||||
PopupMenuButton<NutritionalPlanOptions>(
|
||||
icon: Icon(Icons.more_vert),
|
||||
onSelected: (value) {
|
||||
// Edit
|
||||
if (value == NutritionalPlanOptions.edit) {
|
||||
showFormBottomSheet(
|
||||
context,
|
||||
AppLocalizations.of(context).edit,
|
||||
PlanForm(plan),
|
||||
);
|
||||
|
||||
// Delete
|
||||
} else if (value == NutritionalPlanOptions.delete) {
|
||||
Provider.of<Nutrition>(context, listen: false).deletePlan(plan.id);
|
||||
Navigator.of(context).pushNamed(NutritionalPlanScreen.routeName);
|
||||
}
|
||||
},
|
||||
itemBuilder: (BuildContext context) {
|
||||
return [
|
||||
PopupMenuItem<NutritionalPlanOptions>(
|
||||
value: NutritionalPlanOptions.edit,
|
||||
child: Text(AppLocalizations.of(context).edit),
|
||||
),
|
||||
);
|
||||
const PopupMenuDivider(),
|
||||
PopupMenuItem<NutritionalPlanOptions>(
|
||||
value: NutritionalPlanOptions.delete,
|
||||
child: Text(AppLocalizations.of(context).delete),
|
||||
),
|
||||
];
|
||||
},
|
||||
),
|
||||
],
|
||||
@@ -70,7 +90,7 @@ class _NutritionalPlanScreenState extends State<NutritionalPlanScreen> {
|
||||
final nutritionalPlan = ModalRoute.of(context).settings.arguments as NutritionalPlan;
|
||||
|
||||
return Scaffold(
|
||||
appBar: getAppBar(),
|
||||
appBar: getAppBar(nutritionalPlan),
|
||||
//drawer: AppDrawer(),
|
||||
body: FutureBuilder<NutritionalPlan>(
|
||||
future: _loadNutritionalPlanDetail(context, nutritionalPlan.id),
|
||||
|
||||
@@ -53,16 +53,6 @@ class NutritionalPlanDetailWidget extends StatelessWidget {
|
||||
style: Theme.of(context).textTheme.headline6,
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.edit),
|
||||
onPressed: () {
|
||||
showFormBottomSheet(
|
||||
context,
|
||||
AppLocalizations.of(context).edit,
|
||||
PlanForm(_nutritionalPlan),
|
||||
);
|
||||
},
|
||||
),
|
||||
if (_nutritionalPlan.meals.length > 0)
|
||||
..._nutritionalPlan.meals.map((meal) => MealWidget(meal)).toList(),
|
||||
ElevatedButton(
|
||||
|
||||
Reference in New Issue
Block a user