Deeplinks in Flutter Apps
The Deeplink utility classes enable the definition of handlers for deep links in a Flutter application. Handlers can assess their capability to handle a deep link and perform the navigation accordingly. This setup allows the creation of specific handlers and navigators to manage diverse deep links within the application.
Overview
The DeeplinkNavigator
is an abstract class that defines the interface for a deep link navigator. It has two methods:
findHandler(String link)
: This method takes a string representing a deep link and returns a DeeplinkNavigatorResult.handle({required DeeplinkNavigatorResult navigatorResult, required BuildContext context})
: This method takes aDeeplinkNavigatorResult
and aBuildContext
and handles the navigation based on the result.
abstract class DeeplinkNavigator {
DeeplinkNavigatorResult findHandler(String link);
void handle({
required DeeplinkNavigatorResult navigatorResult,
required BuildContext context,
});
}
DeeplinkNavigatorResult
: This class represents the result of finding a handler for a deep link. It has two properties:
link
: A string representing the deep link.handler
: An optional DeeplinkHandler that can handle the deep link.
class DeeplinkNavigatorResult {
final String link;
final DeeplinkHandler? handler;
DeeplinkNavigatorResult({required this.link, this.handler});
}
DeeplinkOpenFunction
: This is a typedef for a function that takes a deep link and a BuildContext
and opens the deep link.
typedef DeeplinkOpenFunction = void Function({
required String link,
required BuildContext context,
});
DeeplinkHandler
: This is an abstract class that defines the interface for a deep link handler. It has two methods:
deeplinkMatches(String link)
: This method checks if the handler can handle a given deep link.deeplinkNavigate({required String link, required BuildContext context})
: This method navigates to the deep link using the handler.
abstract class DeeplinkHandler {
bool deeplinkMatches(String link);
void deeplinkNavigate({
required String link,
required BuildContext context,
});
}
Usage
CHAT SAMMIAT