Update gym_mode.dart

Added focusNode property to close the keyboard when user press on save button
This commit is contained in:
Khushbu Bora
2021-08-10 13:54:53 +05:30
committed by GitHub
parent 5f496bca80
commit d323f9eda4

View File

@@ -88,8 +88,8 @@ class _GymModeState extends State<GymMode> {
for (var set in widget._workoutDay.sets) {
var firstPage = true;
for (var setting in set.settingsComputed) {
final exercise =
Provider.of<ExercisesProvider>(context, listen: false).findById(setting.exerciseId);
final exercise = Provider.of<ExercisesProvider>(context, listen: false)
.findById(setting.exerciseId);
if (firstPage) {
_exercisePages[exercise.name] = currentPage;
@@ -108,8 +108,10 @@ class _GymModeState extends State<GymMode> {
// Returns the list of exercise overview, sets and pause pages
List<Widget> getContent() {
final exerciseProvider = Provider.of<ExercisesProvider>(context, listen: false);
final workoutProvider = Provider.of<WorkoutPlansProvider>(context, listen: false);
final exerciseProvider =
Provider.of<ExercisesProvider>(context, listen: false);
final workoutProvider =
Provider.of<WorkoutPlansProvider>(context, listen: false);
var currentElement = 1;
List<Widget> out = [];
@@ -200,7 +202,10 @@ class StartPage extends StatelessWidget {
s.exerciseObj.name,
style: Theme.of(context).textTheme.headline6,
),
...set.getSmartRepr(s.exerciseObj).map((e) => Text(e)).toList(),
...set
.getSmartRepr(s.exerciseObj)
.map((e) => Text(e))
.toList(),
SizedBox(height: 15),
],
);
@@ -215,7 +220,8 @@ class StartPage extends StatelessWidget {
ElevatedButton(
child: Text(AppLocalizations.of(context).start),
onPressed: () {
_controller.nextPage(duration: Duration(milliseconds: 200), curve: Curves.bounceIn);
_controller.nextPage(
duration: Duration(milliseconds: 200), curve: Curves.bounceIn);
},
),
NavigationFooter(
@@ -266,6 +272,8 @@ class _LogPageState extends State<LogPage> {
final _weightController = TextEditingController();
var _detailed = false;
FocusNode focusNode = new FocusNode();
@override
void initState() {
super.initState();
@@ -304,9 +312,11 @@ class _LogPageState extends State<LogPage> {
enabled: true,
controller: _repsController,
keyboardType: TextInputType.number,
focusNode: focusNode,
onFieldSubmitted: (_) {},
onSaved: (newValue) {
widget._log.reps = int.parse(newValue!);
focusNode.unfocus();
},
validator: (value) {
try {
@@ -345,7 +355,8 @@ class _LogPageState extends State<LogPage> {
),
onPressed: () {
try {
double newValue = double.parse(_weightController.text) - (2 * minPlateWeight);
double newValue =
double.parse(_weightController.text) - (2 * minPlateWeight);
if (newValue > 0) {
setState(() {
widget._log.weight = newValue;
@@ -393,7 +404,8 @@ class _LogPageState extends State<LogPage> {
),
onPressed: () {
try {
double newValue = double.parse(_weightController.text) + (2 * minPlateWeight);
double newValue =
double.parse(_weightController.text) + (2 * minPlateWeight);
setState(() {
widget._log.weight = newValue;
_weightController.text = newValue.toString();
@@ -464,7 +476,8 @@ class _LogPageState extends State<LogPage> {
// Save the entry on the server
try {
await Provider.of<WorkoutPlansProvider>(context, listen: false).addLog(widget._log);
await Provider.of<WorkoutPlansProvider>(context, listen: false)
.addLog(widget._log);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
duration: Duration(seconds: 2), // default is 4
@@ -498,11 +511,14 @@ class _LogPageState extends State<LogPage> {
style: Theme.of(context).textTheme.headline6,
textAlign: TextAlign.center,
),
...widget._workoutPlan.filterLogsByExercise(widget._exercise, unique: true).map((log) {
...widget._workoutPlan
.filterLogsByExercise(widget._exercise, unique: true)
.map((log) {
return ListTile(
title: Text(log.singleLogRepTextNoNl),
subtitle:
Text(DateFormat.yMd(Localizations.localeOf(context).languageCode).format(log.date)),
subtitle: Text(
DateFormat.yMd(Localizations.localeOf(context).languageCode)
.format(log.date)),
trailing: Icon(Icons.copy),
onTap: () {
setState(() {
@@ -555,7 +571,8 @@ class _LogPageState extends State<LogPage> {
shape: BoxShape.circle,
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 3),
padding:
const EdgeInsets.symmetric(horizontal: 3),
child: SizedBox(
height: 35,
width: 35,
@@ -563,7 +580,8 @@ class _LogPageState extends State<LogPage> {
alignment: Alignment.center,
child: Text(
key.toString(),
style: TextStyle(fontWeight: FontWeight.bold),
style: TextStyle(
fontWeight: FontWeight.bold),
),
),
),
@@ -576,7 +594,8 @@ class _LogPageState extends State<LogPage> {
.toList()
],
)
: MutedText(AppLocalizations.of(context).plateCalculatorNotDivisible),
: MutedText(
AppLocalizations.of(context).plateCalculatorNotDivisible),
),
SizedBox(height: 3),
],
@@ -606,11 +625,16 @@ class _LogPageState extends State<LogPage> {
),
SizedBox(height: 10),
Expanded(
child: (widget._workoutPlan.filterLogsByExercise(widget._exercise).length > 0)
child: (widget._workoutPlan
.filterLogsByExercise(widget._exercise)
.length >
0)
? getPastLogs()
: Container()),
// Only show calculator for barbell
if (widget._log.exerciseObj.equipment.map((e) => e.id).contains(ID_EQUIPMENT_BARBELL))
if (widget._log.exerciseObj.equipment
.map((e) => e.id)
.contains(ID_EQUIPMENT_BARBELL))
getPlates(),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 15),
@@ -671,7 +695,9 @@ class ExerciseOverview extends StatelessWidget {
child: ListView(
scrollDirection: Axis.horizontal,
children: [
..._exercise.images.map((e) => ExerciseImageWidget(image: e)).toList(),
..._exercise.images
.map((e) => ExerciseImageWidget(image: e))
.toList(),
],
),
),
@@ -797,7 +823,8 @@ class _SessionPageState extends State<SessionPage> {
onFieldSubmitted: (_) {},
onTap: () async {
// Stop keyboard from appearing
FocusScope.of(context).requestFocus(new FocusNode());
FocusScope.of(context)
.requestFocus(new FocusNode());
// Open time picker
var pickedTime = await showTimePicker(
@@ -806,17 +833,21 @@ class _SessionPageState extends State<SessionPage> {
);
if (pickedTime != null) {
timeStartController.text = timeToString(pickedTime)!;
timeStartController.text =
timeToString(pickedTime)!;
}
},
onSaved: (newValue) {
_session.timeStart = stringToTime(newValue);
},
validator: (_) {
TimeOfDay startTime = stringToTime(timeStartController.text);
TimeOfDay endTime = stringToTime(timeEndController.text);
TimeOfDay startTime =
stringToTime(timeStartController.text);
TimeOfDay endTime =
stringToTime(timeEndController.text);
if (startTime.isAfter(endTime)) {
return AppLocalizations.of(context).timeStartAhead;
return AppLocalizations.of(context)
.timeStartAhead;
}
return null;
}),
@@ -824,8 +855,8 @@ class _SessionPageState extends State<SessionPage> {
SizedBox(width: 10),
Flexible(
child: TextFormField(
decoration:
InputDecoration(labelText: AppLocalizations.of(context).timeEnd),
decoration: InputDecoration(
labelText: AppLocalizations.of(context).timeEnd),
controller: timeEndController,
onFieldSubmitted: (_) {},
onTap: () async {
@@ -859,7 +890,8 @@ class _SessionPageState extends State<SessionPage> {
// Save the entry on the server
try {
await Provider.of<WorkoutPlansProvider>(context, listen: false)
await Provider.of<WorkoutPlansProvider>(context,
listen: false)
.addSession(_session);
Navigator.of(context).pop();
} on WgerHttpException catch (error) {
@@ -952,7 +984,10 @@ class _TimerWidgetState extends State<TimerWidget> {
child: Center(
child: Text(
DateFormat('m:ss').format(today.add(Duration(seconds: _seconds))),
style: Theme.of(context).textTheme.headline1!.copyWith(color: wgerPrimaryColor),
style: Theme.of(context)
.textTheme
.headline1!
.copyWith(color: wgerPrimaryColor),
),
),
),