From 2a2bb8212f2f7206ece69ea3121d79ec8c263c71 Mon Sep 17 00:00:00 2001 From: Alberto Ponces Date: Mon, 19 Sep 2022 16:24:31 +0100 Subject: [PATCH] fix: Add back button on app bars of secondary views --- .../views/app_selector/app_selector_view.dart | 25 ++++++++++++++++--- lib/ui/views/home/home_view.dart | 1 + lib/ui/views/patcher/patcher_view.dart | 1 + .../patches_selector_view.dart | 25 ++++++++++++++++--- lib/ui/views/settings/settings_view.dart | 1 + .../widgets/shared/custom_sliver_app_bar.dart | 24 ++++++++++++++---- 6 files changed, 64 insertions(+), 13 deletions(-) diff --git a/lib/ui/views/app_selector/app_selector_view.dart b/lib/ui/views/app_selector/app_selector_view.dart index f26f24ec..b6f9ce01 100644 --- a/lib/ui/views/app_selector/app_selector_view.dart +++ b/lib/ui/views/app_selector/app_selector_view.dart @@ -37,12 +37,29 @@ class _AppSelectorViewState extends State { pinned: true, floating: true, snap: false, - title: I18nText('appSelectorView.viewTitle'), + title: I18nText( + 'appSelectorView.viewTitle', + child: Text( + '', + style: TextStyle( + color: Theme.of(context).textTheme.headline6!.color, + ), + ), + ), + leading: IconButton( + icon: Icon( + Icons.arrow_back, + color: Theme.of(context).textTheme.headline6!.color, + ), + onPressed: () => Navigator.of(context).pop(), + ), bottom: PreferredSize( preferredSize: const Size.fromHeight(64.0), child: Padding( padding: const EdgeInsets.symmetric( - vertical: 8.0, horizontal: 12.0), + vertical: 8.0, + horizontal: 12.0, + ), child: SearchBar( showSelectIcon: false, hintText: FlutterI18n.translate( @@ -66,8 +83,8 @@ class _AppSelectorViewState extends State { : model.apps.isEmpty ? const AppSkeletonLoader() : Padding( - padding: const EdgeInsets.only(bottom: 80).add( - const EdgeInsets.symmetric(horizontal: 12.0)), + padding: const EdgeInsets.symmetric(horizontal: 12.0) + .copyWith(bottom: 80), child: Column( children: model .getFilteredApps(_query) diff --git a/lib/ui/views/home/home_view.dart b/lib/ui/views/home/home_view.dart index fbfb9c95..df1a2bec 100644 --- a/lib/ui/views/home/home_view.dart +++ b/lib/ui/views/home/home_view.dart @@ -28,6 +28,7 @@ class HomeView extends StatelessWidget { child: CustomScrollView( slivers: [ CustomSliverAppBar( + isMainView: true, title: I18nText( 'homeView.widgetTitle', child: Text( diff --git a/lib/ui/views/patcher/patcher_view.dart b/lib/ui/views/patcher/patcher_view.dart index edc286a0..de73d07e 100644 --- a/lib/ui/views/patcher/patcher_view.dart +++ b/lib/ui/views/patcher/patcher_view.dart @@ -28,6 +28,7 @@ class PatcherView extends StatelessWidget { body: CustomScrollView( slivers: [ CustomSliverAppBar( + isMainView: true, title: I18nText( 'patcherView.widgetTitle', child: Text( diff --git a/lib/ui/views/patches_selector/patches_selector_view.dart b/lib/ui/views/patches_selector/patches_selector_view.dart index 7f246c57..afe13eca 100644 --- a/lib/ui/views/patches_selector/patches_selector_view.dart +++ b/lib/ui/views/patches_selector/patches_selector_view.dart @@ -39,12 +39,29 @@ class _PatchesSelectorViewState extends State { pinned: true, floating: true, snap: false, - title: I18nText('patchesSelectorView.viewTitle'), + title: I18nText( + 'patchesSelectorView.viewTitle', + child: Text( + '', + style: TextStyle( + color: Theme.of(context).textTheme.headline6!.color, + ), + ), + ), + leading: IconButton( + icon: Icon( + Icons.arrow_back, + color: Theme.of(context).textTheme.headline6!.color, + ), + onPressed: () => Navigator.of(context).pop(), + ), bottom: PreferredSize( preferredSize: const Size.fromHeight(64.0), child: Padding( padding: const EdgeInsets.symmetric( - vertical: 8.0, horizontal: 12.0), + vertical: 8.0, + horizontal: 12.0, + ), child: SearchBar( showSelectIcon: true, hintText: FlutterI18n.translate( @@ -76,8 +93,8 @@ class _PatchesSelectorViewState extends State { ), ) : Padding( - padding: const EdgeInsets.only(bottom: 80) - .add(const EdgeInsets.symmetric(horizontal: 12.0)), + padding: const EdgeInsets.symmetric(horizontal: 12.0) + .copyWith(bottom: 80), child: Column( children: model .getQueriedPatches(_query) diff --git a/lib/ui/views/settings/settings_view.dart b/lib/ui/views/settings/settings_view.dart index fba82539..e28bf551 100644 --- a/lib/ui/views/settings/settings_view.dart +++ b/lib/ui/views/settings/settings_view.dart @@ -24,6 +24,7 @@ class SettingsView extends StatelessWidget { body: CustomScrollView( slivers: [ CustomSliverAppBar( + isMainView: true, title: I18nText( 'settingsView.widgetTitle', child: Text( diff --git a/lib/ui/widgets/shared/custom_sliver_app_bar.dart b/lib/ui/widgets/shared/custom_sliver_app_bar.dart index ea416f1c..45899476 100644 --- a/lib/ui/widgets/shared/custom_sliver_app_bar.dart +++ b/lib/ui/widgets/shared/custom_sliver_app_bar.dart @@ -4,12 +4,14 @@ class CustomSliverAppBar extends StatelessWidget { final Widget title; final List? actions; final PreferredSizeWidget? bottom; + final bool isMainView; const CustomSliverAppBar({ Key? key, required this.title, this.actions, this.bottom, + this.isMainView = false, }) : super(key: key); @override @@ -19,16 +21,28 @@ class CustomSliverAppBar extends StatelessWidget { snap: false, floating: false, expandedHeight: 100.0, - automaticallyImplyLeading: false, + automaticallyImplyLeading: !isMainView, + flexibleSpace: FlexibleSpaceBar( + titlePadding: EdgeInsets.only( + bottom: 14.0, + left: isMainView ? 20.0 : 55.0, + ), + title: title, + ), + leading: isMainView + ? null + : IconButton( + icon: Icon( + Icons.arrow_back, + color: Theme.of(context).textTheme.headline6!.color, + ), + onPressed: () => Navigator.of(context).pop(), + ), backgroundColor: MaterialStateColor.resolveWith( (states) => states.contains(MaterialState.scrolledUnder) ? Theme.of(context).colorScheme.surface : Theme.of(context).canvasColor, ), - flexibleSpace: FlexibleSpaceBar( - titlePadding: const EdgeInsets.only(bottom: 16.0, left: 20.0), - title: title, - ), actions: actions, bottom: bottom, );