Skip to content

Commit

Permalink
Should work
Browse files Browse the repository at this point in the history
  • Loading branch information
Zverik committed Dec 3, 2024
1 parent 2dd5f5c commit d3606f7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
20 changes: 0 additions & 20 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down
34 changes: 31 additions & 3 deletions lib/providers/app_links_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Uri?>((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);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/screens/loading.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -79,6 +80,7 @@ class _LoadingPageState extends ConsumerState<LoadingPage> {
if (location != null) {
ref.read(effectiveLocationProvider.notifier).set(location);
}
await ref.read(geoIntentProvider).checkLatestIntent();

// Alert if there are too many changes loaded.
final needSizeAlert =
Expand Down

0 comments on commit d3606f7

Please sign in to comment.