Long press on plan list to delete a plan
This commit is contained in:
parent
cbb2e2c4b0
commit
4aa6926f5c
61
lib/plan_list.dart
Normal file
61
lib/plan_list.dart
Normal file
|
@ -0,0 +1,61 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:fmassive/database.dart';
|
||||
import 'package:fmassive/edit_plan.dart';
|
||||
import 'package:fmassive/main.dart';
|
||||
import 'package:moor_flutter/moor_flutter.dart';
|
||||
|
||||
class PlanList extends StatelessWidget {
|
||||
const PlanList({
|
||||
super.key,
|
||||
required this.plans,
|
||||
});
|
||||
|
||||
final List<Plan> plans;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListView.builder(
|
||||
itemCount: plans.length,
|
||||
itemBuilder: (context, index) {
|
||||
return ListTile(
|
||||
title: Text(plans[index].days.replaceAll(',', ', ')),
|
||||
subtitle: Text(plans[index].exercises),
|
||||
onLongPress: () => showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('Delete set'),
|
||||
content: Text(
|
||||
'Are you sure you want to delete ${plans[index].days}?'),
|
||||
actions: <Widget>[
|
||||
ElevatedButton(
|
||||
child: const Text('Cancel'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
ElevatedButton(
|
||||
child: const Text('Delete'),
|
||||
onPressed: () async {
|
||||
final navigator = Navigator.of(context);
|
||||
await db.plans.deleteOne(plans[index]);
|
||||
navigator.pop();
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
onTap: () async {
|
||||
await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
EditPlanPage(plan: plans[index].toCompanion(false)),
|
||||
),
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:fmassive/database.dart';
|
||||
import 'package:fmassive/edit_plan.dart';
|
||||
import 'package:fmassive/main.dart';
|
||||
import 'package:fmassive/plan_list.dart';
|
||||
import 'package:moor/moor.dart';
|
||||
|
||||
class PlansPage extends StatelessWidget {
|
||||
|
@ -78,23 +79,7 @@ class _PlansPageState extends State<_PlansPage> {
|
|||
if (plans == null)
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
|
||||
return ListView.builder(
|
||||
itemCount: plans.length,
|
||||
itemBuilder: (context, index) {
|
||||
return ListTile(
|
||||
title: Text(plans[index].days.replaceAll(',', ', ')),
|
||||
subtitle: Text(plans[index].exercises),
|
||||
onTap: () async {
|
||||
await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => EditPlanPage(
|
||||
plan: plans[index].toCompanion(false)),
|
||||
),
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
return PlanList(plans: plans);
|
||||
}),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () async {
|
||||
|
|
Loading…
Reference in New Issue
Block a user