3
3
// found in the LICENSE file.
4
4
5
5
import 'dart:async' ;
6
+ import 'dart:convert' ;
6
7
import 'dart:io' as io;
7
- import 'dart:typed_data' show ByteData, Endian, Uint8List;
8
+ import 'dart:typed_data' show ByteData, Uint8List;
8
9
import 'dart:ui' as ui;
9
- import 'dart:convert' ;
10
10
11
11
// Signals a waiting latch in the native test.
12
12
@pragma ('vm:external-name' , 'Signal' )
@@ -53,7 +53,7 @@ Future<void> get semanticsChanged {
53
53
}
54
54
55
55
@pragma ('vm:entry-point' )
56
- void sendAccessibilityAnnouncement () async {
56
+ Future < void > sendAccessibilityAnnouncement () async {
57
57
// Wait until semantics are enabled.
58
58
if (! ui.PlatformDispatcher .instance.semanticsEnabled) {
59
59
await semanticsChanged;
@@ -91,7 +91,7 @@ void sendAccessibilityAnnouncement() async {
91
91
}
92
92
93
93
@pragma ('vm:entry-point' )
94
- void sendAccessibilityTooltipEvent () async {
94
+ Future < void > sendAccessibilityTooltipEvent () async {
95
95
// Wait until semantics are enabled.
96
96
if (! ui.PlatformDispatcher .instance.semanticsEnabled) {
97
97
await semanticsChanged;
@@ -129,10 +129,13 @@ void sendAccessibilityTooltipEvent() async {
129
129
}
130
130
131
131
@pragma ('vm:entry-point' )
132
- void exitTestExit () async {
132
+ Future < void > exitTestExit () async {
133
133
final Completer <ByteData ?> closed = Completer <ByteData ?>();
134
- ui.channelBuffers.setListener ('flutter/platform' , (ByteData ? data, ui.PlatformMessageResponseCallback callback) async {
135
- final String jsonString = json.encode (< Map <String , String >> [{'response' : 'exit' }]);
134
+ ui.channelBuffers.setListener ('flutter/platform' ,
135
+ (ByteData ? data, ui.PlatformMessageResponseCallback callback) async {
136
+ final String jsonString = json.encode (< Map <String , String >> [
137
+ {'response' : 'exit' }
138
+ ]);
136
139
final ByteData responseData = ByteData .sublistView (utf8.encode (jsonString));
137
140
callback (responseData);
138
141
closed.complete (data);
@@ -141,10 +144,13 @@ void exitTestExit() async {
141
144
}
142
145
143
146
@pragma ('vm:entry-point' )
144
- void exitTestCancel () async {
147
+ Future < void > exitTestCancel () async {
145
148
final Completer <ByteData ?> closed = Completer <ByteData ?>();
146
- ui.channelBuffers.setListener ('flutter/platform' , (ByteData ? data, ui.PlatformMessageResponseCallback callback) async {
147
- final String jsonString = json.encode (< Map <String , String >> [{'response' : 'cancel' }]);
149
+ ui.channelBuffers.setListener ('flutter/platform' ,
150
+ (ByteData ? data, ui.PlatformMessageResponseCallback callback) async {
151
+ final String jsonString = json.encode (< Map <String , String >> [
152
+ {'response' : 'cancel' }
153
+ ]);
148
154
final ByteData responseData = ByteData .sublistView (utf8.encode (jsonString));
149
155
callback (responseData);
150
156
closed.complete (data);
@@ -155,53 +161,52 @@ void exitTestCancel() async {
155
161
final Completer <ByteData ?> exited = Completer <ByteData ?>();
156
162
final String jsonString = json.encode (< String , dynamic > {
157
163
'method' : 'System.exitApplication' ,
158
- 'args' : < String , dynamic > {
159
- 'type' : 'required' , 'exitCode' : 0
160
- }
161
- });
164
+ 'args' : < String , dynamic > {'type' : 'required' , 'exitCode' : 0 }
165
+ });
162
166
ui.PlatformDispatcher .instance.sendPlatformMessage (
163
- 'flutter/platform' ,
164
- ByteData .sublistView (utf8.encode (jsonString)),
165
- (ByteData ? reply) {
166
- exited.complete (reply);
167
- });
167
+ 'flutter/platform' , ByteData .sublistView (utf8.encode (jsonString)),
168
+ (ByteData ? reply) {
169
+ exited.complete (reply);
170
+ });
168
171
await exited.future;
169
172
}
170
173
171
174
@pragma ('vm:entry-point' )
172
- void enableLifecycleTest () async {
175
+ Future < void > enableLifecycleTest () async {
173
176
final Completer <ByteData ?> finished = Completer <ByteData ?>();
174
- ui.channelBuffers.setListener ('flutter/lifecycle' , (ByteData ? data, ui.PlatformMessageResponseCallback callback) async {
177
+ ui.channelBuffers.setListener ('flutter/lifecycle' ,
178
+ (ByteData ? data, ui.PlatformMessageResponseCallback callback) async {
175
179
if (data != null ) {
176
- ui.PlatformDispatcher .instance.sendPlatformMessage (
177
- 'flutter/unittest' ,
178
- data,
179
- (ByteData ? reply) {
180
- finished.complete ();
181
- });
180
+ ui.PlatformDispatcher .instance
181
+ .sendPlatformMessage ('flutter/unittest' , data, (ByteData ? reply) {
182
+ finished.complete ();
183
+ });
182
184
}
183
185
});
184
186
await finished.future;
185
187
}
186
188
187
189
@pragma ('vm:entry-point' )
188
- void enableLifecycleToFrom () async {
189
- ui.channelBuffers.setListener ('flutter/lifecycle' , (ByteData ? data, ui.PlatformMessageResponseCallback callback) async {
190
+ Future <void > enableLifecycleToFrom () async {
191
+ ui.channelBuffers.setListener ('flutter/lifecycle' ,
192
+ (ByteData ? data, ui.PlatformMessageResponseCallback callback) async {
190
193
if (data != null ) {
191
- ui.PlatformDispatcher .instance.sendPlatformMessage (
192
- 'flutter/unittest' ,
193
- data,
194
- (ByteData ? reply) {});
194
+ ui.PlatformDispatcher .instance
195
+ .sendPlatformMessage ('flutter/unittest' , data, (ByteData ? reply) {});
195
196
}
196
197
});
197
198
final Completer <ByteData ?> enabledLifecycle = Completer <ByteData ?>();
198
- ui.PlatformDispatcher .instance.sendPlatformMessage ('flutter/platform' , ByteData .sublistView (utf8.encode ('{"method":"System.initializationComplete"}' )), (ByteData ? data) {
199
+ ui.PlatformDispatcher .instance.sendPlatformMessage (
200
+ 'flutter/platform' ,
201
+ ByteData .sublistView (
202
+ utf8.encode ('{"method":"System.initializationComplete"}' )),
203
+ (ByteData ? data) {
199
204
enabledLifecycle.complete (data);
200
205
});
201
206
}
202
207
203
208
@pragma ('vm:entry-point' )
204
- void sendCreatePlatformViewMethod () async {
209
+ Future < void > sendCreatePlatformViewMethod () async {
205
210
// The platform view method channel uses the standard method codec.
206
211
// See https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/services/message_codecs.dart#L262
207
212
// for the implementation of the encoding and magic number identifiers.
@@ -225,14 +230,15 @@ void sendCreatePlatformViewMethod() async {
225
230
226
231
final Completer <ByteData ?> completed = Completer <ByteData ?>();
227
232
final ByteData bytes = ByteData .sublistView (Uint8List .fromList (data));
228
- ui.PlatformDispatcher .instance.sendPlatformMessage ('flutter/platform_views' , bytes, (ByteData ? response) {
233
+ ui.PlatformDispatcher .instance.sendPlatformMessage (
234
+ 'flutter/platform_views' , bytes, (ByteData ? response) {
229
235
completed.complete (response);
230
236
});
231
237
await completed.future;
232
238
}
233
239
234
240
@pragma ('vm:entry-point' )
235
- void sendGetKeyboardState () async {
241
+ Future < void > sendGetKeyboardState () async {
236
242
// The keyboard method channel uses the standard method codec.
237
243
// See https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/services/message_codecs.dart#L262
238
244
// for the implementation of the encoding and magic number identifiers.
@@ -250,7 +256,8 @@ void sendGetKeyboardState() async {
250
256
251
257
final Completer <void > completer = Completer <void >();
252
258
final ByteData bytes = ByteData .sublistView (Uint8List .fromList (data));
253
- ui.PlatformDispatcher .instance.sendPlatformMessage ('flutter/keyboard' , bytes, (ByteData ? response) {
259
+ ui.PlatformDispatcher .instance.sendPlatformMessage ('flutter/keyboard' , bytes,
260
+ (ByteData ? response) {
254
261
// For magic numbers for decoding a reply envelope, see:
255
262
// https://github.com/flutter/flutter/blob/67271f69f7f88a4edba6d8023099e3bd27a072d2/packages/flutter/lib/src/services/message_codecs.dart#L577-L587
256
263
const int replyEnvelopeSuccess = 0 ;
@@ -259,11 +266,14 @@ void sendGetKeyboardState() async {
259
266
if (response == null ) {
260
267
signalStringValue ('Unexpected null response' );
261
268
} else if (response.lengthInBytes < 2 ) {
262
- signalStringValue ('Unexpected response length of ${response .lengthInBytes } bytes' );
269
+ signalStringValue (
270
+ 'Unexpected response length of ${response .lengthInBytes } bytes' );
263
271
} else if (response.getUint8 (0 ) != replyEnvelopeSuccess) {
264
- signalStringValue ('Unexpected response envelope status: ${response .getUint8 (0 )}' );
272
+ signalStringValue (
273
+ 'Unexpected response envelope status: ${response .getUint8 (0 )}' );
265
274
} else if (response.getUint8 (1 ) != valueMap) {
266
- signalStringValue ('Unexpected response value magic number: ${response .getUint8 (1 )}' );
275
+ signalStringValue (
276
+ 'Unexpected response value magic number: ${response .getUint8 (1 )}' );
267
277
} else {
268
278
signalStringValue ('Success' );
269
279
}
@@ -287,7 +297,7 @@ void verifyNativeFunctionWithParameters() {
287
297
288
298
@pragma ('vm:entry-point' )
289
299
void verifyNativeFunctionWithReturn () {
290
- bool value = signalBoolReturn ();
300
+ final value = signalBoolReturn ();
291
301
signalBoolValue (value);
292
302
}
293
303
@@ -334,15 +344,14 @@ ui.Picture _createColoredBox(ui.Color color, ui.Size size) {
334
344
@pragma ('vm:entry-point' )
335
345
void renderImplicitView () {
336
346
ui.PlatformDispatcher .instance.onBeginFrame = (Duration duration) {
337
- final ui.Size size = ui.Size (800.0 , 600.0 );
338
- final ui.Color red = ui.Color .fromARGB (127 , 255 , 0 , 0 );
347
+ const ui.Size size = ui.Size (800.0 , 600.0 );
348
+ const ui.Color red = ui.Color .fromARGB (127 , 255 , 0 , 0 );
339
349
340
350
final ui.SceneBuilder builder = ui.SceneBuilder ();
341
351
342
352
builder.pushOffset (0.0 , 0.0 );
343
353
344
- builder.addPicture (
345
- ui.Offset (0.0 , 0.0 ), _createColoredBox (red, size));
354
+ builder.addPicture (ui.Offset .zero, _createColoredBox (red, size));
346
355
347
356
builder.pop ();
348
357
0 commit comments