Android 如何使用自定义appbar正确定位主体和抽屉?

Android 如何使用自定义appbar正确定位主体和抽屉?,android,flutter,Android,Flutter,我尝试用转置模糊效果制作appbar, 我的做法是: return Stack(children: <Widget>[ Scaffold( key: _scaffoldKey, backgroundColor: Theme.of(context).backgroundColor, body: Center( child: buildProcurementList(), ), ), Positioned( top: 0.0, left: 0.0, r

我尝试用转置模糊效果制作appbar, 我的做法是:

return Stack(children: <Widget>[
Scaffold(
  key: _scaffoldKey,
  backgroundColor: Theme.of(context).backgroundColor,
  body: Center(
    child: buildProcurementList(),
  ),
),
Positioned(
  top: 0.0,
  left: 0.0,
  right: 0.0,
  child: ClipRect(
    child: BackdropFilter(
      filter: ui.ImageFilter.blur(sigmaX: 5.0, sigmaY: 5.0),
      child: Container(
        child: AppBar(
          backgroundColor: Colors.transparent,
          title: Text(
            'Title',
          ),
          centerTitle: true,
        ),
        decoration:
            BoxDecoration(color: Colors.blue.shade200.withOpacity(0.5)),
      ),
    ),
  ),
),
返回堆栈(子级:[
脚手架(
钥匙:_scaffoldKey,
背景色:主题。背景色,
正文:中(
子项:buildProcurementList(),
),
),
定位(
排名:0.0,
左:0.0,
右:0.0,
孩子:ClipRect(
孩子:背投滤波器(
过滤器:ui.ImageFilter.blur(sigmaX:5.0,sigmaY:5.0),
子:容器(
孩子:AppBar(
背景颜色:颜色。透明,
标题:正文(
“头衔”,
),
标题:对,
),
装饰:
盒子装饰(颜色:Colors.blue.shade200.withOpacity(0.5)),
),
),
),
),
我得到了想要的效果,但由于堆叠,主体和抽屉固定在顶部。请告诉我一种方法,向主体和抽屉添加与appbar大小相同的填充物,就像在普通脚手架中一样


第1步:将堆栈移动到脚手架主体
步骤2:将定位的appbar放入堆叠小部件的最后一个

完整代码

import 'package:flutter/material.dart';
import 'dart:ui' as ui;

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: ListenToDrawerEvent(),
    );
  }
}

class ListenToDrawerEvent extends StatefulWidget {
  @override
  ListenToDrawerEventState createState() {
    return new ListenToDrawerEventState();
  }
}

class ListenToDrawerEventState extends State<ListenToDrawerEvent> {
  GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
  static final List<String> _listViewData = [
    "Inducesmile.com",
    "Flutter Dev",
    "Android Dev",
    "iOS Dev!",
    "React Native Dev!",
    "React Dev!",
    "express Dev!",
    "Laravel Dev!",
    "Angular Dev!",
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: _scaffoldKey,
      /*appBar: AppBar(
        title: Text("Listen to Drawer Open / Close Example"),
        leading: IconButton(
          icon: Icon(Icons.menu),
          onPressed: () {
            _scaffoldKey.currentState.openDrawer();
          },
        ),
      ),*/
      drawer: Drawer(
        child: ListView(
          padding: EdgeInsets.all(10.0),
          children: _listViewData
              .map((data) => ListTile(
                    title: Text(data),
                  ))
              .toList(),
        ),
      ),
      body: Stack(
        children: <Widget>[
          Center(
            child: ListView.builder(
              itemCount: 30,
              itemBuilder: (context, index) {
                return Container(
                  color: Colors.primaries[index % Colors.primaries.length]
                      .withOpacity(0.5),
                  child: ListTile(
                    title: Text('Item $index'),
                  ),
                );
              },
            ),
          ),
          Positioned(
            top: 0.0,
            left: 0.0,
            right: 0.0,
            child: ClipRect(
              child: BackdropFilter(
                filter: ui.ImageFilter.blur(sigmaX: 5.0, sigmaY: 5.0),
                child: Container(
                  child: AppBar(
                      backgroundColor: Colors.transparent,
                      title: Text(
                        'Title',
                      ),
                      centerTitle: true,
                      actions: <Widget>[
                        // action button
                        IconButton(
                          icon: Icon(Icons.access_alarm),
                          onPressed: () {
                            //_select(choices[0]);
                          },
                        ),
                        // action button
                        IconButton(
                          icon: Icon(Icons.memory),
                          onPressed: () {
                            //_select(choices[1]);
                          },
                        ),
                      ]),
                  decoration: BoxDecoration(
                      color: Colors.blue.shade200.withOpacity(0.5)),
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}
导入“包装:颤振/材料.省道”;
将“dart:ui”导入为ui;
void main()=>runApp(MyApp());
类MyApp扩展了无状态小部件{
//此小部件是应用程序的根。
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“颤振演示”,
debugShowCheckedModeBanner:false,
主题:主题数据(
//这是应用程序的主题。
//
//尝试使用“flutter run”运行应用程序。您将看到
//应用程序有一个蓝色工具栏。然后,在不退出应用程序的情况下,重试
//将下面的primarySwatch更改为Colors.green,然后调用
//“热重新加载”(在运行“颤振运行”的控制台中按“r”,
//或者只需将更改保存到颤振IDE中的“热重新加载”。
//请注意,计数器没有重置回零;应用程序
//未重新启动。
主样本:颜色。蓝色,
),
主页:ListenToDroperEvent(),
);
}
}
类ListenToDrawerEvent扩展StatefulWidget{
@凌驾
ListenToDroperReventState createState(){
返回新的ListenToDroperReventState();
}
}
类ListenToDroperReventState扩展了状态{
GlobalKey _scaffoldKey=GlobalKey();
静态最终列表_listViewData=[
“微笑网”,
“颤振开发”,
“安卓开发”,
“iOS开发!”,
“反应本机开发人员!”,
“反应,德夫!”,
“快车开发!”,
“Laravel Dev!”,
“角度偏差!”,
];
@凌驾
小部件构建(构建上下文){
返回脚手架(
钥匙:_scaffoldKey,
/*appBar:appBar(
标题:文本(“听抽屉打开/关闭示例”),
领先:IconButton(
图标:图标(图标菜单),
已按下:(){
_scaffoldKey.currentState.openDrawer();
},
),
),*/
抽屉(
子:ListView(
填充:所有边缘设置(10.0),
子项:\u listViewData
.map((数据)=>ListTile(
标题:文本(数据),
))
.toList(),
),
),
主体:堆栈(
儿童:[
居中(
子项:ListView.builder(
物品计数:30,
itemBuilder:(上下文,索引){
返回容器(
颜色:颜色.原色[索引%颜色.原色.长度]
.不透明度(0.5),
孩子:ListTile(
标题:文本(“项$index”),
),
);
},
),
),
定位(
排名:0.0,
左:0.0,
右:0.0,
孩子:ClipRect(
孩子:背投滤波器(
过滤器:ui.ImageFilter.blur(sigmaX:5.0,sigmaY:5.0),
子:容器(
孩子:AppBar(
背景颜色:颜色。透明,
标题:正文(
“头衔”,
),
标题:对,
行动:[
//动作按钮
图标按钮(
图标:图标(图标访问报警),
已按下:(){
//_选择(选项[0]);
},
),
//动作按钮
图标按钮(
图标:图标(图标。内存),
已按下:(){
//_选择(选项[1]);
},
),
]),
装饰:盒子装饰(
颜色:Colors.blue.shade200.withOpacity(0.5)),
),
),
),
),
],
),
);
}
}