如何在Flutter中创建带有底部彩色边框的AppBar?

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

我想创建一个像这样的应用程序栏,它有一个底部边框以及可以使用海拔来完成的阴影色调。有人可以提供示例代码片段来实现此目的吗

dart flutter appbar
5个回答
67
投票

也许是这样的

AppBar(
   bottom: PreferredSize(
     preferredSize: const Size.fromHeight(4.0),
     child: Container(
        color: Colors.orange,
        height: 4.0,
     ),
   )

52
投票

您可以使用 AppBar 的

shape
属性来实现此目的:

AppBar(
  shape: Border(
    bottom: BorderSide(
      color: Colors.orange,
      width: 4
    )
  ),
  elevation: 4,
  /* ... */
)

11
投票

理想情况下,如果您想要真正可定制的设计,您应该制作自己的应用栏。示例:

class MyAppbar extends StatelessWidget implements PreferredSizeWidget {
  final Widget title;

  const MyAppbar({Key key, this.title}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Material(
      elevation: 26.0,
      color: Colors.white,
      child: Container(
        padding: const EdgeInsets.all(10.0),
        alignment: Alignment.centerLeft,
        decoration: BoxDecoration(
          border: Border(
            bottom: BorderSide(
              color: Colors.deepOrange,
              width: 3.0,
              style: BorderStyle.solid,
            ),
          ),
        ),
        child: title,
      ),
    );
  }

  final Size preferredSize = const Size.fromHeight(kToolbarHeight);
}

1
投票

现在 AppBar 中提供了

shadowColor
属性,您可以像这样轻松使用:

AppBar( shadowColor : Colors.blue )


0
投票

如果您只想使用 AppBar 底部的小部件,我就是这样做的:

appBar: AppBar(
        title: Text('Soroush!'),
        bottom: PreferredSize(
            child: Container(
              color: Colors.white,
              child: TextFormField(),
            ),
            preferredSize: Size.fromHeight(kToolbarHeight)),
© www.soinside.com 2019 - 2024. All rights reserved.