【发布时间】:2021-01-08 10:27:36
【问题描述】:
我希望我的应用程序的用户始终拥有最新版本。如果他们没有最新版本,它应该在应用启动时自动从 Play 商店下载最新版本。我为此使用 in_app_update。我正在表演Performs immediate update
以下是main 之后的启动画面代码。在这里我检查route函数中的更新,如果更新可用则执行更新并导航到homeView,如果不是简单导航到homeView
但每当新版本上传到 Playstore 时,应用程序从未通知新用户更新。他们必须手动去 Playstore 更新应用程序。这是为什么?我在代码中做错了什么还是需要做一些额外的事情?
import 'package:in_app_update/in_app_update.dart';
class SplashView extends StatefulWidget {
@override
_SplashViewState createState() => _SplashViewState();
}
class _SplashViewState extends State<SplashView> {
AppUpdateInfo _updateInfo; // --- To check for update
@override
void initState() {
super.initState();
startTimer();
}
startTimer() async {
var duration = Duration(milliseconds: 1500);
return Timer(duration, route);
}
route() async {
await checkForUpdate();
bool visiting = await ConstantsFtns().getVisitingFlag();
if (_updateInfo?.updateAvailable == true) {
InAppUpdate.performImmediateUpdate().catchError((e) => _showError(e));
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HomeView(),
),
);
} else {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HomeView(),
),
);
}
}
Future<void> checkForUpdate() async {
InAppUpdate.checkForUpdate().then((info) {
setState(() {
_updateInfo = info;
});
}).catchError((e) => _showError(e));
}
void _showError(dynamic exception) {
_scaffoldKey.currentState.showSnackBar(SnackBar(
content:
Text("Exception while checking for error: " + exception.toString()),
));
@override
Widget build(BuildContext context) {
return Material(
child: AnimatedSplashScreen(
.............................
),
);
}
}
我不知道为什么类似问题的建议解决方案对我不起作用。 https://stackoverflow.com/a/62129373/7290043
【问题讨论】:
标签: flutter dart updates google-play-console auto-update