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:
Dragoș Tiselice 2016-08-15 11:13:13 -07:00 committed by GitHub
parent abeb5c7363
commit c0a71e341c

View File

@ -506,6 +506,10 @@ class _MergeableMaterialState extends State<MergeableMaterial> {
slices.add(
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,
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 {
_MergeableMaterialBlockBody({
List<Widget> children,