Loading topic
Future represents one of those operations well. It does not represent what the screen needs to know while the operation runs, after it fails, or when you run it a second time. This chapter explains that gap7 min readAsyncValue, the type Riverpod uses to describe the state of an asynchronous operation. You should already know Dart's Future, async and await, and try/catch. You should also know the basics of Riverpod (Provider, ref.watch, ref.read) and how a Flutter widget's5 min readFuture, async and await, Flutter's build method, and the basics of Riverpod (Provider, ref.watch, ref.read). Dart 3 pattern matching helps for one section. The examples use the Todo class and todosProvider from the earlier chapters. The API name6 min readFuture, async and await, and basic Riverpod: Provider, ref.watch and ref.read. You should also have seen AsyncValue and when from the earlier chapters. Here you learn how to declare the class that owns asynchronous state and the provider that expose6 min readbuild() method of an AsyncNotifier: when Riverpod calls it, what its return value becomes, and which mistakes cause trouble. It assumes you can read Dart Future, async and await, and that you know ref.watch and ref.read. You should also know the AsyncValue sta6 min readAsyncNotifier with a build() method that loads data, and that you know ref.watch and ref.read from plain providers. By the end you will know how ref.watch inside build() keeps async state in sync with the providers it depends on. You will also k5 min readasync/await and try/catch, and that you have written a basic Riverpod Provider. It also assumes you have read the earlier chapters on AsyncValue and on loading initial data in an AsyncNotifier's build() method. By the end you will be able to write m7 min readAsyncNotifier whose build() loads data, and that you can render an AsyncValue with when or a switch. It uses the Todo, TodoRepository, todoRepositoryProvider and todosProvider from the earlier chapters. The behavior described is that of Riverpo7 min readAsyncNotifier loads its data once in build(). Later you will often need that load to run again: the user pulls to refresh, a save succeeds elsewhere, or the user taps "Retry" after an error. Riverpod gives you two calls for this, ref.invalidate and ref.refresh. This chapter explains what 6 min readAsyncNotifier and its build() method, and you know what AsyncValue holds. You also need await and try/catch in Dart. The chapter covers .future, the handle that lets you await an async provider. It explains when to use it instead of the AsyncValue6 min readTodosNotifier from the earlier chapters without a widget tree, a network or a database. You will work with a ProviderContainer, provider overrides, hand-written fakes, and a widget test that checks the loading state.5 min read