Issue
Sorry if this is a stupid question since I don't find any solution. So I know that I can get the version number and update-notifier when the update is available on the play store or app store using some flutter package. But I think that I cant show users what the update is about and there is no package like that exists. So I think I need to implement something like an alert dialog manually to show the updated information before I want to publish the update. So, how can I do it with flutter to show that alert dialog just once after the user update the app? Can shared preferences do that? If so how? And is there really a package or ways that I can show the updated information that I don't know of?
Solution
This should be possible with package_info_plus
and shared_preferences
. You can use package_info_plus
to get the current version and store it with shared_preferences
. Then on app launch, get the current version from package_info_plus
and compare it to the stored version.
Here is an example:
import 'package:shared_preferences/shared_preferences.dart';
import 'package:package_info_plus/package_info_plus.dart';
bool shouldShowUpdateAlert() async {
PackageInfo packageInfo = await PackageInfo.fromPlatform();
final prefs = await SharedPreferences.getInstance();
String version = packageInfo.version;
final String? storedVersion = prefs.getString('appVersion');
await prefs.setString('appVersion', version);
return version != storedVersion;
}
Answered By - Zach
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.