diff --git a/example/lib/example_page_items.dart b/example/lib/example_page_items.dart index 0ad59022c..255328e46 100644 --- a/example/lib/example_page_items.dart +++ b/example/lib/example_page_items.dart @@ -121,8 +121,8 @@ final examplePageItems = [ pageBuilder: (_) => const TilePage(), ), PageItem( - titleBuilder: (context) => const Text('YaruDialogTitle'), - tooltipMessage: 'YaruDialogTitle', + titleBuilder: (context) => const Text('YaruTitleBar'), + tooltipMessage: 'YaruTitleBar', iconBuilder: (context, selected) => selected ? const Icon(YaruIcons.information_filled) : const Icon(YaruIcons.information), diff --git a/example/lib/pages/dialog_page.dart b/example/lib/pages/dialog_page.dart index 1ebd1df00..352920f38 100644 --- a/example/lib/pages/dialog_page.dart +++ b/example/lib/pages/dialog_page.dart @@ -39,23 +39,17 @@ class _DialogPageState extends State { ) ], titlePadding: EdgeInsets.zero, - title: YaruDialogTitle( - title: Row( - mainAxisSize: MainAxisSize.min, - children: const [ - Text('The Title'), - SizedBox( - width: 10, + title: YaruTitleBar( + leading: const Center( + child: SizedBox.square( + dimension: 25, + child: YaruCircularProgressIndicator( + strokeWidth: 3, ), - SizedBox( - height: 25, - child: YaruCircularProgressIndicator( - strokeWidth: 3, - ), - ) - ], + ), ), - isCloseable: isCloseable, + title: const Text('The Title'), + trailing: YaruCloseButton(enabled: isCloseable), ), content: SizedBox( height: 100, diff --git a/lib/src/constants.dart b/lib/src/constants.dart index 16b7c8c88..fb28e222c 100644 --- a/lib/src/constants.dart +++ b/lib/src/constants.dart @@ -1,4 +1,5 @@ const kYaruPagePadding = 20.0; +const kYaruDialogTitleHeight = 72.0; const kYaruDialogTitlePadding = 0.0; const kYaruPageWidth = 500.0; const kYaruContainerRadius = 8.0; diff --git a/lib/src/controls/yaru_title_bar.dart b/lib/src/controls/yaru_title_bar.dart new file mode 100644 index 000000000..32392efbc --- /dev/null +++ b/lib/src/controls/yaru_title_bar.dart @@ -0,0 +1,53 @@ +import 'package:flutter/material.dart'; + +import '../constants.dart'; +import 'yaru_close_button.dart'; + +/// A [Stack] of a [Widget] as [title] with a close button +/// which pops the top-most route off the navigator +/// that most tightly encloses the given context. +/// +class YaruTitleBar extends StatelessWidget { + const YaruTitleBar({ + super.key, + this.leading, + this.title, + this.trailing, + this.centerTitle = true, + }); + + /// The primary title widget. + final Widget? title; + + /// A widget to display before the [title] widget. + final Widget? leading; + + /// A widget to display after the [title] widget. + final Widget? trailing; + + /// Whether the title should be centered. + final bool? centerTitle; + + @override + Widget build(BuildContext context) { + return AppBar( + elevation: 0, + leading: leading, + automaticallyImplyLeading: false, + title: title, + centerTitle: centerTitle, + toolbarHeight: kYaruDialogTitleHeight, + backgroundColor: Colors.transparent, + titleTextStyle: Theme.of(context).dialogTheme.titleTextStyle, + actions: [ + Padding( + padding: const EdgeInsets.all(5), + child: Align( + alignment: Alignment.topRight, + child: trailing ?? const YaruCloseButton(), + ), + ), + ], + ); + } +} diff --git a/lib/src/dialogs/yaru_dialog_title.dart b/lib/src/dialogs/yaru_dialog_title.dart deleted file mode 100644 index b88a49b1f..000000000 --- a/lib/src/dialogs/yaru_dialog_title.dart +++ /dev/null @@ -1,47 +0,0 @@ -import 'package:flutter/material.dart'; - -import '../../yaru_widgets.dart'; - -/// A [Stack] of a [Widget] as [title] with a close button -/// which pops the top-most route off the navigator -/// that most tightly encloses the given context. -/// -class YaruDialogTitle extends StatelessWidget { - const YaruDialogTitle({ - super.key, - this.title, - required this.isCloseable, - this.titleAlignment = Alignment.center, - }); - - /// The [Widget] used for the title - final Widget? title; - - /// The alignment of the [title] - final AlignmentGeometry titleAlignment; - - /// Must provide if this dialog is closeable or not - final bool isCloseable; - - @override - Widget build(BuildContext context) { - return Stack( - alignment: Alignment.topRight, - children: [ - Padding( - padding: const EdgeInsets.only( - left: kYaruPagePadding + 5, // Avoid title overflow on close button - right: kYaruPagePadding, // Avoid title overflow on close button - top: kYaruPagePadding, - bottom: kYaruPagePadding, - ), - child: Align(alignment: titleAlignment, child: title), - ), - Padding( - padding: const EdgeInsets.all(5.0), - child: YaruCloseButton(enabled: isCloseable), - ) - ], - ); - } -} diff --git a/lib/yaru_widgets.dart b/lib/yaru_widgets.dart index 3657be247..f5edbe302 100644 --- a/lib/yaru_widgets.dart +++ b/lib/yaru_widgets.dart @@ -11,10 +11,9 @@ export 'src/controls/yaru_icon_button.dart'; export 'src/controls/yaru_option_button.dart'; export 'src/controls/yaru_progress_indicator.dart'; export 'src/controls/yaru_radio_button.dart'; +export 'src/controls/yaru_title_bar.dart'; export 'src/controls/yaru_toggle_button.dart'; export 'src/controls/yaru_toggle_button_theme.dart'; -// Dialogs -export 'src/dialogs/yaru_dialog_title.dart'; // Extensions export 'src/extensions/border_radius_extension.dart'; // Layouts