Blurred Decoration Image in Flutter

前端 未结 4 813
眼角桃花
眼角桃花 2020-12-25 11:35

I have the background of my app set like so:

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Material         


        
相关标签:
4条回答
  • 2020-12-25 12:14

    Output:


    Container(
      height: 200,
      width: double.maxFinite,
      decoration: BoxDecoration(
        image: DecorationImage(
          image: ExactAssetImage("your_chocolage_image"),
          fit: BoxFit.cover,
        ),
      ),
      child: ClipRRect( // make sure we apply clip it properly
        child: BackdropFilter(
          filter: ImageFilter.blur(sigmaX: 10, sigmaY: 10),
          child: Container(
            alignment: Alignment.center,
            color: Colors.grey.withOpacity(0.1),
            child: Text(
              "CHOCOLATE",
              style: TextStyle(fontSize: 28, fontWeight: FontWeight.bold),
            ),
          ),
        ),
      ),
    )
    
    0 讨论(0)
  • 2020-12-25 12:14

    It's better if you put in ClipRRect, like this :

    Container(
        child: ClipRRect(
          child: Stack(
            children: <Widget>[
              FadeInImage.assetNetwork(
              placeholder: placeholder,
              image: thumbnail,
              fit: BoxFit.cover,
              ),
              BackdropFilter(
                child: Container(
                  color: Colors.black12,
                ),
                filter: ImageFilter.blur(sigmaY: 10, sigmaX: 10),
              )
            ],
          ),
        ),
        width: double.infinity,
      ),
    

    This case apply for Image (Thumbnail) list items correctly.

    0 讨论(0)
  • 2020-12-25 12:27

    All the above answers are correct, I'll reply to @user123456 here since I can't comment yet.

    can i make the BoxDecoration image clickeble – user123456

    Just wrap the whole Container with a GestureDetector

    GestureDetector(
        onTap: () {...},
        child: Container(
            ...
            decoration: BoxDecoration(...),
        ),           
    );
    
    0 讨论(0)
  • 2020-12-25 12:36

    You could do something like this, by blurring the container child instead.

    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return new MaterialApp(
          home: new Container(
            decoration: new BoxDecoration(
              image: new DecorationImage(
                image: new ExactAssetImage('assets/dog.png'),
                fit: BoxFit.cover,
              ),
            ),
            child: new BackdropFilter(
              filter: new ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0),
              child: new Container(
                decoration: new BoxDecoration(color: Colors.white.withOpacity(0.0)),
              ),
            ),
          ),
        );
      }
    }
    

    Screenshot

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