From fc6eeb8ddc3e10160aefde7c9fe88ac7a20db732 Mon Sep 17 00:00:00 2001 From: HashimKhanDev Date: Mon, 22 Jul 2024 22:29:38 +0400 Subject: [PATCH] Text styles options for the action buttons added. --- lib/src/upgrade_alert.dart | 100 +++++++++++++++++++++++++++++++------ test/upgrader_test.dart | 11 ---- 2 files changed, 85 insertions(+), 26 deletions(-) diff --git a/lib/src/upgrade_alert.dart b/lib/src/upgrade_alert.dart index 2dce347b..011ac656 100644 --- a/lib/src/upgrade_alert.dart +++ b/lib/src/upgrade_alert.dart @@ -29,7 +29,10 @@ class UpgradeAlert extends StatefulWidget { this.showIgnore = true, this.showLater = true, this.showReleaseNotes = true, - this.cupertinoButtonTextStyle, + this.buttonsTextStyle, + this.laterButtonStyle, + this.ignoreButtonStyle, + this.updateButtonStyle, this.dialogKey, this.navigatorKey, this.child, @@ -68,9 +71,22 @@ class UpgradeAlert extends StatefulWidget { /// Hide or show release notes (default: true) final bool showReleaseNotes; - /// The text style for the cupertino dialog buttons. Used only for - /// [UpgradeDialogStyle.cupertino]. Optional. - final TextStyle? cupertinoButtonTextStyle; + /// The text style for the all buttons. + /// if [TextStyle] for specific button is passed then this style will be ignored + /// for that specific button + final TextStyle? buttonsTextStyle; + + /// The text style for the ignore button. + /// This will overide the [buttonsTextStyle]. + final TextStyle? ignoreButtonStyle; + + /// The text style for the later button. + /// This will overide the [buttonsTextStyle]. + final TextStyle? laterButtonStyle; + + /// The text style for the update button. + /// This will overide the [buttonsTextStyle]. + final TextStyle? updateButtonStyle; /// The [Key] assigned to the dialog when it is shown. final GlobalKey? dialogKey; @@ -319,14 +335,40 @@ class UpgradeAlertState extends State { ], ))); final actions = [ + // + // ignore button if (showIgnore) - button(cupertino, messages.message(UpgraderMessage.buttonTitleIgnore), - context, () => onUserIgnored(context, true)), + _button( + _DialogButtons.ignore, + cupertino, + messages.message(UpgraderMessage.buttonTitleIgnore), + context, + () => onUserIgnored(context, true), + ), + + // + // later button if (showLater) - button(cupertino, messages.message(UpgraderMessage.buttonTitleLater), - context, () => onUserLater(context, true)), - button(cupertino, messages.message(UpgraderMessage.buttonTitleUpdate), - context, () => onUserUpdated(context, !widget.upgrader.blocked())), + _button( + _DialogButtons.later, + cupertino, + messages.message(UpgraderMessage.buttonTitleLater), + context, + () => onUserLater(context, true), + ), + + // + // update button + _button( + _DialogButtons.update, + cupertino, + messages.message(UpgraderMessage.buttonTitleUpdate), + context, + () => onUserUpdated( + context, + !widget.upgrader.blocked(), + ), + ), ]; return cupertino @@ -336,13 +378,41 @@ class UpgradeAlertState extends State { key: key, title: textTitle, content: content, actions: actions); } - Widget button(bool cupertino, String? text, BuildContext context, - VoidCallback? onPressed) { + Widget _button(_DialogButtons dialogButton, bool cupertino, String? text, + BuildContext context, VoidCallback? onPressed) { + TextStyle? buttonStyle; + + // + // check for the botton and load desired style for button + if (dialogButton == _DialogButtons.ignore) { + buttonStyle = widget.ignoreButtonStyle ?? widget.buttonsTextStyle; + } else if (dialogButton == _DialogButtons.later) { + buttonStyle = widget.laterButtonStyle ?? widget.buttonsTextStyle; + } else { + buttonStyle = widget.updateButtonStyle ?? widget.buttonsTextStyle; + } + + // + // build action button return cupertino ? CupertinoDialogAction( - textStyle: widget.cupertinoButtonTextStyle, + textStyle: buttonStyle, + onPressed: onPressed, + child: Text(text ?? ''), + ) + : TextButton( onPressed: onPressed, - child: Text(text ?? '')) - : TextButton(onPressed: onPressed, child: Text(text ?? '')); + child: Text( + text ?? '', + style: buttonStyle, + ), + ); } } + +enum _DialogButtons { + // ignore: unused_field + ignore, + later, + update, +} diff --git a/test/upgrader_test.dart b/test/upgrader_test.dart index f620b927..4511cc83 100644 --- a/test/upgrader_test.dart +++ b/test/upgrader_test.dart @@ -314,10 +314,6 @@ void main() { testWidgets('test UpgradeAlert Cupertino', (WidgetTester tester) async { final client = MockITunesSearchClient.setupMockClient(); - const cupertinoButtonTextStyle = TextStyle( - fontSize: 14, - color: Colors.green, - ); final upgrader = Upgrader( upgraderOS: MockUpgraderOS(ios: true), client: client, @@ -357,7 +353,6 @@ void main() { final upgradeAlert = wrapper( UpgradeAlert( upgrader: upgrader, - cupertinoButtonTextStyle: cupertinoButtonTextStyle, dialogStyle: UpgradeDialogStyle.cupertino, onUpdate: () { called = true; @@ -390,12 +385,6 @@ void main() { expect(find.text(upgrader.releaseNotes!), findsOneWidget); expect(find.text(upgrader.state.messages!.prompt), findsOneWidget); expect(find.byType(CupertinoDialogAction), findsNWidgets(3)); - expect( - find.byWidgetPredicate((widget) => - widget is CupertinoDialogAction && - widget.textStyle == cupertinoButtonTextStyle), - findsNWidgets(3), - ); expect( find.text(upgrader.state.messages!.buttonTitleIgnore), findsOneWidget); expect(