larryaasen / upgrader

A Flutter package for prompting users to upgrade when there is a newer version of the app in the store.
MIT License
571 stars 281 forks source link

Feature/upgrade announcer widget #464

Open twklessor opened 1 month ago

twklessor commented 1 month ago

Add UpgradeAnnouncer widget. This widget should be used at the top of the widget tree just below MaterialApp. Uses a MaterialBanner with showMaterialBanner. We utilize the scaffoldMessengerKey to make this possible.

This has a distinct advantage over the UpgradeAlert as the MaterialBanner is shown globally; also during navigation.

This is the MaterialBanner shown globally;

image

When the MaterialBanner is tapped a bottom sheet is shown with the appropriate release notes;

screenshot-1

The UpgradeAnnouncer also supports what is called enforceUpgrade which uses the Upgrader.minAppVersion to enforce an update if the current version is lower. This presents a dialog that cannot be dismissed; similar to what the UpgradeAlert supports; image

Simple example of usage;

      MaterialApp(
        scaffoldMessengerKey: rootScaffoldMessengerKey,
        home: UpgradeAnnouncer(
          scaffoldMessengerKey: rootScaffoldMessengerKey,
          child: Scaffold(
            body: const Placeholder(),
            appBar: AppBar(title: const Text('Upgrader test')),
          ),
        ),
      );

Example with customizable icons, text styles and colors;

      const backgroundColor = Colors.red;
      const infoIcon = Icons.add;
      const infoIconColor = Colors.blue;
      const downloadIcon = Icons.abc;
      const downloadIconColor = Colors.yellow;
      const titleTextStyle = TextStyle(color: Colors.amber, fontSize: 20);
      const bottomSheetTitleTextStyle =
          TextStyle(color: Colors.orange, fontSize: 25);
      const bottomSheetReleaseNotesTextStyle =
          TextStyle(color: Colors.purple, fontSize: 30);
      const bottomSheetBackgroundColor = Colors.teal;

      MaterialApp(
        scaffoldMessengerKey: rootScaffoldMessengerKey,
        home: UpgradeAnnouncer(
          scaffoldMessengerKey: rootScaffoldMessengerKey,
          backgroundColor: backgroundColor,
          infoIcon: infoIcon,
          infoIconColor: infoIconColor,
          downloadIcon: downloadIcon,
          downloadIconColor: downloadIconColor,
          titleTextStyle: titleTextStyle,
          bottomSheetTitleTextStyle: bottomSheetTitleTextStyle,
          bottomSheetReleaseNotesTextStyle: bottomSheetReleaseNotesTextStyle,
          bottomSheetBackgroundColor: bottomSheetBackgroundColor,
          child: Scaffold(
            body: const Placeholder(),
            appBar: AppBar(title: const Text('Upgrader test')),
          ),
        ),
      );

This new UpgradeAnnouncer widget is fully backed by a test.

twklessor commented 1 week ago

@larryaasen We are considering making a fork of this package with our additions if it doesn't "fit the cake" but frankly we want to avoid that. We want to give back what you've already given us. We are very open to any feedback, changes or improvements. The UpgradeAnnouncer does have some overlapping features compared to the UpgradeAlert but they do compliment each other.

We already use the UpgradeAnnouncer in 2 production apps.