From f87505fc79280d03aef826c5a075143555809ebd Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Sat, 28 Nov 2020 12:03:18 +0100 Subject: [PATCH] Make workout day header dismissible, with placeholder actions --- lib/screens/workout_plan_screen.dart | 23 +---- lib/widgets/workouts/day.dart | 144 +++++++++++++++++++++++---- 2 files changed, 127 insertions(+), 40 deletions(-) diff --git a/lib/screens/workout_plan_screen.dart b/lib/screens/workout_plan_screen.dart index f2a4b3f99..6b0b59522 100644 --- a/lib/screens/workout_plan_screen.dart +++ b/lib/screens/workout_plan_screen.dart @@ -24,12 +24,12 @@ class _WorkoutPlanScreenState extends State { title: Text(AppLocalizations.of(context).labelWorkoutPlan), actions: [ IconButton( - icon: Icon(Icons.bar_chart), + icon: Icon(Icons.menu), onPressed: () { showDialog( context: context, builder: (context) => AlertDialog( - content: Text("Would open weight log form"), + content: Text("Would open options"), actions: [ TextButton( child: Text( @@ -53,25 +53,6 @@ class _WorkoutPlanScreenState extends State { return Scaffold( appBar: getAppBar(), //drawer: AppDrawer(), - floatingActionButton: FloatingActionButton( - child: const Icon(Icons.play_arrow), - onPressed: () { - showDialog( - context: context, - builder: (context) => AlertDialog( - content: Text("Would start gym mode"), - actions: [ - TextButton( - child: Text( - "Cancel", - ), - onPressed: () => Navigator.of(context).pop(), - ), - ], - ), - ); - }, - ), body: FutureBuilder( future: _loadWorkoutPlanDetail(context, workoutPlan.id), builder: (context, AsyncSnapshot snapshot) => diff --git a/lib/widgets/workouts/day.dart b/lib/widgets/workouts/day.dart index ceab9355e..889cca918 100644 --- a/lib/widgets/workouts/day.dart +++ b/lib/widgets/workouts/day.dart @@ -1,3 +1,19 @@ +/* + * This file is part of wger Workout Manager. + * + * wger Workout Manager is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * wger Workout Manager is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + */ + import 'package:flutter/material.dart'; import 'package:wger/locale/locales.dart'; import 'package:wger/models/workouts/day.dart'; @@ -64,20 +80,7 @@ class WorkoutDayWidget extends StatelessWidget { return Card( child: Column( children: [ - Container( - decoration: BoxDecoration(color: Colors.black12), - padding: const EdgeInsets.symmetric(vertical: 10), - width: double.infinity, - child: Column( - children: [ - Text( - _day.description, - style: Theme.of(context).textTheme.headline6, - ), - Text(_day.getDaysText), - ], - ), - ), + DayHeaderDismissible(day: _day), ..._day.sets .map( (set) => getSetRow(set), @@ -87,11 +90,11 @@ class WorkoutDayWidget extends StatelessWidget { child: Text('Add exercise to day'), onPressed: () { showModalBottomSheet( - context: context, - builder: (BuildContext context) { - return SetFormWidget( - formKey: _formKey, exercisesController: exercisesController); - }); + context: context, + builder: (BuildContext context) { + return SetFormWidget(formKey: _formKey, exercisesController: exercisesController); + }, + ); }, ), Padding( @@ -103,6 +106,109 @@ class WorkoutDayWidget extends StatelessWidget { } } +class DayHeaderDismissible extends StatelessWidget { + const DayHeaderDismissible({ + Key key, + @required Day day, + }) : _day = day, + super(key: key); + + final Day _day; + + @override + Widget build(BuildContext context) { + return Dismissible( + key: Key(_day.id.toString()), + child: Container( + decoration: BoxDecoration(color: Colors.black12), + padding: const EdgeInsets.symmetric(vertical: 10), + width: double.infinity, + child: Column( + children: [ + Text( + _day.description, + style: Theme.of(context).textTheme.headline6, + ), + Text(_day.getDaysText), + ], + ), + ), + secondaryBackground: Container( + color: Theme.of(context).primaryColor, + padding: EdgeInsets.only(right: 10), + child: Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Icon( + Icons.bar_chart, + color: Colors.white, + ), + Text( + 'Log weights', + style: TextStyle(color: Colors.white), + ), + ], + ), + ), + background: Container( + color: Theme.of(context).accentColor, + alignment: Alignment.centerLeft, + padding: EdgeInsets.only(left: 10), + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Text( + 'Gym mode', + style: TextStyle(color: Colors.white), + ), + Icon( + Icons.play_arrow, + color: Colors.white, + ), + ], + ), + ), + confirmDismiss: (direction) async { + // Weight log + if (direction == DismissDirection.endToStart) { + showDialog( + context: context, + builder: (context) => AlertDialog( + content: Text('Would open weight log form for this day'), + actions: [ + TextButton( + child: Text( + "Close", + ), + onPressed: () => Navigator.of(context).pop(), + ), + ], + ), + ); + + // Gym mode + } else { + showDialog( + context: context, + builder: (context) => AlertDialog( + content: Text('Would start gym mode for this day'), + actions: [ + TextButton( + child: Text( + "Close", + ), + onPressed: () => Navigator.of(context).pop(), + ), + ], + ), + ); + } + return false; + }, + ); + } +} + class SetFormWidget extends StatefulWidget { const SetFormWidget({ Key key,