How can I add shadow to the widget in flutter?

前端 未结 8 1489
余生分开走
余生分开走 2020-12-04 09:07

How can I add shadow to the widget like in the picture below?

This is my current widget code.

相关标签:
8条回答
  • 2020-12-04 09:38

    Use Material with shadowColor inside Container like this:

    Container(
      decoration: BoxDecoration(
          borderRadius: BorderRadius.only(
              bottomLeft: Radius.circular(10),
              bottomRight: Radius.circular(10)),
          boxShadow: [
            BoxShadow(
                color: Color(0xffA22447).withOpacity(.05),
                offset: Offset(0, 0),
                blurRadius: 20,
                spreadRadius: 3)
          ]),
      child: Material(
        borderRadius: BorderRadius.only(
            bottomLeft: Radius.circular(10),
            bottomRight: Radius.circular(10)),
        elevation: 5,
        shadowColor: Color(0xffA22447).withOpacity(.05),
        color: Color(0xFFF7F7F7),
        child: SizedBox(
          height: MediaQuery.of(context).size.height / 3,
        ),
      ),
    )
    
    0 讨论(0)
  • 2020-12-04 09:39

    Add box shadow to container in flutter

      Container(
          margin: EdgeInsets.only(left: 30, top: 100, right: 30, bottom: 50),
          height: double.infinity,
          width: double.infinity,
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.only(
              topLeft: Radius.circular(10),
                topRight: Radius.circular(10),
                bottomLeft: Radius.circular(10),
                bottomRight: Radius.circular(10)
            ),
            boxShadow: [
              BoxShadow(
                color: Colors.grey.withOpacity(0.5),
                spreadRadius: 5,
                blurRadius: 7,
                offset: Offset(0, 3), // changes position of shadow
              ),
            ],
          ),
      )
    

    Here is my output

    0 讨论(0)
提交回复
热议问题