Update Bottom Navigator in MainScreen
This commit is contained in:
@@ -9,6 +9,8 @@ import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
import 'package:sfm_app/product/services/api_services.dart';
|
||||
import 'package:sfm_app/product/utils/device_utils.dart';
|
||||
|
||||
import '../../../product/utils/date_time_utils.dart';
|
||||
import '../../device_log/device_logs_model.dart';
|
||||
import '../device_model.dart';
|
||||
|
||||
import '../../../product/base/bloc/base_bloc.dart';
|
||||
@@ -28,6 +30,10 @@ class DetailDeviceBloc extends BlocBase {
|
||||
StreamSink<String> get sinkDeviceLocation => deviceLocation.sink;
|
||||
Stream<String> get streamDeviceLocation => deviceLocation.stream;
|
||||
|
||||
final sensorTemps = StreamController<List<SensorLogs>>.broadcast();
|
||||
StreamSink<List<SensorLogs>> get sinkSensorTemps => sensorTemps.sink;
|
||||
Stream<List<SensorLogs>> get streamSensorTemps => sensorTemps.stream;
|
||||
|
||||
@override
|
||||
void dispose() {}
|
||||
|
||||
@@ -76,4 +82,35 @@ class DetailDeviceBloc extends BlocBase {
|
||||
await DeviceUtils.instance.getFullDeviceLocation(context, areaPath);
|
||||
sinkDeviceLocation.add(fullLocation);
|
||||
}
|
||||
|
||||
void getNearerSensorValue(String thingID) async {
|
||||
List<SensorLogs> sensorTemps = [];
|
||||
DateTime twoDaysAgo = DateTime.now().subtract(const Duration(days: 2));
|
||||
String from = DateTimeUtils.instance.formatDateTimeToString(twoDaysAgo);
|
||||
String now = DateTimeUtils.instance.formatDateTimeToString(DateTime.now());
|
||||
Map<String, dynamic> params = {
|
||||
'thing_id': thingID,
|
||||
'from': from,
|
||||
'to': now,
|
||||
'limit': '500',
|
||||
};
|
||||
final body = await apiServices.getLogsOfDevice(thingID, params);
|
||||
if (body != "") {
|
||||
final data = jsonDecode(body);
|
||||
DeviceLog devicesListLog = DeviceLog.fromJson(data);
|
||||
if (devicesListLog.sensors!.isNotEmpty) {
|
||||
for (var sensor in devicesListLog.sensors!) {
|
||||
if (sensor.name == "8") {
|
||||
if (sensorTemps.length < 100) {
|
||||
sensorTemps.add(sensor);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
sensorTemps = sensorTemps.reversed.toList();
|
||||
sinkSensorTemps.add(sensorTemps);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
import 'package:sfm_app/feature/device_log/device_logs_model.dart';
|
||||
import 'package:sfm_app/product/shared/shared_line_chart.dart';
|
||||
import 'package:simple_ripple_animation/simple_ripple_animation.dart';
|
||||
import 'dart:math' as math;
|
||||
import '../device_model.dart';
|
||||
@@ -110,28 +112,37 @@ class _DetailDeviceScreenState extends State<DetailDeviceScreen> {
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 25,
|
||||
width: 25,
|
||||
child: RippleAnimation(
|
||||
color: DeviceUtils.instance
|
||||
.getColorRiple(
|
||||
deviceSnapshot.data!.state!),
|
||||
delay:
|
||||
const Duration(milliseconds: 800),
|
||||
repeat: true,
|
||||
minRadius: 40,
|
||||
ripplesCount: 6,
|
||||
duration: const Duration(
|
||||
milliseconds: 6 * 300),
|
||||
child: CircleAvatar(
|
||||
minRadius: 20,
|
||||
maxRadius: 20,
|
||||
backgroundImage: AssetImage(
|
||||
stateImgAssets(
|
||||
deviceSnapshot.data!.state!,
|
||||
),
|
||||
),
|
||||
// SizedBox(
|
||||
// height: 25,
|
||||
// width: 25,
|
||||
// child: RippleAnimation(
|
||||
// color: DeviceUtils.instance
|
||||
// .getColorRiple(
|
||||
// deviceSnapshot.data!.state!),
|
||||
// delay:
|
||||
// const Duration(milliseconds: 800),
|
||||
// repeat: true,
|
||||
// minRadius: 40,
|
||||
// ripplesCount: 6,
|
||||
// duration: const Duration(
|
||||
// milliseconds: 6 * 300),
|
||||
// child: CircleAvatar(
|
||||
// minRadius: 20,
|
||||
// maxRadius: 20,
|
||||
// backgroundImage: AssetImage(
|
||||
// stateImgAssets(
|
||||
// deviceSnapshot.data!.state!,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
CircleAvatar(
|
||||
minRadius: 20,
|
||||
maxRadius: 20,
|
||||
backgroundImage: AssetImage(
|
||||
stateImgAssets(
|
||||
deviceSnapshot.data!.state!,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -182,6 +193,33 @@ class _DetailDeviceScreenState extends State<DetailDeviceScreen> {
|
||||
),
|
||||
],
|
||||
),
|
||||
StreamBuilder<List<SensorLogs>>(
|
||||
stream: detailDeviceBloc.streamSensorTemps,
|
||||
builder: (context, sensorTempsSnapshot) {
|
||||
if (sensorTempsSnapshot.data == null) {
|
||||
detailDeviceBloc
|
||||
.getNearerSensorValue(widget.thingID);
|
||||
return const AspectRatio(
|
||||
aspectRatio: 1.5,
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return AspectRatio(
|
||||
aspectRatio: 1.5,
|
||||
child: Container(
|
||||
margin: context.paddingLow,
|
||||
child: sharedLineChart(
|
||||
"Nhiệt độ đo được (°C)",
|
||||
sensorTempsSnapshot.data ?? [],
|
||||
60,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Card(
|
||||
|
||||
Reference in New Issue
Block a user