flutter给图片添加遮罩层

813 阅读1分钟

可以通过DecorationImage的colorFilter属性快速简单的添加遮罩

class LoginView extends GetView<LoginController> {
  const LoginView({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Color(0xff4c4b49),
      body: Container(
        decoration: BoxDecoration(
          image: DecorationImage(
            image: AssetImage('imgs/login.png'),
            fit: BoxFit.cover,
            colorFilter: ColorFilter.mode(Colors.black45, BlendMode.darken),//添加遮罩
          ),
        )
      ),
    );
  }
}

参考链接:Flutter How to Apply Shader Mask to a Background Image