mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Fix ink features painting in YearPicker. (#177014)
Fixes https://github.com/flutter/flutter/issues/155198 ## Description - Fixes ink features painting outside of the `GridView` bounds in `YearPicker` | BEFORE | AFTER | | - | - | | <video alt="before" src="https://github.com/user-attachments/assets/efe86478-a19b-4a1b-b6c1-97f30dbe262b" /> | <video alt="after" src="https://github.com/user-attachments/assets/1c70fbe9-3e89-4b18-bce0-40d81068adbf" /> | ## Pre-launch Checklist - [X] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [X] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [X] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [X] I signed the [CLA]. - [X] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [X] I added new tests to check the change I am making, or this PR is [test-exempt]. - [X] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [X] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
This commit is contained in:
parent
28a1d0b9be
commit
abac27dbcb
@ -1542,18 +1542,20 @@ class _YearPickerState extends State<YearPicker> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
assert(debugCheckHasMaterial(context));
|
||||
return Column(
|
||||
children: <Widget>[
|
||||
const Divider(),
|
||||
Expanded(
|
||||
child: GridView.builder(
|
||||
controller: _scrollController,
|
||||
dragStartBehavior: widget.dragStartBehavior,
|
||||
gridDelegate: _YearPickerGridDelegate(context),
|
||||
itemBuilder: _buildYearItem,
|
||||
itemCount: math.max(_itemCount, minYears),
|
||||
padding: const EdgeInsets.symmetric(horizontal: _yearPickerPadding),
|
||||
child: Material(
|
||||
type: MaterialType.transparency,
|
||||
child: GridView.builder(
|
||||
controller: _scrollController,
|
||||
dragStartBehavior: widget.dragStartBehavior,
|
||||
gridDelegate: _YearPickerGridDelegate(context),
|
||||
itemBuilder: _buildYearItem,
|
||||
itemCount: math.max(_itemCount, minYears),
|
||||
padding: const EdgeInsets.symmetric(horizontal: _yearPickerPadding),
|
||||
),
|
||||
),
|
||||
),
|
||||
const Divider(),
|
||||
|
||||
@ -1734,6 +1734,42 @@ void main() {
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
// Regression test for https://github.com/flutter/flutter/issues/155198.
|
||||
testWidgets('Ink features are painted on inner Material', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
yearPicker(
|
||||
firstDate: DateTime(2020),
|
||||
lastDate: DateTime(2030),
|
||||
selectedDate: DateTime(2025),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(Material), findsNWidgets(2));
|
||||
|
||||
// Material outside the GridView.
|
||||
final MaterialInkController outerMaterial = Material.of(
|
||||
tester.element(find.byType(YearPicker)),
|
||||
);
|
||||
// Material directly wrapping the GridView.
|
||||
final MaterialInkController innerMaterial = Material.of(
|
||||
tester.element(find.byType(GridView)),
|
||||
);
|
||||
|
||||
expect(outerMaterial, isNot(same(innerMaterial)));
|
||||
expect((outerMaterial as dynamic).debugInkFeatures, isNull);
|
||||
expect((innerMaterial as dynamic).debugInkFeatures, isNull);
|
||||
|
||||
// Hover over the 2022 year item to trigger the ink highlight.
|
||||
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
||||
await gesture.addPointer(location: tester.getCenter(find.text('2022')));
|
||||
addTearDown(gesture.removePointer);
|
||||
await tester.pump();
|
||||
|
||||
// Only the inner Material should have ink features.
|
||||
expect((outerMaterial as dynamic).debugInkFeatures, isNull);
|
||||
expect((innerMaterial as dynamic).debugInkFeatures, hasLength(1));
|
||||
});
|
||||
});
|
||||
|
||||
group('Calendar Delegate', () {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user