Unverified Commit 619eccd2 authored by gaowanqiu's avatar gaowanqiu Committed by GitHub

Fix negative usableCrossAxisExtent in release mode (#64441)

parent c26c2363
......@@ -64,3 +64,4 @@ Brian Wang <xinlei966@gmail.com>
CaiJingLong <cjl_spy@163.com>
Alex Li <google@alexv525.com>
Ram Navan <hiramprasad@gmail.com>
meritozh <ah841814092@gmail.com>
......@@ -326,7 +326,8 @@ class SliverGridDelegateWithFixedCrossAxisCount extends SliverGridDelegate {
@override
SliverGridLayout getLayout(SliverConstraints constraints) {
assert(_debugAssertIsValid());
final double usableCrossAxisExtent = constraints.crossAxisExtent - crossAxisSpacing * (crossAxisCount - 1);
final double usableCrossAxisExtent = math.max(0.0,
constraints.crossAxisExtent - crossAxisSpacing * (crossAxisCount - 1));
final double childCrossAxisExtent = usableCrossAxisExtent / crossAxisCount;
final double childMainAxisExtent = childCrossAxisExtent / childAspectRatio;
return SliverGridRegularTileLayout(
......@@ -425,7 +426,8 @@ class SliverGridDelegateWithMaxCrossAxisExtent extends SliverGridDelegate {
SliverGridLayout getLayout(SliverConstraints constraints) {
assert(_debugAssertIsValid(constraints.crossAxisExtent));
final int crossAxisCount = (constraints.crossAxisExtent / (maxCrossAxisExtent + crossAxisSpacing)).ceil();
final double usableCrossAxisExtent = constraints.crossAxisExtent - crossAxisSpacing * (crossAxisCount - 1);
final double usableCrossAxisExtent = math.max(0.0,
constraints.crossAxisExtent - crossAxisSpacing * (crossAxisCount - 1));
final double childCrossAxisExtent = usableCrossAxisExtent / crossAxisCount;
final double childMainAxisExtent = childCrossAxisExtent / childAspectRatio;
return SliverGridRegularTileLayout(
......
......@@ -308,6 +308,44 @@ void main() {
},
);
testWidgets(
'SliverGrid negative usableCrossAxisExtent',
(WidgetTester tester) async {
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: SizedBox(
width: 4,
height: 4,
child: CustomScrollView(
slivers: <Widget>[
SliverGrid(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
crossAxisSpacing: 8,
mainAxisSpacing: 8,
),
delegate: SliverChildListDelegate(
<Widget>[
Container(child: const Center(child: Text('A'))),
Container(child: const Center(child: Text('B'))),
Container(child: const Center(child: Text('C'))),
Container(child: const Center(child: Text('D'))),
],
),
),
],
),
),
),
),
);
expect(tester.takeException(), isNull);
},
);
testWidgets(
'SliverList can handle inaccurate scroll offset due to changes in children list',
(WidgetTester tester) async {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment