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( title: InkWell(
onTap: onTitleTap, onTap: onTitleTap,
child: SizedBox( child: SizedBox(
@@ -202,24 +202,4 @@ class ChannelHeader extends StatelessWidget implements PreferredSizeWidget {
@override @override
final Size preferredSize; 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.showConnectionStateTile = false,
this.preNavigationCallback, this.preNavigationCallback,
this.subtitle, this.subtitle,
this.centerTitle,
this.leading, this.leading,
this.actions, this.actions,
this.backgroundColor, this.backgroundColor,
this.elevation,
}) : super(key: key); }) : super(key: key);
/// Pass this if you don't have a [StreamChatClient] in your widget tree. /// 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 /// Subtitle widget
final Widget? subtitle; final Widget? subtitle;
/// Whether the title should be centered
final bool? centerTitle;
/// Leading widget /// Leading widget
/// By default it shows the logged in user avatar /// By default it shows the logged in user avatar
final Widget? leading; final Widget? leading;
@@ -94,6 +99,9 @@ class ChannelListHeader extends StatelessWidget implements PreferredSizeWidget {
/// The background color for this [ChannelListHeader]. /// The background color for this [ChannelListHeader].
final Color? backgroundColor; final Color? backgroundColor;
/// The elevation for this [ChannelListHeader].
final double? elevation;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final _client = client ?? StreamChat.of(context).client; final _client = client ?? StreamChat.of(context).client;
@@ -128,10 +136,10 @@ class ChannelListHeader extends StatelessWidget implements PreferredSizeWidget {
systemOverlayStyle: theme.brightness == Brightness.dark systemOverlayStyle: theme.brightness == Brightness.dark
? SystemUiOverlayStyle.light ? SystemUiOverlayStyle.light
: SystemUiOverlayStyle.dark, : SystemUiOverlayStyle.dark,
elevation: 1, elevation: elevation ?? 1,
backgroundColor: backgroundColor:
backgroundColor ?? channelListHeaderThemeData.color, backgroundColor ?? channelListHeaderThemeData.color,
centerTitle: true, centerTitle: centerTitle,
leading: leading ?? leading: leading ??
Center( Center(
child: user != null child: user != null
@@ -65,11 +65,13 @@ class ThreadHeader extends StatelessWidget implements PreferredSizeWidget {
this.onBackPressed, this.onBackPressed,
this.title, this.title,
this.subtitle, this.subtitle,
this.centerTitle,
this.leading, this.leading,
this.actions, this.actions,
this.onTitleTap, this.onTitleTap,
this.showTypingIndicator = true, this.showTypingIndicator = true,
this.backgroundColor, this.backgroundColor,
this.elevation,
}) : preferredSize = const Size.fromHeight(kToolbarHeight), }) : preferredSize = const Size.fromHeight(kToolbarHeight),
super(key: key); super(key: key);
@@ -92,6 +94,9 @@ class ThreadHeader extends StatelessWidget implements PreferredSizeWidget {
/// Subtitle widget /// Subtitle widget
final Widget? subtitle; final Widget? subtitle;
/// Whether the title should be centered
final bool? centerTitle;
/// Leading widget /// Leading widget
final Widget? leading; final Widget? leading;
@@ -105,6 +110,9 @@ class ThreadHeader extends StatelessWidget implements PreferredSizeWidget {
/// The background color of this [ThreadHeader]. /// The background color of this [ThreadHeader].
final Color? backgroundColor; final Color? backgroundColor;
/// The elevation for this [ThreadHeader].
final double? elevation;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final channelHeaderTheme = ChannelHeaderTheme.of(context); final channelHeaderTheme = ChannelHeaderTheme.of(context);
@@ -134,7 +142,7 @@ class ThreadHeader extends StatelessWidget implements PreferredSizeWidget {
systemOverlayStyle: theme.brightness == Brightness.dark systemOverlayStyle: theme.brightness == Brightness.dark
? SystemUiOverlayStyle.light ? SystemUiOverlayStyle.light
: SystemUiOverlayStyle.dark, : SystemUiOverlayStyle.dark,
elevation: 1, elevation: elevation ?? 1,
leading: leading ?? leading: leading ??
(showBackButton (showBackButton
? StreamBackButton( ? StreamBackButton(
@@ -144,7 +152,7 @@ class ThreadHeader extends StatelessWidget implements PreferredSizeWidget {
) )
: const SizedBox()), : const SizedBox()),
backgroundColor: backgroundColor ?? channelHeaderTheme.color, backgroundColor: backgroundColor ?? channelHeaderTheme.color,
centerTitle: true, centerTitle: centerTitle,
actions: actions, actions: actions,
title: InkWell( title: InkWell(
onTap: onTitleTap, onTap: onTitleTap,