android - 如何使用 in_app_update 强制用户从 Flutter 中的 Play 商店更新应用
问题描述
我希望我的应用程序的用户始终拥有最新版本。如果他们没有最新版本,它应该首先从 Play 商店下载最新版本,如图所示。
我找到了一个名为Upgrader的软件包,但这只是提示。如图所示,它没有链接到 Play 商店。
编辑
正如Maadhav Sharma所建议的,现在我正在使用in_app_update包,但它说没有可用的更新。
这是我的代码:
....
class _TnPState extends State<TnP> {
ThemeBloc _themeBloc;
FirebaseMessaging _firebaseMessaging;
NotificationBloc _notificationBloc;
String _test;
@override
void initState() {
_themeBloc = ThemeBloc();
_firebaseMessaging = FirebaseMessaging();
_notificationBloc = NotificationBloc();
_firebaseMessaging.configure(
onMessage: (notification) async => _notificationBloc.yes(),
onResume: (notification) async => _notificationBloc.yes(),
onLaunch: (notification) async => _notificationBloc.yes(),
);
checkForUpdate();
super.initState();
}
Future<void> checkForUpdate() async {
InAppUpdate.checkForUpdate().then((info) {
String display = info.toString();
setState((){
_test = display;
});
});
}
@override
Widget build(BuildContext context) {
return StreamBuilder<AppTheme>(
stream: _themeBloc.themeStream,
initialData: AppTheme.Light,
builder: (context, AsyncSnapshot<AppTheme> snapshot) {
return MaterialApp(
title: 'TnP',
debugShowCheckedModeBanner: false,
theme: appThemeData[snapshot.data],
home: _test==null ?
Container() :
InAppUpdateScreen(display: _test),//SplashScreen(),
);
},
);
}
}
InAppUpdateScreen
只显示文本。
Play商店中的应用程序显示更新可用:
但是通过 playstore 安装的旧版本的应用程序没有显示更新:
知道如何解决这个问题吗?
解决方案
有一个你想要的包:
https ://pub.dev/packages/in_app_update
Android
此插件集成了官方 Android API 以在 2019 年发布的应用更新中执行:https ://developer.android.com/guide/app-bundle/in-app-updates
iOS
iOS 不提供此类功能。您可能想查看例如https://pub.dev/packages/upgrader。如果您在 iOS 设备上调用上述方法,您将遇到未实现的异常。
谢谢...
推荐阅读
- javascript - JQuery DOM 操作:即使使用 parseInt(),2 个数字的总和也会生成 NaN
- django - 序列化 Django。如何设置自定义模板
- javascript - 无论如何在本地存储中使用星号或其他方法?
- java - 无法从 JLabel 的子类运行方法
- react-native - 堆栈导航器之间的反应导航返回
- swift - 如何使用类方法作为闭包而不在该方法/闭包中持有对 self 的强引用?
- google-maps - 如何修复 Android Studio 中不可转换的类型
- google-app-engine - ffmpeg 无法在谷歌应用引擎标准 nodejs 中正确执行
- ios - iOS 13 - FileManager url(forPublishingUbiquitousItemAt:expiration:) 不再工作
- mongodb - 如何在Mongo中减去两个日期