Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
cf37c2cd
Unverified
Commit
cf37c2cd
authored
Nov 25, 2019
by
Jonah Williams
Committed by
GitHub
Nov 25, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add assert for negative child count in ListView.builder (#45506)
parent
1888fa35
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
1 deletion
+35
-1
scroll_view.dart
packages/flutter/lib/src/widgets/scroll_view.dart
+4
-1
scrollable.dart
packages/flutter/lib/src/widgets/scrollable.dart
+2
-0
scroll_view_test.dart
packages/flutter/test/widgets/scroll_view_test.dart
+29
-0
No files found.
packages/flutter/lib/src/widgets/scroll_view.dart
View file @
cf37c2cd
...
...
@@ -81,6 +81,7 @@ abstract class ScrollView extends StatelessWidget {
assert
(!
shrinkWrap
||
center
==
null
),
assert
(
anchor
!=
null
),
assert
(
anchor
>=
0.0
&&
anchor
<=
1.0
),
assert
(
semanticChildCount
==
null
||
semanticChildCount
>=
0
),
primary
=
primary
??
controller
==
null
&&
identical
(
scrollDirection
,
Axis
.
vertical
),
physics
=
physics
??
(
primary
==
true
||
(
primary
==
null
&&
controller
==
null
&&
identical
(
scrollDirection
,
Axis
.
vertical
))
?
const
AlwaysScrollableScrollPhysics
()
:
null
),
super
(
key:
key
);
...
...
@@ -943,7 +944,9 @@ class ListView extends BoxScrollView {
double
cacheExtent
,
int
semanticChildCount
,
DragStartBehavior
dragStartBehavior
=
DragStartBehavior
.
start
,
})
:
childrenDelegate
=
SliverChildBuilderDelegate
(
})
:
assert
(
itemCount
==
null
||
itemCount
>=
0
),
assert
(
semanticChildCount
==
null
||
semanticChildCount
<=
itemCount
),
childrenDelegate
=
SliverChildBuilderDelegate
(
itemBuilder
,
childCount:
itemCount
,
addAutomaticKeepAlives:
addAutomaticKeepAlives
,
...
...
packages/flutter/lib/src/widgets/scrollable.dart
View file @
cf37c2cd
...
...
@@ -88,6 +88,7 @@ class Scrollable extends StatefulWidget {
assert
(
dragStartBehavior
!=
null
),
assert
(
viewportBuilder
!=
null
),
assert
(
excludeFromSemantics
!=
null
),
assert
(
semanticChildCount
==
null
||
semanticChildCount
>=
0
),
super
(
key:
key
);
/// The direction in which this widget scrolls.
...
...
@@ -643,6 +644,7 @@ class _ScrollSemantics extends SingleChildRenderObjectWidget {
@required
this
.
semanticChildCount
,
Widget
child
,
})
:
assert
(
position
!=
null
),
assert
(
semanticChildCount
==
null
||
semanticChildCount
>=
0
),
super
(
key:
key
,
child:
child
);
final
ScrollPosition
position
;
...
...
packages/flutter/test/widgets/scroll_view_test.dart
View file @
cf37c2cd
...
...
@@ -559,4 +559,33 @@ void main() {
expect
(
tester
.
takeException
(),
isInstanceOf
<
Exception
>());
expect
(
finder
,
findsOneWidget
);
});
testWidgets
(
'ListView.builder asserts on negative childCount'
,
(
WidgetTester
tester
)
async
{
expect
(()
=>
ListView
.
builder
(
itemBuilder:
(
BuildContext
context
,
int
index
)
{
return
const
SizedBox
();
},
itemCount:
-
1
,
),
throwsA
(
isInstanceOf
<
AssertionError
>()));
});
testWidgets
(
'ListView.builder asserts on negative semanticChildCount'
,
(
WidgetTester
tester
)
async
{
expect
(()
=>
ListView
.
builder
(
itemBuilder:
(
BuildContext
context
,
int
index
)
{
return
const
SizedBox
();
},
itemCount:
1
,
semanticChildCount:
-
1
,
),
throwsA
(
isInstanceOf
<
AssertionError
>()));
});
testWidgets
(
'ListView.builder asserts on nonsensical childCount/semanticChildCount'
,
(
WidgetTester
tester
)
async
{
expect
(()
=>
ListView
.
builder
(
itemBuilder:
(
BuildContext
context
,
int
index
)
{
return
const
SizedBox
();
},
itemCount:
1
,
semanticChildCount:
4
,
),
throwsA
(
isInstanceOf
<
AssertionError
>()));
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment