-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.dart
77 lines (70 loc) · 1.95 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import 'dart:typed_data';
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:screenshotx_linux/screenshotx_linux.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final _screenshotxLinuxPlugin = ScreenshotXLinux();
Uint8List? imageBytes;
Color? pickedColor;
@override
void initState() {
super.initState();
}
@override
void dispose() {
_screenshotxLinuxPlugin.close();
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
floatingActionButton: Row(
children: [
FloatingActionButton(
onPressed: () async {
var color = await _screenshotxLinuxPlugin.pickColor();
if (color != null) {
pickedColor = color;
}
setState(() {});
},
child: const Icon(Icons.camera),
),
FloatingActionButton(
onPressed: () async {
var image = await _screenshotxLinuxPlugin.captureFullScreen();
if (image != null) {
final pngBytes =
await image.toByteData(format: ImageByteFormat.png);
imageBytes = Uint8List.view(pngBytes!.buffer);
}
setState(() {});
},
child: const Icon(Icons.camera),
),
],
),
body: ColoredBox(
color: pickedColor ?? Colors.white,
child: Center(
child: imageBytes != null
? Image.memory(imageBytes!)
: const Text("No Screenshot Taken"),
),
),
),
);
}
}