Fix sidebar navigation context lifecycle #1
No files matched your search
@@ -13,7 +13,12 @@ class SettingsButton extends StatelessWidget {
|
|||||||
// Opens the settings page sliding in from the right — matches the
|
// Opens the settings page sliding in from the right — matches the
|
||||||
// sidebar end-drawer animation so it feels like one continuous motion.
|
// sidebar end-drawer animation so it feels like one continuous motion.
|
||||||
static void open(BuildContext context) {
|
static void open(BuildContext context) {
|
||||||
Navigator.of(context).push(
|
openWithNavigator(Navigator.of(context, rootNavigator: true));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void openWithNavigator(NavigatorState navigator) {
|
||||||
|
if (!navigator.mounted) return;
|
||||||
|
navigator.push(
|
||||||
PageRouteBuilder(
|
PageRouteBuilder(
|
||||||
transitionDuration: const Duration(milliseconds: 300),
|
transitionDuration: const Duration(milliseconds: 300),
|
||||||
reverseTransitionDuration: const Duration(milliseconds: 250),
|
reverseTransitionDuration: const Duration(milliseconds: 250),
|
||||||
|
|||||||
@@ -126,8 +126,11 @@ class _SidebarDrawerState extends State<SidebarDrawer> {
|
|||||||
icon: Icons.settings,
|
icon: Icons.settings,
|
||||||
label: 'Settings',
|
label: 'Settings',
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.of(context).pop();
|
final drawerNavigator = Navigator.of(context);
|
||||||
SettingsButton.open(context);
|
final rootNavigator =
|
||||||
|
Navigator.of(context, rootNavigator: true);
|
||||||
|
drawerNavigator.pop();
|
||||||
|
SettingsButton.openWithNavigator(rootNavigator);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
||||||
@@ -135,8 +138,15 @@ class _SidebarDrawerState extends State<SidebarDrawer> {
|
|||||||
icon: Icons.system_update_alt,
|
icon: Icons.system_update_alt,
|
||||||
label: 'Check for updates',
|
label: 'Check for updates',
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.of(context).pop();
|
final drawerNavigator = Navigator.of(context);
|
||||||
Updater.check(context);
|
final rootNavigator =
|
||||||
|
Navigator.of(context, rootNavigator: true);
|
||||||
|
final messenger = ScaffoldMessenger.of(context);
|
||||||
|
drawerNavigator.pop();
|
||||||
|
Updater.checkWithHandles(
|
||||||
|
navigator: rootNavigator,
|
||||||
|
messenger: messenger,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
||||||
|
|||||||
+27
-10
@@ -115,32 +115,45 @@ class Updater {
|
|||||||
return '$prefix$v${isLocal ? ' (installed)' : ''}';
|
return '$prefix$v${isLocal ? ' (installed)' : ''}';
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<void> check(BuildContext context) async {
|
static Future<void> check(BuildContext context) {
|
||||||
|
final navigator = Navigator.of(context, rootNavigator: true);
|
||||||
|
final messenger = ScaffoldMessenger.of(context);
|
||||||
|
return checkWithHandles(
|
||||||
|
navigator: navigator,
|
||||||
|
messenger: messenger,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> checkWithHandles({
|
||||||
|
required NavigatorState navigator,
|
||||||
|
required ScaffoldMessengerState messenger,
|
||||||
|
}) async {
|
||||||
final info = await PackageInfo.fromPlatform();
|
final info = await PackageInfo.fromPlatform();
|
||||||
final localVersion = info.version;
|
final localVersion = info.version;
|
||||||
if (localVersion.isEmpty) {
|
if (localVersion.isEmpty) {
|
||||||
_showSnackBar(context, 'Could not determine app version',
|
_showSnackBar(messenger, 'Could not determine app version',
|
||||||
isError: true);
|
isError: true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final latestVersion = await GitHubUpdater.fetchLatestVersion();
|
final latestVersion = await GitHubUpdater.fetchLatestVersion();
|
||||||
if (latestVersion == null) {
|
if (latestVersion == null) {
|
||||||
_showSnackBar(context, 'Could not reach GitHub', isError: true);
|
_showSnackBar(messenger, 'Could not reach GitHub', isError: true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_compareVersions(localVersion, latestVersion) >= 0) {
|
if (_compareVersions(localVersion, latestVersion) >= 0) {
|
||||||
_showSnackBar(context, 'Up to date');
|
_showSnackBar(messenger, 'Up to date');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final source = await installSource;
|
final source = await installSource;
|
||||||
final storeName = source == InstallSource.playStore ? 'Play Store' : 'GitHub';
|
final storeName =
|
||||||
if (!context.mounted) return;
|
source == InstallSource.playStore ? 'Play Store' : 'GitHub';
|
||||||
|
if (!navigator.mounted) return;
|
||||||
|
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: navigator.context,
|
||||||
builder: (ctx) => AlertDialog(
|
builder: (ctx) => AlertDialog(
|
||||||
backgroundColor: AppColors.bgCard,
|
backgroundColor: AppColors.bgCard,
|
||||||
title: const Text('Update available',
|
title: const Text('Update available',
|
||||||
@@ -171,9 +184,13 @@ class Updater {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _showSnackBar(BuildContext context, String message,
|
static void _showSnackBar(
|
||||||
{bool isError = false}) {
|
ScaffoldMessengerState messenger,
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
String message, {
|
||||||
|
bool isError = false,
|
||||||
|
}) {
|
||||||
|
if (!messenger.mounted) return;
|
||||||
|
messenger.showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
content: Row(
|
content: Row(
|
||||||
children: [
|
children: [
|
||||||
|
|||||||
Reference in new issue
Block a user