Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DialogTitle: don't hide 🫥 properties with strings #286

Merged
merged 9 commits into from
Oct 13, 2022
8 changes: 8 additions & 0 deletions example/lib/example_page_items.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'pages/banner_page.dart';
import 'pages/carousel_page.dart';
import 'pages/check_button_page.dart';
import 'pages/color_disk_page.dart';
import 'pages/dialog_page.dart';
import 'pages/draggable_page.dart';
import 'pages/expandable_page.dart';
import 'pages/icon_button_page.dart';
Expand Down Expand Up @@ -103,4 +104,11 @@ final examplePageItems = <PageItem>[
const Icon(YaruIcons.format_unordered_list),
pageBuilder: (_) => const TilePage(),
),
PageItem(
titleBuilder: (context) => const Text('YaruDialogTitle'),
iconBuilder: (context, selected) => selected
? const Icon(YaruIcons.information_filled)
: const Icon(YaruIcons.information),
pageBuilder: (_) => const DialogPage(),
),
];
96 changes: 96 additions & 0 deletions example/lib/pages/dialog_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import 'package:flutter/material.dart';
import 'package:yaru_widgets/yaru_widgets.dart';

class DialogPage extends StatefulWidget {
const DialogPage({super.key});

@override
State<DialogPage> createState() => _DialogPageState();
}

class _DialogPageState extends State<DialogPage> {
bool isCloseable = true;
@override
Widget build(BuildContext context) {
return SizedBox(
width: 400,
child: Padding(
padding: const EdgeInsets.all(kYaruPagePadding),
child: Column(
children: [
YaruTile(
title: const Text('YaruDialogTitle'),
trailing: OutlinedButton(
onPressed: () => showDialog(
barrierDismissible: isCloseable,
context: context,
builder: (context) {
return AlertDialog(
actions: [
if (!isCloseable)
OutlinedButton(
onPressed: () => Navigator.maybePop(context),
child: Text(
'Evil Force-Close',
style: TextStyle(
color: Theme.of(context).errorColor,
),
),
)
],
titlePadding: EdgeInsets.zero,
title: YaruDialogTitle(
title: Row(
mainAxisSize: MainAxisSize.min,
children: const [
Text('The Title'),
SizedBox(
width: 10,
),
SizedBox(
height: 25,
child: YaruCircularProgressIndicator(
strokeWidth: 3,
),
)
],
),
isCloseable: isCloseable,
),
content: SizedBox(
height: 100,
child: YaruBanner(
surfaceTintColor: Colors.pink,
name: Text(
isCloseable
? 'You can close me'
: 'You cannot close me',
),
subtitle: Text(
isCloseable ? 'Please' : 'No way',
),
icon: Text(
isCloseable ? '🪟' : '💅',
style: const TextStyle(fontSize: 30),
),
),
),
);
},
),
child: const Text('Open dialog'),
),
),
YaruTile(
title: const Text('isCloseable'),
trailing: Switch(
value: isCloseable,
onChanged: (value) => setState(() => isCloseable = value),
),
),
],
),
),
);
}
}
26 changes: 26 additions & 0 deletions lib/src/controls/yaru_close_button.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:flutter/material.dart';
import 'package:yaru_icons/yaru_icons.dart';

import 'yaru_icon_button.dart';

class YaruCloseButton extends StatelessWidget {
const YaruCloseButton({
Key? key,
this.enabled = true,
this.onPressed,
}) : super(key: key);

final bool enabled;
final Function()? onPressed;

@override
Widget build(BuildContext context) {
return YaruIconButton(
style: IconButton.styleFrom(
fixedSize: const Size.square(34),
),
onPressed: enabled ? onPressed ?? Navigator.of(context).maybePop : null,
icon: const Icon(YaruIcons.window_close),
);
}
}
61 changes: 11 additions & 50 deletions lib/src/dialogs/yaru_dialog_title.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,26 @@ import 'package:flutter/material.dart';

import '../../yaru_widgets.dart';

/// A [Stack] of a [Text] with given [title] and an [IconButton]
/// 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,
this.closeIconData = Icons.close,
this.textAlign,
this.mainAxisAlignment,
this.crossAxisAlignment,
this.onPressed,
this.titleWidget,
required this.isCloseable,
this.titleAlignment = Alignment.center,
});

/// The [String] used for the title
final String? title;
/// The [Widget] used for the title
final Widget? title;

/// An optional [Widget] displayed right to the [title]
final Widget? titleWidget;
/// The alignment of the [title]
final AlignmentGeometry titleAlignment;

/// The optional [IconData] used for the [IconButton]
/// which defaults to [Icons.close]
final IconData? closeIconData;

/// The optional [TextAlign], defaults to [TextAlign.center]
final TextAlign? textAlign;

/// The optional [MainAxisAlignment] used for the title [Row],
/// which defaults to [MainAxisAlignment.start]
final MainAxisAlignment? mainAxisAlignment;

/// The optional [CrossAxisAlignment] used for the title [Row],
/// which defaults to [CrossAxisAlignment.center]
final CrossAxisAlignment? crossAxisAlignment;

/// The optional callback, defaults to pop the current route
final Function()? onPressed;
/// Must provide if this dialog is closeable or not
final bool isCloseable;

@override
Widget build(BuildContext context) {
Expand All @@ -54,31 +35,11 @@ class YaruDialogTitle extends StatelessWidget {
top: kYaruPagePadding,
bottom: kYaruPagePadding,
),
child: Row(
mainAxisAlignment: mainAxisAlignment ?? MainAxisAlignment.start,
crossAxisAlignment: crossAxisAlignment ?? CrossAxisAlignment.center,
children: [
Text(
title ?? '',
textAlign: textAlign,
),
if (titleWidget != null)
const SizedBox(
width: 10,
),
if (titleWidget != null) titleWidget!
],
),
child: Align(alignment: titleAlignment, child: title),
),
Padding(
padding: const EdgeInsets.all(5.0),
child: YaruIconButton(
style: IconButton.styleFrom(
fixedSize: const Size.square(34),
),
onPressed: onPressed ?? () => Navigator.pop(context),
icon: Icon(closeIconData ?? Icons.close),
),
child: YaruCloseButton(enabled: isCloseable),
)
],
);
Expand Down
1 change: 1 addition & 0 deletions lib/yaru_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export 'src/constants.dart';
// Controls
export 'src/controls/yaru_back_button.dart';
export 'src/controls/yaru_check_button.dart';
export 'src/controls/yaru_close_button.dart';
export 'src/controls/yaru_color_disk.dart';
export 'src/controls/yaru_icon_button.dart';
export 'src/controls/yaru_option_button.dart';
Expand Down