box widget in flutter code example

Example 1: stateless widget flutter

class GreenFrog extends StatelessWidget {
  const GreenFrog({ Key key }) : super(key: key);

  
  Widget build(BuildContext context) {
    return Container(color: const Color(0xFF2DBD3A));
  }
}

Example 2: flutter inhereted widget

class MyInherited extends InheritedWidget {
  const MyInherited({
    Key key,
     Widget child,
  }) : super(key: key, child: child);


  static MyInherited of(BuildContext context) {
    return context.dependOnInheritedWidgetOfExactType<MyInherited>();
  }

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

Tags:

Dart Example