Skip to content

Commit

Permalink
DialogTitle: don't hide 馃 properties with strings
Browse files Browse the repository at this point in the history
Fixes #277
  • Loading branch information
Feichtmeier committed Oct 12, 2022
1 parent e501a8e commit be4ff50
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 34 deletions.
8 changes: 8 additions & 0 deletions example/lib/example_page_items.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:yaru_icons/yaru_icons.dart';
import 'pages/banner_page.dart';
import 'pages/carousel_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 @@ -89,4 +90,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),
),
),
],
),
),
);
}
}
46 changes: 12 additions & 34 deletions lib/src/dialogs/yaru_dialog_title.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:yaru_icons/yaru_icons.dart';

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

Expand All @@ -10,26 +11,17 @@ 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 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 alignment of the [title]
final AlignmentGeometry titleAlignment;

/// The optional [MainAxisAlignment] used for the title [Row],
/// which defaults to [MainAxisAlignment.start]
Expand All @@ -39,8 +31,8 @@ class YaruDialogTitle extends StatelessWidget {
/// 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,30 +46,16 @@ 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),
onPressed: isCloseable ? () => Navigator.maybePop(context) : null,
icon: const Icon(YaruIcons.window_close),
),
)
],
Expand Down

0 comments on commit be4ff50

Please sign in to comment.