Размытое изображение с текстом, наложенным на флаттер - PullRequest
0 голосов
/ 10 октября 2019

Мне нужно размыть изображения на заднем плане и сделать наложение четким, но по какой-то причине текст также размыт, и, поскольку у меня есть GridView в двух столбцах, последнее изображение во втором столбце будетправильно, с понятным текстом, но все остальное неверно.

Expanded(
              child: SmartRefresher(
                  enablePullDown: true,
                  header: WaterDropHeader(),
                  controller: _refreshController,
                  onRefresh: _refreshNews,
                  child: GridView.count(
                    crossAxisCount: 2,
                    childAspectRatio: 1.5,
                    crossAxisSpacing: 1.5,
                    mainAxisSpacing: 1,
                    padding:
                    EdgeInsets.only(left: 1, top: 0, right: 1, bottom: 60),
                    children: List.generate(
                        items.length,
                            (index) =>
                            Stack(
                              children: [
                                ClipRRect(
                                  child:
                                  Image.network(items[index].get_photoUrl),
                                  borderRadius: BorderRadius.circular(30),
                                ),
                                BackdropFilter(
                                  filter: prefix0.ImageFilter.blur(
                                    sigmaY: 1,
                                    sigmaX: 1,
                                  ),
                                  child: Container(
                                      color: Colors.black.withOpacity(0)),
                                ),
                                Center(
                                  child: Text(
                                    items[index].get_title,
                                    style: prefix1.TextStyle(
                                        fontSize: 12, color: Colors.white),
                                  ),
                                )
                              ],
                            )
                    ),
                  )))

Ответы [ 2 ]

1 голос
/ 10 октября 2019

Результат:

Expanded(
              child: SmartRefresher(
                  enablePullDown: true,
                  header: WaterDropHeader(),
                  controller: _refreshController,
                  onRefresh: _refreshNews,
                  child: GridView.count(
                    crossAxisCount: 2,
                    childAspectRatio: 1.5,
                    crossAxisSpacing: 1.5,
                    mainAxisSpacing: 1,
                    padding:
                        EdgeInsets.only(left: 1, top: 0, right: 1, bottom: 60),
                    children: List.generate(
                      items.length,
                      (index) => Stack(
                        children: <Widget>[
                          ClipRRect(
                            child: Container(
                              decoration: BoxDecoration(
                                image: DecorationImage(
                                  image:
                                      NetworkImage(items[index].get_photoUrl),
                                ),
                              ),
                              child: new BackdropFilter(
                                filter: new ImageFilter.blur(
                                    sigmaX: 1.5, sigmaY: 1.5),
                                child: Container(
                                    color: Colors.white.withOpacity(0.0)),
                              ),
                            ),
                            borderRadius: BorderRadius.circular(30),
                          ),
                          Center(child: Text(items[index].get_title))
                        ],
                      ),
                    ),
                  )))
1 голос
/ 10 октября 2019
1.you can use Stack to show picture and text in the same container.

  e.g ->   new BackdropFilter(
            filter: new ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0),
            child: new Container(
              decoration: new BoxDecoration(color:          
          Colors.white.withOpacity(0.0)),
            ),
          )

Full example ->

Widget build(BuildContext context) {
return MaterialApp(
  home: Scaffold(
    body: Stack(
      children: <Widget>[
        new Container(
          decoration: new BoxDecoration(
            image: new DecorationImage(
              image: new ExactAssetImage('assets/dog.png'), 
                        // NetworkImage("url")
              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)),
            ),
          ),
        ),
        Text("hello flutter ")
      ],
     ),
    ),
  );
 }

попробуйте

  Happy Coding :))
...