/
main.dart
338 lines (328 loc) · 12.6 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
import 'dart:async';
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:smartterrarium/controller_page.dart';
import 'package:page_transition/page_transition.dart';
import 'package:smartterrarium/graph.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'smart-terrarium',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'smart-terrarium'),
debugShowCheckedModeBanner: false,
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
late Future<RecoardResults> res;
@override
void initState() {
super.initState();
res = getRecord();
print(res);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('smart-terrarium'),
backgroundColor: Colors.lime,
),
body: Center(
child:Container(
child: Stack(
alignment: AlignmentDirectional.center,
children: <Widget>[
Container(
alignment: Alignment.center,
width: 500,
height: 500,
child: Stack(
alignment: AlignmentDirectional.center,
children: <Widget>[
Container(
alignment: Alignment.bottomCenter,
width: 160,
height: 500,
child: Container(
width: 160,
height: 40,
child: OutlinedButton(
child: const Text('これまでの記録'),
style: OutlinedButton.styleFrom(
foregroundColor: Colors.black,
shape: const StadiumBorder(),
side: const BorderSide(color: Colors.green),
),
onPressed: () {
Navigator.push(
context,
PageTransition(
child: GraphPage(), //画面遷移先
type: PageTransitionType.topToBottom, //アニメー
duration: const Duration(milliseconds: 300),// ションの種類
),
);
},
),
),
),
Container(
alignment: Alignment.topCenter,
width: 160,
height: 500,
child: Container(
width: 160,
height: 40,
child: OutlinedButton(
child: const Text('温度設定'),
style: OutlinedButton.styleFrom(
foregroundColor: Colors.black,
shape: const StadiumBorder(),
side: const BorderSide(color: Colors.green),
),
onPressed: () {
Navigator.push(
context,
PageTransition(
child: ControllerPage(), //画面遷移先
type: PageTransitionType.bottomToTop, //アニメーションの種類
duration: const Duration(milliseconds: 300),
),
);
},
),
),
),
Container(
alignment: Alignment.centerRight,
width: 500,
height: 100,
),
Container(
alignment: Alignment.centerLeft,
width: 500,
height: 100,
),
// Container(
// width: 500,
// height: 500,
// child: FutureBuilder<ApiResults>(
// future: res,
// builder: (context, snapshot) {
// if (snapshot.hasData) {
// return Text(
// snapshot.data!.message.toString()
// );
// } else if (snapshot.hasError) {
// return Text("${snapshot.error}");
// }
// return CircularProgressIndicator();
// },
// ),
// ),
],
),
),//大外の黄緑のボックス
Container(
alignment: Alignment.center,
width: 300,
height: 300,
decoration: BoxDecoration(
color: Colors.lime,
borderRadius: BorderRadius.circular(10),
boxShadow: [
BoxShadow(
offset: Offset(10, 10),
color: Theme.of(context).scaffoldBackgroundColor,
blurRadius: 20,
),
BoxShadow(
offset: Offset(-10, -10),
color: Theme.of(context).scaffoldBackgroundColor,
blurRadius: 20,
),
],
),
child: Stack(
children: <Widget>[
Container(
alignment: Alignment.center,
height: 100,
width: 120,
child: Container(
alignment: Alignment.center,
height: 50,
width: 200,
decoration: const BoxDecoration(
color: Colors.white,
border: Border(),
borderRadius: BorderRadius.only(
topRight: Radius.circular(50),
bottomRight: Radius.circular(50),
),
),
child: const Text(
'現在温度',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
),
),//現在温度
Container(
alignment: Alignment.centerRight,
height: 200,
width: 300,
child: Container(
alignment: Alignment.center,
height: 80,
width: 180,
decoration: const BoxDecoration(
color: Colors.white,
border: Border(),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(50),
bottomLeft: Radius.circular(50),
),
),
child: FutureBuilder<RecoardResults>(
future: res,
builder: (context, snapshot) {
if (snapshot.hasData) {
return Text(
"${snapshot.data!.temperature.toStringAsFixed(1)}°C",
style: const TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
color: Colors.black,
),
);
} else if (snapshot.hasError) {
return Text("${snapshot.error}");
}
return CircularProgressIndicator();
},
),
),
),//現在温度値
Container(
alignment: Alignment.bottomRight,
height: 260,
width: 300,
child: Container(
alignment: Alignment.center,
height: 80,
width: 180,
decoration: const BoxDecoration(
color: Colors.white,
border: Border(),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(50),
bottomLeft: Radius.circular(50),
),
),
child: FutureBuilder<RecoardResults>(
future: res,
builder: (context, snapshot) {
if (snapshot.hasData) {
return Text(
"${snapshot.data!.humidity.toStringAsFixed(1)}%",
style: const TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
color: Colors.black,
),
);
} else if (snapshot.hasError) {
return Text("${snapshot.error}");
}
return CircularProgressIndicator();
},
),
),
),//現在湿度値
Container(
alignment: Alignment.bottomLeft,
height: 200,
width: 120,
child: Container(
alignment: Alignment.center,
height: 50,
width: 200,
decoration: const BoxDecoration(
color: Colors.white,
border: Border(),
borderRadius: BorderRadius.only(
topRight: Radius.circular(50),
bottomRight: Radius.circular(50),
),
),
child: const Text(
'現在湿度',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
),
),//現在湿度
],
),//真ん中の黄緑のボックス
),//内側の緑色のボックス
],
),
),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
class RecoardResults {
final String timestamp;
final double temperature;
final double humidity;
final int heat_flag;
RecoardResults({
required this.timestamp,
required this.temperature,
required this.humidity,
required this.heat_flag,
});
factory RecoardResults.fromJson(Map<String, dynamic> json) {
return RecoardResults(
timestamp: json['timestamp'],
temperature: json['temperature'],
humidity: json['humidity'],
heat_flag: json['heat_flag'],
);
}
}
Future<RecoardResults> getRecord() async {
var url = "http://192.168.11.26:8000/get_record/";
final response = await http.get(Uri.parse(url));
print("****" + response.body);
if (response.statusCode == 200) {
return RecoardResults.fromJson(json.decode(response.body));
} else {
throw Exception('Failed');
}
}