title: How to use AnimatedSwitcher and CustomScrollView together
body: <p>I want switch status with animation in <code>CustomScrollView</code>, but it throw error.</p>
  
  <pre class="lang-dart prettyprint-override"><code>class SliverAnimatedSwitcher extends StatefulWidget {
    final state;
  
    const SliverAnimatedSwitcher({Key key, this.state}) : super(key: key);
  
    @override
    _SliverAnimatedSwitcherState createState() =&gt; _SliverAnimatedSwitcherState();
  }
  
  class _SliverAnimatedSwitcherState extends State&lt;SliverAnimatedSwitcher&gt; {
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        body: CustomScrollView(
          slivers: &lt;Widget&gt;[
            SliverAppBar(
              title: Text('SliverAnimatedSwitcher'),
            ),
            _buildContent(),
          ],
        ),
      );
    }
  
    get state =&gt; widget.state;
  
    Widget _buildContent() {
      var content;
      if (state.isNotEmpty == true) {
        content = SliverList(
          delegate: SliverChildBuilderDelegate(
            (context, index) {
              var item = state.items[index];
              return ListTile(
                title: Text(item.title),
              );
            },
            childCount: state.items.length,
          ),
        );
      } else if (state.isError) {
        content = SliverFillRemaining(
          key: Key('error'),
          child: Container(alignment: Alignment.center, child: Text('Error')),
        );
      } else if (state.isLoading) {
        content = SliverFillRemaining(
          key: Key('loading'),
          child: Container(alignment: Alignment.center, child: Text('Loading')),
        );
      } else {
        content = SliverFillRemaining(
          key: Key('empty'),
          child: Container(alignment: Alignment.center, child: Text('Empty')),
        );
      }
      return AnimatedSwitcher(
        duration: Duration(milliseconds: 300),
        child: content,
      );
    }
  }
  </code></pre>