Factor out plan_tile
This commit is contained in:
parent
fbffc0cf4a
commit
202ec599d6
|
@ -1,10 +1,7 @@
|
|||
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';
|
||||
import 'package:fmassive/plan_tile.dart';
|
||||
|
||||
class PlanList extends StatelessWidget {
|
||||
const PlanList({
|
||||
|
@ -21,51 +18,7 @@ class PlanList extends StatelessWidget {
|
|||
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)),
|
||||
),
|
||||
);
|
||||
});
|
||||
return PlanTile(plan: plans[index], weekday: weekday);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
55
lib/plan_tile.dart
Normal file
55
lib/plan_tile.dart
Normal file
|
@ -0,0 +1,55 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:fmassive/database.dart';
|
||||
import 'package:fmassive/main.dart';
|
||||
import 'package:fmassive/start_plan.dart';
|
||||
import 'package:moor_flutter/moor_flutter.dart';
|
||||
|
||||
class PlanTile extends StatelessWidget {
|
||||
PlanTile({
|
||||
super.key,
|
||||
required this.plan,
|
||||
required this.weekday,
|
||||
});
|
||||
|
||||
final Plan plan;
|
||||
final String weekday;
|
||||
final tapPosition = GlobalKey();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MenuAnchor(
|
||||
menuChildren: [
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
await db.plans.deleteOne(plan);
|
||||
},
|
||||
child: const Text("Delete"),
|
||||
),
|
||||
],
|
||||
builder: (context, controller, child) {
|
||||
return ListTile(
|
||||
title: Text(
|
||||
plan.days.replaceAll(',', ', '),
|
||||
style: TextStyle(
|
||||
fontWeight: plan.days.contains(weekday) ? FontWeight.bold : null,
|
||||
decoration:
|
||||
plan.days.contains(weekday) ? TextDecoration.underline : null,
|
||||
),
|
||||
),
|
||||
subtitle: Text(plan.exercises),
|
||||
onLongPress: () {
|
||||
controller.open();
|
||||
},
|
||||
onTap: () async {
|
||||
await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => StartPlan(plan: plan.toCompanion(false)),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user