flutter-navigation
/flutter-navigation
Wyjaśnia i wdraża nawigację Flutter: Navigator 1.0, go_router, przekierowania logowania, linki głębokie i obsługę cofania.
- Autor
- Dee9975 ↗
- Repozytorium
- cc-skills-flutter ↗
- Licencja
- MIT
- Ostatnia zmiana repozytorium
- 05.11.2026
Ocena i bezpieczeństwo
- Pliki w paczce
- 1
- Skrypty
- 0
- Komentarze HTML
- 0
- Adresy URL w SKILL.md
- 2
Brak sygnałów. Repozytorium zmienione 05.11.2026, bez odwołań do wycofanych modeli i API.
MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.
Co robi i kiedy
Wyjaśnia i wdraża nawigację Flutter: Navigator 1.0, go_router, przekierowania logowania, linki głębokie i obsługę cofania.
Oryginalny opis (EN)
Flutter navigation and routing — Navigator 1.0 (push/pop, returning results) vs Router API, go_router setup (GoRoute, path and query parameters, nested routes, ShellRoute and StatefulShellRoute for bottom navigation with preserved stacks), redirects for authentication with refreshListenable, typed routes, deep links and app links (Android intent filters, iOS associated domains), web URL strategy, PopScope for back handling, dialogs and bottom sheets. Use when adding screens, wiring deep links, building tab navigation, or guarding routes behind login.
Jak działa
- Choosing an approach
- The router (lib/src/core/router/router.dart)
- Navigating
- Auth redirects
- AppShell (lib/src/core/router/appshell.dart)
- Typed routes
- Deep links
- Web
- Back handling
- Dialogs and sheets
Podgląd SKILL.md
---
name: flutter-navigation
description: "Flutter navigation and routing — Navigator 1.0 (push/pop, returning results) vs Router API, go_router setup (GoRoute, path and query parameters, nested routes, ShellRoute and StatefulShellRoute for bottom navigation with preserved stacks), redirects for authentication with refreshListenable, typed routes, deep links and app links (Android intent filters, iOS associated domains), web URL strategy, PopScope for back handling, dialogs and bottom sheets. Use when adding screens, wiring deep links, building tab navigation, or guarding routes behind login."
license: MIT
metadata:
author: Matiss Kalnins
version: "0.5.0"
---
**Persona:** You make every screen addressable by URL. Navigation state is derived from app state (auth, onboarding), not scattered imperatively through button handlers.
## Choosing an approach
- **Small app, no deep links, no web**: `Navigator.push` with `MaterialPageRoute` is fine.
- **Anything else**: use **go_router** (the Flutter team's package). It handles deep links, web URLs, redirects, and nested navigation through the Router API.
- Use `auto_route` only if the project already does.
## The router (lib/src/core/router/router.dart)
There's one router. It's a keepAlive provider in `core/router/`, which imports every feature barrel. Features don't export route lists.
```dart
@Riverpod(keepAlive: true)
GoRouter router(Ref ref) {
// Player details exist in more than one tab, so each tab opens them in its
// own stack instead of jumping to another tab.
Widget playerDetails(BuildContext context, GoRouterState state) {
final int playerId = int.tryParse(state.pathParameters["id"] ?? "") ?? 0;
return PlayerDetailsScreen(playerId: playerId);
}
final router = GoRouter(
initialLocation: "/teams",
routes: [
// One branch per bottom navigation tab, in the order of the tabs.
StatefulShellRoute.indexedStack(
builder: (context, state, navigationShell) {
return AppShell(navigationShell: navigationShell);
},
branches: [
StatefulShellBranch(
routes: [
GoRoute(
path: "/teams",
builder: (context, state) => const TeamsScreen(),
routes: [
GoRoute(
path: "team/:abr",
builder: (context, state) {
// `extra` is lost on deep links and web refreshes, so
// fall back to a standing holding only the
// abbreviation from the path.
final TeamStanding standing = switch (state.extra) {
final TeamStanding standing => standing,
_ => TeamStanding(
teamAbbrev: LocalizedName(value: state.pathParameters["abr"] ?? ""),
),
};
return TeamDetailsScreen(standing: standing);
},
),
GoRoute(path: "player/:id", builder: playerDetails),
],
),
],
),
StatefulShellBranch(
routes: [
GoRoute(
path: "/leaders",
builder: (context, state) => const LeadersScreen(),
routes: [GoRoute(path: "player/:id", builder: playerDetails)],
),
],
),
],
),
],
);
ref.onDispose(router.dispose);
return router;
}
```
- **Tabs** are `StatefulShellRoute.indexedStack` branches, so each tab keeps its own stack. Detail screens are nested `GoRoute`s under their tab.
- **A screen reachable from several tabs** is registered in each tab with a shared builder, written as a local function inside the provider (`playerDetails`). Tapping a player in Leaders then stays in the Leaders tab.
- **Path parameters** are parsed defensively: `int.tryParse(state.pathParameters["id"] ?? "") ?? 0`.
- **`extra`** may carry an already-loaded object to avoid a refetch flash. Always fall back to something built from the path, since `extra` is lost on deep links and web refresh.
- Dispose the router with `ref.onDispose(router.dispose)`, and pass it to `MaterialApp.router(routerConfig: ref.watch(routerProvider))`.
## Navigating
- Components navigate directly: `onTap: () { unawaited(context.push("/leaders/player/${leader.id}")); }`. `push` returns a `Future`, so wrap it in `unawaited`.
- `context.push` adds a page on top of the current tab's stack. `context.go` replaces the stack to match the URL. Use `go` only to jump between unrelated places.
- Pass IDs in the path. Use `extra` only as the optional optimization above.
## Auth redirects
```dart
GoRouter(
refreshListenable: authNotifier, // re-run redirect when auth changes
redirect: (context, state) {
final bool loggingIn = state.matchedLocation == "/login";
return switch ((authNotifier.isLoggedIn, loggingIn)) {
(false, false) => "/login?from=${Uri.encodeComponent(state.uri.toString())}",
(true, true) => state.uri.queryParameters["from"] ?? "/",
_ => null, // no redirect
};
},
routes: [...],
);
```
Keep `redirect` synchronous and cheap. Resolve the auth state before the router starts (on a splash route) instead of awaiting inside `redirect`.
## AppShell (lib/src/core/router/app_shell.dart)
```dart
/// Bottom navigation bar around the current tab's screen.
///
/// Each tab is a branch of a [StatefulShellRoute], so it keeps its own
/// navigation stack when the user switches tabs.
class const AppShell({
super.key,
required final StatefulNavigationShell navigationShell,
}) extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: navigationShell,
bottomNavigationBar: NavigationBar(
selectedIndex: navigationShell.currentIndex,
onDestinationSelected: _onTabSelected,
destinations: const [
NavigationDestination(icon: Icon(Icons.shield_outlined), selectedIcon: Icon(Icons.shield), label: "Teams"),
NavigationDestination(icon: Icon(Icons.leaderboard_outlined), selectedIcon: Icon(Icons.leaderboard), label: "Leaders"),
],
),
);
}
/// Switches tab. Tapping the current tab again pops it back to its root.
void _onTabSelected(int index) {
navigationShell.goBranch(index, initialLocation: index == navigationShell.currentIndex);
}
}
```
## Typed routes
For larger apps, use `go_router_builder` (`@TypedGoRoute`) so `ProductRoute(id: "42").go(context)` is checked at compile time instead of using string paths.
## Deep links
- Android: add an `<intent-filter android:autoVerify="true">` with your `https` host to `AndroidManifest.xml`, and host `/.well-known/assetlinks.json`.
- iOS: add `applinks:yourdomain.com` under Associated Domains, and host `apple-app-site-association`.
- Test with `adb shell am start -a android.intent.action.VIEW -d "https://yourdomain.com/products/42"` and `xcrun simctl openurl booted "https://..."`.
- Every deep-linkable route has to work from a cold start, with no assumption that some previous screen ran first.
## Web
Call `usePathUrlStrategy()` (from `flutter_web_plugins`) before `runApp` for clean URLs without `#`. The server then has to rewrite unknown paths to `index.html`.
## Back handling
Use `PopScope` (not the deprecated `WillPopScope`):
```dart
PopScope(
canPop: !hasUnsavedChanges,
onPopInvokedWithResult: (didPop, result) async {
if (didPop) return;
if (await confirmDiscard(context) && context.mounted) Navigator.of(context).pop();
},
child: form,
);
```
## Dialogs and sheets
`showDialog` / `showModalBottomSheet` return a `Future` of the popped value. Close them with `Navigator.of(context).pop(value)` or `context.pop(value)`. They sit on the root navigator by default. Pass `useRootNavigator: false` to keep one inside a shell branch.
Wersje
| Repozytorium | Wynik | Licencja |
|---|---|---|
| Ta strona · Dee9975/cc-skills-flutter | 100 | MIT |
| HoangNguyen0403/agent-skills-standard | 100 | MIT |
| HoangNguyen0403/agent-skills-standard | 100 | MIT |
| madteacher/mad-agents-skills | 100 | MIT |
| thiennc-tesoglobal/flutter-skills | 90 | BSD-3-Clause |
Migawka bazy z 13.11.2026 · wersja paczki da51a912f5ef (skrót SHA-256 całej paczki)
Pobrania w ostatnich 30 dniach: 0 · ranking
Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.
Podobne skille
- 100flutter-go-router
Dodaje lub naprawia nawigację w aplikacji Flutter przez go_router: trasy, parametry, przekierowania logowania i deep linki. - 100flutter-implementing-navigation-and-routing
Obsługuje routing, nawigację i deep linki w aplikacji Flutter, przy przechodzeniu między ekranami i nawigacji opartej na URL. - 90flutter-core:flutter-navigation-routing
Projektuje nawigację i routing we Flutterze: deklaratywne trasy, GoRouter, linki głębokie, strażników tras i złożone przepływy. - 100flutter-setup-declarative-routing
Konfiguruje deklaratywny routing GoRouter: deep linki, nawigację opartą na URL, hierarchie ShellRoute i strażników tras. - 90mobile-navigation
Projektuje i sprawdza nawigację mobilną, stan ekranu i linki głębokie: zakładki, stosy, modale, przycisk wstecz i przekierowania logowania. - 100navigation-and-routing
Wymusza jeden globalny GoRouter w lib/routing/ podłączony przez MaterialApp.router, tożsamość w parametrach ścieżki, rozróżnienie context.go i context.push oraz strażników przekierowań opartych na Riverpod.