Adaptive app bar leading

This commit is contained in:
LittleSheep 2024-07-12 22:37:58 +08:00
parent a2db9a7ae4
commit 156e6f1075
14 changed files with 19 additions and 13 deletions

View File

@ -130,7 +130,7 @@ class _ArticlePublishScreenState extends State<ArticlePublishScreen> {
color: Theme.of(context).colorScheme.surface, color: Theme.of(context).colorScheme.surface,
child: Scaffold( child: Scaffold(
appBar: AppBar( appBar: AppBar(
leading: const AppBarLeadingButton(), leading: AppBarLeadingButton.adaptive(context),
title: AppBarTitle('articlePublish'.tr), title: AppBarTitle('articlePublish'.tr),
centerTitle: false, centerTitle: false,
toolbarHeight: SolianTheme.toolbarHeight(context), toolbarHeight: SolianTheme.toolbarHeight(context),

View File

@ -56,7 +56,7 @@ class _CallScreenState extends State<CallScreen> {
color: Theme.of(context).colorScheme.surface, color: Theme.of(context).colorScheme.surface,
child: Scaffold( child: Scaffold(
appBar: AppBar( appBar: AppBar(
leading: const AppBarLeadingButton(), leading: AppBarLeadingButton.adaptive(context),
centerTitle: true, centerTitle: true,
toolbarHeight: SolianTheme.toolbarHeight(context), toolbarHeight: SolianTheme.toolbarHeight(context),
title: RichText( title: RichText(

View File

@ -193,7 +193,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
leading: const AppBarLeadingButton(), leading: AppBarLeadingButton.adaptive(context),
title: AppBarTitle(title), title: AppBarTitle(title),
centerTitle: false, centerTitle: false,
titleSpacing: SolianTheme.titleSpacing(context), titleSpacing: SolianTheme.titleSpacing(context),

View File

@ -44,7 +44,7 @@ class _ChatScreenState extends State<ChatScreen> {
color: Theme.of(context).colorScheme.surface, color: Theme.of(context).colorScheme.surface,
child: Scaffold( child: Scaffold(
appBar: AppBar( appBar: AppBar(
leading: const AppBarLeadingButton(), leading: AppBarLeadingButton.adaptive(context),
title: AppBarTitle('chat'.tr), title: AppBarTitle('chat'.tr),
centerTitle: false, centerTitle: false,
toolbarHeight: SolianTheme.toolbarHeight(context), toolbarHeight: SolianTheme.toolbarHeight(context),

View File

@ -63,7 +63,7 @@ class _DraftBoxScreenState extends State<DraftBoxScreen> {
color: Theme.of(context).colorScheme.surface, color: Theme.of(context).colorScheme.surface,
child: Scaffold( child: Scaffold(
appBar: AppBar( appBar: AppBar(
leading: const AppBarLeadingButton(), leading: AppBarLeadingButton.adaptive(context),
title: AppBarTitle('draftBox'.tr), title: AppBarTitle('draftBox'.tr),
centerTitle: false, centerTitle: false,
toolbarHeight: SolianTheme.toolbarHeight(context), toolbarHeight: SolianTheme.toolbarHeight(context),

View File

@ -64,7 +64,7 @@ class _HomeScreenState extends State<HomeScreen> {
centerTitle: false, centerTitle: false,
floating: true, floating: true,
toolbarHeight: SolianTheme.toolbarHeight(context), toolbarHeight: SolianTheme.toolbarHeight(context),
leading: const AppBarLeadingButton(), leading: AppBarLeadingButton.adaptive(context),
actions: [ actions: [
const BackgroundStateWidget(), const BackgroundStateWidget(),
const NotificationButton(), const NotificationButton(),

View File

@ -134,7 +134,7 @@ class _PostPublishScreenState extends State<PostPublishScreen> {
color: Theme.of(context).colorScheme.surface, color: Theme.of(context).colorScheme.surface,
child: Scaffold( child: Scaffold(
appBar: AppBar( appBar: AppBar(
leading: const AppBarLeadingButton(), leading: AppBarLeadingButton.adaptive(context),
title: AppBarTitle('postPublish'.tr), title: AppBarTitle('postPublish'.tr),
centerTitle: false, centerTitle: false,
toolbarHeight: SolianTheme.toolbarHeight(context), toolbarHeight: SolianTheme.toolbarHeight(context),

View File

@ -59,7 +59,7 @@ class _RealmListScreenState extends State<RealmListScreen> {
color: Theme.of(context).colorScheme.surface, color: Theme.of(context).colorScheme.surface,
child: Scaffold( child: Scaffold(
appBar: AppBar( appBar: AppBar(
leading: const AppBarLeadingButton(), leading: AppBarLeadingButton.adaptive(context),
title: AppBarTitle('realm'.tr), title: AppBarTitle('realm'.tr),
centerTitle: false, centerTitle: false,
toolbarHeight: SolianTheme.toolbarHeight(context), toolbarHeight: SolianTheme.toolbarHeight(context),

View File

@ -99,7 +99,7 @@ class _RealmOrganizeScreenState extends State<RealmOrganizeScreen> {
color: Theme.of(context).colorScheme.surface, color: Theme.of(context).colorScheme.surface,
child: Scaffold( child: Scaffold(
appBar: AppBar( appBar: AppBar(
leading: const AppBarLeadingButton(), leading: AppBarLeadingButton.adaptive(context),
title: AppBarTitle('realmOrganizing'.tr), title: AppBarTitle('realmOrganizing'.tr),
centerTitle: false, centerTitle: false,
toolbarHeight: SolianTheme.toolbarHeight(context), toolbarHeight: SolianTheme.toolbarHeight(context),

View File

@ -91,7 +91,7 @@ class _RealmViewScreenState extends State<RealmViewScreen> {
handle: handle:
NestedScrollView.sliverOverlapAbsorberHandleFor(context), NestedScrollView.sliverOverlapAbsorberHandleFor(context),
sliver: SliverAppBar( sliver: SliverAppBar(
leading: const AppBarLeadingButton(), leading: AppBarLeadingButton.adaptive(context),
title: Text(_realm?.name ?? 'loading'.tr), title: Text(_realm?.name ?? 'loading'.tr),
centerTitle: false, centerTitle: false,
actions: [ actions: [

View File

@ -22,7 +22,7 @@ class CenteredShell extends StatelessWidget {
return Scaffold( return Scaffold(
appBar: showAppBar appBar: showAppBar
? AppBar( ? AppBar(
leading: const AppBarLeadingButton(), leading: AppBarLeadingButton.adaptive(context),
title: AppBarTitle(state.topRoute?.name?.tr ?? 'page'.tr), title: AppBarTitle(state.topRoute?.name?.tr ?? 'page'.tr),
centerTitle: false, centerTitle: false,
toolbarHeight: SolianTheme.toolbarHeight(context), toolbarHeight: SolianTheme.toolbarHeight(context),

View File

@ -44,7 +44,7 @@ class SidebarShell extends StatelessWidget {
return Scaffold( return Scaffold(
appBar: showAppBar appBar: showAppBar
? AppBar( ? AppBar(
leading: const AppBarLeadingButton(), leading: AppBarLeadingButton.adaptive(context),
title: AppBarTitle(state.topRoute?.name?.tr ?? 'page'.tr), title: AppBarTitle(state.topRoute?.name?.tr ?? 'page'.tr),
centerTitle: false, centerTitle: false,
toolbarHeight: SolianTheme.toolbarHeight(context), toolbarHeight: SolianTheme.toolbarHeight(context),

View File

@ -22,7 +22,7 @@ class TitleShell extends StatelessWidget {
return Scaffold( return Scaffold(
appBar: showAppBar appBar: showAppBar
? AppBar( ? AppBar(
leading: const AppBarLeadingButton(), leading: AppBarLeadingButton.adaptive(context),
title: AppBarTitle(state.topRoute?.name?.tr ?? 'page'.tr), title: AppBarTitle(state.topRoute?.name?.tr ?? 'page'.tr),
centerTitle: false, centerTitle: false,
toolbarHeight: SolianTheme.toolbarHeight(context), toolbarHeight: SolianTheme.toolbarHeight(context),

View File

@ -4,6 +4,12 @@ import 'package:solian/shells/root_shell.dart';
class AppBarLeadingButton extends StatelessWidget { class AppBarLeadingButton extends StatelessWidget {
const AppBarLeadingButton({super.key}); const AppBarLeadingButton({super.key});
static Widget? adaptive(BuildContext context) {
final hasContent =
Navigator.canPop(context) || rootScaffoldKey.currentState!.hasDrawer;
return hasContent ? const AppBarLeadingButton() : null;
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (Navigator.canPop(context)) { if (Navigator.canPop(context)) {