Split up routes
This commit is contained in:
parent
5584f44b92
commit
03eaa16842
1
.vim/coc-settings.json
Normal file
1
.vim/coc-settings.json
Normal file
|
@ -0,0 +1 @@
|
|||
{}
|
17
lib/best_page.dart
Normal file
17
lib/best_page.dart
Normal file
|
@ -0,0 +1,17 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
class BestPage extends StatelessWidget {
|
||||
const BestPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Best'),
|
||||
),
|
||||
body: const Center(
|
||||
child: Text('Welcome to the Best Page!'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
86
lib/edit_set.dart
Normal file
86
lib/edit_set.dart
Normal file
|
@ -0,0 +1,86 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:fmassive/home_page.dart';
|
||||
|
||||
class EditGymSetPage extends StatefulWidget {
|
||||
final GymSet gymSet;
|
||||
|
||||
EditGymSetPage({required this.gymSet});
|
||||
|
||||
@override
|
||||
_EditGymSetPageState createState() => _EditGymSetPageState();
|
||||
}
|
||||
|
||||
class _EditGymSetPageState extends State<EditGymSetPage> {
|
||||
final TextEditingController _nameController = TextEditingController();
|
||||
final TextEditingController _repsController = TextEditingController();
|
||||
final TextEditingController _weightController = TextEditingController();
|
||||
|
||||
late GymSet _editedGymSet;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Initialize the edited GymSet object with the values from the input GymSet object
|
||||
_editedGymSet = GymSet(
|
||||
name: widget.gymSet.name,
|
||||
reps: widget.gymSet.reps,
|
||||
weight: widget.gymSet.weight,
|
||||
created: DateTime.now());
|
||||
// Set the text controller values
|
||||
_nameController.text = _editedGymSet.name;
|
||||
_repsController.text = _editedGymSet.reps.toString();
|
||||
_weightController.text = _editedGymSet.weight.toString();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Edit Gym Set'),
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
TextFormField(
|
||||
controller: _nameController,
|
||||
decoration: const InputDecoration(labelText: 'Name'),
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_editedGymSet.name = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
TextFormField(
|
||||
controller: _repsController,
|
||||
decoration: const InputDecoration(labelText: 'Reps'),
|
||||
keyboardType: TextInputType.number,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_editedGymSet.reps = int.tryParse(value) ?? 0;
|
||||
});
|
||||
},
|
||||
),
|
||||
TextFormField(
|
||||
controller: _weightController,
|
||||
decoration: const InputDecoration(labelText: 'Weight (kg)'),
|
||||
keyboardType: TextInputType.number,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_editedGymSet.weight = int.tryParse(value) ?? 0;
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context, _editedGymSet);
|
||||
},
|
||||
child: const Icon(Icons.check),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
172
lib/home_page.dart
Normal file
172
lib/home_page.dart
Normal file
|
@ -0,0 +1,172 @@
|
|||
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)));
|
||||
}
|
||||
}
|
136
lib/main.dart
136
lib/main.dart
|
@ -1,127 +1,45 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:fmassive/best_page.dart';
|
||||
import 'package:fmassive/edit_set.dart';
|
||||
import 'package:fmassive/home_page.dart';
|
||||
import 'package:fmassive/plans_page.dart';
|
||||
import 'package:fmassive/settings_page.dart';
|
||||
import 'package:fmassive/timer_page.dart';
|
||||
import 'package:fmassive/workouts_page.dart';
|
||||
|
||||
void main() {
|
||||
runApp(MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
MyApp({Key? key}) : super(key: key);
|
||||
|
||||
final navigatorKey = GlobalKey<NavigatorState>();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final edit = EditGymSetPage(
|
||||
gymSet: GymSet(name: '', reps: 0, weight: 0, created: DateTime.now()));
|
||||
|
||||
final Map<String, WidgetBuilder> routes = {
|
||||
'/home': (context) => HomePage(),
|
||||
'/plans': (context) => const PlansPage(),
|
||||
'/best': (context) => const BestPage(),
|
||||
'/workouts': (context) => const WorkoutsPage(),
|
||||
'/timer': (context) => const TimerPage(),
|
||||
'/settings': (context) => const SettingsPage(),
|
||||
'/edit-set': (context) => edit,
|
||||
};
|
||||
|
||||
return MaterialApp(
|
||||
title: 'Gym App',
|
||||
theme: ThemeData(
|
||||
primarySwatch: Colors.blue,
|
||||
visualDensity: VisualDensity.adaptivePlatformDensity,
|
||||
),
|
||||
home: HomePage(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class HomePage extends StatelessWidget {
|
||||
final List<String> _pageTitles = [
|
||||
'Home',
|
||||
'Plans',
|
||||
'Best',
|
||||
'Workouts',
|
||||
'Timer',
|
||||
'Settings'
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(_pageTitles[0]),
|
||||
),
|
||||
drawer: Drawer(
|
||||
child: ListView.builder(
|
||||
itemCount: _pageTitles.length,
|
||||
itemBuilder: (context, index) {
|
||||
return ListTile(
|
||||
title: Text(_pageTitles[index]),
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
Navigator.pushNamed(
|
||||
context, '/${_pageTitles[index].toLowerCase()}');
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
body: Center(
|
||||
child: Text('Welcome to the Home Page!'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class PlansPage extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Plans'),
|
||||
),
|
||||
body: Center(
|
||||
child: Text('Welcome to the Plans Page!'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class BestPage extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Best'),
|
||||
),
|
||||
body: Center(
|
||||
child: Text('Welcome to the Best Page!'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class WorkoutsPage extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Workouts'),
|
||||
),
|
||||
body: Center(
|
||||
child: Text('Welcome to the Workouts Page!'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TimerPage extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Timer'),
|
||||
),
|
||||
body: Center(
|
||||
child: Text('Welcome to the Timer Page!'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class SettingsPage extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Settings'),
|
||||
),
|
||||
body: Center(
|
||||
child: Text('Welcome to the Settings Page!'),
|
||||
),
|
||||
initialRoute: '/home',
|
||||
routes: routes,
|
||||
navigatorKey: navigatorKey,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
17
lib/plans_page.dart
Normal file
17
lib/plans_page.dart
Normal file
|
@ -0,0 +1,17 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
class PlansPage extends StatelessWidget {
|
||||
const PlansPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Plans'),
|
||||
),
|
||||
body: const Center(
|
||||
child: Text('Welcome to the Plans Page!'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
17
lib/settings_page.dart
Normal file
17
lib/settings_page.dart
Normal file
|
@ -0,0 +1,17 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
class SettingsPage extends StatelessWidget {
|
||||
const SettingsPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Settings'),
|
||||
),
|
||||
body: const Center(
|
||||
child: Text('Welcome to the Settings Page!'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
17
lib/timer_page.dart
Normal file
17
lib/timer_page.dart
Normal file
|
@ -0,0 +1,17 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
class TimerPage extends StatelessWidget {
|
||||
const TimerPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Timer'),
|
||||
),
|
||||
body: const Center(
|
||||
child: Text('Welcome to the Timer Page!'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
17
lib/workouts_page.dart
Normal file
17
lib/workouts_page.dart
Normal file
|
@ -0,0 +1,17 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
class WorkoutsPage extends StatelessWidget {
|
||||
const WorkoutsPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Workouts'),
|
||||
),
|
||||
body: const Center(
|
||||
child: Text('Welcome to the Workouts Page!'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -7,13 +7,12 @@
|
|||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'package:fmassive/main.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
||||
// Build our app and trigger a frame.
|
||||
await tester.pumpWidget(const MyApp());
|
||||
await tester.pumpWidget(MyApp());
|
||||
|
||||
// Verify that our counter starts at 0.
|
||||
expect(find.text('0'), findsOneWidget);
|
||||
|
|
Loading…
Reference in New Issue
Block a user