首页 > 解决方案 > Flutter:为全背景应用一个渐变

问题描述

如何将此处的渐变应用到应用程序背景?你能看到应用栏和脚手架主体上的渐变向下移动,就像它们是一个小部件而不是两个每个都有自己颜色的小部件一样?

标签: flutter

解决方案


您需要使用容器作为脚手架的背景来添加渐变。您也可以使用Opacity小部件使容器或任何小部件透明。但这是您正在寻找的确切解决方案:

Scaffold(
  body: Container(
    height: MediaQuery.of(context).size.height,
    width: MediaQuery.of(context).size.width,
    decoration: BoxDecoration(
      gradient: LinearGradient(
          colors: [Color(0xFF282a57), Colors.black],
          begin: Alignment.topCenter,
          end: Alignment.bottomCenter),
    ),
    child: Column(
      children: <Widget>[
        Padding(
          padding: const EdgeInsets.fromLTRB(20, 50, 20, 0),
          child: Container(
            child: Row(
              children: <Widget>[
                Icon(Icons.menu,color: Colors.white,),
                Spacer(),
                Text("Expense",style: TextStyle(color: Colors.white,fontSize: 18,)),
                Spacer(),
                Icon(Icons.clear, color: Colors.white,)
              ],
            ),
          ),
        ),
      ],
    ),
  )

推荐阅读