Some minor improvements to the AsyncSnapshot API (#63347)

This commit is contained in:
Ian Hickson 2020-08-10 11:11:02 -07:00 committed by GitHub
parent 65d9faa1b4
commit a49ba95af8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -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);

View File

@ -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 {