mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Some minor improvements to the AsyncSnapshot API (#63347)
This commit is contained in:
parent
65d9faa1b4
commit
a49ba95af8
@ -163,6 +163,14 @@ class _StreamBuilderBaseState<T, S> extends State<StreamBuilderBase<T, S>> {
|
||||
|
||||
/// The state of connection to an asynchronous computation.
|
||||
///
|
||||
/// The usual flow of state is as follows:
|
||||
///
|
||||
/// 1. [none], maybe with some initial data.
|
||||
/// 2. [waiting], indicating that the asynchronous operation has begun,
|
||||
/// typically with the data being null.
|
||||
/// 3. [active], with data being non-null, and possible changing over time.
|
||||
/// 4. [done], with data being non-null.
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [AsyncSnapshot], which augments a connection state with information
|
||||
@ -206,6 +214,9 @@ class AsyncSnapshot<T> {
|
||||
/// Creates an [AsyncSnapshot] in [ConnectionState.none] with null data and error.
|
||||
const AsyncSnapshot.nothing() : this._(ConnectionState.none, null, null);
|
||||
|
||||
/// Creates an [AsyncSnapshot] in [ConnectionState.waiting] with null data and error.
|
||||
const AsyncSnapshot.waiting() : this._(ConnectionState.waiting, null, null);
|
||||
|
||||
/// Creates an [AsyncSnapshot] in the specified [state] and with the specified [data].
|
||||
const AsyncSnapshot.withData(ConnectionState state, T data) : this._(state, data, null);
|
||||
|
||||
|
@ -32,6 +32,14 @@ void main() {
|
||||
throwsStateError,
|
||||
);
|
||||
});
|
||||
test('AsyncSnapshot basic constructors', () {
|
||||
expect(const AsyncSnapshot<int>.nothing().connectionState, ConnectionState.none);
|
||||
expect(const AsyncSnapshot<int>.nothing().data, isNull);
|
||||
expect(const AsyncSnapshot<int>.nothing().error, isNull);
|
||||
expect(const AsyncSnapshot<int>.waiting().connectionState, ConnectionState.waiting);
|
||||
expect(const AsyncSnapshot<int>.waiting().data, isNull);
|
||||
expect(const AsyncSnapshot<int>.waiting().error, isNull);
|
||||
});
|
||||
});
|
||||
group('Async smoke tests', () {
|
||||
testWidgets('FutureBuilder', (WidgetTester tester) async {
|
||||
|
Loading…
Reference in New Issue
Block a user