widget_to_image 2.0.0 copy "widget_to_image: ^2.0.0" to clipboard
widget_to_image: ^2.0.0 copied to clipboard

A simple package to convert any of your widgets into an image.

example/lib/main.dart

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

import 'package:widget_to_image/widget_to_image.dart';

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

class MyApp extends StatelessWidget {
	@override
	Widget build(BuildContext context) {
		return MaterialApp(
			title: 'Widget To Image',
			home: MyHomePage(),
		);
	}
}

class MyHomePage extends StatefulWidget {
	const MyHomePage({
		Key? key
	}) : super(key: key);

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

class MyHomePageState extends State<MyHomePage> {
	ByteData? _byteData;
	GlobalKey _globalKey = GlobalKey();

	@override
	void initState() {
		super.initState();
	}

	@override
	void dispose() {
		super.dispose();
	}

	@override
	Widget build(BuildContext context) {
		return  RepaintBoundary(
			key: _globalKey,
			child: Scaffold(
				body: Center(
					child: Column(
						mainAxisAlignment: MainAxisAlignment.center,
						children: [
							ElevatedButton(
								onPressed: _callRepaintBoundaryToImage,
								child: Text('Repaint Boundary To Image'),
							),
							ElevatedButton(
								onPressed: _callWidgetToImage,
								child: Text('Widget To Image'),
							),
							_byteData != null ? Container(
								height: 200,
								decoration: BoxDecoration(
									border: Border.all(color: Colors.black)
								),
								child: Image.memory(
									_byteData!.buffer.asUint8List()
								),
							) : Container()
						],
					),
				)
			),
		);
	}

	_callRepaintBoundaryToImage() async {
		ByteData byteData = await WidgetToImage.repaintBoundaryToImage(this._globalKey);
		setState(() => _byteData = byteData);
	}

	_callWidgetToImage() async {
		ByteData byteData = await WidgetToImage.widgetToImage(Container(
			width: 100,
			height: 100,
			color: Colors.blue,
		));
		setState(() => _byteData = byteData);
	}
}
34
likes
80
pub points
86%
popularity

Publisher

verified publishernicolas-bruckert.com

A simple package to convert any of your widgets into an image.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on widget_to_image