fix a throw due to double precison (#92486)

This commit is contained in:
xubaolin
2021-10-27 10:13:05 +08:00
committed by GitHub
parent 9afb45a44f
commit b025e38e17
2 changed files with 36 additions and 1 deletions

View File

@@ -577,7 +577,7 @@ class _DropdownRoute<T> extends PopupRoute<_DropdownRouteResult<T>> {
scrollOffset = math.min(scrollOffset, preferredMenuHeight - menuHeight);
}
assert(menuHeight == menuBottom - menuTop);
assert((menuBottom - menuTop - menuHeight).abs() < precisionErrorTolerance);
return _MenuLimits(menuTop, menuBottom, menuHeight, scrollOffset);
}
}

View File

@@ -3595,4 +3595,39 @@ void main() {
}
}
});
// Regression test for https://github.com/flutter/flutter/issues/92438
testWidgets('Do not throw due to the double precision', (WidgetTester tester) async {
const String value = 'One';
const double itemHeight = 77.701;
final List<DropdownMenuItem<String>> menuItems = <String>[
value,
'Two',
'Free',
].map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList();
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Center(
child: DropdownButton<String>(
value: value,
itemHeight: itemHeight,
onChanged: (_) {},
items: menuItems,
),
),
),
),
);
await tester.tap(find.text(value));
await tester.pumpAndSettle();
expect(tester.takeException(), null);
});
}