diff --git a/dev/integration_tests/hybrid_android_views/lib/android_platform_view.dart b/dev/integration_tests/hybrid_android_views/lib/android_platform_view.dart index b5f487b8af..536497506e 100644 --- a/dev/integration_tests/hybrid_android_views/lib/android_platform_view.dart +++ b/dev/integration_tests/hybrid_android_views/lib/android_platform_view.dart @@ -15,9 +15,9 @@ class AndroidPlatformView extends StatelessWidget { /// native view. /// `viewType` identifies the type of Android view to create. const AndroidPlatformView({ - Key key, + Key? key, this.onPlatformViewCreated, - @required this.viewType, + required this.viewType, }) : assert(viewType != null), super(key: key); @@ -29,7 +29,7 @@ class AndroidPlatformView extends StatelessWidget { /// Callback to invoke after the platform view has been created. /// /// May be null. - final PlatformViewCreatedCallback onPlatformViewCreated; + final PlatformViewCreatedCallback? onPlatformViewCreated; @override Widget build(BuildContext context) { @@ -52,7 +52,7 @@ class AndroidPlatformView extends StatelessWidget { ) ..addOnPlatformViewCreatedListener(params.onPlatformViewCreated); if (onPlatformViewCreated != null) { - controller.addOnPlatformViewCreatedListener(onPlatformViewCreated); + controller.addOnPlatformViewCreatedListener(onPlatformViewCreated!); } return controller..create(); }, diff --git a/dev/integration_tests/hybrid_android_views/lib/future_data_handler.dart b/dev/integration_tests/hybrid_android_views/lib/future_data_handler.dart index ed9b29b454..612bd110ba 100644 --- a/dev/integration_tests/hybrid_android_views/lib/future_data_handler.dart +++ b/dev/integration_tests/hybrid_android_views/lib/future_data_handler.dart @@ -19,15 +19,15 @@ class FutureDataHandler { /// Registers a lazy handler that will be invoked on the next message from the driver. Completer registerHandler(String key) { _handlers[key] = Completer(); - return _handlers[key]; + return _handlers[key]!; } - Future handleMessage(String message) async { + Future handleMessage(String? message) async { if (_handlers[message] == null) { return 'Unsupported driver message: $message.\n' 'Supported messages are: ${_handlers.keys}.'; } - final DriverHandler handler = await _handlers[message].future; + final DriverHandler handler = await _handlers[message]!.future; return handler(); } } diff --git a/dev/integration_tests/hybrid_android_views/lib/main.dart b/dev/integration_tests/hybrid_android_views/lib/main.dart index da6fe5d244..936de3f66f 100644 --- a/dev/integration_tests/hybrid_android_views/lib/main.dart +++ b/dev/integration_tests/hybrid_android_views/lib/main.dart @@ -21,7 +21,7 @@ void main() { } class Home extends StatelessWidget { - const Home({Key key}) : super(key: key); + const Home({Key? key}) : super(key: key); @override Widget build(BuildContext context) { diff --git a/dev/integration_tests/hybrid_android_views/lib/motion_events_page.dart b/dev/integration_tests/hybrid_android_views/lib/motion_events_page.dart index f370555e21..c9f6150bff 100644 --- a/dev/integration_tests/hybrid_android_views/lib/motion_events_page.dart +++ b/dev/integration_tests/hybrid_android_views/lib/motion_events_page.dart @@ -17,7 +17,7 @@ import 'page.dart'; const String kEventsFileName = 'touchEvents'; class MotionEventsPage extends PageWidget { - const MotionEventsPage({Key key}) + const MotionEventsPage({Key? key}) : super('Motion Event Tests', const ValueKey('MotionEventsListTile'), key: key); @override @@ -27,7 +27,7 @@ class MotionEventsPage extends PageWidget { } class MotionEventsBody extends StatefulWidget { - const MotionEventsBody({Key key}) : super(key: key); + const MotionEventsBody({Key? key}) : super(key: key); @override State createState() => MotionEventsBodyState(); @@ -36,7 +36,7 @@ class MotionEventsBody extends StatefulWidget { class MotionEventsBodyState extends State { static const int kEventsBufferSize = 1000; - MethodChannel viewChannel; + MethodChannel? viewChannel; /// The list of motion events that were passed to the FlutterView. List> flutterViewEvents = >[]; @@ -87,7 +87,7 @@ class MotionEventsBodyState extends State { onPressed: () { const StandardMessageCodec codec = StandardMessageCodec(); saveRecordedEvents( - codec.encodeMessage(flutterViewEvents), context); + codec.encodeMessage(flutterViewEvents)!, context); }, ), ), @@ -120,13 +120,13 @@ class MotionEventsBodyState extends State { .cast>() .map>((Map e) =>e.cast()) .toList(); - await viewChannel.invokeMethod('pipeTouchEvents'); + await viewChannel!.invokeMethod('pipeTouchEvents'); print('replaying ${recordedEvents.length} motion events'); for (final Map event in recordedEvents.reversed) { await channel.invokeMethod('synthesizeEvent', event); } - await viewChannel.invokeMethod('stopTouchEvents'); + await viewChannel!.invokeMethod('stopTouchEvents'); if (flutterViewEvents.length != embeddedViewEvents.length) return 'Synthesized ${flutterViewEvents.length} events but the embedded view received ${embeddedViewEvents.length} events'; @@ -153,13 +153,13 @@ class MotionEventsBodyState extends State { } Future saveRecordedEvents(ByteData data, BuildContext context) async { - if (!await channel.invokeMethod('getStoragePermission')) { + if (await channel.invokeMethod('getStoragePermission') != true) { showMessage( context, 'External storage permissions are required to save events'); return; } try { - final Directory outDir = await getExternalStorageDirectory(); + final Directory outDir = (await getExternalStorageDirectory())!; // This test only runs on Android so we can assume path separator is '/'. final File file = File('${outDir.path}/$kEventsFileName'); await file.writeAsBytes(data.buffer.asUint8List(0, data.lengthInBytes), flush: true); @@ -177,15 +177,15 @@ class MotionEventsBodyState extends State { } void onPlatformViewCreated(int id) { - viewChannel = MethodChannel('simple_view/$id'); - viewChannel.setMethodCallHandler(onViewMethodChannelCall); + viewChannel = MethodChannel('simple_view/$id') + ..setMethodCallHandler(onViewMethodChannelCall); driverDataHandler.registerHandler('run test').complete(playEventsFile); } void listenToFlutterViewEvents() { - viewChannel.invokeMethod('pipeTouchEvents'); + viewChannel!.invokeMethod('pipeTouchEvents'); Timer(const Duration(seconds: 3), () { - viewChannel.invokeMethod('stopTouchEvents'); + viewChannel!.invokeMethod('stopTouchEvents'); }); } @@ -225,7 +225,7 @@ class MotionEventsBodyState extends State { } class TouchEventDiff extends StatelessWidget { - const TouchEventDiff(this.originalEvent, this.synthesizedEvent, {Key key}) : super(key: key); + const TouchEventDiff(this.originalEvent, this.synthesizedEvent, {Key? key}) : super(key: key); final Map originalEvent; final Map synthesizedEvent; diff --git a/dev/integration_tests/hybrid_android_views/lib/nested_view_event_page.dart b/dev/integration_tests/hybrid_android_views/lib/nested_view_event_page.dart index b9583b0735..1c894d2ee2 100644 --- a/dev/integration_tests/hybrid_android_views/lib/nested_view_event_page.dart +++ b/dev/integration_tests/hybrid_android_views/lib/nested_view_event_page.dart @@ -12,7 +12,7 @@ import 'future_data_handler.dart'; import 'page.dart'; class NestedViewEventPage extends PageWidget { - const NestedViewEventPage({Key key}) + const NestedViewEventPage({Key? key}) : super('Nested View Event Tests', const ValueKey('NestedViewEventTile'), key: key); @override @@ -20,7 +20,7 @@ class NestedViewEventPage extends PageWidget { } class NestedViewEventBody extends StatefulWidget { - const NestedViewEventBody({Key key}) : super(key: key); + const NestedViewEventBody({Key? key}) : super(key: key); @override State createState() => NestedViewEventBodyState(); @@ -33,10 +33,10 @@ enum _LastTestStatus { } class NestedViewEventBodyState extends State { - MethodChannel viewChannel; + MethodChannel? viewChannel; _LastTestStatus _lastTestStatus = _LastTestStatus.pending; - String lastError; - int id; + String? lastError; + int? id; int nestedViewClickCount = 0; bool showPlatformView = true; @@ -96,7 +96,7 @@ class NestedViewEventBodyState extends State { Widget _statusWidget() { assert(_lastTestStatus != _LastTestStatus.pending); - final String message = _lastTestStatus == _LastTestStatus.success ? 'Success' : lastError; + final String message = _lastTestStatus == _LastTestStatus.success ? 'Success' : lastError!; return Container( color: _lastTestStatus == _LastTestStatus.success ? Colors.green : Colors.red, child: Text( @@ -116,7 +116,7 @@ class NestedViewEventBodyState extends State { }); } try { - await viewChannel.invokeMethod('showAndHideAlertDialog'); + await viewChannel!.invokeMethod('showAndHideAlertDialog'); setState(() { _lastTestStatus = _LastTestStatus.success; }); @@ -136,7 +136,7 @@ class NestedViewEventBodyState extends State { Future onChildViewPressed() async { try { - await viewChannel.invokeMethod('addChildViewAndWaitForClick'); + await viewChannel!.invokeMethod('addChildViewAndWaitForClick'); setState(() { nestedViewClickCount++; }); @@ -167,6 +167,6 @@ class NestedViewEventBodyState extends State { viewChannel = MethodChannel('simple_view/$id'); }); driverDataHandler.registerHandler('hierarchy') - .complete(() => channel.invokeMethod('getViewHierarchy')); + .complete(() async => (await channel.invokeMethod('getViewHierarchy'))!); } } diff --git a/dev/integration_tests/hybrid_android_views/lib/page.dart b/dev/integration_tests/hybrid_android_views/lib/page.dart index ce81aafab9..dbcd8fa59e 100644 --- a/dev/integration_tests/hybrid_android_views/lib/page.dart +++ b/dev/integration_tests/hybrid_android_views/lib/page.dart @@ -8,7 +8,7 @@ import 'package:flutter/material.dart'; // /// A testing page has to override this in order to be put as one of the items in the main page. abstract class PageWidget extends StatelessWidget { - const PageWidget(this.title, this.tileKey, {Key key}) : super(key: key); + const PageWidget(this.title, this.tileKey, {Key? key}) : super(key: key); /// The title of the testing page /// diff --git a/dev/integration_tests/hybrid_android_views/pubspec.yaml b/dev/integration_tests/hybrid_android_views/pubspec.yaml index 4ebde4cfb7..0c1eaec966 100644 --- a/dev/integration_tests/hybrid_android_views/pubspec.yaml +++ b/dev/integration_tests/hybrid_android_views/pubspec.yaml @@ -4,7 +4,7 @@ publish_to: none description: An integration test for hybrid composition on Android version: 1.0.0+1 environment: - sdk: '>=2.9.0 <3.0.0' + sdk: '>=2.12.0 <3.0.0' dependencies: flutter: diff --git a/dev/integration_tests/hybrid_android_views/test_driver/main_test.dart b/dev/integration_tests/hybrid_android_views/test_driver/main_test.dart index a10b764fc1..7bf884339f 100644 --- a/dev/integration_tests/hybrid_android_views/test_driver/main_test.dart +++ b/dev/integration_tests/hybrid_android_views/test_driver/main_test.dart @@ -6,7 +6,7 @@ import 'package:flutter_driver/flutter_driver.dart'; import 'package:test/test.dart' hide TypeMatcher, isInstanceOf; Future main() async { - FlutterDriver driver; + late FlutterDriver driver; setUpAll(() async { driver = await FlutterDriver.connect();