This commit is contained in:
Yaakov Schectman 2024-10-28 15:52:43 -04:00
parent f76978e34f
commit b04c30be64
2 changed files with 27 additions and 12 deletions

View File

@ -32,18 +32,24 @@ final class MainApp extends StatefulWidget {
class _MainAppState extends State<MainApp> {
@override
Widget build(BuildContext context) {
final List<DisplayFeature> displayFeatures = MediaQuery.of(context).displayFeatures;
displayFeatures.retainWhere((DisplayFeature feature) => feature.type == DisplayFeatureType.cutout);
final List<DisplayFeature> displayFeatures =
MediaQuery.of(context).displayFeatures;
displayFeatures.retainWhere(
(DisplayFeature feature) => feature.type == DisplayFeatureType.cutout);
String text;
if (displayFeatures.isEmpty) {
text = 'CutoutNone';
} else if (displayFeatures.length > 1) {text = 'CutoutMany';}
else {
final Rect cutout =displayFeatures[0].bounds;
} else if (displayFeatures.length > 1) {
text = 'CutoutMany';
} else {
final Rect cutout = displayFeatures[0].bounds;
if (cutout.top == 0) {
text = 'CutoutTop';
} else if (cutout.left == 0) {text = 'CutoutLeft';}
else {text = 'CutoutNeither';}
} else if (cutout.left == 0) {
text = 'CutoutLeft';
} else {
text = 'CutoutNeither';
}
}
return MaterialApp(
debugShowCheckedModeBanner: false,

View File

@ -11,7 +11,6 @@ import 'package:test/test.dart';
const String _tallCutout = 'com.android.internal.display.cutout.emulation.tall';
void main() async {
late final FlutterDriver flutterDriver;
late final NativeDriver nativeDriver;
@ -20,9 +19,17 @@ void main() async {
nativeDriver = await AndroidNativeDriver.connect(flutterDriver);
await flutterDriver.waitUntilFirstFrameRasterized();
// Enable developer settings in order to simulate a cutout.
await Process.run('adb', <String>['shell', 'settings', 'put', 'global', 'development_settings_enabled', '1']);
await Process.run('adb', <String>[
'shell',
'settings',
'put',
'global',
'development_settings_enabled',
'1'
]);
// Simulate the tall cutout. A singular cutout that aligns to the "top" of the display.
await Process.run('adb', <String>['shell', 'cmd', 'overlay', 'enable', _tallCutout]);
await Process.run(
'adb', <String>['shell', 'cmd', 'overlay', 'enable', _tallCutout]);
});
tearDownAll(() async {
@ -33,14 +40,16 @@ void main() async {
test('cutout should be on top in portrait mode', () async {
await nativeDriver.rotateResetDefault();
await flutterDriver.waitFor(find.byType('Text'));
final String status = await flutterDriver.getText(find.byValueKey('CutoutTop'));
final String status =
await flutterDriver.getText(find.byValueKey('CutoutTop'));
expect(status, 'Cutout status: CutoutTop');
}, timeout: const Timeout(Duration(seconds: 5)));
test('cutout should be on left in landscape mode', () async {
await nativeDriver.rotateToLandscape();
await flutterDriver.waitFor(find.byType('Text'));
final String status = await flutterDriver.getText(find.byValueKey('CutoutLeft'));
final String status =
await flutterDriver.getText(find.byValueKey('CutoutLeft'));
expect(status, 'Cutout status: CutoutLeft');
}, timeout: const Timeout(Duration(seconds: 5)));