@@ -18,14 +18,6 @@ void main() {
1818 internalBootstrapBrowserTest (() => testMain);
1919}
2020
21- ByteData _toByteData (List <int > bytes) {
22- final ByteData byteData = ByteData (bytes.length);
23- for (int i = 0 ; i < bytes.length; i++ ) {
24- byteData.setUint8 (i, bytes[i]);
25- }
26- return byteData;
27- }
28-
2921void testMain () {
3022 group ('Keyboard' , () {
3123 /// Used to save and restore [ui.window.onPlatformMessage] after each test.
@@ -236,21 +228,13 @@ void testMain() {
236228 });
237229
238230 test ('prevents default when key is handled by the framework' , () {
239- ByteData _toByteData (List <int > bytes) {
240- final ByteData byteData = ByteData (bytes.length);
241- for (int i = 0 ; i < bytes.length; i++ ) {
242- byteData.setUint8 (i, bytes[i]);
243- }
244- return byteData;
245- }
246-
247231 Keyboard .initialize ();
248232
249233 int count = 0 ;
250234 ui.window.onPlatformMessage = (String channel, ByteData data,
251235 ui.PlatformMessageResponseCallback callback) {
252236 count += 1 ;
253- ByteData response = _toByteData (utf8. encode (json. encode ( < String , dynamic > {'handled' : true })) );
237+ ByteData response = const JSONMessageCodec (). encodeMessage ( < String , dynamic > {'handled' : true });
254238 callback (response);
255239 };
256240
@@ -273,7 +257,7 @@ void testMain() {
273257 ui.window.onPlatformMessage = (String channel, ByteData data,
274258 ui.PlatformMessageResponseCallback callback) {
275259 count += 1 ;
276- ByteData response = _toByteData (utf8. encode (json. encode ( < String , dynamic > {'handled' : false })) );
260+ ByteData response = const JSONMessageCodec (). encodeMessage ( < String , dynamic > {'handled' : false });
277261 callback (response);
278262 };
279263
@@ -320,7 +304,7 @@ void testMain() {
320304 ui.window.onPlatformMessage = (String channel, ByteData data,
321305 ui.PlatformMessageResponseCallback callback) {
322306 count += 1 ;
323- ByteData response = _toByteData (utf8. encode (json. encode ( < String , dynamic > {'handled' : true })) );
307+ ByteData response = const JSONMessageCodec (). encodeMessage ( < String , dynamic > {'handled' : true });
324308 callback (response);
325309 };
326310
0 commit comments