feat: add elevation and centerTitle to ThreadHeader and ChannelListHeader

This commit is contained in:
S-ecki
2022-03-09 17:18:09 +01:00
parent 00d2948930
commit a7eaee29d6
3 changed files with 21 additions and 25 deletions
@@ -170,7 +170,7 @@ class ChannelHeader extends StatelessWidget implements PreferredSizeWidget {
),
),
],
centerTitle: _getEffectiveCenterTitle(theme),
centerTitle: centerTitle,
title: InkWell(
onTap: onTitleTap,
child: SizedBox(
@@ -202,24 +202,4 @@ class ChannelHeader extends StatelessWidget implements PreferredSizeWidget {
@override
final Size preferredSize;
/// Returns the effective center title for the current theme and platform.
///
/// This code is aligned with the [AppBar]'s [AppBar.centerTitle].
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;
}
}
}
@@ -56,9 +56,11 @@ class ChannelListHeader extends StatelessWidget implements PreferredSizeWidget {
this.showConnectionStateTile = false,
this.preNavigationCallback,
this.subtitle,
this.centerTitle,
this.leading,
this.actions,
this.backgroundColor,
this.elevation,
}) : super(key: key);
/// Pass this if you don't have a [StreamChatClient] in your widget tree.
@@ -83,6 +85,9 @@ class ChannelListHeader extends StatelessWidget implements PreferredSizeWidget {
/// Subtitle widget
final Widget? subtitle;
/// Whether the title should be centered
final bool? centerTitle;
/// Leading widget
/// By default it shows the logged in user avatar
final Widget? leading;
@@ -94,6 +99,9 @@ class ChannelListHeader extends StatelessWidget implements PreferredSizeWidget {
/// The background color for this [ChannelListHeader].
final Color? backgroundColor;
/// The elevation for this [ChannelListHeader].
final double? elevation;
@override
Widget build(BuildContext context) {
final _client = client ?? StreamChat.of(context).client;
@@ -128,10 +136,10 @@ class ChannelListHeader extends StatelessWidget implements PreferredSizeWidget {
systemOverlayStyle: theme.brightness == Brightness.dark
? SystemUiOverlayStyle.light
: SystemUiOverlayStyle.dark,
elevation: 1,
elevation: elevation ?? 1,
backgroundColor:
backgroundColor ?? channelListHeaderThemeData.color,
centerTitle: true,
centerTitle: centerTitle,
leading: leading ??
Center(
child: user != null
@@ -65,11 +65,13 @@ class ThreadHeader extends StatelessWidget implements PreferredSizeWidget {
this.onBackPressed,
this.title,
this.subtitle,
this.centerTitle,
this.leading,
this.actions,
this.onTitleTap,
this.showTypingIndicator = true,
this.backgroundColor,
this.elevation,
}) : preferredSize = const Size.fromHeight(kToolbarHeight),
super(key: key);
@@ -92,6 +94,9 @@ class ThreadHeader extends StatelessWidget implements PreferredSizeWidget {
/// Subtitle widget
final Widget? subtitle;
/// Whether the title should be centered
final bool? centerTitle;
/// Leading widget
final Widget? leading;
@@ -105,6 +110,9 @@ class ThreadHeader extends StatelessWidget implements PreferredSizeWidget {
/// The background color of this [ThreadHeader].
final Color? backgroundColor;
/// The elevation for this [ThreadHeader].
final double? elevation;
@override
Widget build(BuildContext context) {
final channelHeaderTheme = ChannelHeaderTheme.of(context);
@@ -134,7 +142,7 @@ class ThreadHeader extends StatelessWidget implements PreferredSizeWidget {
systemOverlayStyle: theme.brightness == Brightness.dark
? SystemUiOverlayStyle.light
: SystemUiOverlayStyle.dark,
elevation: 1,
elevation: elevation ?? 1,
leading: leading ??
(showBackButton
? StreamBackButton(
@@ -144,7 +152,7 @@ class ThreadHeader extends StatelessWidget implements PreferredSizeWidget {
)
: const SizedBox()),
backgroundColor: backgroundColor ?? channelHeaderTheme.color,
centerTitle: true,
centerTitle: centerTitle,
actions: actions,
title: InkWell(
onTap: onTitleTap,