Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. versionCheck(context) async {
  2. //Get Current installed version of app
  3. final PackageInfo info = await PackageInfo.fromPlatform();
  4. double currentVersion = double.parse(info.version.trim().replaceAll(".", ""));
  5.  
  6. //Get Latest version info from firebase config
  7. final RemoteConfig remoteConfig = await RemoteConfig.instance;
  8.  
  9. try {
  10. // Using default duration to force fetching from remote server.
  11. await remoteConfig.fetch(expiration: const Duration(seconds: 0));
  12. await remoteConfig.activateFetched();
  13. remoteConfig.getString('force_update_current_version');
  14. double newVersion = double.parse(remoteConfig
  15. .getString('force_update_current_version')
  16. .trim()
  17. .replaceAll(".", ""));
  18. if (newVersion > currentVersion) {
  19. _showVersionDialog(context);
  20. }
  21. } on FetchThrottledException catch (exception) {
  22. // Fetch throttled.
  23. print(exception);
  24. } catch (exception) {
  25. print('Unable to fetch remote config. Cached or default values will be '
  26. 'used');
  27. }
  28. }
  29.  
  30. @override
  31. void initState() {
  32. try {
  33. versionCheck(context);
  34. } catch (e) {
  35. print(e);
  36. }
  37. super.initState();
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement