Flutter widgets

111 阅读1分钟

1. RepaintBoundary

用于获取组件截图

 RepaintBoundary(
              key: key,
              child: Container(
                child: Stack(
                  children: <Widget>[
                    Positioned(
                      child: ClipOval(
                        child: Image.network(
                          "http://pic13.nipic.com/20110409/7119492_114440620000_2.jpg",
                          width: 300.0,
                          height: 300.0,
                          fit: BoxFit.fill,
                        ),
                      ),
                      left: 10.0,
                    ),
                  ],
                ),
              ),
            ),
            

获取widget截图

RenderRepaintBoundary boundary = key.currentContext.findRenderObject();
        ui.Image image = await boundary.toImage(pixelRatio: 1.5);
        ByteData data = await image.toByteData(
          format: ui.ImageByteFormat.png,
        );
        images = data.buffer.asUint8List();

2. BackdropFilter

Stack(
  fit: StackFit.expand,
  children: <Widget>[
    Text('0' * 10000),
    Center(
      child: ClipRect(  // <-- clips to the 200x200 [Container] below
        child: BackdropFilter(
          filter: ui.ImageFilter.blur(
            sigmaX: 5.0,
            sigmaY: 5.0,
          ),
          child: Container(
            alignment: Alignment.center,
            width: 200.0,
            height: 200.0,
            child: Text('Hello World'),
          ),
        ),
      ),
    ),
  ],
)