-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.dart
105 lines (97 loc) · 3.34 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// ignore_for_file: avoid_unnecessary_containers
import 'dart:async';
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:theta/theta.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
var responseText = 'camera response';
bool showStream = false;
StreamController controller = StreamController();
@override
Widget build(BuildContext context) {
Preview preview = Preview(controller);
return MaterialApp(
home: Scaffold(
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
Expanded(
flex: 8,
child: !showStream
? Container(
child: SingleChildScrollView(
child: Text(responseText),
),
)
: Container(
child: StreamBuilder(
stream: controller.stream,
builder:
(BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.hasData) {
var imageData =
Uint8List.fromList(snapshot.data);
return Image.memory(
imageData,
gaplessPlayback: true,
);
} else {
return Container();
}
},
),
)),
Expanded(
flex: 1,
child: Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
OutlinedButton(
onPressed: () async {
var response = await ThetaBase.get('info');
setState(() {
responseText = response;
});
},
child: const Text('info'),
),
OutlinedButton(
onPressed: () async {
var response =
await preview.getLivePreview(frames: 300);
setState(() {
showStream = true;
});
},
child: const Text('stream'),
),
OutlinedButton(
onPressed: () async {
preview.stopPreview();
setState(() {
showStream = false;
});
},
child: const Text('stop preview'),
),
],
),
),
),
],
),
),
),
);
}
}