How to get build and version number of Flutter app

后端 未结 4 1462
旧巷少年郎
旧巷少年郎 2020-12-14 05:03

I am currently developing an application which is currently in beta mode. Due to this, I would like to show them what version they are on. For example, \"v1.0b10 - iOS\". So

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-14 06:00

    You can try new_version plugin.

    New Version Plugin

    void versionCheckToLogin() async {
        final NewVersion newVersion = NewVersion(context: context);
        VersionStatus versionStatus = await newVersion.getVersionStatus();
        if (versionStatus != null && versionStatus.canUpdate) {
          await ConfirmDialog(
              context: context,
              title: 'Update Available',
              body: Text('A new version, ${versionStatus.storeVersion}, is available.'),
              acceptButton: 'Update Now',
              cancelButton: 'Update Later'
          ).then((ConfirmAction res) async {
            if (res == ConfirmAction.CONFIRM && await canLaunch(versionStatus.appStoreLink)) {
              await launch(versionStatus.appStoreLink, forceWebView: true);
            }
          });
        }
      }
    

    Custom Alert Dialog Box

    enum ConfirmAction{ CONFIRM, CANCEL }
    Future ConfirmDialog({
      BuildContext context,
      String title,
      Widget body,
      String acceptButton,
      String cancelButton
    })
    => showDialog(
        context: context,
        barrierDismissible: false,
        builder: (BuildContext context) => AlertDialog(
          title: Wrap(
            crossAxisAlignment: WrapCrossAlignment.center,
            spacing: 4,
            children: [
              Text(title)
            ],
          ),
          content: Wrap(
            runSpacing: 10,
            children: [
              body,
            ],
          ),
          actions: [
            FlatButton(
                padding: EdgeInsets.all(6),
                child: Text(acceptButton ?? 'Confirm'),
                onPressed: (){
                  Navigator.of(context, rootNavigator: true).pop(ConfirmAction.CONFIRM);
                }
            ),
            FlatButton(
                padding: EdgeInsets.all(6),
                child: Text(cancelButton ?? 'Cancel'),
                onPressed: (){
                  Navigator.of(context, rootNavigator: true).pop(ConfirmAction.CANCEL);
                }
            ),
          ],
        )
    );
    

提交回复
热议问题