62 lines
2.0 KiB
Dart
62 lines
2.0 KiB
Dart
|
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)),
|
||
|
),
|
||
|
);
|
||
|
});
|
||
|
},
|
||
|
);
|
||
|
}
|
||
|
}
|