appbar actions flutter code example

Example 1: flutter appbar widget

Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('AppBar Title', textAlign: TextAlign.center),
      ),

Example 2: flutter appbar actions with tabs

class MyStatefulWidget extends StatefulWidget{

  MyStatefulWidgetState createState() => MyStatefulWidgetState();

  static MyStatefulWidgetState of(BuildContext context){
    return (context.inheritFromWidgetOfExactType(_MyInheritedStateContainer) as _MyInheritedStateContainer).data;
  }
}
class MyStatefulWidgetState extends State<MyStatefulWidget>{

String variableCalledHello = "Hello World";

  void initState() {
    super.initState();
  }
 
  Widget build(BuildContext context) {
   return new _MyInheritedStateContainer(data:this,child:/* Body here */);
  }
}
class _MyInheritedStateContainer extends InheritedWidget{
    _MyInheritedStateContainer({
Key key,
     Widget child,
     this.data,
  }) : super(key: key, child: child);

final MyStatefulWidgetState data;

 
  bool updateShouldNotify(_MyInheritedStateContainer oldWidget) {
    return true;
  }
}

Tags:

Dart Example