mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Refactor android_view example (#83160)
This commit is contained in:
parent
ee17ebe51f
commit
efdbe40330
@ -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> {
|
|||||||
.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> {
|
|||||||
|
|
||||||
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');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user