-
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
design: Add snackbar with link to changelog on new version
- Loading branch information
1 parent
21e7c3f
commit e5bbb75
Showing
6 changed files
with
69 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import 'package:flutter_gen/gen_l10n/l10n.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
import 'package:url_launcher/url_launcher_string.dart'; | ||
|
||
import 'package:fluffychat/config/app_config.dart'; | ||
import 'package:fluffychat/utils/platform_infos.dart'; | ||
|
||
abstract class UpdateNotifier { | ||
static const String versionStoreKey = 'last_known_version'; | ||
|
||
static void showUpdateSnackBar(BuildContext context) async { | ||
final scaffoldMessenger = ScaffoldMessenger.of(context); | ||
final currentVersion = await PlatformInfos.getVersion(); | ||
final store = await SharedPreferences.getInstance(); | ||
final storedVersion = store.getString(versionStoreKey); | ||
|
||
if (currentVersion != storedVersion) { | ||
if (storedVersion != null) { | ||
ScaffoldFeatureController? controller; | ||
controller = scaffoldMessenger.showSnackBar( | ||
SnackBar( | ||
duration: const Duration(seconds: 30), | ||
content: Row( | ||
children: [ | ||
IconButton( | ||
icon: Icon( | ||
Icons.close_outlined, | ||
size: 20, | ||
color: Theme.of(context).colorScheme.onPrimary, | ||
), | ||
onPressed: () => controller?.close(), | ||
), | ||
Expanded( | ||
child: Text( | ||
L10n.of(context)!.updateInstalled(currentVersion), | ||
), | ||
), | ||
], | ||
), | ||
action: SnackBarAction( | ||
label: L10n.of(context)!.changelog, | ||
onPressed: () => launchUrlString(AppConfig.changelogUrl), | ||
), | ||
), | ||
); | ||
} | ||
await store.setString(versionStoreKey, currentVersion); | ||
} | ||
} | ||
} |