Added global keys to Material slices. (#5386)
Because parent structure changes when slices gets separated and merged, children widgets can be rebuilt redundantly. This commit adds a global key to each child so that the framework always knows its children apart.
This commit is contained in:
parent
abeb5c7363
commit
c0a71e341c
@ -506,6 +506,10 @@ class _MergeableMaterialState extends State<MergeableMaterial> {
|
|||||||
|
|
||||||
slices.add(
|
slices.add(
|
||||||
new Material(
|
new Material(
|
||||||
|
// Since slices live in different Material widgets, the parent
|
||||||
|
// hierarchy can change and lead to the slice being rebuilt. Using
|
||||||
|
// a global key solves the issue.
|
||||||
|
key: new _MergeableMaterialSliceKey(_children[i].key),
|
||||||
type: MaterialType.transparency,
|
type: MaterialType.transparency,
|
||||||
child: slice.child
|
child: slice.child
|
||||||
)
|
)
|
||||||
@ -539,6 +543,23 @@ class _MergeableMaterialState extends State<MergeableMaterial> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _MergeableMaterialSliceKey extends GlobalKey {
|
||||||
|
const _MergeableMaterialSliceKey(this.value) : super.constructor();
|
||||||
|
|
||||||
|
final LocalKey value;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(dynamic other) {
|
||||||
|
if (other is! _MergeableMaterialSliceKey)
|
||||||
|
return false;
|
||||||
|
final _MergeableMaterialSliceKey typedOther = other;
|
||||||
|
return value == typedOther.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => value.hashCode;
|
||||||
|
}
|
||||||
|
|
||||||
class _MergeableMaterialBlockBody extends BlockBody {
|
class _MergeableMaterialBlockBody extends BlockBody {
|
||||||
_MergeableMaterialBlockBody({
|
_MergeableMaterialBlockBody({
|
||||||
List<Widget> children,
|
List<Widget> children,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user