Unverified Commit ecbea9a9 authored by Abhishek Ghaskata's avatar Abhishek Ghaskata Committed by GitHub

Update android_views to null safety (#80557)

parent 599c95a8
...@@ -20,7 +20,7 @@ void main() { ...@@ -20,7 +20,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) {
......
...@@ -18,7 +18,7 @@ MethodChannel channel = const MethodChannel('android_views_integration'); ...@@ -18,7 +18,7 @@ MethodChannel channel = const MethodChannel('android_views_integration');
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
...@@ -35,7 +35,7 @@ class MotionEventsPage extends PageWidget { ...@@ -35,7 +35,7 @@ class MotionEventsPage extends PageWidget {
class FutureDataHandler { class FutureDataHandler {
final Completer<DataHandler> handlerCompleter = Completer<DataHandler>(); final Completer<DataHandler> handlerCompleter = Completer<DataHandler>();
Future<String> handleMessage(String message) async { Future<String> handleMessage(String? message) async {
final DataHandler handler = await handlerCompleter.future; final DataHandler handler = await handlerCompleter.future;
return handler(message); return handler(message);
} }
...@@ -44,7 +44,7 @@ class FutureDataHandler { ...@@ -44,7 +44,7 @@ class FutureDataHandler {
FutureDataHandler driverDataHandler = FutureDataHandler(); FutureDataHandler driverDataHandler = FutureDataHandler();
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();
...@@ -53,7 +53,7 @@ class MotionEventsBody extends StatefulWidget { ...@@ -53,7 +53,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; late 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>>[];
...@@ -103,7 +103,7 @@ class MotionEventsBodyState extends State<MotionEventsBody> { ...@@ -103,7 +103,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);
}, },
), ),
), ),
...@@ -171,15 +171,15 @@ class MotionEventsBodyState extends State<MotionEventsBody> { ...@@ -171,15 +171,15 @@ 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);
showMessage(context, 'Saved original events to ${file.path}'); showMessage(context, 'Saved original events to ${file.path}');
} catch (e) { } catch (e) {
...@@ -209,7 +209,7 @@ class MotionEventsBodyState extends State<MotionEventsBody> { ...@@ -209,7 +209,7 @@ class MotionEventsBodyState extends State<MotionEventsBody> {
}); });
} }
Future<String> handleDriverMessage(String message) async { Future<String> handleDriverMessage(String? message) async {
switch (message) { switch (message) {
case 'run test': case 'run test':
return playEventsFile(); return playEventsFile();
...@@ -253,7 +253,7 @@ class MotionEventsBodyState extends State<MotionEventsBody> { ...@@ -253,7 +253,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;
......
...@@ -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
/// ///
......
...@@ -10,7 +10,7 @@ import 'package:flutter/services.dart'; ...@@ -10,7 +10,7 @@ import 'package:flutter/services.dart';
import 'page.dart'; import 'page.dart';
class WindowManagerIntegrationsPage extends PageWidget { class WindowManagerIntegrationsPage extends PageWidget {
const WindowManagerIntegrationsPage({Key key}) const WindowManagerIntegrationsPage({Key? key})
: super('Window Manager Integrations Tests', const ValueKey<String>('WmIntegrationsListTile'), key: key); : super('Window Manager Integrations Tests', const ValueKey<String>('WmIntegrationsListTile'), key: key);
@override @override
...@@ -18,7 +18,7 @@ class WindowManagerIntegrationsPage extends PageWidget { ...@@ -18,7 +18,7 @@ class WindowManagerIntegrationsPage extends PageWidget {
} }
class WindowManagerBody extends StatefulWidget { class WindowManagerBody extends StatefulWidget {
const WindowManagerBody({Key key}) : super(key: key); const WindowManagerBody({Key? key}) : super(key: key);
@override @override
State<WindowManagerBody> createState() => WindowManagerBodyState(); State<WindowManagerBody> createState() => WindowManagerBodyState();
...@@ -32,10 +32,10 @@ enum _LastTestStatus { ...@@ -32,10 +32,10 @@ enum _LastTestStatus {
class WindowManagerBodyState extends State<WindowManagerBody> { class WindowManagerBodyState extends State<WindowManagerBody> {
MethodChannel viewChannel; MethodChannel? viewChannel;
_LastTestStatus lastTestStatus = _LastTestStatus.pending; _LastTestStatus lastTestStatus = _LastTestStatus.pending;
String lastError; String? lastError;
int id; int? id;
int windowClickCount = 0; int windowClickCount = 0;
@override @override
...@@ -87,11 +87,11 @@ class WindowManagerBodyState extends State<WindowManagerBody> { ...@@ -87,11 +87,11 @@ class WindowManagerBodyState extends State<WindowManagerBody> {
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(
message, message!,
key: const ValueKey<String>('Status'), key: const ValueKey<String>('Status'),
style: TextStyle( style: TextStyle(
color: lastTestStatus == _LastTestStatus.error ? Colors.yellow : null, color: lastTestStatus == _LastTestStatus.error ? Colors.yellow : null,
...@@ -107,7 +107,7 @@ class WindowManagerBodyState extends State<WindowManagerBody> { ...@@ -107,7 +107,7 @@ class WindowManagerBodyState extends State<WindowManagerBody> {
}); });
} }
try { try {
await viewChannel.invokeMethod<void>('showAndHideAlertDialog'); await viewChannel?.invokeMethod<void>('showAndHideAlertDialog');
setState(() { setState(() {
lastTestStatus = _LastTestStatus.success; lastTestStatus = _LastTestStatus.success;
}); });
...@@ -121,7 +121,7 @@ class WindowManagerBodyState extends State<WindowManagerBody> { ...@@ -121,7 +121,7 @@ class WindowManagerBodyState extends State<WindowManagerBody> {
Future<void> onAddWindowPressed() async { Future<void> onAddWindowPressed() async {
try { try {
await viewChannel.invokeMethod<void>('addWindowAndWaitForClick'); await viewChannel?.invokeMethod<void>('addWindowAndWaitForClick');
setState(() { setState(() {
windowClickCount++; windowClickCount++;
}); });
......
...@@ -4,7 +4,7 @@ publish_to: none ...@@ -4,7 +4,7 @@ publish_to: none
description: An integration test for embedded platform views description: An integration test for embedded platform views
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