new_version_plus 0.0.12 new_version_plus: ^0.0.12 copied to clipboard
Check if your user has the most recent version of your Flutter app.
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:new_version_plus/new_version_plus.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
String release = "";
@override
void initState() {
super.initState();
// Instantiate NewVersion manager object (Using GCP Console app as example)
final newVersion = NewVersionPlus(
iOSId: 'com.disney.disneyplus', androidId: 'com.whatsapp', androidPlayStoreCountry: "es_ES", androidHtmlReleaseNotes: true, //support country code
);
// You can let the plugin handle fetching the status and showing a dialog,
// or you can fetch the status and display your own dialog, or no dialog.
final ver = VersionStatus(
appStoreLink: '',
localVersion: '',
storeVersion: '',
releaseNotes: '',
originalStoreVersion: '',
);
print(ver);
const simpleBehavior = true;
// if (simpleBehavior) {
basicStatusCheck(newVersion);
// }
// else {
// advancedStatusCheck(newVersion);
// }
}
basicStatusCheck(NewVersionPlus newVersion) async {
final version = await newVersion.getVersionStatus();
if (version != null) {
release = version.releaseNotes ?? "";
setState(() {});
}
newVersion.showAlertIfNecessary(
context: context,
launchModeVersion: LaunchModeVersion.external,
);
}
advancedStatusCheck(NewVersionPlus newVersion) async {
final status = await newVersion.getVersionStatus();
if (status != null) {
debugPrint(status.releaseNotes);
debugPrint(status.appStoreLink);
debugPrint(status.localVersion);
debugPrint(status.storeVersion);
debugPrint(status.canUpdate.toString());
newVersion.showUpdateDialog(
context: context,
versionStatus: status,
dialogTitle: 'Custom Title',
dialogText: 'Custom Text',
launchModeVersion: LaunchModeVersion.external,
allowDismissal: false,
);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Example App"),
),
body: SafeArea(
child: Center(
child: Html(data: release),
),
),
);
}
}