flutter - 我想更新 Playstore 中的应用版本以向用户显示消息对话框
问题描述
我是新手。我想在 Playstore 中更新新版本的应用程序,以向用户显示消息对话框以更新新版本,我使用了插件 version_check 0.2.0。当用户已经更新,但它仍然显示相同的消息对话框。更新后如何不显示消息对话框。谁能帮助我?
解决方案
由于问题中的一切都不清楚,您应该按照给定的步骤来实现相同的目标。
步骤 1. 转到 Firebase 中的远程配置并添加图像中显示的一些参数,然后发布它。
步骤 2. 创建函数 VersionCheck 和 _showVersionDialog,如下所示:
versionCheck(){
//Get Current installed version of app
WidgetsBinding.instance.addPostFrameCallback((_) async {
final PackageInfo info = await PackageInfo.fromPlatform();
double currentVersion = double.parse(info.version.trim().replaceAll(".", ""));
//Get Latest version info from firebase config
final RemoteConfig remoteConfig = await RemoteConfig.instance;
try {
// Using default duration to force fetching from remote server.
await remoteConfig.fetch(expiration: const Duration(seconds: 0));
await remoteConfig.activateFetched();
remoteConfig.getString('force_update_current_version');
double newVersion = double.parse(remoteConfig
.getString('force_update_current_version')
.trim()
.replaceAll(".", ""));
if (newVersion > currentVersion) {
setState(() {
versionCode = remoteConfig.getString('force_update_current_version');
aboutVersion = remoteConfig.getString('update_feature');
});
_showVersionDialog(context);
}
} on FetchThrottledException catch (exception) {
// Fetch throttled.
print(exception);
} catch (exception) {
print('Unable to fetch remote config. Cached or default values will be '
'used');
}
});
}
_showVersionDialog(context) async {
await showDialog<String>(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
String title = "Update Available";
String message =
"About Update: \n";
return ButtonBarTheme(
data: ButtonBarThemeData(alignment: MainAxisAlignment.center),
child: new AlertDialog(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(30)),
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(title),
Text("v"+versionCode),
],
),
content: Container(
height: 80,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(message,style: TextStyle(fontWeight: FontWeight.bold),),
Text(aboutVersion),
],
),
),
actions: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: RaisedButton(
child: new Text(
'Update',
style: TextStyle(color: Colors.white),
),
color: Color(0xFF121A21),
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0),
),
onPressed: () {
_launchURL(PLAY_STORE_URL);
},
),
),
],
),
);
},
);
}
步骤 3. 在主屏幕的 init 函数中调用 VersionCheck,如下所示。
@override
void initState() {
Future.delayed(const Duration(milliseconds: 5000), () {
if(mounted){
setState(() {
versionCheck();
});
}
});
super.initState();
}
第 4 步。每当您希望更新对话框出现在屏幕上时,只需将 Firebase 远程配置中的版本代码值增加为您的实际版本代码值即可。
这将帮助你实现你想要的。
推荐阅读
- php - 使用imagick php转换PDF多页创建双文件
- php - 控制器中的第二种方法不起作用 PHP MVC
- bash - 如何使用 grep/awk/sed 在分隔符之间隔离文件的一部分,可能会交叉线
- c# - 我无法使用矩阵容器打印名称是否有可能使用矩阵打印名称?
- css - kendo ui 角度拆分面板更改背景颜色
- couchdb - 文档架构性能
- virtual-reality - 使用谷歌纸板在 VR 模式下 A-Frame 光标不移动
- python - 3d 内核和 3d 图像(说 RGB)的矩阵乘法究竟是如何发生的以提供 2d 输出?
- ruby-on-rails - 当我尝试从 ruby on rails 应用程序链接 twitter 时出现 500 内部服务器错误
- javascript - Google App Engine:修改 Cloud Run 环境