title: Change AppBar title dynamically in Flutter
body: <p>I have a reusable AppBar widget in different class. Have to set the app bar title from an API response. Once the appBar title is set, it should be same for all the screens.</p>
  <p>AppBar.dart</p>
  <pre><code>import 'package:flutter/material.dart';
  
  class CustomAppBar extends StatefulWidget implements PreferredSizeWidget {
    CustomAppBar({Key key})
        : preferredSize = Size.fromHeight(kToolbarHeight),
          super(key: key);
  
    @override
    final Size preferredSize; // default is 56.0
  
    @override
    _CustomAppBarState createState() =&gt; _CustomAppBarState();
  }
  
  class _CustomAppBarState extends State&lt;CustomAppBar&gt; {
    @override
    Widget build(BuildContext context) {
      return AppBar(
        title: Text('Emotely'),
        flexibleSpace: Container(
          decoration: BoxDecoration(
            gradient: LinearGradient(
              colors: [themeColor, themeColorLight],
            ),
          ),
        ),
      );
    }
  }
  </code></pre>
  <p>MainScreen.dart</p>
  <pre><code>//api response
  
      upload(String base64Image) {
          var body = jsonEncode({&quot;image&quot;: base64Image});
          http
              .post(api, headers: {&quot;Content-Type&quot;: &quot;application/json&quot;}, body: body)
              .then((result) {
            print(result.body);
            setStatus(result.statusCode == 200 ? result.body : errMessage);
          })
  
  @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: CustomAppBar(), //Need to change the AppBar Title here
        body: Container(
          padding: EdgeInsets.all(30.0),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: &lt;Widget&gt;[]
  </code></pre>