how to change default messages in upgrader in flutter

130 Views Asked by At

I want to change title and body content need to change

UpgradeAlert( upgrader: Upgrader( canDismissDialog: false, showLater: true, showIgnore: false, showReleaseNotes: false, dialogStyle:Platform.isAndroid?UpgradeDialogStyle.material: UpgradeDialogStyle.cupertino, ),

1

There are 1 best solutions below

0
Abdullah Ihsan On

I know I'm a bit late but you can change the default message by using the messages parameter inside the Upgrader constructor.

home: UpgradeAlert(
          shouldPopScope: () => Platform.isIOS ? false : true,
          upgrader: Upgrader(
            languageCode: 'en',
            debugDisplayAlways: true,
            messages: EnglishUpgradeMessages()
          ),
          dialogStyle: Platform.isIOS
              ? UpgradeDialogStyle.cupertino
              : UpgradeDialogStyle.material,
          child: const TabScreen(),
        ),

And you can define your custom class by extending the UpgraderMessages class. Override your message function and change it to whatever you like. Using this method you can also implement localisation.

class EnglishUpgradeMessages extends UpgraderMessages {
  /// Override the message function to provide custom language localization.
  @override
  String message(UpgraderMessage messageKey) {
    if (languageCode == 'en') {
      switch (messageKey) {
        case UpgraderMessage.body:
          return 'A new version of {{appName}} is available!';
        case UpgraderMessage.buttonTitleIgnore:
          return 'Ignore';
        case UpgraderMessage.buttonTitleLater:
          return 'Later';
        case UpgraderMessage.buttonTitleUpdate:
          return 'Update Now';
        case UpgraderMessage.prompt:
          return 'Do you Want to update?';
        case UpgraderMessage.releaseNotes:
          return 'Release Notes';
        case UpgraderMessage.title:
          return 'Update App?';
        default:
        return super.message(messageKey)!;
      }
    }
    // Messages that are not provided above can still use the default values.
    return super.message(messageKey)!;
  }
}