From cd4a848b7937927641cfdeb0842cd04d2e8271d7 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Sun, 10 Nov 2024 15:42:35 +0100 Subject: [PATCH] Remove the CustomScrollView This was only needed for the custom scrolling background / header that was removed some time ago --- lib/screens/routine_list_screen.dart | 2 +- lib/screens/routine_logs_screen.dart | 97 ++++----------------- lib/screens/routine_screen.dart | 105 +++-------------------- lib/widgets/core/progress_indicator.dart | 15 ++++ lib/widgets/routines/app_bar.dart | 91 ++++++++++++++++++-- 5 files changed, 128 insertions(+), 182 deletions(-) create mode 100644 lib/widgets/core/progress_indicator.dart diff --git a/lib/screens/routine_list_screen.dart b/lib/screens/routine_list_screen.dart index ee39edda..25703fb4 100644 --- a/lib/screens/routine_list_screen.dart +++ b/lib/screens/routine_list_screen.dart @@ -34,7 +34,7 @@ class RoutineListScreen extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( - appBar: const WorkoutOverviewAppBar(), + appBar: const RoutineListAppBar(), floatingActionButton: FloatingActionButton( onPressed: () { Navigator.pushNamed( diff --git a/lib/screens/routine_logs_screen.dart b/lib/screens/routine_logs_screen.dart index 4d6aa7df..08e7750f 100644 --- a/lib/screens/routine_logs_screen.dart +++ b/lib/screens/routine_logs_screen.dart @@ -17,20 +17,12 @@ */ import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:provider/provider.dart'; import 'package:wger/models/workouts/routine.dart'; import 'package:wger/providers/routines.dart'; -import 'package:wger/screens/form_screen.dart'; -import 'package:wger/theme/theme.dart'; -import 'package:wger/widgets/routines/forms.dart'; +import 'package:wger/widgets/routines/app_bar.dart'; import 'package:wger/widgets/routines/workout_logs.dart'; -enum WorkoutOptions { - edit, - delete, -} - class WorkoutLogsScreen extends StatelessWidget { const WorkoutLogsScreen(); @@ -43,82 +35,25 @@ class WorkoutLogsScreen extends StatelessWidget { @override Widget build(BuildContext context) { - const appBarForeground = Colors.white; final routine = ModalRoute.of(context)!.settings.arguments as Routine; return Scaffold( - body: CustomScrollView( - slivers: [ - SliverAppBar( - pinned: true, - iconTheme: const IconThemeData(color: appBarForeground), - backgroundColor: wgerPrimaryColor, - flexibleSpace: FlexibleSpaceBar( - titlePadding: const EdgeInsets.fromLTRB(56, 0, 56, 16), - title: Text( - routine.name, - style: Theme.of(context).textTheme.titleLarge?.copyWith(color: appBarForeground), + appBar: RoutineDetailAppBar(routine), + body: FutureBuilder( + future: _loadFullWorkout(context, routine.id!), + builder: (context, AsyncSnapshot snapshot) => ListView( + children: [ + if (snapshot.connectionState == ConnectionState.waiting) + const SizedBox( + height: 200, + child: Center(child: CircularProgressIndicator()), + ) + else + Consumer( + builder: (context, value, child) => WorkoutLogs(routine), ), - ), - actions: [ - PopupMenuButton( - icon: const Icon(Icons.more_vert, color: appBarForeground), - onSelected: (value) { - // Edit - if (value == WorkoutOptions.edit) { - Navigator.pushNamed( - context, - FormScreen.routeName, - arguments: FormScreenArguments( - AppLocalizations.of(context).edit, - WorkoutForm(routine), - ), - ); - - // Delete - } else if (value == WorkoutOptions.delete) { - Provider.of(context, listen: false) - .deleteWorkout(routine.id!); - Navigator.of(context).pop(); - - // Toggle Mode - } - }, - itemBuilder: (BuildContext context) { - return [ - PopupMenuItem( - value: WorkoutOptions.edit, - child: Text(AppLocalizations.of(context).edit), - ), - const PopupMenuDivider(), - PopupMenuItem( - value: WorkoutOptions.delete, - child: Text(AppLocalizations.of(context).delete), - ), - ]; - }, - ), - ], - ), - FutureBuilder( - future: _loadFullWorkout(context, routine.id!), - builder: (context, AsyncSnapshot snapshot) => SliverList( - delegate: SliverChildListDelegate( - [ - if (snapshot.connectionState == ConnectionState.waiting) - const SizedBox( - height: 200, - child: Center(child: CircularProgressIndicator()), - ) - else - Consumer( - builder: (context, value, child) => WorkoutLogs(routine), - ), - ], - ), - ), - ), - ], + ], + ), ), ); } diff --git a/lib/screens/routine_screen.dart b/lib/screens/routine_screen.dart index 5f8800e3..3a08c166 100644 --- a/lib/screens/routine_screen.dart +++ b/lib/screens/routine_screen.dart @@ -17,22 +17,13 @@ */ import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:provider/provider.dart'; import 'package:wger/models/workouts/routine.dart'; import 'package:wger/providers/routines.dart'; -import 'package:wger/screens/form_screen.dart'; -import 'package:wger/screens/routine_logs_screen.dart'; -import 'package:wger/theme/theme.dart'; -import 'package:wger/widgets/routines/forms.dart'; +import 'package:wger/widgets/core/progress_indicator.dart'; +import 'package:wger/widgets/routines/app_bar.dart'; import 'package:wger/widgets/routines/routine_detail.dart'; -enum WorkoutOptions { - edit, - delete, - logs, -} - class RoutineScreen extends StatelessWidget { const RoutineScreen(); @@ -45,90 +36,22 @@ class RoutineScreen extends StatelessWidget { @override Widget build(BuildContext context) { - const appBarForeground = Colors.white; final routine = ModalRoute.of(context)!.settings.arguments as Routine; return Scaffold( - body: CustomScrollView( - slivers: [ - SliverAppBar( - pinned: true, - iconTheme: const IconThemeData(color: appBarForeground), - backgroundColor: wgerPrimaryColor, - flexibleSpace: FlexibleSpaceBar( - titlePadding: const EdgeInsets.fromLTRB(56, 0, 56, 16), - title: Text( - routine.name, - style: Theme.of(context).textTheme.titleLarge?.copyWith(color: appBarForeground), + appBar: RoutineDetailAppBar(routine), + body: FutureBuilder( + future: _loadFullWorkout(context, routine.id!), + builder: (context, AsyncSnapshot snapshot) => ListView( + children: [ + if (snapshot.connectionState == ConnectionState.waiting) + const BoxedProgressIndicator() + else + Consumer( + builder: (context, value, child) => RoutineDetail(routine), ), - ), - actions: [ - PopupMenuButton( - icon: const Icon(Icons.more_vert, color: appBarForeground), - onSelected: (value) { - switch (value) { - case WorkoutOptions.edit: - Navigator.pushNamed( - context, - FormScreen.routeName, - arguments: FormScreenArguments( - AppLocalizations.of(context).edit, - WorkoutForm(routine), - ), - ); - - case WorkoutOptions.logs: - Navigator.pushNamed( - context, - WorkoutLogsScreen.routeName, - arguments: routine, - ); - - case WorkoutOptions.delete: - Provider.of(context, listen: false) - .deleteWorkout(routine.id!); - Navigator.of(context).pop(); - } - }, - itemBuilder: (BuildContext context) { - return [ - PopupMenuItem( - value: WorkoutOptions.logs, - child: Text(AppLocalizations.of(context).labelWorkoutLogs), - ), - PopupMenuItem( - value: WorkoutOptions.edit, - child: Text(AppLocalizations.of(context).edit), - ), - const PopupMenuDivider(), - PopupMenuItem( - value: WorkoutOptions.delete, - child: Text(AppLocalizations.of(context).delete), - ), - ]; - }, - ), - ], - ), - FutureBuilder( - future: _loadFullWorkout(context, routine.id!), - builder: (context, AsyncSnapshot snapshot) => SliverList( - delegate: SliverChildListDelegate( - [ - if (snapshot.connectionState == ConnectionState.waiting) - const SizedBox( - height: 200, - child: Center(child: CircularProgressIndicator()), - ) - else - Consumer( - builder: (context, value, child) => RoutineDetail(routine), - ), - ], - ), - ), - ), - ], + ], + ), ), ); } diff --git a/lib/widgets/core/progress_indicator.dart b/lib/widgets/core/progress_indicator.dart new file mode 100644 index 00000000..d81261d0 --- /dev/null +++ b/lib/widgets/core/progress_indicator.dart @@ -0,0 +1,15 @@ +import 'package:flutter/material.dart'; + +class BoxedProgressIndicator extends StatelessWidget { + const BoxedProgressIndicator({ + super.key, + }); + + @override + Widget build(BuildContext context) { + return const SizedBox( + height: 200, + child: Center(child: CircularProgressIndicator()), + ); + } +} diff --git a/lib/widgets/routines/app_bar.dart b/lib/widgets/routines/app_bar.dart index eb1b7563..375fd820 100644 --- a/lib/widgets/routines/app_bar.dart +++ b/lib/widgets/routines/app_bar.dart @@ -18,16 +18,29 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:provider/provider.dart'; +import 'package:wger/models/workouts/routine.dart'; +import 'package:wger/providers/routines.dart'; import 'package:wger/screens/add_exercise_screen.dart'; import 'package:wger/screens/exercises_screen.dart'; +import 'package:wger/screens/form_screen.dart'; +import 'package:wger/screens/routine_logs_screen.dart'; +import 'package:wger/widgets/routines/forms.dart'; -enum _WorkoutAppBarOptions { +enum _RoutineAppBarOptions { list, contribute, } -class WorkoutOverviewAppBar extends StatelessWidget implements PreferredSizeWidget { - const WorkoutOverviewAppBar(); +enum _RoutineDetailBarOptions { + edit, + delete, + logs, +} + +class RoutineListAppBar extends StatelessWidget implements PreferredSizeWidget { + const RoutineListAppBar(); + @override Widget build(BuildContext context) { return AppBar( @@ -36,22 +49,22 @@ class WorkoutOverviewAppBar extends StatelessWidget implements PreferredSizeWidg PopupMenuButton( itemBuilder: (context) { return [ - PopupMenuItem<_WorkoutAppBarOptions>( - value: _WorkoutAppBarOptions.list, + PopupMenuItem<_RoutineAppBarOptions>( + value: _RoutineAppBarOptions.list, child: Text(AppLocalizations.of(context).exerciseList), ), - PopupMenuItem<_WorkoutAppBarOptions>( - value: _WorkoutAppBarOptions.contribute, + PopupMenuItem<_RoutineAppBarOptions>( + value: _RoutineAppBarOptions.contribute, child: Text(AppLocalizations.of(context).contributeExercise), ), ]; }, onSelected: (value) { switch (value) { - case _WorkoutAppBarOptions.contribute: + case _RoutineAppBarOptions.contribute: Navigator.of(context).pushNamed(AddExerciseScreen.routeName); break; - case _WorkoutAppBarOptions.list: + case _RoutineAppBarOptions.list: Navigator.of(context).pushNamed(ExercisesScreen.routeName); break; } @@ -64,3 +77,63 @@ class WorkoutOverviewAppBar extends StatelessWidget implements PreferredSizeWidg @override Size get preferredSize => const Size.fromHeight(kToolbarHeight); } + +class RoutineDetailAppBar extends StatelessWidget implements PreferredSizeWidget { + final Routine routine; + + const RoutineDetailAppBar(this.routine); + + @override + Widget build(BuildContext context) { + return AppBar( + title: Text(routine.name), + actions: [ + PopupMenuButton( + itemBuilder: (context) { + return [ + PopupMenuItem<_RoutineDetailBarOptions>( + value: _RoutineDetailBarOptions.logs, + child: Text(AppLocalizations.of(context).labelWorkoutLogs), + ), + PopupMenuItem<_RoutineDetailBarOptions>( + value: _RoutineDetailBarOptions.edit, + child: Text(AppLocalizations.of(context).edit), + ), + PopupMenuItem<_RoutineDetailBarOptions>( + value: _RoutineDetailBarOptions.delete, + child: Text(AppLocalizations.of(context).delete), + ), + ]; + }, + onSelected: (value) { + switch (value) { + case _RoutineDetailBarOptions.edit: + Navigator.pushNamed( + context, + FormScreen.routeName, + arguments: FormScreenArguments( + AppLocalizations.of(context).edit, + WorkoutForm(routine), + ), + ); + + case _RoutineDetailBarOptions.logs: + Navigator.pushNamed( + context, + WorkoutLogsScreen.routeName, + arguments: routine, + ); + + case _RoutineDetailBarOptions.delete: + Provider.of(context, listen: false).deleteWorkout(routine.id!); + Navigator.of(context).pop(); + } + }, + ), + ], + ); + } + + @override + Size get preferredSize => const Size.fromHeight(kToolbarHeight); +}