Files
2022-11-26 00:35:40 +01:00

1.5 KiB

complete_example

This a slightly more complicated example, featuring:

  • Riverpod's new [AsyncNotifier] (Riverpod v2)
  • GoRouter's asynchronous redirect API
  • Riverpod Annotation code generation tool
  • GoRouterBuilder code generation tool
  • A slightly more complicated and asynchronous authentication model
  • A basic authorization model
  • An intermediate splash page
  • Some basic persistence API usage

This is the "main" example of this repo; its objective is to define some best practices when using Riverpod + GoRouter (as opposed to other examples, which are just community-driven).

Note. The tests are intentionally not being updated and the route-level redirect is missing. We're waiting on this PR before completing this example. The rest of the example is fine, tho.

Nonetheless:

  • This has to be considered as a "best effort" example that aims to integrate as much best practices as possible;
  • Indeed, we can all agree that there is no magical silver bullet that fits in every possible use case: use with caution..

Dependencies:

  • GoRouter v5
  • Riverpod v2
  • GoRouterBuilder v1
  • RiverpodAnnotation v1
  • SharedPreferences v2

Getting started

First, read the code:

  • 'lib/main.dart' has UI elements
  • 'lib/router' has the routing logic
  • 'lib/entities.dart' has domain logic

Most of the actions are mocked, here. Then, run:

flutter pub run build_runner watch -d flutter test flutter run

Enjoy!