Make BoxDecoration image faded/transparent

前端 未结 4 1316
无人共我
无人共我 2020-12-24 01:40

I have the following snippet of code and I would like to make the image faded such that it does not interfere with other items in the container. Is there a filter that could

4条回答
  •  甜味超标
    2020-12-24 01:48

    You could give your DecorationImage a ColorFilter to make the background image grey (use a saturation color filter) or semi transparent (use a dstATop color filter).

    Code for this example is below.

    import 'package:flutter/material.dart';
    
    void main() {
      runApp(new MyApp());
    }
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return new MaterialApp(
          home: new HomePage(),
        );
      }
    }
    
    class HomePage extends StatelessWidget {
      @override
      Widget build(BuildContext context) => new Scaffold(
        appBar: new AppBar(
          title: new Text('Grey Example'),
        ),
        body: new Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            new Card(
              child: new Container(
                child: new Text(
                  'Hello world',
                  style: Theme.of(context).textTheme.display4
                ),
                decoration: new BoxDecoration(
                  color: const Color(0xff7c94b6),
                  image: new DecorationImage(
                    fit: BoxFit.cover,
                    colorFilter: new ColorFilter.mode(Colors.black.withOpacity(0.2), BlendMode.dstATop),
                    image: new NetworkImage(
                      'http://www.allwhitebackground.com/images/2/2582-190x190.jpg',
                    ),
                  ),
                ),
              ),
            ),
          ],
        ),
      );
    }
    

    The Opacity widget is another option.

    You could also pre apply the effect to the asset.

提交回复
热议问题