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

Refactor android_view example (#83160)

parent ee17ebe5
...@@ -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;
late 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>>[];
...@@ -137,14 +137,14 @@ class MotionEventsBodyState extends State<MotionEventsBody> { ...@@ -137,14 +137,14 @@ class MotionEventsBodyState extends State<MotionEventsBody> {
.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 channel.invokeMethod<void>('pipeFlutterViewEvents'); await channel.invokeMethod<void>('pipeFlutterViewEvents');
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 channel.invokeMethod<void>('stopFlutterViewEvents'); await channel.invokeMethod<void>('stopFlutterViewEvents');
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';
...@@ -196,16 +196,16 @@ class MotionEventsBodyState extends State<MotionEventsBody> { ...@@ -196,16 +196,16 @@ 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); viewChannel?.setMethodCallHandler(onViewMethodChannelCall);
driverDataHandler.handlerCompleter.complete(handleDriverMessage); driverDataHandler.handlerCompleter.complete(handleDriverMessage);
} }
void listenToFlutterViewEvents() { void listenToFlutterViewEvents() {
channel.invokeMethod<void>('pipeFlutterViewEvents'); channel.invokeMethod<void>('pipeFlutterViewEvents');
viewChannel.invokeMethod<void>('pipeTouchEvents'); viewChannel?.invokeMethod<void>('pipeTouchEvents');
Timer(const Duration(seconds: 3), () { Timer(const Duration(seconds: 3), () {
channel.invokeMethod<void>('stopFlutterViewEvents'); channel.invokeMethod<void>('stopFlutterViewEvents');
viewChannel.invokeMethod<void>('stopTouchEvents'); viewChannel?.invokeMethod<void>('stopTouchEvents');
}); });
} }
......
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