GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • back_stack · you own the back stack
  • GitHubGitHub (opens in a new tab)
  • Edit this page

This view

  • Original page
  • New address

GeezerVison is showing androidpoet.github.io — back_stack – back_stack

Introduction

back_stack

You own the back stack. Navigation is a List you push and pop — type-safe, observable, no route graph.

back_stack brings Jetpack Compose Navigation 3's "you own the back stack" model to Flutter. Destinations are plain Dart types, checked by the compiler, and the UI just renders the list.

// Destinations are typed objects — arguments are real, checked fields.
abstract class AppKey extends NavKey { const AppKey(); }
class Home    extends AppKey { const Home(); }
class Product extends AppKey { const Product(this.id); final int id; }
 
// One line per screen.
final entries = NavEntries<AppKey>()
  ..on<Home>((context, key) => const HomeScreen())
  ..on<Product>((context, key) => ProductScreen(id: key.id));
 
// The back stack is a list you own.
final stack = NavStack<AppKey>.of(const Home());
 
void main() => runApp(BackStackApp<AppKey>(stack: stack, entries: entries));

That's a complete app. Navigate by changing the list — from anywhere:

stack.push(const Product(42));    // forward
stack.pop();                      // back
stack.replaceAll([const Home()]); // reset a flow (e.g. after login)

System back, predictive back, and the hardware button already flow into the list. Everything else is one parameter on BackStackApp — the wiring is internal:

You wantYou pass
Deep links, web URLs, shareable linkslinks: — one NavLinks table
Restoration across process deathalready on with links: — see Restoration
Async link resolution ("does this doc exist?")onLinkAsync:
Links from a native plugin (app_links)initialLink: / linkStream:
Persistent chrome around the navigatorshell:
Bottom tabs with per-tab historythe sibling widget, BackStackTabsApp

And because the stack is plain data, testing is stack.push(...) then expect(stack.keys, [...]) — no harness, no mocks.

Next

  • Getting started — install and your first stack.
  • Core concepts — the whole model in a few ideas.
  • Migrating from go_router — a mapping guide.
  • Live demo ↗ (opens in a new tab) — the shop demo with real URL sync, running in your browser.
Getting started
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.