Migrate hybrid_android_views to null safety (#84140)
This commit is contained in:
parent
64bf4ed480
commit
075991c249
@ -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();
|
||||
},
|
||||
|
@ -19,15 +19,15 @@ class FutureDataHandler {
|
||||
/// Registers a lazy handler that will be invoked on the next message from the driver.
|
||||
Completer<DriverHandler> registerHandler(String key) {
|
||||
_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) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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<String>('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<MotionEventsBody> {
|
||||
static const int kEventsBufferSize = 1000;
|
||||
|
||||
MethodChannel viewChannel;
|
||||
MethodChannel? viewChannel;
|
||||
|
||||
/// The list of motion events that were passed to the FlutterView.
|
||||
List<Map<String, dynamic>> flutterViewEvents = <Map<String, dynamic>>[];
|
||||
@ -87,7 +87,7 @@ class MotionEventsBodyState extends State<MotionEventsBody> {
|
||||
onPressed: () {
|
||||
const StandardMessageCodec codec = StandardMessageCodec();
|
||||
saveRecordedEvents(
|
||||
codec.encodeMessage(flutterViewEvents), context);
|
||||
codec.encodeMessage(flutterViewEvents)!, context);
|
||||
},
|
||||
),
|
||||
),
|
||||
@ -120,13 +120,13 @@ class MotionEventsBodyState extends State<MotionEventsBody> {
|
||||
.cast<Map<dynamic, dynamic>>()
|
||||
.map<Map<String, dynamic>>((Map<dynamic, dynamic> e) =>e.cast<String, dynamic>())
|
||||
.toList();
|
||||
await viewChannel.invokeMethod<void>('pipeTouchEvents');
|
||||
await viewChannel!.invokeMethod<void>('pipeTouchEvents');
|
||||
print('replaying ${recordedEvents.length} motion events');
|
||||
for (final Map<String, dynamic> event in recordedEvents.reversed) {
|
||||
await channel.invokeMethod<void>('synthesizeEvent', event);
|
||||
}
|
||||
|
||||
await viewChannel.invokeMethod<void>('stopTouchEvents');
|
||||
await viewChannel!.invokeMethod<void>('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<MotionEventsBody> {
|
||||
}
|
||||
|
||||
Future<void> saveRecordedEvents(ByteData data, BuildContext context) async {
|
||||
if (!await channel.invokeMethod<bool>('getStoragePermission')) {
|
||||
if (await channel.invokeMethod<bool>('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<MotionEventsBody> {
|
||||
}
|
||||
|
||||
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<void>('pipeTouchEvents');
|
||||
viewChannel!.invokeMethod<void>('pipeTouchEvents');
|
||||
Timer(const Duration(seconds: 3), () {
|
||||
viewChannel.invokeMethod<void>('stopTouchEvents');
|
||||
viewChannel!.invokeMethod<void>('stopTouchEvents');
|
||||
});
|
||||
}
|
||||
|
||||
@ -225,7 +225,7 @@ class MotionEventsBodyState extends State<MotionEventsBody> {
|
||||
}
|
||||
|
||||
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> synthesizedEvent;
|
||||
|
@ -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<String>('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<NestedViewEventBody> createState() => NestedViewEventBodyState();
|
||||
@ -33,10 +33,10 @@ enum _LastTestStatus {
|
||||
}
|
||||
|
||||
class NestedViewEventBodyState extends State<NestedViewEventBody> {
|
||||
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<NestedViewEventBody> {
|
||||
|
||||
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<NestedViewEventBody> {
|
||||
});
|
||||
}
|
||||
try {
|
||||
await viewChannel.invokeMethod<void>('showAndHideAlertDialog');
|
||||
await viewChannel!.invokeMethod<void>('showAndHideAlertDialog');
|
||||
setState(() {
|
||||
_lastTestStatus = _LastTestStatus.success;
|
||||
});
|
||||
@ -136,7 +136,7 @@ class NestedViewEventBodyState extends State<NestedViewEventBody> {
|
||||
|
||||
Future<void> onChildViewPressed() async {
|
||||
try {
|
||||
await viewChannel.invokeMethod<void>('addChildViewAndWaitForClick');
|
||||
await viewChannel!.invokeMethod<void>('addChildViewAndWaitForClick');
|
||||
setState(() {
|
||||
nestedViewClickCount++;
|
||||
});
|
||||
@ -167,6 +167,6 @@ class NestedViewEventBodyState extends State<NestedViewEventBody> {
|
||||
viewChannel = MethodChannel('simple_view/$id');
|
||||
});
|
||||
driverDataHandler.registerHandler('hierarchy')
|
||||
.complete(() => channel.invokeMethod<String>('getViewHierarchy'));
|
||||
.complete(() async => (await channel.invokeMethod<String>('getViewHierarchy'))!);
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
///
|
||||
|
@ -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:
|
||||
|
@ -6,7 +6,7 @@ import 'package:flutter_driver/flutter_driver.dart';
|
||||
import 'package:test/test.dart' hide TypeMatcher, isInstanceOf;
|
||||
|
||||
Future<void> main() async {
|
||||
FlutterDriver driver;
|
||||
late FlutterDriver driver;
|
||||
|
||||
setUpAll(() async {
|
||||
driver = await FlutterDriver.connect();
|
||||
|
Loading…
x
Reference in New Issue
Block a user