mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Add tests for material_state_mouse_cursor.0.dart API example. (#145987)
This PR contributes to https://github.com/flutter/flutter/issues/130459 ### Description - Updates `examples/api/lib/material/material_state/material_state_mouse_cursor.0.dart` to allow enable/disable `ListTile` in tests; - Adds tests for `examples/api/lib/material/material_state/material_state_mouse_cursor.0.dart`.
This commit is contained in:
parent
69db714fbb
commit
e6f078fff5
@ -313,7 +313,6 @@ final Set<String> _knownMissingTests = <String>{
|
||||
'examples/api/test/material/bottom_app_bar/bottom_app_bar.1_test.dart',
|
||||
'examples/api/test/material/theme/theme_extension.1_test.dart',
|
||||
'examples/api/test/material/material_state/material_state_border_side.0_test.dart',
|
||||
'examples/api/test/material/material_state/material_state_mouse_cursor.0_test.dart',
|
||||
'examples/api/test/material/material_state/material_state_outlined_border.0_test.dart',
|
||||
'examples/api/test/material/material_state/material_state_property.0_test.dart',
|
||||
'examples/api/test/material/selectable_region/selectable_region.0_test.dart',
|
||||
|
@ -17,7 +17,10 @@ class MaterialStateMouseCursorExampleApp extends StatelessWidget {
|
||||
home: Scaffold(
|
||||
appBar: AppBar(title: const Text('MaterialStateMouseCursor Sample')),
|
||||
body: const Center(
|
||||
child: MaterialStateMouseCursorExample(),
|
||||
child: MaterialStateMouseCursorExample(
|
||||
// TRY THIS: Switch to get a different mouse cursor while hovering ListTile.
|
||||
enabled: false,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@ -40,14 +43,20 @@ class ListTileCursor extends MaterialStateMouseCursor {
|
||||
}
|
||||
|
||||
class MaterialStateMouseCursorExample extends StatelessWidget {
|
||||
const MaterialStateMouseCursorExample({super.key});
|
||||
const MaterialStateMouseCursorExample({
|
||||
required this.enabled,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final bool enabled;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const ListTile(
|
||||
title: Text('Disabled ListTile'),
|
||||
enabled: false,
|
||||
mouseCursor: ListTileCursor(),
|
||||
return ListTile(
|
||||
title: const Text('ListTile'),
|
||||
enabled: enabled,
|
||||
onTap: () {},
|
||||
mouseCursor: const ListTileCursor(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,77 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_api_samples/material/material_state/material_state_mouse_cursor.0.dart'
|
||||
as example;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'MaterialStateMouseCursorExampleApp displays ListTile',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const example.MaterialStateMouseCursorExampleApp(),
|
||||
);
|
||||
|
||||
expect(find.byType(ListTile), findsOneWidget);
|
||||
expect(find.text('ListTile'), findsOneWidget);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'ListTile displays correct mouse cursor when enabled',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: example.MaterialStateMouseCursorExample(enabled: true),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final TestGesture gesture = await tester.createGesture(
|
||||
kind: PointerDeviceKind.mouse,
|
||||
);
|
||||
await gesture.addPointer(
|
||||
location: tester.getCenter(find.byType(ListTile)),
|
||||
);
|
||||
addTearDown(gesture.removePointer);
|
||||
|
||||
expect(
|
||||
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
|
||||
SystemMouseCursors.click,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'ListTile displays correct mouse cursor when disabled',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: example.MaterialStateMouseCursorExample(enabled: false),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final TestGesture gesture = await tester.createGesture(
|
||||
kind: PointerDeviceKind.mouse,
|
||||
);
|
||||
await gesture.addPointer(
|
||||
location: tester.getCenter(find.byType(ListTile)),
|
||||
);
|
||||
addTearDown(gesture.removePointer);
|
||||
|
||||
expect(
|
||||
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
|
||||
SystemMouseCursors.forbidden,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue
Block a user