-
Notifications
You must be signed in to change notification settings - Fork 0
/
sub_future_provider.dart
51 lines (46 loc) · 1.56 KB
/
sub_future_provider.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import 'package:flutter/widgets.dart';
import 'package:flutter_sub/flutter_sub.dart';
import 'package:flutter_sub_provider/src/sub_provider.dart';
import 'package:provider/provider.dart';
/// Listens to a [Future] and exposes its result to `child` and its descendants.
///
/// The [keys] property can be used to recreate the [Future] when desired.
///
/// It is considered an error to pass a future that can emit errors without
/// providing a `catchError` method.
///
/// {@macro provider.updateshouldnotify}
///
/// This is a wrapper around [FutureProvider] with added [SubValue.keys].
///
/// See also:
/// - [Future], which is listened to by [SubFutureProvider].
class SubFutureProvider<T> extends SubProvider0<Future<T>> {
/// Listens to a [Future] and exposes its result to `child` and its descendants.
const SubFutureProvider({
required super.create,
required this.initialData,
super.keys,
this.catchError,
this.updateShouldNotify,
super.builder,
super.child,
});
/// The data provided before the [Future] has loaded.
final T initialData;
/// Called to handle errors that might occur in the [Future].
final ErrorBuilder<T>? catchError;
/// {@macro provider.updateshouldnotify}
final UpdateShouldNotify<T>? updateShouldNotify;
@override
Widget buildWithValue(BuildContext context, Future<T> value, Widget? child) {
return FutureProvider<T>.value(
value: value,
initialData: initialData,
updateShouldNotify: updateShouldNotify,
builder: builder,
catchError: catchError,
child: child,
);
}
}