flutter_deep_linking 0.1.0

  • Readme
  • Changelog
  • Installing
  • new89

🧭 Handle all your routing with proper deep links and handle them declaratively!

Getting started #

1. 📦 Add this package to your dependencies: #

dependencies:
  flutter_deep_linking: ^0.1.0

2. 🧭 Create a Router containing all your routes: #

final router = Router(
  routes: [
    Route(
      // This matches any HTTP or HTTPS URI pointing to schul-cloud.org.
      // Due to `isOptional`, this also matches URIs without a scheme or domain,
      // but not other domains.
      matcher: Matcher.webHost('schul-cloud.org', isOptional: true),
      // These nested routes are evaluated only if the above condition matches.
      routes: [
        Route(
          matcher: Matcher.path('courses'),
          materialBuilder: (_, __) => CoursesPage(),
          routes: [
            // If this route matches, it is used. Otherwise, we fall back to the
            // outer courses-route.
            Route(
              // {courseId} is a parameter matches a single path segment.
              matcher: Matcher.path('{courseId}'),
              materialBuilder: (_, RouteResult result) {
                // You can access the matched parameters using `result[<name>]`.
                return CourseDetailPage(result['courseId']);
              },
            ),
          ],
        ),
        Route(
          // Matcher.path can also match nested paths.
          matcher: Matcher.path('user/settings'),
          materialBuilder: (_, __) => SettingsPage(),
        ),
      ],
    ),
    // This route doesn't specify a matcher and hence matches any route.
    Route(
      materialBuilder: (_, RouteResult result) => NotFoundPage(result.uri),
    ),
  ],
);

Note: Flutter also defines a class called Route which can lead to some confusion. If you import package:flutter/widgets.dart in the same file as flutter_deep_linking, you can ignore Flutter's Route with import 'package:flutter/widgets.dart' hide Route;.

Router accepts a list of Routes which are searched top to bottom, depth first. Using Matchers you can match parts of the URI. Inner Matchers can't access parts of the URI that have already been matched by an outer Matcher.

To build the actual page, you can specify either of:

3. 🎯 Let your Router take care of resolving URIs in MaterialApp (or CupertinoApp or a custom Navigator): #

MaterialApp(
  onGenerateRoute: router.onGenerateRoute,
  // ...
)

4. 🚀 Use your new routes! #

When navigating, use navigator.pushNamed(uriString) instead of calling navigator.push(builder) and benefit from loose coupling!

And if you build an app in addition to a website, you can use a package like uni_links to receive incoming links and directly forward them to flutter_deep_linking.

More information #

Matchers #

Available Matchers:

  • Matcher.scheme: Matches a URI scheme like https.
  • Matcher.webScheme: Conveniently matches http or https.
  • Matcher.host: Matches a URI host like schul-cloud.org.
  • Matcher.webHost: Conveniently matches a webScheme (see above) and a URI host.
  • Matcher.path: Matches a single or multiple URI path segments like courses/{courseId}, whereas courseId is a placeholder and will match exactly one segment.

You can also combine Matchers within a single Route:

  • matcher1 & matcher2 matches both Matchers in sequence.
  • matcher1 | matcher2 evaluates both Matchers in sequence and returns the first match.

RouteResult #

RouteResult most importantly contains:

  • uri: The initial URI (which can be used e.g. to access query parameters).
  • parameters: A Map<String, String> of matched parameters, also accessible via result[<name>].
  • settings: The RouteSettings that should be forwarded to the generated (Flutter) Route.

Changelog #

This project adheres to Semantic Versioning.

Unreleased #

0.1.0 - 2020-03-13 #

Initial release 🎉

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_deep_linking: ^0.1.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_deep_linking/flutter_deep_linking.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
82
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
89
Learn more about scoring.

We analyzed this package on Mar 31, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Maintenance suggestions

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and flutter_deep_linking.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
meta ^1.1.8 1.1.8
Transitive dependencies
collection 1.14.11 1.14.12
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test
pedantic ^1.8.0
test ^1.6.0