-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cat-voices): registration confirm exit dialog (#949)
* feat: confirm exit dialog * chore: make builder method private
- Loading branch information
1 parent
980e714
commit b611980
Showing
9 changed files
with
285 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
catalyst_voices/lib/pages/registration/registration_exit_confirm_dialog.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import 'package:catalyst_voices/widgets/widgets.dart'; | ||
import 'package:catalyst_voices_assets/catalyst_voices_assets.dart'; | ||
import 'package:catalyst_voices_brands/catalyst_voices_brands.dart'; | ||
import 'package:catalyst_voices_localization/catalyst_voices_localization.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class RegistrationExitConfirmDialog extends StatelessWidget { | ||
const RegistrationExitConfirmDialog({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final l10n = context.l10n; | ||
|
||
return VoicesQuestionDialog( | ||
title: Text(l10n.warning.toUpperCase()), | ||
icon: const _WarningIcon(), | ||
subtitle: Text(l10n.registrationExitConfirmDialogSubtitle.toUpperCase()), | ||
content: Padding( | ||
padding: const EdgeInsets.only(bottom: 30), | ||
child: Text(l10n.registrationExitConfirmDialogContent), | ||
), | ||
actions: [ | ||
VoicesQuestionActionItem.negative( | ||
l10n.registrationExitConfirmDialogContinue, | ||
type: VoicesQuestionActionType.filled, | ||
), | ||
VoicesQuestionActionItem.positive( | ||
l10n.registrationExitConfirmDialogCancel, | ||
type: VoicesQuestionActionType.text, | ||
), | ||
], | ||
); | ||
} | ||
} | ||
|
||
class _WarningIcon extends StatelessWidget { | ||
const _WarningIcon(); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final theme = Theme.of(context); | ||
final color = theme.colors.iconsError!; | ||
|
||
return VoicesAvatar( | ||
border: Border.all( | ||
color: color, | ||
width: 3, | ||
), | ||
icon: VoicesAssets.icons.exclamation.buildIcon(size: 36), | ||
backgroundColor: Colors.transparent, | ||
foregroundColor: color, | ||
radius: 40, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
catalyst_voices/lib/widgets/modals/voices_question_dialog.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import 'package:catalyst_voices/widgets/buttons/voices_filled_button.dart'; | ||
import 'package:catalyst_voices/widgets/buttons/voices_text_button.dart'; | ||
import 'package:catalyst_voices/widgets/modals/voices_alert_dialog.dart'; | ||
import 'package:catalyst_voices/widgets/modals/voices_dialog.dart'; | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
enum VoicesQuestionActionType { filled, text } | ||
|
||
final class VoicesQuestionActionItem extends Equatable { | ||
final String name; | ||
final bool isPositive; | ||
final VoicesQuestionActionType type; | ||
|
||
const VoicesQuestionActionItem.positive( | ||
this.name, { | ||
this.type = VoicesQuestionActionType.filled, | ||
}) : isPositive = true; | ||
|
||
const VoicesQuestionActionItem.negative( | ||
this.name, { | ||
this.type = VoicesQuestionActionType.text, | ||
}) : isPositive = false; | ||
|
||
@override | ||
List<Object?> get props => [ | ||
name, | ||
isPositive, | ||
type, | ||
]; | ||
} | ||
|
||
/// Simple dialog when working with yes/no type of dialogs. | ||
/// | ||
/// example: | ||
/// ```dart | ||
/// final confirmed = await VoicesQuestionDialog.show( | ||
/// context, | ||
/// builder: (_) => const RegistrationExitConfirmDialog(), | ||
/// ); | ||
///``` | ||
class VoicesQuestionDialog extends StatelessWidget { | ||
/// [VoicesAlertDialog.title]. | ||
final Widget title; | ||
|
||
/// [VoicesAlertDialog.icon]. | ||
final Widget? icon; | ||
|
||
/// [VoicesAlertDialog.subtitle]. | ||
final Widget? subtitle; | ||
|
||
/// [VoicesAlertDialog.content]. | ||
final Widget? content; | ||
|
||
/// List of yes/no actions, usually only 2 make sense. | ||
/// See [VoicesQuestionActionItem] for config details. | ||
final List<VoicesQuestionActionItem> actions; | ||
|
||
static Future<bool> show( | ||
BuildContext context, { | ||
required WidgetBuilder builder, | ||
bool fallback = false, | ||
}) async { | ||
final result = await VoicesDialog.show<bool>( | ||
context: context, | ||
builder: builder, | ||
); | ||
|
||
return result ?? fallback; | ||
} | ||
|
||
const VoicesQuestionDialog({ | ||
super.key, | ||
required this.title, | ||
this.icon, | ||
this.subtitle, | ||
this.content, | ||
required this.actions, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return VoicesAlertDialog( | ||
title: title, | ||
icon: icon, | ||
subtitle: subtitle, | ||
content: content, | ||
buttons: actions.map((e) => _buildItem(context, item: e)).toList(), | ||
); | ||
} | ||
|
||
Widget _buildItem( | ||
BuildContext context, { | ||
required VoicesQuestionActionItem item, | ||
}) { | ||
switch (item.type) { | ||
case VoicesQuestionActionType.filled: | ||
return VoicesFilledButton( | ||
onTap: () => Navigator.of(context).pop(item.isPositive), | ||
child: Text(item.name), | ||
); | ||
case VoicesQuestionActionType.text: | ||
return VoicesTextButton( | ||
onTap: () => Navigator.of(context).pop(item.isPositive), | ||
child: Text(item.name), | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters