From 622efa7ba27e2eeb25ea079fbfdf99fa01d8ce16 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Wed, 27 Apr 2022 11:52:07 +0200 Subject: [PATCH] extract getEffectiveCenterTitle --- .../lib/src/channel_header.dart | 23 ++++-------------- .../lib/src/thread_header.dart | 24 +++++-------------- .../stream_chat_flutter/lib/src/utils.dart | 22 +++++++++++++++++ 3 files changed, 33 insertions(+), 36 deletions(-) diff --git a/packages/stream_chat_flutter/lib/src/channel_header.dart b/packages/stream_chat_flutter/lib/src/channel_header.dart index 05799fdf..2716ea00 100644 --- a/packages/stream_chat_flutter/lib/src/channel_header.dart +++ b/packages/stream_chat_flutter/lib/src/channel_header.dart @@ -112,7 +112,11 @@ class ChannelHeader extends StatelessWidget implements PreferredSizeWidget { @override Widget build(BuildContext context) { - final effectiveCenterTitle = _getEffectiveCenterTitle(Theme.of(context)); + final effectiveCenterTitle = getEffectiveCenterTitle( + Theme.of(context), + actions: actions, + centerTitle: centerTitle, + ); final channel = StreamChannel.of(context).channel; final channelHeaderTheme = ChannelHeaderTheme.of(context); @@ -205,21 +209,4 @@ class ChannelHeader extends StatelessWidget implements PreferredSizeWidget { @override final Size preferredSize; - - bool _getEffectiveCenterTitle(ThemeData theme) { - if (centerTitle != null) return centerTitle!; - if (theme.appBarTheme.centerTitle != null) { - return theme.appBarTheme.centerTitle!; - } - switch (theme.platform) { - case TargetPlatform.android: - case TargetPlatform.fuchsia: - case TargetPlatform.linux: - case TargetPlatform.windows: - return false; - case TargetPlatform.iOS: - case TargetPlatform.macOS: - return actions == null || actions!.length < 2; - } - } } diff --git a/packages/stream_chat_flutter/lib/src/thread_header.dart b/packages/stream_chat_flutter/lib/src/thread_header.dart index 53aaa37e..199b8a44 100644 --- a/packages/stream_chat_flutter/lib/src/thread_header.dart +++ b/packages/stream_chat_flutter/lib/src/thread_header.dart @@ -115,7 +115,12 @@ class ThreadHeader extends StatelessWidget implements PreferredSizeWidget { @override Widget build(BuildContext context) { - final effectiveCenterTitle = _getEffectiveCenterTitle(Theme.of(context)); + final effectiveCenterTitle = getEffectiveCenterTitle( + Theme.of(context), + actions: actions, + centerTitle: centerTitle, + ); + final channelHeaderTheme = ChannelHeaderTheme.of(context); final defaultSubtitle = subtitle ?? @@ -191,21 +196,4 @@ class ThreadHeader extends StatelessWidget implements PreferredSizeWidget { @override final Size preferredSize; - - bool _getEffectiveCenterTitle(ThemeData theme) { - if (centerTitle != null) return centerTitle!; - if (theme.appBarTheme.centerTitle != null) { - return theme.appBarTheme.centerTitle!; - } - switch (theme.platform) { - case TargetPlatform.android: - case TargetPlatform.fuchsia: - case TargetPlatform.linux: - case TargetPlatform.windows: - return false; - case TargetPlatform.iOS: - case TargetPlatform.macOS: - return actions == null || actions!.length < 2; - } - } } diff --git a/packages/stream_chat_flutter/lib/src/utils.dart b/packages/stream_chat_flutter/lib/src/utils.dart index 3825263d..3d012194 100644 --- a/packages/stream_chat_flutter/lib/src/utils.dart +++ b/packages/stream_chat_flutter/lib/src/utils.dart @@ -17,6 +17,28 @@ Future launchURL(BuildContext context, String url) async { } } +/// Get centerTitle considering a default and platform specific behaviour +bool getEffectiveCenterTitle( + ThemeData theme, { + bool? centerTitle, + List? actions, +}) { + if (centerTitle != null) return centerTitle; + if (theme.appBarTheme.centerTitle != null) { + return theme.appBarTheme.centerTitle!; + } + switch (theme.platform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + return false; + case TargetPlatform.iOS: + case TargetPlatform.macOS: + return actions == null || actions.length < 2; + } +} + /// Shows confirmation dialog Future showConfirmationDialog( BuildContext context, {