title: Flutter How to check if Sliver AppBar is expanded or collapsed?
body: <p>I am using a <a href="https://docs.flutter.io/flutter/material/SliverAppBar-class.html" rel="noreferrer"><strong>SliverAppBar</strong></a> in Flutter, with a background widget.</p>
  
  <p>The thing is When it's <em>expanded</em>, the title and icons (leading and actions) should be <em>white</em> in order to be seen correctly, and when it's <em>collapsed</em>, they should be changed to <em>black</em>.</p>
  
  <p>Any ideas on how I can get a <strong>bool</strong> out of it? Or other ways of resolving this problem.</p>
  
  <p>Thank you. </p>
  
  <pre><code>class SliverExample extends StatefulWidget {
    final Widget backgroundWidget;
    final Widget bodyWidgets;
  
    SliverExample({
      this.backgroundWidget,
      this.body,
    });
    @override
    _SliverExampleState createState() =&gt; _SliverExampleState();
  }
  
  class _SliverExampleState extends State&lt;SliverExample&gt; {
  
    // I need something like this
    // To determine if SliverAppBar is expanded or not.
    bool isAppBarExpanded = false;
  
    @override
    Widget build(BuildContext context) {
  
      // To change the item's color accordingly
      // To be used in multiple places in code
      Color itemColor = isAppBarExpanded ? Colors.white : Colors.black;
  
      // In my case PrimaryColor is white,
      // and the background widget is dark
  
      return Scaffold(
        body: CustomScrollView(
          slivers: &lt;Widget&gt;[
            SliverAppBar(
              pinned: true,
              leading: BackButton(
                color: itemColor, // Here
              ),
              actions: &lt;Widget&gt;[
                IconButton(
                  icon: Icon(
                    Icons.shopping_cart,
                    color: itemColor, // Here
                  ),
                  onPressed: () {},
                ),
              ],
              expandedHeight: 200.0,
              flexibleSpace: FlexibleSpaceBar(
                centerTitle: true,
                title: Text(
                  'title',
                  style: TextStyle(
                    fontSize: 18.0,
                    color: itemColor, // Here
                  ),
                ),
                // Not affecting the question.              
                background: widget.backgroundWidget,
              ),
            ),
            // Not affecting the question.
            SliverToBoxAdapter(child: widget.body),
          ],
        ),
      );
    }
  }
  </code></pre>