A simple package who convert widgets to image types;
Types Supported:
- Uint8List
- ByteData
- Image
- Dart:ui Image
- Add this to your package's
pubspec.yamlfile:
dependencies:
widget_to_image: any- Get the package using your IDE's GUI or via command line with
$ pub get- Import the
widgets_to_image.dartfile in your app
import 'package:convert_widget_to_image/widget_to_image.dart';- First wrap you widget in a
RepaintBoundary()and give him aGobalKey()
RepaintBoundary(
key: key,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12))),
onPressed: () {},
child: Text('Simple Button'),
),
)- Then pass the key to the WidgetToImage selecting the constructor of type that you want
final dartUiImage = await WidgetToImage.asDartUiImage(key);
final byte = await WidgetToImage.asByteData(key);
final uint = await WidgetToImage.asUint8List(key);
final image = await WidgetToImage.asImage(key);Feel free to do pull requests or ask for changes on issues(on gitHub). There is a simple example on the github.