-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #806 from ann-who/geo_intents
Open geo intents
- Loading branch information
Showing
10 changed files
with
164 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import 'package:every_door/screens/browser.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class NavigationHelper { | ||
static Widget navigateByUri(Uri uri) { | ||
if (uri.scheme == 'geo' && uri.path.isNotEmpty) { | ||
return BrowserPage(); | ||
} | ||
return BrowserPage(); | ||
} | ||
} |
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,69 @@ | ||
import 'package:every_door/providers/geolocation.dart'; | ||
import 'package:every_door/providers/location.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:app_links/app_links.dart'; | ||
import 'package:latlong2/latlong.dart'; | ||
import 'package:logging/logging.dart'; | ||
|
||
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* { | ||
await for (final uri in AppLinks().uriLinkStream) { | ||
if (uri.scheme == 'geo' && uri.path.isNotEmpty) { | ||
_handleGeoIntent(uri, ref); | ||
} | ||
|
||
yield uri; | ||
} | ||
}); | ||
|
||
void _handleGeoIntent(Uri uri, StreamProviderRef<Uri?> ref) { | ||
final location = _parseLatLngFromGeoUri(uri); | ||
if (location != null) { | ||
ref.read(geolocationProvider.notifier).disableTracking(); | ||
ref.read(effectiveLocationProvider.notifier).set(location); | ||
} | ||
} | ||
|
||
LatLng? _parseLatLngFromGeoUri(Uri uri) { | ||
try { | ||
final coords = uri.path.split(','); | ||
if (coords.length == 2) { | ||
final lat = double.parse(coords[0]); | ||
final lng = double.parse(coords[1]); | ||
return LatLng(lat, lng); | ||
} | ||
} catch (e) { | ||
Logger('AppLinks').warning('Failed to parse coordinates'); | ||
} | ||
return null; | ||
} |
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,6 @@ | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
||
final navigatonKeyProvider = Provider<GlobalKey<NavigatorState>>((ref) { | ||
return GlobalKey<NavigatorState>(); | ||
}); |
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