fmassive/lib/plan_list.dart

73 lines
2.5 KiB
Dart

import 'package:flutter/material.dart';
import 'package:fmassive/constants.dart';
import 'package:fmassive/database.dart';
import 'package:fmassive/edit_plan.dart';
import 'package:fmassive/main.dart';
import 'package:fmassive/start_plan.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) {
final weekday = weekdayNames[DateTime.now().weekday - 1];
return ListView.builder(
itemCount: plans.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(plans[index].days.replaceAll(',', ', '),
style: TextStyle(
fontWeight: plans[index].days.contains(weekday)
? FontWeight.bold
: null,
decoration: plans[index].days.contains(weekday)
? TextDecoration.underline
: null)),
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) =>
StartPlan(plan: plans[index].toCompanion(false)),
),
);
});
},
);
}
}