배터리, 습도, 온도, 전압 데이터 출력
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_map/flutter_map.dart';
|
import 'package:flutter_map/flutter_map.dart';
|
||||||
import 'package:latlong2/latlong.dart';
|
import 'package:latlong2/latlong.dart';
|
||||||
@@ -44,13 +46,14 @@ class _HomeScreenContentState extends State<HomeScreenContent> {
|
|||||||
}
|
}
|
||||||
// 25.12.03 지은 추가 끝
|
// 25.12.03 지은 추가 끝
|
||||||
|
|
||||||
void test() async {
|
Future<Map<String, dynamic>?> test() async {
|
||||||
final data = await _api.getTimeseries(target: "*", limit: 200);
|
final data = await _api.getTimeseries(target: "*", limit: 200);
|
||||||
|
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
print("받은 데이터 길이: ${data['samples'].length}");
|
print("받은 데이터 길이: ${data['samples'].length}");
|
||||||
print(data['samples'][0]); // 첫 번째 데이터 출력
|
print(data['samples'][0]); // 첫 번째 데이터 출력
|
||||||
}
|
}
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _selectedImageIndex = 0;
|
int _selectedImageIndex = 0;
|
||||||
@@ -69,9 +72,48 @@ class _HomeScreenContentState extends State<HomeScreenContent> {
|
|||||||
'FAN': false,
|
'FAN': false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
double? _battPct;
|
||||||
|
double? _volt;
|
||||||
|
double? _temp;
|
||||||
|
double? _humi;
|
||||||
|
Timer? _timer;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_loadBattPct();
|
||||||
|
_timer = Timer.periodic(const Duration(seconds: 2), (_) => _loadBattPct());
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_timer?.cancel();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _loadBattPct() async {
|
||||||
|
final data = await test(); // Future → Map으로 resolve
|
||||||
|
|
||||||
|
if (data == null) return;
|
||||||
|
|
||||||
|
// samples[0]에서 batt_pct 값 읽기
|
||||||
|
final battPct = data['samples'][0]['batt_pct'];
|
||||||
|
final volt = data['samples'][0]['pv_volt'];
|
||||||
|
final temp = data['samples'][0]['temp'];
|
||||||
|
final humi = data['samples'][0]['humi'];
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
// 숫자/문자 둘 다 안전하게 처리
|
||||||
|
_battPct = battPct.toDouble();
|
||||||
|
_volt = volt.toDouble();
|
||||||
|
_temp = temp.toDouble();
|
||||||
|
_humi = humi.toDouble();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
test();
|
|
||||||
return Container(
|
return Container(
|
||||||
color: _pageBackgroundColor,
|
color: _pageBackgroundColor,
|
||||||
child: Column(
|
child: Column(
|
||||||
@@ -283,11 +325,20 @@ class _HomeScreenContentState extends State<HomeScreenContent> {
|
|||||||
painter: _BatteryArcPainter(
|
painter: _BatteryArcPainter(
|
||||||
backgroundColor: _accentContainerColor,
|
backgroundColor: _accentContainerColor,
|
||||||
color: _mainBlueColor,
|
color: _mainBlueColor,
|
||||||
percentage: 1.0,
|
percentage: _battPct!.floor()/100 ,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Text('86', style: TextStyle(fontSize: 24, fontWeight: FontWeight.w600, color: _mainTextColor)),
|
Text(
|
||||||
|
_battPct == null
|
||||||
|
? '--' // 아직 로딩 전
|
||||||
|
: _battPct!.floor().toString(),
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 24,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: _mainTextColor,
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -513,9 +564,21 @@ class _HomeScreenContentState extends State<HomeScreenContent> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
_buildSensorInfoRow(Icons.water_drop_outlined, '습도: 60%', '습도'),
|
_buildSensorInfoRow(
|
||||||
|
Icons.water_drop_outlined,
|
||||||
|
_humi == null
|
||||||
|
? '--' // 아직 로딩 전
|
||||||
|
: '습도: '+_humi!.floor().toString()+'%',
|
||||||
|
'습도'
|
||||||
|
),
|
||||||
const SizedBox(height: 24),
|
const SizedBox(height: 24),
|
||||||
_buildSensorInfoRow(Icons.thermostat, '온도: 24.5℃', '온도'),
|
_buildSensorInfoRow(
|
||||||
|
Icons.thermostat,
|
||||||
|
_temp == null
|
||||||
|
? '--' // 아직 로딩 전
|
||||||
|
: '온도: '+_temp!.floor().toString()+'℃',
|
||||||
|
'온도'
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user