You can use keys to hard-reset the state of a subtree.
And if you want to reset the subtree only partially, you can add a GlobalKey on the top of the other key.
In the end you'll have:
Widget build(BuildContext context) {
return Provider(
key: ObjectKey(someIdentifier),
builder: (_) => Foo(),
child: SomeSubtree(
key: GlobalObjectKey(context),
),
);
}
In such case, if someIdentifier
changes, the state of Provider
will reset but Subtree
will be preserved.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…