Skip to content

Commit

Permalink
feat: Add Uri as String
Browse files Browse the repository at this point in the history
  • Loading branch information
llfbandit committed May 7, 2021
1 parent 77e07fa commit 55b6f96
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.1.0
* Breaking: String uri added on `onAppLink` for custom handling like uppercased uri.
* Feat: `getInitialAppLinkString` and `getLatestAppLinkString` added to reflect the above change.

## 2.0.0+1
* Minimal sample added (Thanks to @JamesCullum).

Expand Down
7 changes: 4 additions & 3 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class _MyAppState extends State<MyApp> {

void initDeepLinks() async {
final _appLinks = AppLinks(
onAppLink: (Uri uri) {
onAppLink: (Uri uri, String stringUri) {
openAppLink(uri);
},
);
Expand Down Expand Up @@ -64,7 +64,7 @@ class _MyAppState extends State<MyApp> {
var uri = Uri.parse(settings.name);
var firstLevel =
uri.pathSegments.length > 0 ? uri.pathSegments.first : "";
switch(firstLevel) {
switch (firstLevel) {
case "book":
if (uri.pathSegments.length > 1) {
// Navigated to /book/:id
Expand All @@ -88,7 +88,8 @@ class _MyAppState extends State<MyApp> {
Widget defaultScreen() {
return Scaffold(
appBar: AppBar(title: const Text('Default Screen')),
body: Center(child: const Text('Launch an intent to get to the second screen')),
body: Center(
child: const Text('Launch an intent to get to the second screen')),
);
}

Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
path: ".."
relative: true
source: path
version: "2.0.0+1"
version: "2.1.0"
async:
dependency: transitive
description:
Expand Down
23 changes: 19 additions & 4 deletions lib/app_links.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import 'dart:async';
import 'package:flutter/services.dart';

/// Callback when your app is woke up by an incoming link
/// [uri] and [stringUri] are same value.
/// [stringUri] is available for custom handling like uppercased uri.
///
typedef void OnAppLinkFunction(Uri uri);
typedef void OnAppLinkFunction(Uri uri, String stringUri);

/// Android App Links, Deep Links,
/// iOs Universal Links and Custom URL schemes handler
Expand Down Expand Up @@ -34,7 +36,8 @@ class AppLinks {
switch (call.method) {
case _onAppLinkMethod:
if (call.arguments != null) {
onAppLink(Uri.parse(call.arguments.toString()));
final uri = call.arguments.toString();
onAppLink(Uri.parse(uri), uri);
}
}

Expand All @@ -46,18 +49,30 @@ class AppLinks {
/// Gets the initial / first link
/// returns [Uri] or [null]
Future<Uri?> getInitialAppLink() async {
final result = await _channel.invokeMethod(_getInitialAppLinkMethod);
final result = await getInitialAppLinkString();
if (result == null) return null;

return Uri.tryParse(result);
}

/// Gets the initial / first link
/// returns [Uri] as String or [null]
Future<String?> getInitialAppLinkString() async {
return await _channel.invokeMethod(_getInitialAppLinkMethod);
}

/// Gets the latest link
/// returns [Uri] or [null]
Future<Uri?> getLatestAppLink() async {
final result = await _channel.invokeMethod(_getLatestAppLinkMethod);
final result = await getLatestAppLinkString();
if (result == null) return null;

return Uri.tryParse(result);
}

/// Gets the latest link
/// returns [Uri] as String or [null]
Future<String?> getLatestAppLinkString() async {
return await _channel.invokeMethod(_getLatestAppLinkMethod);
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: app_links
description: Android App Links, Deep Links, iOs Universal Links and Custom URL schemes handler for Flutter.
version: 2.0.0+1
version: 2.1.0
homepage: https://github.com/llfbandit/app_links

environment:
Expand Down

0 comments on commit 55b6f96

Please sign in to comment.