flame_component_screenshot 1.0.2
flame_component_screenshot: ^1.0.2 copied to clipboard
A utility to render and capture Flame components as images or PNG files for use in Flutter apps or local storage.
example/lib/main.dart
import 'package:flame_component_screenshot/flame_component_screenshot.dart';
import 'package:flutter/material.dart';
import 'package:flame/components.dart';
import 'dart:ui' as ui;
void main() {
runApp(const MaterialApp(home: ScreenshotExample()));
}
class ScreenshotExample extends StatelessWidget {
const ScreenshotExample({super.key});
Future<Image> generateImage() async {
final component = TextComponent(
text: 'Certificate of Achievement',
textRenderer: TextPaint(style: const TextStyle(fontSize: 24, color: Colors.black)),
);
return await FlameComponentScreenshot.captureToMemoryImage(
component: component,
size: component.size,
pixelRatio: 3
);
}
Future<ui.Image> capturedImage() async {
final component = TextComponent(
text: 'Certificate of Achievement',
textRenderer: TextPaint(style: const TextStyle(fontSize: 10, color: Colors.black)),
);
return await FlameComponentScreenshot.renderToImage(
component: component,
size: component.size,
pixelRatio: 40
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Flame Capture Example')),
body: Center(
child: Container(
height: 50,
width: 100,
color: Colors.green,
child: FutureBuilder<Image>(
future: generateImage(),
builder: (context, snapshot) {
if (!snapshot.hasData) return const CircularProgressIndicator(color: Colors.red,);
return snapshot.data!;
},
),
),
),
);
}
}