简体   繁体   中英

Flutter : Imageblur filter is filling the whole parent widget . I tried using positioned widget and container with custom heights.But not working

I've used a network image and I want to blur the a small section of the image for the Image Captions. But Backdropfilter and imagefilter.blur is filling the whole image.

 Container(
        height: 400,
        width: 350,
        child: ClipRRect(
          borderRadius: BorderRadius.circular(25),
          child: Stack(
            children: [
              Image.network(
                "https://www.newsbtc.com/wp-content/uploads/2020/12/shutterstock_104159111.jpg",
                fit: BoxFit.cover,
                height: 400,
                width: 350,
              ),
              Positioned(
                top: 100,
                child: BackdropFilter(
                  filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
                  child: Container(
                    height: 200,
                    color: Colors.transparent,
                    child: Text(
                      "Data",
                      style: TextStyle(fontSize: 30),
                    ),
                  ),
                ),
              )
            ],
          ),
        ),
      ),

Current Output

在此处输入图像描述

Required Output

在此处输入图像描述

You can copy paste run full code below
You can use ClipRect

Positioned(
        bottom: 0,
        child: ClipRect(
          child: BackdropFilter(

working demo

在此处输入图像描述

full code

import 'package:flutter/material.dart';
import 'dart:ui';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {  
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(       
        primarySwatch: Colors.blue,        
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  
  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {     
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {    
    return Scaffold(
      appBar: AppBar(        
        title: Text(widget.title),
      ),
      body: Container(
        height: 400,
        width: 350,
        child: ClipRRect(
          borderRadius: BorderRadius.circular(25),
          child: Stack(
            children: [
              Image.network(
                "https://www.newsbtc.com/wp-content/uploads/2020/12/shutterstock_104159111.jpg",
                fit: BoxFit.cover,
                height: 400,
                width: 350,
              ),
              Positioned(
                bottom: 0,
                child: ClipRect(
                  child: BackdropFilter(
                    filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
                    child: Container(
                      height: 200,
                      width: MediaQuery.of(context).size.width,
                      color: Colors.transparent,
                      child: Text(
                        "Data",
                        style: TextStyle(fontSize: 30),
                      ),
                    ),
                  ),
                ),
              )
            ],
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), 
    );
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM