[Flutter] Widget to image

final GlobalKey genKey = GlobalKey();

RepaintBoundary(
    key: genKey,
    child: ListTile(
        leading: CircleAvatar(),
        title: Text("www.ayavn.us"),
    ),
),


### Save image

import 'package:path_provider/path_provider.dart';

Future<void> takePicture() async {
  RenderRepaintBoundary boundary = genKey.currentContext.findRenderObject();
  ui.Image image = await boundary.toImage();
  final directory = (await getApplicationDocumentsDirectory()).path;
  ByteData byteData = await image.toByteData(format: ui.ImageByteFormat.png);
  Uint8List pngBytes = byteData.buffer.asUint8List();
  File imgFile = new File('$directory/photo.png');
  imgFile.writeAsBytes(pngBytes);
}

Bonus

Comments !

Links

Social