All Projects → mono0926 → route_observer_mixin

mono0926 / route_observer_mixin

Licence: MIT License
RouteObserveMixin provides easy access to didPush/didPop/didPushNext/didPopNext.

Programming Languages

dart
5743 projects
swift
15916 projects
kotlin
9241 projects
objective c
16641 projects - #2 most used programming language

Projects that are alternatives of or similar to route observer mixin

manjaro-sway
🚧 manjaro linux with wayland 🖼, sway 🌴 and a lot of ♥
Stars: ✭ 326 (+1107.41%)
Mutual labels:  package
vim-npr
Sensible 'gf' for Node Path Relative JS module resolution per project 🐿
Stars: ✭ 19 (-29.63%)
Mutual labels:  package
scaffold-package-command
Scaffolds WP-CLI commands with functional tests, full README.md, and more.
Stars: ✭ 51 (+88.89%)
Mutual labels:  package
BETS
Package to obtain and analyze thousands of Brazilian economic time series
Stars: ✭ 34 (+25.93%)
Mutual labels:  package
repogen
Easy-to-use signed APT repository generator with a web-based package browser.
Stars: ✭ 34 (+25.93%)
Mutual labels:  package
pkglite
Compact Package Representations
Stars: ✭ 16 (-40.74%)
Mutual labels:  package
dynamic-utils
Utility functions to perform dynamic operations on Android.
Stars: ✭ 86 (+218.52%)
Mutual labels:  package
ux
Laravel UI, Auth, & CRUD scaffolding package using Bootstrap & Livewire.
Stars: ✭ 34 (+25.93%)
Mutual labels:  package
video-downloader
Video Downloader for Facebook.
Stars: ✭ 63 (+133.33%)
Mutual labels:  package
bali
Bali - Minimalist Golang build and packaging tool
Stars: ✭ 59 (+118.52%)
Mutual labels:  package
ferryd
Fast, safe and reliable transit for the delivery of software updates to users.
Stars: ✭ 43 (+59.26%)
Mutual labels:  package
svelte-credit-card
A svelte component to render a credit card 💳
Stars: ✭ 30 (+11.11%)
Mutual labels:  package
RouteOne
Route for PHP
Stars: ✭ 21 (-22.22%)
Mutual labels:  route
laravel-meta
a package for working with models meta in laravel
Stars: ✭ 78 (+188.89%)
Mutual labels:  package
laravel-provider
The Laravel Framework Service Provider for Railt
Stars: ✭ 19 (-29.63%)
Mutual labels:  package
EasyWayLocation
This library contain all utils related to google location. like, getting lat or long, Address and Location Setting dialog, many more...
Stars: ✭ 142 (+425.93%)
Mutual labels:  route
oexec
oexec is a Go package to execute shell commands in specified order
Stars: ✭ 21 (-22.22%)
Mutual labels:  package
portuguese-utils
A set of useful utils for developing portuguese apps
Stars: ✭ 20 (-25.93%)
Mutual labels:  package
action
📦📊 GitHub Action to reports on the size of your npm package
Stars: ✭ 36 (+33.33%)
Mutual labels:  package
koii
A simple middleware for displaying routes in an express application
Stars: ✭ 73 (+170.37%)
Mutual labels:  route

route_observer_mixin

Gif

RouteObserveMixin provides easy access to didPush/didPop/didPushNext/didPopNext.

Usage

1. Wrap MaterialApp with RouteObserverProvider.

void main() {
  runApp(
    MultiProvider(
      providers: [
        // 1. Wrap MaterialApp with RouteObserverProvider.
        RouteObserverProvider(),
        ChangeNotifierProvider(create: (context) => Logger())
      ],
      child: const App(),
    ),
  );

  // Of course, this is also ok.
  // I demonstrated that [MultiProvider] can be used for RouteObserverProvider👍

  /*
  runApp(
    RouteObserverProvider(
      child: App(),
    ),
  );
  */
}

2. Pass RouteObserverProvider.of(context) to navigatorObservers.

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      // 2. Pass RouteObserverProvider.of(context) to navigatorObservers.
      navigatorObservers: [RouteObserverProvider.of(context)],
      home: const APage(),
    );
  }
}

3. Add with RouteAware, RouteObserverMixin to State and override RouteAware methods.

class APage extends StatefulWidget {
  const APage({Key key}) : super(key: key);

  @override
  _APageState createState() => _APageState();
}

// 3. Add `with RouteAware, RouteObserverMixin` to State and override RouteAware methods.
class _APageState extends State<APage> with RouteAware, RouteObserverMixin {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('A Page'),
      ),
      body: Center(
        child: RaisedButton(
          onPressed: () {
            Navigator.of(context).push<void>(
              MaterialPageRoute(
                builder: (context) => const BPage(),
              ),
            );
          },
          child: const Text('B Page'),
        ),
      ),
    );
  }

  /// Called when the top route has been popped off, and the current route
  /// shows up.
  @override
  void didPopNext() { }

  /// Called when the current route has been pushed.
  @override
  void didPush() { }

  /// Called when the current route has been popped off.
  @override
  void didPop() { }

  /// Called when a new route has been pushed, and the current route is no
  /// longer visible.
  @override
  void didPushNext() { }
}

Example

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].