ente/lib/ui/components/title_bar_widget.dart

153 lines
4.8 KiB
Dart
Raw Normal View History

2022-10-25 09:03:11 +00:00
import 'package:flutter/material.dart';
import 'package:photos/theme/ente_theme.dart';
import 'package:photos/ui/components/buttons/icon_button_widget.dart';
2022-10-25 09:03:11 +00:00
class TitleBarWidget extends StatelessWidget {
2022-11-02 14:19:39 +00:00
final IconButtonWidget? leading;
final String? title;
final String? caption;
final Widget? flexibleSpaceTitle;
final String? flexibleSpaceCaption;
final List<Widget>? actionIcons;
2022-10-27 05:45:57 +00:00
final bool isTitleH2WithoutLeading;
2022-10-27 06:20:38 +00:00
final bool isFlexibleSpaceDisabled;
2022-11-02 16:06:08 +00:00
final bool isOnTopOfScreen;
2022-11-08 09:27:39 +00:00
final Color? backgroundColor;
const TitleBarWidget({
2022-11-02 14:19:39 +00:00
this.leading,
this.title,
this.caption,
this.flexibleSpaceTitle,
this.flexibleSpaceCaption,
this.actionIcons,
2022-10-27 05:45:57 +00:00
this.isTitleH2WithoutLeading = false,
2022-10-27 06:20:38 +00:00
this.isFlexibleSpaceDisabled = false,
2022-11-02 16:06:08 +00:00
this.isOnTopOfScreen = true,
2022-11-08 09:27:39 +00:00
this.backgroundColor,
super.key,
});
2022-10-25 09:03:11 +00:00
@override
Widget build(BuildContext context) {
const toolbarHeight = 48.0;
final textTheme = getEnteTextTheme(context);
final colorTheme = getEnteColorScheme(context);
2022-10-25 09:03:11 +00:00
return SliverAppBar(
2022-11-08 09:27:39 +00:00
backgroundColor: backgroundColor,
2022-11-02 16:06:08 +00:00
primary: isOnTopOfScreen ? true : false,
toolbarHeight: toolbarHeight,
2022-10-25 09:03:11 +00:00
leadingWidth: 48,
automaticallyImplyLeading: false,
pinned: true,
2022-11-02 16:06:08 +00:00
expandedHeight: isFlexibleSpaceDisabled ? toolbarHeight : 102,
2022-10-25 09:03:11 +00:00
centerTitle: false,
2022-11-02 16:06:08 +00:00
titleSpacing: 4,
title: Padding(
2022-10-27 05:45:57 +00:00
padding: EdgeInsets.only(left: isTitleH2WithoutLeading ? 16 : 0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
title == null
? const SizedBox.shrink()
: Text(
title!,
2022-10-27 05:45:57 +00:00
style: isTitleH2WithoutLeading
? textTheme.h2Bold
: textTheme.largeBold,
),
2022-10-27 05:45:57 +00:00
caption == null || isTitleH2WithoutLeading
? const SizedBox.shrink()
: Text(
caption!,
style: textTheme.mini.copyWith(color: colorTheme.textMuted),
)
],
),
2022-10-25 09:03:11 +00:00
),
actions: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 4),
2022-10-25 09:03:11 +00:00
child: Row(
2022-10-27 05:45:57 +00:00
children: _actionsWithPaddingInBetween(),
2022-10-25 09:03:11 +00:00
),
),
],
2022-10-27 05:45:57 +00:00
leading: isTitleH2WithoutLeading
? null
2022-11-02 14:19:39 +00:00
: leading ??
IconButtonWidget(
icon: Icons.arrow_back_outlined,
iconButtonType: IconButtonType.primary,
onTap: () {
Navigator.pop(context);
},
),
2022-10-27 06:20:38 +00:00
flexibleSpace: isFlexibleSpaceDisabled
? null
: FlexibleSpaceBar(
background: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
2022-10-27 06:20:38 +00:00
mainAxisSize: MainAxisSize.min,
children: <Widget>[
const SizedBox(height: toolbarHeight),
Padding(
padding: const EdgeInsets.symmetric(
vertical: 4,
horizontal: 16,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
flexibleSpaceTitle == null
? const SizedBox.shrink()
: flexibleSpaceTitle!,
flexibleSpaceCaption == null
? const SizedBox.shrink()
: Text(
flexibleSpaceCaption!,
style: textTheme.small.copyWith(
color: colorTheme.textMuted,
),
overflow: TextOverflow.ellipsis,
maxLines: 1,
)
],
),
),
],
),
),
2022-10-27 06:20:38 +00:00
),
2022-10-25 09:03:11 +00:00
);
}
2022-10-27 05:45:57 +00:00
_actionsWithPaddingInBetween() {
if (actionIcons == null) {
return <Widget>[const SizedBox.shrink()];
}
final actions = <Widget>[];
bool addWhiteSpace = false;
final length = actionIcons!.length;
int index = 0;
if (length == 0) {
return <Widget>[const SizedBox.shrink()];
}
if (length == 1) {
return actionIcons;
}
while (index < length) {
if (!addWhiteSpace) {
actions.add(actionIcons![index]);
index++;
addWhiteSpace = true;
} else {
actions.add(const SizedBox(width: 4));
addWhiteSpace = false;
}
}
return actions;
}
2022-10-25 09:03:11 +00:00
}