Remove edit button from start_plan
This just messes up our navigation stack too much and makes it confusing when you go backwards.
This commit is contained in:
parent
a9486727b2
commit
6908623ba2
|
@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/material.dart' as material;
|
import 'package:flutter/material.dart' as material;
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:fmassive/database.dart';
|
import 'package:fmassive/database.dart';
|
||||||
import 'package:fmassive/edit_plan.dart';
|
|
||||||
import 'package:fmassive/main.dart';
|
import 'package:fmassive/main.dart';
|
||||||
import 'package:moor_flutter/moor_flutter.dart';
|
import 'package:moor_flutter/moor_flutter.dart';
|
||||||
|
|
||||||
|
@ -30,11 +29,15 @@ class _StartPlanState extends State<StartPlan> {
|
||||||
..addColumns([db.gymSets.name, db.gymSets.sets])
|
..addColumns([db.gymSets.name, db.gymSets.sets])
|
||||||
..where(db.gymSets.name.isIn(exercises))
|
..where(db.gymSets.name.isIn(exercises))
|
||||||
..groupBy([db.gymSets.name, db.gymSets.sets]))
|
..groupBy([db.gymSets.name, db.gymSets.sets]))
|
||||||
.map((row) =>
|
.map(
|
||||||
MapEntry(row.read(db.gymSets.name), row.read(db.gymSets.sets)),)
|
(row) =>
|
||||||
|
MapEntry(row.read(db.gymSets.name), row.read(db.gymSets.sets)),
|
||||||
|
)
|
||||||
.get();
|
.get();
|
||||||
final map = Map.fromIterables(
|
final map = Map.fromIterables(
|
||||||
query.map((entry) => entry.key), query.map((entry) => entry.value),);
|
query.map((entry) => entry.key),
|
||||||
|
query.map((entry) => entry.value),
|
||||||
|
);
|
||||||
setState(() {
|
setState(() {
|
||||||
totals = [];
|
totals = [];
|
||||||
for (var exercise in exercises) {
|
for (var exercise in exercises) {
|
||||||
|
@ -54,7 +57,9 @@ class _StartPlanState extends State<StartPlan> {
|
||||||
.map((row) => MapEntry(row.read(db.gymSets.name), row.read(countExp)))
|
.map((row) => MapEntry(row.read(db.gymSets.name), row.read(countExp)))
|
||||||
.get();
|
.get();
|
||||||
final map = Map.fromIterables(
|
final map = Map.fromIterables(
|
||||||
query.map((entry) => entry.key), query.map((entry) => entry.value),);
|
query.map((entry) => entry.key),
|
||||||
|
query.map((entry) => entry.value),
|
||||||
|
);
|
||||||
setState(() {
|
setState(() {
|
||||||
counts = [];
|
counts = [];
|
||||||
for (var exercise in exercises) {
|
for (var exercise in exercises) {
|
||||||
|
@ -76,7 +81,9 @@ class _StartPlanState extends State<StartPlan> {
|
||||||
final firstSet = sets.first;
|
final firstSet = sets.first;
|
||||||
repsController.text = firstSet.reps.toString();
|
repsController.text = firstSet.reps.toString();
|
||||||
repsController.selection = TextSelection(
|
repsController.selection = TextSelection(
|
||||||
baseOffset: 0, extentOffset: firstSet.reps.toString().length,);
|
baseOffset: 0,
|
||||||
|
extentOffset: firstSet.reps.toString().length,
|
||||||
|
);
|
||||||
weightController.text = firstSet.weight.toString();
|
weightController.text = firstSet.weight.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,93 +106,86 @@ class _StartPlanState extends State<StartPlan> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
List<Widget> actions = [];
|
|
||||||
if (widget.plan.id.present)
|
|
||||||
actions.add(IconButton(
|
|
||||||
onPressed: () async {
|
|
||||||
await Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (context) => EditPlanPage(plan: widget.plan),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
icon: const Icon(Icons.edit),),);
|
|
||||||
|
|
||||||
if (totals.isEmpty || counts.isEmpty) return Container();
|
if (totals.isEmpty || counts.isEmpty) return Container();
|
||||||
|
|
||||||
return SafeArea(
|
return SafeArea(
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
appBar: AppBar(title: const Text('Start plan'), actions: actions),
|
appBar: AppBar(title: const Text('Start plan')),
|
||||||
body: Padding(
|
body: Padding(
|
||||||
padding: const EdgeInsets.all(16.0),
|
padding: const EdgeInsets.all(16.0),
|
||||||
child: material.Column(
|
child: material.Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
itemBuilder: ((context, index) {
|
itemBuilder: ((context, index) {
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(exercises[index]),
|
title: Text(exercises[index]),
|
||||||
subtitle: Text("${counts[index]}/${totals[index]}"),
|
subtitle: Text("${counts[index]}/${totals[index]}"),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
setState(() {
|
|
||||||
selectedExercise = index;
|
|
||||||
focus(index);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
leading: Radio<int>(
|
|
||||||
value: index,
|
|
||||||
groupValue: selectedExercise,
|
|
||||||
onChanged: (value) {
|
|
||||||
print("onChanged $value");
|
|
||||||
if (value == null) return;
|
|
||||||
setState(() {
|
setState(() {
|
||||||
selectedExercise = value;
|
selectedExercise = index;
|
||||||
focus(index);
|
focus(index);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
leading: Radio<int>(
|
||||||
);
|
value: index,
|
||||||
}),
|
groupValue: selectedExercise,
|
||||||
itemCount: exercises.length,
|
onChanged: (value) {
|
||||||
|
print("onChanged $value");
|
||||||
|
if (value == null) return;
|
||||||
|
setState(() {
|
||||||
|
selectedExercise = value;
|
||||||
|
focus(index);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
itemCount: exercises.length,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
TextFormField(
|
||||||
TextFormField(
|
decoration: const InputDecoration(labelText: 'Reps'),
|
||||||
decoration: const InputDecoration(labelText: 'Reps'),
|
controller: repsController,
|
||||||
controller: repsController,
|
focusNode: repsNode,
|
||||||
focusNode: repsNode,
|
onTap: () {
|
||||||
onTap: () {
|
repsController.selection = TextSelection(
|
||||||
repsController.selection = TextSelection(
|
baseOffset: 0,
|
||||||
baseOffset: 0, extentOffset: repsController.text.length,);
|
extentOffset: repsController.text.length,
|
||||||
},
|
);
|
||||||
),
|
},
|
||||||
TextFormField(
|
),
|
||||||
decoration: const InputDecoration(labelText: 'Weight'),
|
TextFormField(
|
||||||
controller: weightController,
|
decoration: const InputDecoration(labelText: 'Weight'),
|
||||||
focusNode: weightNode,
|
controller: weightController,
|
||||||
onTap: () {
|
focusNode: weightNode,
|
||||||
weightController.selection = TextSelection(
|
onTap: () {
|
||||||
baseOffset: 0, extentOffset: weightController.text.length,);
|
weightController.selection = TextSelection(
|
||||||
},
|
baseOffset: 0,
|
||||||
),
|
extentOffset: weightController.text.length,
|
||||||
],
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
floatingActionButton: FloatingActionButton(
|
||||||
floatingActionButton: FloatingActionButton(
|
onPressed: () async {
|
||||||
onPressed: () async {
|
final gymSet = GymSetsCompanion(
|
||||||
final gymSet = GymSetsCompanion(
|
|
||||||
created: Value(DateTime.now().toIso8601String()),
|
created: Value(DateTime.now().toIso8601String()),
|
||||||
name: Value(exercises[selectedExercise]),
|
name: Value(exercises[selectedExercise]),
|
||||||
reps: Value(int.tryParse(repsController.text) ?? 0),
|
reps: Value(int.tryParse(repsController.text) ?? 0),
|
||||||
weight: Value(double.tryParse(weightController.text) ?? 0),);
|
weight: Value(double.tryParse(weightController.text) ?? 0),
|
||||||
await db.into(db.gymSets).insert(gymSet);
|
);
|
||||||
const platform = MethodChannel('com.massive/android');
|
await db.into(db.gymSets).insert(gymSet);
|
||||||
platform.invokeMethod('timer', [180000]);
|
const platform = MethodChannel('com.massive/android');
|
||||||
await getCounts();
|
platform.invokeMethod('timer', [180000]);
|
||||||
},
|
await getCounts();
|
||||||
child: const Icon(Icons.check),
|
},
|
||||||
|
child: const Icon(Icons.check),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user