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
67a18fa5
Commit
67a18fa5
authored
Mar 23, 2016
by
Hans Muller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
TwoLevelList fails to restore sublist expanded state
parent
a8c108de
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
61 additions
and
18 deletions
+61
-18
two_level_list.dart
packages/flutter/lib/src/material/two_level_list.dart
+5
-2
basic.dart
packages/flutter/lib/src/widgets/basic.dart
+22
-0
debug.dart
packages/flutter/lib/src/widgets/debug.dart
+30
-13
framework.dart
packages/flutter/lib/src/widgets/framework.dart
+1
-1
virtual_viewport.dart
packages/flutter/lib/src/widgets/virtual_viewport.dart
+3
-2
No files found.
packages/flutter/lib/src/material/two_level_list.dart
View file @
67a18fa5
...
...
@@ -154,11 +154,14 @@ class _TwoLevelSublistState extends State<TwoLevelSublist> {
}
class
TwoLevelList
extends
StatelessWidget
{
TwoLevelList
({
Key
key
,
this
.
items
,
this
.
type
:
MaterialListType
.
twoLine
})
:
super
(
key:
key
);
TwoLevelList
({
Key
key
,
this
.
scrollableKey
,
this
.
items
,
this
.
type
:
MaterialListType
.
twoLine
})
:
super
(
key:
key
);
final
List
<
Widget
>
items
;
final
MaterialListType
type
;
final
Key
scrollableKey
;
@override
Widget
build
(
BuildContext
context
)
=>
new
Block
(
children:
items
);
Widget
build
(
BuildContext
context
)
{
return
new
Block
(
children:
KeyedSubtree
.
ensureUniqueKeysForList
(
items
),
scrollableKey:
scrollableKey
);
}
}
packages/flutter/lib/src/widgets/basic.dart
View file @
67a18fa5
...
...
@@ -7,6 +7,7 @@ import 'dart:ui' as ui show Image;
import
'package:flutter/rendering.dart'
;
import
'package:flutter/services.dart'
;
import
'debug.dart'
;
import
'framework.dart'
;
export
'package:flutter/animation.dart'
;
...
...
@@ -2575,6 +2576,27 @@ class KeyedSubtree extends StatelessWidget {
/// The widget below this widget in the tree.
final
Widget
child
;
/// Wrap each item in a KeyedSubtree whose key is based on the item's existing key or
/// its list index + baseIndex.
static
List
<
Widget
>
ensureUniqueKeysForList
(
Iterable
<
Widget
>
items
,
{
int
baseIndex:
0
})
{
if
(
items
==
null
||
items
.
isEmpty
)
return
items
;
List
<
Widget
>
itemsWithUniqueKeys
=
<
Widget
>[];
int
itemIndex
=
baseIndex
;
for
(
Widget
item
in
items
)
{
itemsWithUniqueKeys
.
add
(
new
KeyedSubtree
(
key:
item
.
key
!=
null
?
new
ValueKey
<
Key
>(
item
.
key
)
:
new
ValueKey
<
int
>(
itemIndex
),
child:
item
));
itemIndex
+=
1
;
}
assert
(!
debugItemsHaveDuplicateKeys
(
itemsWithUniqueKeys
));
return
items
;
}
@override
Widget
build
(
BuildContext
context
)
=>
child
;
}
...
...
packages/flutter/lib/src/widgets/debug.dart
View file @
67a18fa5
...
...
@@ -25,22 +25,39 @@ bool debugCheckHasMediaQuery(BuildContext context) {
return
true
;
}
bool
debugHasDuplicateKeys
(
Widget
parent
,
Iterable
<
Widget
>
children
)
{
Key
_firstNonUniqueKey
(
Iterable
<
Widget
>
widgets
)
{
Set
<
Key
>
keySet
=
new
HashSet
<
Key
>();
for
(
Widget
widget
in
widgets
)
{
assert
(
widget
!=
null
);
if
(
widget
.
key
==
null
)
continue
;
if
(!
keySet
.
add
(
widget
.
key
))
return
widget
.
key
;
}
return
null
;
}
bool
debugChildrenHaveDuplicateKeys
(
Widget
parent
,
Iterable
<
Widget
>
children
)
{
assert
(()
{
Set
<
Key
>
keySet
=
new
HashSet
<
Key
>();
for
(
Widget
child
in
children
)
{
assert
(
child
!=
null
);
if
(
child
.
key
==
null
)
continue
;
if
(!
keySet
.
add
(
child
.
key
))
{
throw
new
FlutterError
(
'Duplicate keys found.
\n
'
'If multiple keyed nodes exist as children of another node, they must have unique keys.
\n
'
'
$parent
has multiple children with key "
${child.key}
".'
);
}
final
Key
nonUniqueKey
=
_firstNonUniqueKey
(
children
);
if
(
nonUniqueKey
!=
null
)
{
throw
new
FlutterError
(
'Duplicate keys found.
\n
'
'If multiple keyed nodes exist as children of another node, they must have unique keys.
\n
'
'
$parent
has multiple children with key
$nonUniqueKey
.'
);
}
return
true
;
});
return
false
;
}
bool
debugItemsHaveDuplicateKeys
(
Iterable
<
Widget
>
items
)
{
assert
(()
{
final
Key
nonUniqueKey
=
_firstNonUniqueKey
(
items
);
if
(
nonUniqueKey
!=
null
)
throw
new
FlutterError
(
'Duplicate key found:
$nonUniqueKey
.
\n
'
);
return
true
;
});
return
false
;
}
packages/flutter/lib/src/widgets/framework.dart
View file @
67a18fa5
...
...
@@ -1937,7 +1937,7 @@ class SingleChildRenderObjectElement extends RenderObjectElement {
/// Instantiation of RenderObjectWidgets that can have a list of children
class
MultiChildRenderObjectElement
extends
RenderObjectElement
{
MultiChildRenderObjectElement
(
MultiChildRenderObjectWidget
widget
)
:
super
(
widget
)
{
assert
(!
debug
Has
DuplicateKeys
(
widget
,
widget
.
children
));
assert
(!
debug
ChildrenHave
DuplicateKeys
(
widget
,
widget
.
children
));
}
@override
...
...
packages/flutter/lib/src/widgets/virtual_viewport.dart
View file @
67a18fa5
...
...
@@ -173,8 +173,9 @@ abstract class VirtualViewportElement extends RenderObjectElement {
Key
key
=
child
.
key
!=
null
?
new
ValueKey
<
Key
>(
child
.
key
)
:
new
ValueKey
<
int
>(
childIndex
);
newWidgets
[
i
]
=
new
RepaintBoundary
(
key:
key
,
child:
child
);
}
assert
(!
debugHasDuplicateKeys
(
widget
,
newWidgets
));
_materializedChildren
=
updateChildren
(
_materializedChildren
,
newWidgets
);
assert
(!
debugChildrenHaveDuplicateKeys
(
widget
,
newWidgets
));
_materializedChildren
=
updateChildren
(
_materializedChildren
,
newWidgets
.
toList
());
}
@override
...
...
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