173 lines
4.5 KiB
Dart
173 lines
4.5 KiB
Dart
|
import 'package:flutter/material.dart';
|
||
|
import 'package:fmassive/edit_set.dart';
|
||
|
|
||
|
class HomePage extends StatelessWidget {
|
||
|
HomePage({super.key});
|
||
|
|
||
|
final List<Map<String, dynamic>> _pageData = [
|
||
|
{'title': 'Home', 'icon': Icons.home},
|
||
|
{'title': 'Plans', 'icon': Icons.calendar_today},
|
||
|
{'title': 'Best', 'icon': Icons.star},
|
||
|
{'title': 'Workouts', 'icon': Icons.fitness_center},
|
||
|
{'title': 'Timer', 'icon': Icons.timer},
|
||
|
{'title': 'Settings', 'icon': Icons.settings},
|
||
|
];
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
return Scaffold(
|
||
|
appBar: AppBar(
|
||
|
title: Text(_pageData[0]['title']),
|
||
|
),
|
||
|
drawer: Drawer(
|
||
|
child: ListView.builder(
|
||
|
itemCount: _pageData.length,
|
||
|
itemBuilder: (context, index) {
|
||
|
return ListTile(
|
||
|
leading: Icon(_pageData[index]['icon']),
|
||
|
title: Text(_pageData[index]['title']),
|
||
|
onTap: () {
|
||
|
Navigator.pop(context);
|
||
|
Navigator.pushNamed(
|
||
|
context, '/${_pageData[index]['title'].toLowerCase()}');
|
||
|
},
|
||
|
);
|
||
|
},
|
||
|
),
|
||
|
),
|
||
|
body: const Center(
|
||
|
child: GymSetPage(),
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class GymSet {
|
||
|
String name;
|
||
|
int reps;
|
||
|
int weight;
|
||
|
DateTime created;
|
||
|
|
||
|
GymSet(
|
||
|
{required this.name,
|
||
|
required this.reps,
|
||
|
required this.weight,
|
||
|
required this.created});
|
||
|
}
|
||
|
|
||
|
class GymSetPage extends StatefulWidget {
|
||
|
const GymSetPage({Key? key}) : super(key: key);
|
||
|
|
||
|
@override
|
||
|
_GymSetPageState createState() => _GymSetPageState();
|
||
|
}
|
||
|
|
||
|
class _GymSetPageState extends State<GymSetPage> {
|
||
|
final List<GymSet> _gymSets = [
|
||
|
GymSet(
|
||
|
name: "Bench press",
|
||
|
reps: 10,
|
||
|
weight: 50,
|
||
|
created: DateTime(2022, 1, 1)),
|
||
|
GymSet(
|
||
|
name: "Bench press",
|
||
|
reps: 8,
|
||
|
weight: 60,
|
||
|
created: DateTime(2022, 1, 2)),
|
||
|
GymSet(
|
||
|
name: "Bench press",
|
||
|
reps: 6,
|
||
|
weight: 70,
|
||
|
created: DateTime(2022, 1, 3)),
|
||
|
GymSet(
|
||
|
name: "Shoulder press",
|
||
|
reps: 12,
|
||
|
weight: 40,
|
||
|
created: DateTime(2022, 1, 4)),
|
||
|
GymSet(
|
||
|
name: "Shoulder press",
|
||
|
reps: 15,
|
||
|
weight: 35,
|
||
|
created: DateTime(2022, 1, 5)),
|
||
|
];
|
||
|
|
||
|
List<GymSet> _searchResults = [];
|
||
|
|
||
|
final TextEditingController _searchController = TextEditingController();
|
||
|
|
||
|
void _searchGymSets(String searchQuery) {
|
||
|
List<GymSet> results = [];
|
||
|
|
||
|
if (searchQuery.isEmpty) {
|
||
|
results = _gymSets;
|
||
|
} else {
|
||
|
for (int i = 0; i < _gymSets.length; i++) {
|
||
|
if (_gymSets[i].reps.toString().contains(searchQuery) ||
|
||
|
_gymSets[i].weight.toString().contains(searchQuery) ||
|
||
|
_gymSets[i].created.toString().contains(searchQuery) ||
|
||
|
_gymSets[i].name.contains(searchQuery)) {
|
||
|
results.add(_gymSets[i]);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
setState(() {
|
||
|
_searchResults = results;
|
||
|
});
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
void initState() {
|
||
|
super.initState();
|
||
|
|
||
|
// Initialize the search results to all the gym sets
|
||
|
_searchResults = _gymSets;
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
return Scaffold(
|
||
|
appBar: AppBar(
|
||
|
automaticallyImplyLeading: false,
|
||
|
title: TextField(
|
||
|
controller: _searchController,
|
||
|
decoration: const InputDecoration(
|
||
|
hintText: 'Search Gym Sets',
|
||
|
border: InputBorder.none,
|
||
|
),
|
||
|
onChanged: (searchQuery) {
|
||
|
_searchGymSets(searchQuery);
|
||
|
},
|
||
|
),
|
||
|
),
|
||
|
body: ListView.builder(
|
||
|
itemCount: _searchResults.length,
|
||
|
itemBuilder: (context, index) {
|
||
|
return ListTile(
|
||
|
title: Text(
|
||
|
'${_searchResults[index].name}: ${_searchResults[index].reps}x${_searchResults[index].weight}kg'),
|
||
|
onTap: () {
|
||
|
Navigator.push(
|
||
|
context,
|
||
|
MaterialPageRoute(
|
||
|
builder: (context) =>
|
||
|
EditGymSetPage(gymSet: _searchResults[index]),
|
||
|
),
|
||
|
);
|
||
|
});
|
||
|
},
|
||
|
),
|
||
|
floatingActionButton: FloatingActionButton(
|
||
|
onPressed: () {
|
||
|
Navigator.push(
|
||
|
context,
|
||
|
MaterialPageRoute(
|
||
|
builder: (context) =>
|
||
|
EditGymSetPage(gymSet: _searchResults[0]),
|
||
|
),
|
||
|
);
|
||
|
},
|
||
|
child: const Icon(Icons.add)));
|
||
|
}
|
||
|
}
|