Unverified Commit 075991c2 authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Migrate hybrid_android_views to null safety (#84140)

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