flutter_ut_ver 0.0.1 flutter_ut_ver: ^0.0.1 copied to clipboard
A UT app verison manager plugin in flutter.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:flutter_ut_ver/bean/upgrade_info_entity.dart';
import 'package:flutter_ut_ver/flutter_ut_ver.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: TestWidget()),
);
}
}
class TestWidget extends StatefulWidget {
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return TestState();
}
}
class TestState extends State<TestWidget> {
String _platformVersion = 'Unknown';
String _latestAppVersion = 'fetching...';
final GlobalKey<State> _loadingKey = new GlobalKey<State>();
@override
void initState() {
// TODO: implement initState
super.initState();
initPlatformState();
FlutterUtVer.init(
androidKey: 'a250924b-77b6-5ad3-aba2-8bb52349cf6b',
iOSKey: '088730ea-8679-5cd8-b488-98c4af56c9c6');
}
@override
Widget build(BuildContext context) {
return Center(
child: Column(
children: [
Text(
'Running on: $_platformVersion\n Remote Version: $_latestAppVersion'),
ElevatedButton(
onPressed: () {
_checkUpdate(context);
},
child: Text('检测版本信息'))
],
));
}
void _checkUpdate(BuildContext context) async {
//show loading dialog
// showDialog(
// context: context,
// builder: (_) => SimpleDialog(
// key: _loadingKey,
// children: [const CupertinoActivityIndicator()],
// ));
await FlutterUtVer.checkUpgrade(context).then((value) => print("$value")); // check upgrade
// Navigator.of(_loadingKey.currentContext, rootNavigator: true).pop();//close the loading dialog
// .then((value) => FlutterUtVer.checkUpgrade(context))
// .then((value) => Navigator.pop(context));
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
platformVersion = await FlutterUtVer.platformVersion;
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
}
}