2023-04-07 11:50:02 +12:00
|
|
|
import 'package:flutter/material.dart';
|
2023-04-11 11:41:10 +12:00
|
|
|
import 'package:fmassive/database.dart';
|
2023-04-13 18:58:26 +12:00
|
|
|
import 'package:fmassive/edit_plan.dart';
|
2023-04-11 11:41:10 +12:00
|
|
|
import 'package:fmassive/main.dart';
|
2023-11-11 15:24:57 +13:00
|
|
|
import 'package:fmassive/plan_list.dart';
|
2023-04-11 11:41:10 +12:00
|
|
|
import 'package:moor/moor.dart';
|
2023-04-07 11:50:02 +12:00
|
|
|
|
|
|
|
class PlansPage extends StatelessWidget {
|
2023-04-13 18:58:26 +12:00
|
|
|
const PlansPage({super.key, required this.search});
|
|
|
|
|
|
|
|
final String search;
|
2023-04-07 11:50:02 +12:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-04-13 18:58:26 +12:00
|
|
|
return Scaffold(
|
2023-04-11 11:41:10 +12:00
|
|
|
body: Center(
|
2023-04-13 18:58:26 +12:00
|
|
|
child: _PlansPage(search: search),
|
2023-04-07 11:50:02 +12:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2023-04-11 11:41:10 +12:00
|
|
|
|
|
|
|
class _PlansPage extends StatefulWidget {
|
2023-11-29 13:01:11 +13:00
|
|
|
const _PlansPage({required this.search});
|
2023-04-13 18:58:26 +12:00
|
|
|
|
|
|
|
final String search;
|
2023-04-11 11:41:10 +12:00
|
|
|
|
|
|
|
@override
|
|
|
|
createState() => _PlansPageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _PlansPageState extends State<_PlansPage> {
|
2023-04-13 18:58:26 +12:00
|
|
|
bool showSearch = false;
|
|
|
|
late Stream<List<Plan>> stream;
|
2023-04-11 11:41:10 +12:00
|
|
|
|
2023-04-13 18:58:26 +12:00
|
|
|
@override
|
|
|
|
initState() {
|
|
|
|
super.initState();
|
|
|
|
setStream();
|
|
|
|
}
|
2023-04-11 11:41:10 +12:00
|
|
|
|
2023-04-13 18:58:26 +12:00
|
|
|
void setStream() {
|
|
|
|
stream = (db.select(db.plans)
|
|
|
|
..where((gymSet) => gymSet.days.contains(widget.search))
|
|
|
|
..limit(10, offset: 0))
|
|
|
|
.watch();
|
2023-04-11 11:41:10 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2023-04-13 18:58:26 +12:00
|
|
|
didUpdateWidget(covariant _PlansPage oldWidget) {
|
|
|
|
super.didUpdateWidget(oldWidget);
|
|
|
|
setStream();
|
|
|
|
}
|
|
|
|
|
|
|
|
void toggleSearch() {
|
|
|
|
setState(() {
|
|
|
|
showSearch = !showSearch;
|
|
|
|
});
|
2023-04-11 11:41:10 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
2023-04-13 18:58:26 +12:00
|
|
|
body: StreamBuilder<List<Plan>>(
|
|
|
|
stream: stream,
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
final plans = snapshot.data;
|
2023-04-11 11:41:10 +12:00
|
|
|
|
2023-11-11 14:53:38 +13:00
|
|
|
if (snapshot.hasError)
|
|
|
|
return Center(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
child: Text(
|
|
|
|
'Error: ${snapshot.error}',
|
|
|
|
style: Theme.of(context).textTheme.headlineSmall,
|
2023-11-30 13:02:50 +13:00
|
|
|
),),
|
2023-11-11 14:53:38 +13:00
|
|
|
);
|
|
|
|
|
2023-11-30 10:37:50 +13:00
|
|
|
if (plans == null) return Container();
|
2023-04-11 11:41:10 +12:00
|
|
|
|
2023-11-11 15:24:57 +13:00
|
|
|
return PlanList(plans: plans);
|
2023-11-30 13:02:50 +13:00
|
|
|
},),
|
2023-04-13 18:58:26 +12:00
|
|
|
floatingActionButton: FloatingActionButton(
|
|
|
|
onPressed: () async {
|
|
|
|
await Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (context) => const EditPlanPage(
|
2023-11-10 23:43:06 +13:00
|
|
|
plan: PlansCompanion(
|
2023-11-30 13:02:50 +13:00
|
|
|
days: Value(''), exercises: Value(''),),),
|
2023-04-13 18:58:26 +12:00
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
2023-11-30 13:02:50 +13:00
|
|
|
child: const Icon(Icons.add),),);
|
2023-04-11 11:41:10 +12:00
|
|
|
}
|
|
|
|
}
|