74 lines
1.8 KiB
Dart
74 lines
1.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:native_updater/native_updater.dart';
|
|
|
|
void main() => runApp(MyApp());
|
|
|
|
class MyApp extends StatelessWidget {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
title: 'native_updater example',
|
|
home: Home(),
|
|
);
|
|
}
|
|
}
|
|
|
|
class Home extends StatefulWidget {
|
|
@override
|
|
_HomeState createState() => _HomeState();
|
|
}
|
|
|
|
class _HomeState extends State<Home> {
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
checkVersion();
|
|
}
|
|
|
|
Future<void> checkVersion() async {
|
|
/// For example: You got status code of 412 from the
|
|
/// response of HTTP request.
|
|
/// Let's say the statusCode 412 requires you to force update
|
|
int statusCode = 412;
|
|
|
|
/// This could be kept in our local
|
|
int localVersion = 9;
|
|
|
|
/// This could get from the API
|
|
int serverLatestVersion = 10;
|
|
|
|
Future.delayed(Duration.zero, () {
|
|
if (statusCode == 412) {
|
|
NativeUpdater.displayUpdateAlert(
|
|
context,
|
|
forceUpdate: true,
|
|
appStoreUrl: '<Your App Store URL>',
|
|
iOSDescription: '<Your iOS description>',
|
|
iOSUpdateButtonLabel: 'Upgrade',
|
|
iOSCloseButtonLabel: 'Exit',
|
|
);
|
|
} else if (serverLatestVersion > localVersion) {
|
|
NativeUpdater.displayUpdateAlert(
|
|
context,
|
|
forceUpdate: false,
|
|
appStoreUrl: '<Your App Store URL>',
|
|
iOSDescription: '<Your description>',
|
|
iOSUpdateButtonLabel: 'Upgrade',
|
|
iOSIgnoreButtonLabel: 'Next Time',
|
|
);
|
|
}
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text('Your App'),
|
|
),
|
|
body: Center(
|
|
child: Text('Testing...'),
|
|
),
|
|
);
|
|
}
|
|
} |