Flutter:有没有一种方法可以使sliverAppBar在按下按钮时消失

问题描述 投票:0回答:1

我想知道是否有一种方法可以使sliverAppBar在按下按钮后消失。不仅仅是滚动。

flutter appbar flutter-sliver
1个回答
1
投票

是的,有可能。在下面的示例中查看。

import 'package:flutter/material.dart';

  class Ch1 extends StatefulWidget {

    @override
    _Ch1State createState() => _Ch1State();
  }

  class _Ch1State extends State<Ch1> {
    bool check = true;

    @override
    Widget build(BuildContext context) {
      return Scaffold(
        body: NestedScrollView(
          headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
            return <Widget>[
               if(check)SliverAppBar(
                expandedHeight: 200.0,
                floating: false,
                pinned: true,
                flexibleSpace: FlexibleSpaceBar(
                    centerTitle: true,
                    title: Text("Collapsing Toolbar",
                        style: TextStyle(
                          color: Colors.white,
                          fontSize: 16.0,
                        )),
                    background: Image.network(
                      "https://images.pexels.com/photos/396547/pexels-photo-396547.jpeg?auto=compress&cs=tinysrgb&h=350",
                      fit: BoxFit.cover,
                    )),
              ),
            ];
          } ,
          body: Center(
            child: InkWell(
              onTap: (){
                setState(() {
                  check= !check;
                });
              },
                child: Text("Press"),
            ),
          ),
        ),
      );
    }
  }
© www.soinside.com 2019 - 2024. All rights reserved.