flutter_deep_linking
🧭 적절한 딥 링크를 사용하여 모든 라우팅을 처리하고 선언적으로 처리하세요!
- 스타
- 8
- 포크
- 2
- 최근 푸시(UTC)
- 2024. 9. 3.
- 프로젝트 상태
- 활성
원본 README
아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
🧭 Handle all your routing with proper deep links and handle them declaratively!
What this package is about
This package takes declaratively defined Routes and receives a URI during navigation, evaluates those and then returns a PageRoute for the correct page. This means, you can now benefit from loose coupling and navigate using:
Navigator.of(context).pushNamed('/articles/$id')
instead of hardcoding the corresponding widget everytime:
Navigator.of(context)
.push(MaterialPageRoute(builder: (_) => ArticlePage(id)));
What this package is not about
This package doesn't catch incoming deep links from other apps. For this, I recommend uni_links.
You can, however, combine both packages. Just forward any received deep links to your Navigator and flutter_deep_linking takes care of resolving them. This also works with the initial deep link:
String initialLink = await getInitialLink(); // from uni_links
return MaterialApp(
initialRoute: initialLink,
onGenerateRoute: router.onGenerateRoute, // from flutter_deep_linking
// ...
);
Getting started
1. 🧭 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 classes called
Route&RouteBuilderwhich can lead to some confusion. If you importpackage:flutter/widgets.dartin the same file asflutter_deep_linking, you can ignore Flutter'sRoute&RouteBuilderwithimport 'package:flutter/widgets.dart' hide Route, RouteBuilder;.
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:
Route.builder: Takes aRouteResultand returns an instance of Flutter'sRoute.Route.materialBuilder(Convenience property): Takes a [BuildContext] and aRouteResultand returns a widget, which is then wrapped inMaterialPageRoute.
2. 🎯 Let your Router take care of resolving URIs in MaterialApp (or CupertinoApp or a custom Navigator):
MaterialApp(
onGenerateRoute: router.onGenerateRoute,
// ...
)
3. 🚀 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 likehttps.Matcher.webScheme: Conveniently matcheshttporhttps.Matcher.host: Matches a URI host likeschul-cloud.org.Matcher.webHost: Conveniently matches awebScheme(see above) and a URI host.Matcher.path: Matches a single or multiple URI path segments likecourses/{courseId}, whereascourseIdis a placeholder and will match exactly one segment.
You can also combine Matchers within a single Route:
matcher1 & matcher2matches bothMatchers in sequence.matcher1 | matcher2evaluates bothMatchers 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: AMap<String, String>of matched parameters, also accessible viaresult[<name>].settings: TheRouteSettingsthat should be forwarded to the generated (Flutter)Route.
분류
사용 중인 의존성
의존성 목록 6 개
- collection
^1.15.0 - flutter
{"sdk":"flutter"} - meta
^1.3.0 - extra_pedantic개발 의존성
^1.3.0 - flutter_test개발 의존성
{"sdk":"flutter"} - test개발 의존성
^1.16.0
프로젝트에 맞는 저장소를 선택하려면?
사용 목적에 따라 검색하고 개발 활동을 비교한 뒤 원본 저장소에서 요구 사항을 확인하세요.
- 이름, 작성자 또는 설명으로 검색하고 기술 주제로 범위를 좁힙니다.
- 스타, 포크, 최근 푸시를 함께 비교하세요. 스타는 관심의 지표이며 품질을 보장하지 않습니다.
- 사용하기 전에 GitHub에서 README, 라이선스, Issues를 확인하세요.
출처 및 관리
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗