feat(flutter): 增加关键操作震动反馈
This commit is contained in:
1 parent
e609e3ad8d
commit
8a481d5c62
20 files changed
+308
-72
No files matched your search
@@ -0,0 +1,23 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
test('should_keep_haptic_calls_inside_platform_wrapper', () {
|
||||
final violations = <String>[];
|
||||
for (final entity in Directory('lib').listSync(recursive: true)) {
|
||||
if (entity is! File || !entity.path.endsWith('.dart')) continue;
|
||||
if (entity.path.endsWith('lib/core/platform/haptics.dart')) continue;
|
||||
final lines = entity.readAsLinesSync();
|
||||
for (var index = 0; index < lines.length; index++) {
|
||||
if (lines[index].contains('HapticFeedback.')) {
|
||||
violations.add('${entity.path}:${index + 1}');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
expect(violations, isEmpty, reason: violations.join('\n'));
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fruitshorts/core/platform/haptics.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
test('should_ignore_platform_errors_when_haptics_are_unavailable', () async {
|
||||
const channel = SystemChannels.platform;
|
||||
final messenger =
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger;
|
||||
messenger.setMockMethodCallHandler(channel, (_) async {
|
||||
throw PlatformException(code: 'unavailable');
|
||||
});
|
||||
addTearDown(() => messenger.setMockMethodCallHandler(channel, null));
|
||||
|
||||
const haptics = FlutterHaptics();
|
||||
await expectLater(haptics.selectionClick(), completes);
|
||||
await expectLater(haptics.lightImpact(), completes);
|
||||
await expectLater(haptics.mediumImpact(), completes);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user