Split up home page and set list
This commit is contained in:
parent
e834499644
commit
1445c19933
|
@ -1,14 +1,10 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:fmassive/best_page.dart';
|
import 'package:fmassive/best_page.dart';
|
||||||
import 'package:fmassive/database.dart';
|
|
||||||
import 'package:fmassive/edit_set.dart';
|
|
||||||
import 'package:fmassive/main.dart';
|
|
||||||
import 'package:fmassive/plans_page.dart';
|
import 'package:fmassive/plans_page.dart';
|
||||||
import 'package:fmassive/settings_page.dart';
|
import 'package:fmassive/settings_page.dart';
|
||||||
import 'package:fmassive/timer_page.dart';
|
import 'package:fmassive/timer_page.dart';
|
||||||
import 'package:fmassive/workouts_page.dart';
|
import 'package:fmassive/workouts_page.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:fmassive/set_list.dart';
|
||||||
import 'package:moor_flutter/moor_flutter.dart';
|
|
||||||
|
|
||||||
class HomePage extends StatefulWidget {
|
class HomePage extends StatefulWidget {
|
||||||
const HomePage({super.key});
|
const HomePage({super.key});
|
||||||
|
@ -53,7 +49,7 @@ class RootPage extends State<HomePage> {
|
||||||
case 'Plans':
|
case 'Plans':
|
||||||
return PlansPage(search: search);
|
return PlansPage(search: search);
|
||||||
default:
|
default:
|
||||||
return _HomePageWidget(search: search);
|
return SetList(search: search);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,92 +103,3 @@ class RootPage extends State<HomePage> {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _HomePageWidget extends StatefulWidget {
|
|
||||||
final String search;
|
|
||||||
|
|
||||||
const _HomePageWidget({Key? key, required this.search}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
createState() => _HomePage();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _HomePage extends State<_HomePageWidget> {
|
|
||||||
bool showSearch = false;
|
|
||||||
late Stream<List<GymSet>> stream;
|
|
||||||
|
|
||||||
@override
|
|
||||||
initState() {
|
|
||||||
super.initState();
|
|
||||||
setStream();
|
|
||||||
}
|
|
||||||
|
|
||||||
void setStream() {
|
|
||||||
stream = (db.select(db.gymSets)
|
|
||||||
..where((gymSet) => gymSet.name.contains(widget.search))
|
|
||||||
..limit(10, offset: 0))
|
|
||||||
.watch();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
didUpdateWidget(covariant _HomePageWidget oldWidget) {
|
|
||||||
super.didUpdateWidget(oldWidget);
|
|
||||||
setStream();
|
|
||||||
}
|
|
||||||
|
|
||||||
void toggleSearch() {
|
|
||||||
setState(() {
|
|
||||||
showSearch = !showSearch;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
body: StreamBuilder<List<GymSet>>(
|
|
||||||
stream: stream,
|
|
||||||
builder: (context, snapshot) {
|
|
||||||
final gymSets = snapshot.data;
|
|
||||||
|
|
||||||
if (gymSets == null)
|
|
||||||
return const Center(child: CircularProgressIndicator());
|
|
||||||
|
|
||||||
return ListView.builder(
|
|
||||||
itemCount: gymSets.length,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
return ListTile(
|
|
||||||
title: Text(gymSets[index].name),
|
|
||||||
subtitle: Text(
|
|
||||||
"${gymSets[index].reps} x ${gymSets[index].weight}kg"),
|
|
||||||
trailing: Text(DateFormat("yyyy-MM-dd")
|
|
||||||
.format(DateTime.parse(gymSets[index].created))),
|
|
||||||
onTap: () async {
|
|
||||||
await Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (context) => EditGymSetPage(
|
|
||||||
gymSet: gymSets[index].toCompanion(false)),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
floatingActionButton: FloatingActionButton(
|
|
||||||
onPressed: () async {
|
|
||||||
await Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (context) => EditGymSetPage(
|
|
||||||
gymSet: GymSetsCompanion(
|
|
||||||
name: const Value(''),
|
|
||||||
reps: const Value(0),
|
|
||||||
weight: const Value(0),
|
|
||||||
image: const Value(''),
|
|
||||||
created: Value(DateTime.now().toString()))),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
child: const Icon(Icons.add)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
95
lib/set_list.dart
Normal file
95
lib/set_list.dart
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:fmassive/database.dart';
|
||||||
|
import 'package:fmassive/edit_set.dart';
|
||||||
|
import 'package:fmassive/main.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:moor_flutter/moor_flutter.dart';
|
||||||
|
|
||||||
|
class SetList extends StatefulWidget {
|
||||||
|
final String search;
|
||||||
|
|
||||||
|
const SetList({Key? key, required this.search}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
createState() => _SetList();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SetList extends State<SetList> {
|
||||||
|
bool showSearch = false;
|
||||||
|
late Stream<List<GymSet>> stream;
|
||||||
|
|
||||||
|
@override
|
||||||
|
initState() {
|
||||||
|
super.initState();
|
||||||
|
setStream();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setStream() {
|
||||||
|
stream = (db.select(db.gymSets)
|
||||||
|
..where((gymSet) => gymSet.name.contains(widget.search))
|
||||||
|
..limit(10, offset: 0))
|
||||||
|
.watch();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
didUpdateWidget(covariant SetList oldWidget) {
|
||||||
|
super.didUpdateWidget(oldWidget);
|
||||||
|
setStream();
|
||||||
|
}
|
||||||
|
|
||||||
|
void toggleSearch() {
|
||||||
|
setState(() {
|
||||||
|
showSearch = !showSearch;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
body: StreamBuilder<List<GymSet>>(
|
||||||
|
stream: stream,
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
final gymSets = snapshot.data;
|
||||||
|
|
||||||
|
if (gymSets == null)
|
||||||
|
return const Center(child: CircularProgressIndicator());
|
||||||
|
|
||||||
|
return ListView.builder(
|
||||||
|
itemCount: gymSets.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
return ListTile(
|
||||||
|
title: Text(gymSets[index].name),
|
||||||
|
subtitle: Text(
|
||||||
|
"${gymSets[index].reps} x ${gymSets[index].weight}kg"),
|
||||||
|
trailing: Text(DateFormat("yyyy-MM-dd")
|
||||||
|
.format(DateTime.parse(gymSets[index].created))),
|
||||||
|
onTap: () async {
|
||||||
|
await Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => EditGymSetPage(
|
||||||
|
gymSet: gymSets[index].toCompanion(false)),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
floatingActionButton: FloatingActionButton(
|
||||||
|
onPressed: () async {
|
||||||
|
await Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => EditGymSetPage(
|
||||||
|
gymSet: GymSetsCompanion(
|
||||||
|
name: const Value(''),
|
||||||
|
reps: const Value(0),
|
||||||
|
weight: const Value(0),
|
||||||
|
image: const Value(''),
|
||||||
|
created: Value(DateTime.now().toString()))),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: const Icon(Icons.add)));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user