简体   繁体   English

Flutter 圆角appbar带彩线

[英]Flutter rounded appbar with color line

i have a rounded Appbar with a color line.我有一个带有彩色线条的圆形 Appbar。 Here is a Screenshot.这是一个屏幕截图。 I want the color line to follow the rounding.我希望颜色线跟随舍入。 Is this possible, since I have not found anything about it?这可能吗,因为我还没有找到任何关于它的信息?

This is my code so far:到目前为止,这是我的代码:

class LoginPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(
          "Test",
          style: TextStyle(fontStyle: FontStyle.italic),
        ),
        centerTitle: true,
        elevation: 10,
        backgroundColor: Colors.cyan[900],
        bottom: PreferredSize(
            preferredSize: Size.fromHeight(4.0),
            child: SizedBox(
              height: 5,
              child: Container(
                color: Colors.orange,
              ),
            )),
        shadowColor: Colors.cyan[900],
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.vertical(
            bottom: Radius.circular(30),
          ),
        ),
      ),
    );
  }
}

you can create your own custom Appbar by implementing PreferredSizeWidget您可以通过实现PreferredSizeWidget创建自己的自定义 Appbar

and the curved border can be achieved through nesting two containers where the space between them (padding in this case represents the stroke width) and the color of the parent container represents the color of the border.弯曲的边框可以通过嵌套两个容器来实现,它们之间的空间(本例中的填充表示笔划宽度),父容器的颜色表示边框的颜色。

here is full example这是完整的例子

class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
  const CustomAppBar({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 80.0,
      padding: EdgeInsets.only(bottom: 6.0),
      decoration: BoxDecoration(
        color: Colors.amber,
        borderRadius: BorderRadius.only(
          bottomLeft: Radius.circular(16.0),
          bottomRight: Radius.circular(16.0),
        ),
      ),
      child: Container(
        height: double.infinity,
        padding: EdgeInsets.symmetric(horizontal: 8.0),
        decoration: BoxDecoration(
            color: AppTheme.primaryColor,
            borderRadius: BorderRadius.only(
              bottomLeft: Radius.circular(16.0),
              bottomRight: Radius.circular(16.0),
            ),
            boxShadow: [BoxShadow(color: AppTheme.primaryColor.withOpacity(.4), spreadRadius: 2.0, blurRadius: 12.0)]),
        child: Center(
          child: Text("Hello Custom Appbar"),
        ),
      ),
    );
  }

  @override
  Size get preferredSize => Size(double.infinity, 150.0);
}

then use it like然后像使用它

Scaffold(
      appBar: CustomAppBar() ,

border will cover whole appbar, is this what you want?边框将覆盖整个应用栏,这是你想要的吗?

Scaffold(
      extendBody: true,
      appBar: AppBar(
        title: Text(
          "Test",
          style: TextStyle(fontStyle: FontStyle.italic),
        ),
        centerTitle: true,
        elevation: 10,
        backgroundColor: Colors.cyan[900],
        shadowColor: Colors.cyan[900],
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.vertical(
            bottom: Radius.circular(30),
          ),
          side: BorderSide(width: 3.0, color: Colors.orange),
        ),
      ),

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

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