nav key scope
This commit is contained in:
parent
1ed23d40ba
commit
25dc291ba4
4 changed files with 27 additions and 26 deletions
|
@ -60,7 +60,6 @@ class AvesApp extends StatefulWidget {
|
||||||
static final _unsupportedLocales = {'ar', 'ckb', 'fa', 'gl', 'he', 'hi', 'nn', 'sk', 'th'}.map(Locale.new).toSet();
|
static final _unsupportedLocales = {'ar', 'ckb', 'fa', 'gl', 'he', 'hi', 'nn', 'sk', 'th'}.map(Locale.new).toSet();
|
||||||
static final List<Locale> supportedLocales = AppLocalizations.supportedLocales.where((v) => !_unsupportedLocales.contains(v)).toList();
|
static final List<Locale> supportedLocales = AppLocalizations.supportedLocales.where((v) => !_unsupportedLocales.contains(v)).toList();
|
||||||
static final ValueNotifier<EdgeInsets> cutoutInsetsNotifier = ValueNotifier(EdgeInsets.zero);
|
static final ValueNotifier<EdgeInsets> cutoutInsetsNotifier = ValueNotifier(EdgeInsets.zero);
|
||||||
static final GlobalKey<NavigatorState> navigatorKey = GlobalKey(debugLabel: 'app-navigator');
|
|
||||||
|
|
||||||
// do not monitor all `ModalRoute`s, which would include popup menus,
|
// do not monitor all `ModalRoute`s, which would include popup menus,
|
||||||
// so that we can react to fullscreen `PageRoute`s only
|
// so that we can react to fullscreen `PageRoute`s only
|
||||||
|
@ -156,6 +155,7 @@ class _AvesAppState extends State<AvesApp> with WidgetsBindingObserver {
|
||||||
// - `OpenUpwardsPageTransitionsBuilder` on Pie / API 28
|
// - `OpenUpwardsPageTransitionsBuilder` on Pie / API 28
|
||||||
// - `ZoomPageTransitionsBuilder` on Android 10 / API 29 and above (default in Flutter v3.0.0)
|
// - `ZoomPageTransitionsBuilder` on Android 10 / API 29 and above (default in Flutter v3.0.0)
|
||||||
static const defaultPageTransitionsBuilder = FadeUpwardsPageTransitionsBuilder();
|
static const defaultPageTransitionsBuilder = FadeUpwardsPageTransitionsBuilder();
|
||||||
|
static final GlobalKey<NavigatorState> _navigatorKey = GlobalKey(debugLabel: 'app-navigator');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
@ -259,7 +259,7 @@ class _AvesAppState extends State<AvesApp> with WidgetsBindingObserver {
|
||||||
accessibleNavigation: false,
|
accessibleNavigation: false,
|
||||||
),
|
),
|
||||||
child: MaterialApp(
|
child: MaterialApp(
|
||||||
navigatorKey: AvesApp.navigatorKey,
|
navigatorKey: _navigatorKey,
|
||||||
home: home,
|
home: home,
|
||||||
navigatorObservers: _navigatorObservers,
|
navigatorObservers: _navigatorObservers,
|
||||||
builder: (context, child) => _decorateAppChild(
|
builder: (context, child) => _decorateAppChild(
|
||||||
|
@ -510,7 +510,7 @@ class _AvesAppState extends State<AvesApp> with WidgetsBindingObserver {
|
||||||
|
|
||||||
void applyForceTvLayout() {
|
void applyForceTvLayout() {
|
||||||
_onTvLayoutChanged();
|
_onTvLayoutChanged();
|
||||||
unawaited(AvesApp.navigatorKey.currentState!.pushAndRemoveUntil(
|
unawaited(_navigatorKey.currentState!.pushAndRemoveUntil(
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
settings: const RouteSettings(name: HomePage.routeName),
|
settings: const RouteSettings(name: HomePage.routeName),
|
||||||
builder: (_) => _getFirstPage(),
|
builder: (_) => _getFirstPage(),
|
||||||
|
@ -572,7 +572,7 @@ class _AvesAppState extends State<AvesApp> with WidgetsBindingObserver {
|
||||||
}
|
}
|
||||||
|
|
||||||
reportService.log('New intent data=$intentData');
|
reportService.log('New intent data=$intentData');
|
||||||
AvesApp.navigatorKey.currentState!.pushReplacement(DirectMaterialPageRoute(
|
_navigatorKey.currentState!.pushReplacement(DirectMaterialPageRoute(
|
||||||
settings: const RouteSettings(name: HomePage.routeName),
|
settings: const RouteSettings(name: HomePage.routeName),
|
||||||
builder: (_) => _getFirstPage(intentData: intentData),
|
builder: (_) => _getFirstPage(intentData: intentData),
|
||||||
));
|
));
|
||||||
|
|
|
@ -21,7 +21,6 @@ import 'package:aves/services/media/enums.dart';
|
||||||
import 'package:aves/services/media/media_edit_service.dart';
|
import 'package:aves/services/media/media_edit_service.dart';
|
||||||
import 'package:aves/theme/durations.dart';
|
import 'package:aves/theme/durations.dart';
|
||||||
import 'package:aves/utils/android_file_utils.dart';
|
import 'package:aves/utils/android_file_utils.dart';
|
||||||
import 'package:aves/widgets/aves_app.dart';
|
|
||||||
import 'package:aves/widgets/collection/collection_page.dart';
|
import 'package:aves/widgets/collection/collection_page.dart';
|
||||||
import 'package:aves/widgets/collection/entry_set_action_delegate.dart';
|
import 'package:aves/widgets/collection/entry_set_action_delegate.dart';
|
||||||
import 'package:aves/widgets/common/action_mixins/feedback.dart';
|
import 'package:aves/widgets/common/action_mixins/feedback.dart';
|
||||||
|
@ -91,14 +90,15 @@ mixin EntryStorageMixin on FeedbackMixin, PermissionAwareMixin, SizeAwareMixin {
|
||||||
unawaited(source.refreshUris(newUris));
|
unawaited(source.refreshUris(newUris));
|
||||||
|
|
||||||
final l10n = context.l10n;
|
final l10n = context.l10n;
|
||||||
|
// get navigator beforehand because
|
||||||
|
// local context may be deactivated when action is triggered after navigation
|
||||||
|
final navigator = Navigator.maybeOf(context);
|
||||||
final showAction = isMainMode && newUris.isNotEmpty
|
final showAction = isMainMode && newUris.isNotEmpty
|
||||||
? SnackBarAction(
|
? SnackBarAction(
|
||||||
label: l10n.showButtonLabel,
|
label: l10n.showButtonLabel,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
// local context may be deactivated when action is triggered after navigation
|
if (navigator != null) {
|
||||||
final context = AvesApp.navigatorKey.currentContext;
|
navigator.pushAndRemoveUntil(
|
||||||
if (context != null) {
|
|
||||||
Navigator.maybeOf(context)?.pushAndRemoveUntil(
|
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
settings: const RouteSettings(name: CollectionPage.routeName),
|
settings: const RouteSettings(name: CollectionPage.routeName),
|
||||||
builder: (context) => CollectionPage(
|
builder: (context) => CollectionPage(
|
||||||
|
@ -235,17 +235,18 @@ mixin EntryStorageMixin on FeedbackMixin, PermissionAwareMixin, SizeAwareMixin {
|
||||||
|
|
||||||
SnackBarAction? action;
|
SnackBarAction? action;
|
||||||
if (count > 0 && appMode == AppMode.main) {
|
if (count > 0 && appMode == AppMode.main) {
|
||||||
|
// get navigator beforehand because
|
||||||
|
// local context may be deactivated when action is triggered after navigation
|
||||||
|
final navigator = Navigator.maybeOf(context);
|
||||||
if (toBin) {
|
if (toBin) {
|
||||||
if (movedEntries.isNotEmpty) {
|
if (movedEntries.isNotEmpty) {
|
||||||
action = SnackBarAction(
|
action = SnackBarAction(
|
||||||
// TODO TLAD [l10n] key for "RESTORE"
|
// TODO TLAD [l10n] key for "RESTORE"
|
||||||
label: l10n.entryActionRestore.toUpperCase(),
|
label: l10n.entryActionRestore.toUpperCase(),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
// local context may be deactivated when action is triggered after navigation
|
if (navigator != null) {
|
||||||
final context = AvesApp.navigatorKey.currentContext;
|
|
||||||
if (context != null) {
|
|
||||||
doMove(
|
doMove(
|
||||||
context,
|
navigator.context,
|
||||||
moveType: MoveType.fromBin,
|
moveType: MoveType.fromBin,
|
||||||
entries: movedEntries,
|
entries: movedEntries,
|
||||||
hideShowAction: true,
|
hideShowAction: true,
|
||||||
|
@ -258,10 +259,8 @@ mixin EntryStorageMixin on FeedbackMixin, PermissionAwareMixin, SizeAwareMixin {
|
||||||
action = SnackBarAction(
|
action = SnackBarAction(
|
||||||
label: l10n.showButtonLabel,
|
label: l10n.showButtonLabel,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
// local context may be deactivated when action is triggered after navigation
|
if (navigator != null) {
|
||||||
final context = AvesApp.navigatorKey.currentContext;
|
_showMovedItems(navigator.context, destinationAlbums, movedOps);
|
||||||
if (context != null) {
|
|
||||||
_showMovedItems(context, destinationAlbums, movedOps);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -21,7 +21,6 @@ import 'package:aves/services/common/services.dart';
|
||||||
import 'package:aves/services/media/enums.dart';
|
import 'package:aves/services/media/enums.dart';
|
||||||
import 'package:aves/theme/durations.dart';
|
import 'package:aves/theme/durations.dart';
|
||||||
import 'package:aves/utils/android_file_utils.dart';
|
import 'package:aves/utils/android_file_utils.dart';
|
||||||
import 'package:aves/widgets/aves_app.dart';
|
|
||||||
import 'package:aves/widgets/common/action_mixins/entry_storage.dart';
|
import 'package:aves/widgets/common/action_mixins/entry_storage.dart';
|
||||||
import 'package:aves/widgets/common/action_mixins/vault_aware.dart';
|
import 'package:aves/widgets/common/action_mixins/vault_aware.dart';
|
||||||
import 'package:aves/widgets/common/extensions/build_context.dart';
|
import 'package:aves/widgets/common/extensions/build_context.dart';
|
||||||
|
@ -245,18 +244,21 @@ class AlbumChipSetActionDelegate extends ChipSetActionDelegate<AlbumFilter> with
|
||||||
source.createAlbum(directory);
|
source.createAlbum(directory);
|
||||||
|
|
||||||
final filter = AlbumFilter(directory, source.getAlbumDisplayName(context, directory));
|
final filter = AlbumFilter(directory, source.getAlbumDisplayName(context, directory));
|
||||||
|
// get navigator beforehand because
|
||||||
|
// local context may be deactivated when action is triggered after navigation
|
||||||
|
final navigator = Navigator.maybeOf(context);
|
||||||
final showAction = SnackBarAction(
|
final showAction = SnackBarAction(
|
||||||
label: l10n.showButtonLabel,
|
label: l10n.showButtonLabel,
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
// local context may be deactivated when action is triggered after navigation
|
// local context may be deactivated when action is triggered after navigation
|
||||||
final context = AvesApp.navigatorKey.currentContext;
|
if (navigator != null) {
|
||||||
if (context != null) {
|
final context = navigator.context;
|
||||||
final highlightInfo = context.read<HighlightInfo>();
|
final highlightInfo = context.read<HighlightInfo>();
|
||||||
if (context.currentRouteName == AlbumListPage.routeName) {
|
if (context.currentRouteName == AlbumListPage.routeName) {
|
||||||
highlightInfo.trackItem(FilterGridItem(filter, null), highlightItem: filter);
|
highlightInfo.trackItem(FilterGridItem(filter, null), highlightItem: filter);
|
||||||
} else {
|
} else {
|
||||||
highlightInfo.set(filter);
|
highlightInfo.set(filter);
|
||||||
await Navigator.maybeOf(context)?.pushAndRemoveUntil(
|
await navigator.pushAndRemoveUntil(
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
settings: const RouteSettings(name: AlbumListPage.routeName),
|
settings: const RouteSettings(name: AlbumListPage.routeName),
|
||||||
builder: (_) => const AlbumListPage(),
|
builder: (_) => const AlbumListPage(),
|
||||||
|
|
|
@ -10,7 +10,6 @@ import 'package:aves/services/common/services.dart';
|
||||||
import 'package:aves/services/media/enums.dart';
|
import 'package:aves/services/media/enums.dart';
|
||||||
import 'package:aves/theme/durations.dart';
|
import 'package:aves/theme/durations.dart';
|
||||||
import 'package:aves/utils/android_file_utils.dart';
|
import 'package:aves/utils/android_file_utils.dart';
|
||||||
import 'package:aves/widgets/aves_app.dart';
|
|
||||||
import 'package:aves/widgets/collection/collection_page.dart';
|
import 'package:aves/widgets/collection/collection_page.dart';
|
||||||
import 'package:aves/widgets/common/action_mixins/feedback.dart';
|
import 'package:aves/widgets/common/action_mixins/feedback.dart';
|
||||||
import 'package:aves/widgets/common/action_mixins/permission_aware.dart';
|
import 'package:aves/widgets/common/action_mixins/permission_aware.dart';
|
||||||
|
@ -112,16 +111,17 @@ class VideoActionDelegate with FeedbackMixin, PermissionAwareMixin, SizeAwareMix
|
||||||
final l10n = context.l10n;
|
final l10n = context.l10n;
|
||||||
if (success) {
|
if (success) {
|
||||||
final _collection = collection;
|
final _collection = collection;
|
||||||
|
// get navigator beforehand because
|
||||||
|
// local context may be deactivated when action is triggered after navigation
|
||||||
|
final navigator = Navigator.maybeOf(context);
|
||||||
final showAction = _collection != null
|
final showAction = _collection != null
|
||||||
? SnackBarAction(
|
? SnackBarAction(
|
||||||
label: l10n.showButtonLabel,
|
label: l10n.showButtonLabel,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
// local context may be deactivated when action is triggered after navigation
|
if (navigator != null) {
|
||||||
final context = AvesApp.navigatorKey.currentContext;
|
|
||||||
if (context != null) {
|
|
||||||
final source = _collection.source;
|
final source = _collection.source;
|
||||||
final newUri = newFields['uri'] as String?;
|
final newUri = newFields['uri'] as String?;
|
||||||
Navigator.maybeOf(context)?.pushAndRemoveUntil(
|
navigator.pushAndRemoveUntil(
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
settings: const RouteSettings(name: CollectionPage.routeName),
|
settings: const RouteSettings(name: CollectionPage.routeName),
|
||||||
builder: (context) => CollectionPage(
|
builder: (context) => CollectionPage(
|
||||||
|
|
Loading…
Reference in a new issue