fix a HapticFeedback.vibrate NNBD bug (flutter/engine#25350)

This commit is contained in:
xubaolin
2021-04-02 05:39:01 +08:00
committed by GitHub
parent 1a617496d9
commit 01ef94a8e0
2 changed files with 21 additions and 2 deletions

View File

@@ -389,7 +389,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
});
return;
case 'HapticFeedback.vibrate':
final String type = decoded.arguments;
final String? type = decoded.arguments;
domRenderer.vibrate(_getHapticFeedbackDuration(type));
_replyToPlatformMessage(
callback, codec.encodeSuccessEnvelope(true));
@@ -499,7 +499,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
_replyToPlatformMessage(callback, null);
}
int _getHapticFeedbackDuration(String type) {
int _getHapticFeedbackDuration(String? type) {
switch (type) {
case 'HapticFeedbackType.lightImpact':
return DomRenderer.vibrateLightImpact;

View File

@@ -37,5 +37,24 @@ void testMain() {
[true],
);
});
test('responds to flutter/platform HapticFeedback.vibrate', () async {
const MethodCodec codec = JSONMethodCodec();
final Completer<ByteData?> completer = Completer<ByteData?>();
ui.PlatformDispatcher.instance.sendPlatformMessage(
'flutter/platform',
codec.encodeMethodCall(MethodCall(
'HapticFeedback.vibrate',
)),
completer.complete,
);
final ByteData? response = await completer.future;
expect(response, isNotNull);
expect(
codec.decodeEnvelope(response!),
true,
);
});
});
}