【问题标题】:Drawer not show up at SliverAppBar抽屉没有出现在 SliverAppBar
【发布时间】:2021-12-25 07:15:53
【问题描述】:

我想在我的SliverAppBar 中添加一个Drawer 我的代码里面没有任何错误但是当我运行代码时抽屉没有显示出来。

这是我的代码

body: CustomScrollView(
    slivers: <Widget>[
      SliverLayoutBuilder(
        builder: (BuildContext context, constraints) {
          final scrolled = constraints.scrollOffset > 50;
          final scrolledicon = constraints.scrollOffset > 0;

          return SliverAppBar(
            expandedHeight: 20,
            toolbarHeight: 65,
            leading: Padding(
              padding: const EdgeInsets.only(top: 2),
              child: Icon(DBIcons.logo, color: Colors.red, size: 50),
            ),
            actions: [
              Padding(
                padding: const EdgeInsets.all(10),
                child: IconButton(
                  icon: Icon(Icons.menu),
                  color: scrolledicon ? Colors.white : Colors.black,
                  onPressed: (){
                    Drawer(
                      child: Center(
                        child: Text('This is Drawer'),
                      ),
                    );
                  },
                ),
              ),
            ],
            backgroundColor: scrolled ? Colors.black : Colors.transparent,
            elevation: 0,
            pinned: true,
          );
        },
      ),

【问题讨论】:

    标签: flutter flutter-layout drawerlayout


    【解决方案1】:

    请看here

    在你的 Scaffold 中,你必须注册一个抽屉

    Scaffold(
        ...
        drawer: Drawer(child: Center(
                        child: Text('This is Drawer'),
        ),
        ...
      );
    

    使用 onPressed 您将打开抽屉的请求发送到脚手架:

    onPressed: () => Scaffold.of(context).openDrawer(),
    

    【讨论】:

      猜你喜欢
      • 2019-05-27
      • 1970-01-01
      • 1970-01-01
      • 2015-11-16
      • 2023-03-22
      • 2011-06-22
      • 1970-01-01
      • 1970-01-01
      • 2021-11-21
      相关资源
      最近更新 更多