navigation_history_observer 1.0.3+1 copy "navigation_history_observer: ^1.0.3+1" to clipboard
navigation_history_observer: ^1.0.3+1 copied to clipboard

outdated

A Flutter NavigatorObserver that stores a collection of pushed routes history, as well as the popped history.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:navigation_history_observer/navigation_history_observer.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: ExamplePage(pageNum: 1,),
      navigatorObservers: [NavigationHistoryObserver()],
    );
  }
}

class ExamplePage extends StatefulWidget {

  ExamplePage({Key key, this.pageNum}) : super(key: key);

  final int pageNum;

  @override
  _ExamplePageState createState() => _ExamplePageState();

}

class _ExamplePageState extends State<ExamplePage> {

  final NavigationHistoryObserver historyObserver = NavigationHistoryObserver();

  int historyCount = 0;
  int poppedCount = 0;

  @override
  void initState() {
    super.initState();

    historyCount = historyObserver.history.length;
    poppedCount = historyObserver.poppedRoutes.length;

    historyObserver.historyChangeStream.listen(
      (change) => setState(() {
          historyCount = historyObserver.history.length;
          poppedCount = historyObserver.poppedRoutes.length;
        }
      )
    );
  }

  @override
  Widget build(BuildContext context) =>
      Scaffold(
        appBar: AppBar(
          title: Row(
            children: <Widget>[
              Text("Navigation example ${widget.pageNum}"),
            ],
          ),
        ),
        body: Center(
          child: Column(
            children: <Widget>[
              Text("Welcome to the navigation page!"),
              Text("History has $historyCount routes"),
              Text("There are $poppedCount popped routes"),
              RaisedButton(
                child: Text("Navigate to a new page"),
                onPressed: () => Navigator.push(
                    context,
                    MaterialPageRoute(
                        builder: (context) => ExamplePage(pageNum: widget.pageNum + 1)
                    )
                ),
              )
            ],
          ),
        ),
      );
}
62
likes
0
pub points
95%
popularity

Publisher

unverified uploader

A Flutter NavigatorObserver that stores a collection of pushed routes history, as well as the popped history.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

built_collection, flutter

More

Packages that depend on navigation_history_observer