mirror of
https://github.com/rrousselGit/riverpod.git
synced 2025-08-15 02:06:53 +08:00

We have way too many duplicates of the same code snippets. This makes migrating code to newer versions difficult, as lots of clones need to be updated. Let's remove duplicates by enabling translation of comments inside snippets
28 lines
777 B
Dart
28 lines
777 B
Dart
// ignore_for_file: unused_local_variable, avoid_multiple_declarations_per_line, omit_local_variable_types, prefer_final_locals, use_key_in_widget_constructors
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
class User {
|
|
late String firstName, lastName;
|
|
}
|
|
|
|
final userProvider = FutureProvider(
|
|
(ref) => User()
|
|
..firstName = 'John'
|
|
..lastName = 'Doe',
|
|
);
|
|
/* SNIPPET START */
|
|
final provider = FutureProvider((ref) async {
|
|
// {@template watch}
|
|
// Wait for a user to be available, and listen to only the "firstName" property
|
|
// {@endtemplate}
|
|
final firstName = await ref.watch(
|
|
userProvider.selectAsync((it) => it.firstName),
|
|
);
|
|
|
|
// {@template todo}
|
|
// TODO use "firstName" to fetch something else
|
|
// {@endtemplate}
|
|
});
|
|
/* SNIPPET END */
|