Unverified Commit a49ba95a authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Some minor improvements to the AsyncSnapshot API (#63347)

parent 65d9faa1
...@@ -163,6 +163,14 @@ class _StreamBuilderBaseState<T, S> extends State<StreamBuilderBase<T, S>> { ...@@ -163,6 +163,14 @@ class _StreamBuilderBaseState<T, S> extends State<StreamBuilderBase<T, S>> {
/// The state of connection to an asynchronous computation. /// 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: /// See also:
/// ///
/// * [AsyncSnapshot], which augments a connection state with information /// * [AsyncSnapshot], which augments a connection state with information
...@@ -206,6 +214,9 @@ class AsyncSnapshot<T> { ...@@ -206,6 +214,9 @@ class AsyncSnapshot<T> {
/// Creates an [AsyncSnapshot] in [ConnectionState.none] with null data and error. /// Creates an [AsyncSnapshot] in [ConnectionState.none] with null data and error.
const AsyncSnapshot.nothing() : this._(ConnectionState.none, null, null); 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]. /// Creates an [AsyncSnapshot] in the specified [state] and with the specified [data].
const AsyncSnapshot.withData(ConnectionState state, T data) : this._(state, data, null); const AsyncSnapshot.withData(ConnectionState state, T data) : this._(state, data, null);
......
...@@ -32,6 +32,14 @@ void main() { ...@@ -32,6 +32,14 @@ void main() {
throwsStateError, 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', () { group('Async smoke tests', () {
testWidgets('FutureBuilder', (WidgetTester tester) async { testWidgets('FutureBuilder', (WidgetTester tester) async {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment