new_version_plus 0.0.5 new_version_plus: ^0.0.5 copied to clipboard
Check if your user has the most recent version of your Flutter app.
import 'package:flutter/material.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> {
@override
void initState() {
super.initState();
// Instantiate NewVersion manager object (Using GCP Console app as example)
final newVersion = NewVersionPlus(
iOSId: 'com.google.Vespa',
androidId: 'com.disney.disneyplus',
);
// 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.
const simpleBehavior = true;
if (simpleBehavior) {
basicStatusCheck(newVersion);
}
// else {
// advancedStatusCheck(newVersion);
// }
}
basicStatusCheck(NewVersionPlus newVersion) {
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',
);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Example App"),
),
);
}
}