diff --git a/lib/main.dart b/lib/main.dart index 7b8d619..823f072 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -2,10 +2,7 @@ import 'dart:async'; import 'dart:io'; import 'package:every_door/helpers/log_store.dart'; -import 'package:every_door/helpers/navigation_helper.dart'; -import 'package:every_door/providers/app_links_provider.dart'; import 'package:every_door/providers/language.dart'; -import 'package:every_door/providers/navigation_provider.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:every_door/constants.dart'; @@ -47,25 +44,8 @@ class EveryDoorApp extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { - final navigatorKey = ref.read(navigatonKeyProvider); - final uriAsyncValue = ref.watch(uriLinkStreamProvider); - - WidgetsBinding.instance.addPostFrameCallback((_) { - uriAsyncValue.whenData((uri) { - if (uri != null) { - final screen = NavigationHelper.navigateByUri(uri); - if (context.mounted) { - navigatorKey.currentState?.push( - MaterialPageRoute(builder: (context) => screen), - ); - } - } - }); - }); - return Portal( child: MaterialApp( - navigatorKey: navigatorKey, title: kAppTitle, theme: ThemeData( primarySwatch: Colors.blue, diff --git a/lib/providers/app_links_provider.dart b/lib/providers/app_links_provider.dart index 0ca6249..9081423 100644 --- a/lib/providers/app_links_provider.dart +++ b/lib/providers/app_links_provider.dart @@ -5,11 +5,39 @@ import 'package:app_links/app_links.dart'; import 'package:latlong2/latlong.dart'; import 'package:logging/logging.dart'; -final appLinksProvider = Provider((ref) => AppLinks()); +final geoIntentProvider = Provider((ref) => GeoIntentController(ref)); + +class GeoIntentController { + final Ref _ref; + + GeoIntentController(this._ref) { + initStreamListener(); + } + + initStreamListener() async { + await for (final uri in AppLinks().uriLinkStream) { + _handleGeoIntent(uri); + } + } + + checkLatestIntent() async { + final latest = await AppLinks().getLatestLink(); + if (latest != null) _handleGeoIntent(latest); + } + + _handleGeoIntent(Uri uri) { + if (uri.scheme == 'geo' && uri.path.isNotEmpty) { + final location = _parseLatLngFromGeoUri(uri); + if (location != null) { + _ref.read(geolocationProvider.notifier).disableTracking(); + _ref.read(effectiveLocationProvider.notifier).set(location); + } + } + } +} final uriLinkStreamProvider = StreamProvider((ref) async* { - final appLinks = ref.watch(appLinksProvider); - await for (final uri in appLinks.uriLinkStream) { + await for (final uri in AppLinks().uriLinkStream) { if (uri.scheme == 'geo' && uri.path.isNotEmpty) { _handleGeoIntent(uri, ref); } diff --git a/lib/screens/loading.dart b/lib/screens/loading.dart index cd7c8bc..84ea619 100644 --- a/lib/screens/loading.dart +++ b/lib/screens/loading.dart @@ -1,5 +1,6 @@ import 'dart:async'; +import 'package:every_door/providers/app_links_provider.dart'; import 'package:every_door/providers/changes.dart'; import 'package:every_door/providers/changeset_tags.dart'; import 'package:every_door/providers/geolocation.dart'; @@ -79,6 +80,7 @@ class _LoadingPageState extends ConsumerState { if (location != null) { ref.read(effectiveLocationProvider.notifier).set(location); } + await ref.read(geoIntentProvider).checkLatestIntent(); // Alert if there are too many changes loaded. final needSizeAlert =