create custom widget in flutter code example
Example 1: stateless widget flutter
class GreenFrog extends StatelessWidget {
const GreenFrog({ Key key }) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(color: const Color(0xFF2DBD3A));
}
}
Example 2: flutter inhereted widget
class MyInherited extends InheritedWidget {
const MyInherited({
Key key,
@required Widget child,
}) : super(key: key, child: child);
static MyInherited of(BuildContext context) {
return context.dependOnInheritedWidgetOfExactType<MyInherited>();
}
@override
bool updateShouldNotify(MyInherited old) => false;
}