📜  颤振继承小部件 - 任何代码示例

📅  最后修改于: 2022-03-11 14:58:59.888000             🧑  作者: Mango

代码示例1
class MyInherited extends InheritedWidget {
  const MyInherited({
    Key? key,
    required Widget child,
  }) : super(key: key, child: child);


  // Here be dragons: null check (!) used, but if there's no
  // MyInhereted over where you used it this will throw.
  static MyInherited of(BuildContext context) {
    return context.dependOnInheritedWidgetOfExactType()!;
  }

  //if you have properties, it should look something like:
  // bool updateShouldNotify(MyInherited old) => old.prop !== new.prop;
  
  //if you don't: 
  @override
  bool updateShouldNotify(MyInherited old) => false;
}