简体   繁体   English

如何在 flutter 中制作圆形浮动应用栏

[英]How to make a rounded floating app bar in flutter

Could I get some help?我能得到一些帮助吗? I wanna make an app bar like this one, and there was a package that does it but it is deprecated我想做一个像这样的应用栏,有一个 package 可以做到,但它已被弃用

圆形应用栏图片

You can use a PreferredSizeWidget to build a custom app bar, giving a preferred app bar height.您可以使用PreferredSizeWidget构建自定义应用栏,提供首选的应用栏高度。

You could use a Container with a margin as a child and build the UI using a ROW您可以使用带有边距的Container作为子级,并使用 ROW 构建 UI

Appbar has a shape that can be edited Appbar有一个可以编辑的形状

AppBar(
shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.only(
                  topLeft: Radius.circular(25.0),
                  topRight: Radius.circular(25.0)
                )
)

try this尝试这个

class CustomBarWidget extends StatelessWidget { class CustomBarWidget 扩展 StatelessWidget {

  GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: _scaffoldKey,
      body: Container(
        height: 160.0,
        child: Stack(
          children: <Widget>[
           
            Positioned(
              top: 10.0,
              left: 0.0,
              right: 0.0,
              child: Container(
                padding: EdgeInsets.symmetric(horizontal: 20.0),
                child: DecoratedBox(
                  decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(1.0),
                      border: Border.all(
                          color: Colors.grey.withOpacity(0.5), width: 1.0),
                      color: Colors.white),
                  child: Row(
                    children: [
                      IconButton(
                        icon: Icon(
                          Icons.menu,
                          color: Colors.red,
                        ),
                        onPressed: () {
                          print("your menu action here");
                          _scaffoldKey.currentState.openDrawer();
                        },
                      ),
                      Expanded(
                        child: TextField(
                          decoration: InputDecoration(
                            hintText: "Search",
                          ),
                        ),
                      ),
                      IconButton(
                        icon: Icon(
                          Icons.search,
                          color: Colors.red,
                        ),
                        onPressed: () {
                          print("your menu action here");
                        },
                      ),
                      IconButton(
                        icon: Icon(
                          Icons.notifications,
                          color: Colors.red,
                        ),
                        onPressed: () {
                          print("your menu action here");
                        },
                      ),
                    ],
                  ),
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}

Here you go给你 go

  floatingActionButtonLocation: FloatingActionButtonLocation.centerTop,
  floatingActionButton: Column(children: [
    Container(
      decoration: BoxDecoration(
          color: Colors.red, borderRadius: BorderRadius.circular(5)),
      margin: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
      child: Padding(
        padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 5),
        child: Row(
          children: [Text("a")],
        ),
      ),
    ),
  ]),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM