From 6633964ca1ea0ade32fa45cd5a9b3a03aa970973 Mon Sep 17 00:00:00 2001 From: tamslo Date: Thu, 21 Nov 2024 16:22:12 +0100 Subject: [PATCH] refactor(app): pass whether to remove focus and to resize content to both scaffold types --- app/lib/common/widgets/page_scaffold.dart | 58 +++++++++++++---------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/app/lib/common/widgets/page_scaffold.dart b/app/lib/common/widgets/page_scaffold.dart index 92451a5f..629ebef9 100644 --- a/app/lib/common/widgets/page_scaffold.dart +++ b/app/lib/common/widgets/page_scaffold.dart @@ -29,37 +29,42 @@ Widget buildTitle(String text, { String? tooltipText }) { ); } -Scaffold pageScaffold({ +Widget pageScaffold({ required List body, required String title, List? actions, bool canNavigateBack = true, + BuildContext? contextToDismissFocusOnTap, + bool resizeToAvoidBottomInset = false, Key? key, }) { - return Scaffold( - key: key, - resizeToAvoidBottomInset: false, - body: CustomScrollView(slivers: [ - SliverAppBar( - scrolledUnderElevation: 0, - backgroundColor: PharMeTheme.appBarTheme.backgroundColor, - foregroundColor: PharMeTheme.appBarTheme.foregroundColor, - elevation: PharMeTheme.appBarTheme.elevation, - leadingWidth: PharMeTheme.appBarTheme.leadingWidth, - automaticallyImplyLeading: canNavigateBack, - floating: true, - pinned: true, - snap: false, - centerTitle: PharMeTheme.appBarTheme.centerTitle, - title: buildTitle(title), - actions: actions, - titleSpacing: _getTitleSpacing(backButtonPresent: canNavigateBack), - ), - SliverPadding( - padding: pagePadding(), - sliver: SliverList(delegate: SliverChildListDelegate(body)), - ), - ]), + return GestureDetector( + onTap: () => _maybeRemoveFocus(contextToDismissFocusOnTap), + child: Scaffold( + key: key, + resizeToAvoidBottomInset: resizeToAvoidBottomInset, + body: CustomScrollView(slivers: [ + SliverAppBar( + scrolledUnderElevation: 0, + backgroundColor: PharMeTheme.appBarTheme.backgroundColor, + foregroundColor: PharMeTheme.appBarTheme.foregroundColor, + elevation: PharMeTheme.appBarTheme.elevation, + leadingWidth: PharMeTheme.appBarTheme.leadingWidth, + automaticallyImplyLeading: canNavigateBack, + floating: true, + pinned: true, + snap: false, + centerTitle: PharMeTheme.appBarTheme.centerTitle, + title: buildTitle(title), + actions: actions, + titleSpacing: _getTitleSpacing(backButtonPresent: canNavigateBack), + ), + SliverPadding( + padding: pagePadding(), + sliver: SliverList(delegate: SliverChildListDelegate(body)), + ), + ]), + ), ); } @@ -75,6 +80,7 @@ Widget unscrollablePageScaffold({ List? actions, bool canNavigateBack = true, BuildContext? contextToDismissFocusOnTap, + bool resizeToAvoidBottomInset = false, Key? key, }) { final appBar = title == null @@ -96,7 +102,7 @@ Widget unscrollablePageScaffold({ child: Scaffold( key: key, appBar: appBar, - resizeToAvoidBottomInset: false, + resizeToAvoidBottomInset: resizeToAvoidBottomInset, body: SafeArea( child: Padding( padding: pagePadding(),