Skip to content

Commit

Permalink
Text styles options for the action buttons added.
Browse files Browse the repository at this point in the history
  • Loading branch information
HashimKhanDev committed Jul 22, 2024
1 parent fa02d08 commit fc6eeb8
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 26 deletions.
100 changes: 85 additions & 15 deletions lib/src/upgrade_alert.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -319,14 +335,40 @@ class UpgradeAlertState extends State<UpgradeAlert> {
],
)));
final actions = <Widget>[
//
// 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
Expand All @@ -336,13 +378,41 @@ class UpgradeAlertState extends State<UpgradeAlert> {
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,
}
11 changes: 0 additions & 11 deletions test/upgrader_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -357,7 +353,6 @@ void main() {
final upgradeAlert = wrapper(
UpgradeAlert(
upgrader: upgrader,
cupertinoButtonTextStyle: cupertinoButtonTextStyle,
dialogStyle: UpgradeDialogStyle.cupertino,
onUpdate: () {
called = true;
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit fc6eeb8

Please sign in to comment.