Skip to content

Commit

Permalink
Migrate dynamic_links package to null safety.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas-Sander committed Aug 9, 2023
1 parent ad1f58b commit bd32600
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 21 deletions.
10 changes: 5 additions & 5 deletions lib/dynamic_links/lib/src/dynamic_links.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ typedef OnLinkErrorCallback = Future<dynamic> Function(
OnDynamicLinkErrorException error);

class OnDynamicLinkErrorException implements Exception {
final String code, message;
final String? code, message;
final dynamic details;
OnDynamicLinkErrorException(this.code, this.message, this.details);
}
Expand All @@ -24,19 +24,19 @@ class OnDynamicLinkErrorException implements Exception {
/// You can get an instance by calling [DynamicLinks.instance].
abstract class DynamicLinks {
/// Singleton of [DynamicLinks].
static DynamicLinks instance;
static DynamicLinks? instance;

/// Attempts to retrieve the dynamic link which launched the app.
///
/// This method always returns a Future. That Future completes to null if
/// there is no pending dynamic link or any call to this method after the
/// the first attempt.
Future<DynamicLinkData> getInitialLink();
Future<DynamicLinkData?>? getInitialLink();

/// Configures onLink listeners: it has two methods for success and failure.
void onLink({
OnLinkSuccessCallback onSuccess,
OnLinkErrorCallback onError,
OnLinkSuccessCallback? onSuccess,
OnLinkErrorCallback? onError,
});

Future<DynamicLinkData> getLinkData(String dynamicLink);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FirebaseDynamicLinks extends DynamicLinks {
FirebaseDynamicLinks(this._firebaseDynamicLinks);

@override
Future<DynamicLinkData> getInitialLink() async {
Future<DynamicLinkData?> getInitialLink() async {
try {
final pending = await _firebaseDynamicLinks.getInitialLink();
return _getPendingFromFirebase(pending);
Expand All @@ -27,7 +27,7 @@ class FirebaseDynamicLinks extends DynamicLinks {
}
}

DynamicLinkData _getPendingFromFirebase(fb.PendingDynamicLinkData pending) {
DynamicLinkData _getPendingFromFirebase(fb.PendingDynamicLinkData? pending) {
return DynamicLinkData(
pending?.link,
DynamicLinkDataAndroid(
Expand All @@ -39,10 +39,10 @@ class FirebaseDynamicLinks extends DynamicLinks {
void onLink({onSuccess, onError}) {
_firebaseDynamicLinks.onLink.listen(
(pending) {
onSuccess(_getPendingFromFirebase(pending));
onSuccess!(_getPendingFromFirebase(pending));
},
onError: (error) async {
onError(OnDynamicLinkErrorException(
onError!(OnDynamicLinkErrorException(
error.code, error.message, error.details));
},
cancelOnError: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import 'package:dynamic_links/src/models/dynamic_link_data.dart';
import '../dynamic_links.dart';

class LocalDynamicLinks extends DynamicLinks {
DynamicLinkData getInitialDataReturn;
DynamicLinkData onLinkSuccessReturn;
OnDynamicLinkErrorException onLinkErrorReturn;
DynamicLinkData? getInitialDataReturn;
DynamicLinkData? onLinkSuccessReturn;
OnDynamicLinkErrorException? onLinkErrorReturn;

@override
Future<DynamicLinkData> getInitialLink() {
Expand All @@ -23,10 +23,10 @@ class LocalDynamicLinks extends DynamicLinks {
@override
void onLink({onSuccess, onError}) {
if (onLinkSuccessReturn != null) {
onSuccess(onLinkSuccessReturn);
onSuccess!(onLinkSuccessReturn!);
}
if (onLinkErrorReturn != null) {
onError(onLinkErrorReturn);
onError!(onLinkErrorReturn!);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import '../dynamic_links.dart';

class StubDynamicLinks extends DynamicLinks {
@override
Future<DynamicLinkData> getInitialLink() {
Future<DynamicLinkData>? getInitialLink() {
return null;
}

Expand Down
8 changes: 4 additions & 4 deletions lib/dynamic_links/lib/src/models/dynamic_link_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class DynamicLinkData {
final DynamicLinkDataIOS ios;

/// Deep link parameter of the dynamic link.
final Uri link;
final Uri? link;
}

/// Provides android specific data from received dynamic link.
Expand All @@ -36,7 +36,7 @@ class DynamicLinkDataAndroid {
/// The time the user clicked on the dynamic link.
///
/// Equals the number of milliseconds that have elapsed since January 1, 1970.
final int clickTimestamp;
final int? clickTimestamp;

/// The minimum version of your app that can open the link.
///
Expand All @@ -45,7 +45,7 @@ class DynamicLinkDataAndroid {
///
/// If the installed app is an older version, the user is taken to the Play
/// Store to upgrade the app.
final int minimumVersion;
final int? minimumVersion;
}

/// Provides iOS specific data from received dynamic link.
Expand All @@ -56,5 +56,5 @@ class DynamicLinkDataIOS {
///
/// It is app developer's responsibility to open AppStore when received link
/// declares higher [minimumVersion] than currently installed.
final String minimumVersion;
final String? minimumVersion;
}
3 changes: 1 addition & 2 deletions lib/dynamic_links/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
name: dynamic_links
description: A new Flutter package project.
version: 0.0.1
homepage:
publish_to: none

environment:
sdk: ">=2.10.0 <3.0.0"
sdk: '>=2.12.0 <3.0.0'

dependencies:
firebase_dynamic_links: ^5.1.0
Expand Down

0 comments on commit bd32600

Please sign in to comment.