diff --git a/packages/flutter/lib/src/widgets/async.dart b/packages/flutter/lib/src/widgets/async.dart index 58f838fc08..7e755524c2 100644 --- a/packages/flutter/lib/src/widgets/async.dart +++ b/packages/flutter/lib/src/widgets/async.dart @@ -40,7 +40,7 @@ import 'framework.dart'; /// recent interaction is needed for widget building. abstract class StreamBuilderBase extends StatefulWidget { /// Creates a [StreamBuilderBase] connected to the specified [stream]. - const StreamBuilderBase({ super.key, this.stream }); + const StreamBuilderBase({ super.key, required this.stream }); /// The asynchronous computation to which this builder is currently connected, /// possibly null. When changed, the current summary is updated using @@ -391,7 +391,7 @@ class StreamBuilder extends StreamBuilderBase> { const StreamBuilder({ super.key, this.initialData, - super.stream, + required super.stream, required this.builder, }); @@ -521,7 +521,7 @@ class FutureBuilder extends StatefulWidget { /// The [builder] must not be null. const FutureBuilder({ super.key, - this.future, + required this.future, this.initialData, required this.builder, }); diff --git a/packages/flutter/test/widgets/async_test.dart b/packages/flutter/test/widgets/async_test.dart index a3cb13abb0..9c68541206 100644 --- a/packages/flutter/test/widgets/async_test.dart +++ b/packages/flutter/test/widgets/async_test.dart @@ -105,7 +105,7 @@ void main() { testWidgets('gracefully handles transition from null future', (WidgetTester tester) async { final GlobalKey key = GlobalKey(); await tester.pumpWidget(FutureBuilder( - key: key, builder: snapshotText, + key: key, builder: snapshotText, future: null, )); expect(find.text('AsyncSnapshot(ConnectionState.none, null, null, null)'), findsOneWidget); final Completer completer = Completer(); @@ -122,7 +122,7 @@ void main() { )); expect(find.text('AsyncSnapshot(ConnectionState.waiting, null, null, null)'), findsOneWidget); await tester.pumpWidget(FutureBuilder( - key: key, builder: snapshotText, + key: key, builder: snapshotText, future: null, )); expect(find.text('AsyncSnapshot(ConnectionState.none, null, null, null)'), findsOneWidget); completer.complete('hello'); @@ -170,6 +170,7 @@ void main() { final GlobalKey key = GlobalKey(); await tester.pumpWidget(FutureBuilder( key: key, + future: null, builder: snapshotText, initialData: 'I', )); @@ -179,6 +180,7 @@ void main() { final GlobalKey key = GlobalKey(); await tester.pumpWidget(FutureBuilder( key: key, + future: null, builder: snapshotText, initialData: 'I', )); @@ -215,7 +217,7 @@ void main() { testWidgets('gracefully handles transition from null stream', (WidgetTester tester) async { final GlobalKey key = GlobalKey(); await tester.pumpWidget(StreamBuilder( - key: key, builder: snapshotText, + key: key, builder: snapshotText, stream: null, )); expect(find.text('AsyncSnapshot(ConnectionState.none, null, null, null)'), findsOneWidget); final StreamController controller = StreamController(); @@ -232,7 +234,7 @@ void main() { )); expect(find.text('AsyncSnapshot(ConnectionState.waiting, null, null, null)'), findsOneWidget); await tester.pumpWidget(StreamBuilder( - key: key, builder: snapshotText, + key: key, builder: snapshotText, stream: null, )); expect(find.text('AsyncSnapshot(ConnectionState.none, null, null, null)'), findsOneWidget); }); @@ -285,6 +287,7 @@ void main() { final GlobalKey key = GlobalKey(); await tester.pumpWidget(StreamBuilder( key: key, + stream: null, builder: snapshotText, initialData: 'I', )); @@ -335,15 +338,15 @@ void main() { }); testWidgets('when Future is null', (WidgetTester tester) async { await tester.pumpWidget(Column(children: [ - FutureBuilder(builder: snapshotText), - StreamBuilder(builder: snapshotText), + FutureBuilder(builder: snapshotText, future: null), + StreamBuilder(builder: snapshotText, stream: null,), ])); expect(find.text('AsyncSnapshot(ConnectionState.none, null, null, null)'), findsNWidgets(2)); }); testWidgets('when initialData is used with null Future and Stream', (WidgetTester tester) async { await tester.pumpWidget(Column(children: [ - FutureBuilder(builder: snapshotText, initialData: 'I'), - StreamBuilder(builder: snapshotText, initialData: 'I'), + FutureBuilder(builder: snapshotText, initialData: 'I', future: null), + StreamBuilder(builder: snapshotText, initialData: 'I', stream: null), ])); expect(find.text('AsyncSnapshot(ConnectionState.none, I, null, null)'), findsNWidgets(2)); });