fix(bugs): update message when in progress
This commit is contained in:
@@ -4,6 +4,7 @@ import 'dart:developer';
|
||||
|
||||
import 'package:sfm_app/feature/devices/device_model.dart';
|
||||
import 'package:sfm_app/product/base/bloc/base_bloc.dart';
|
||||
import 'package:sfm_app/product/constant/app/app_constants.dart';
|
||||
import 'package:sfm_app/product/services/api_services.dart';
|
||||
import 'package:sfm_app/product/utils/date_time_utils.dart';
|
||||
|
||||
@@ -28,6 +29,10 @@ class DeviceLogsBloc extends BlocBase {
|
||||
StreamSink<List<SensorLogs>> get sinkSensors => sensors.sink;
|
||||
Stream<List<SensorLogs>> get streamSensors => sensors.stream;
|
||||
|
||||
final message = StreamController<String>.broadcast();
|
||||
StreamSink<String> get sinkmessage => message.sink;
|
||||
Stream<String> get streammessage => message.stream;
|
||||
|
||||
@override
|
||||
void dispose() {}
|
||||
|
||||
@@ -49,11 +54,10 @@ class DeviceLogsBloc extends BlocBase {
|
||||
DateTime fromDate,
|
||||
List<SensorLogs> sensors,
|
||||
) async {
|
||||
log("SensorLength: ${sensors.length}");
|
||||
sinkmessage.add(ApplicationConstants.LOADING);
|
||||
String fromDateString =
|
||||
DateTimeUtils.instance.formatDateTimeToString(fromDate);
|
||||
String now = DateTimeUtils.instance.formatDateTimeToString(DateTime.now());
|
||||
// List<SensorLogs> sensors = [];
|
||||
Map<String, dynamic> params = {
|
||||
'thing_id': thingID,
|
||||
'from': fromDateString,
|
||||
@@ -74,8 +78,9 @@ class DeviceLogsBloc extends BlocBase {
|
||||
for (var sensor in devicesListLog.sensors!) {
|
||||
sensors.add(sensor);
|
||||
}
|
||||
} else {
|
||||
sinkmessage.add(ApplicationConstants.NO_DATA);
|
||||
}
|
||||
|
||||
sinkSensors.add(sensors);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'dart:developer';
|
||||
import 'package:dropdown_button2/dropdown_button2.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:sfm_app/product/constant/app/app_constants.dart';
|
||||
import 'widgets/tag_widget.dart';
|
||||
import '../devices/device_model.dart';
|
||||
import '../../bloc/device_logs_bloc.dart';
|
||||
@@ -116,9 +117,7 @@ class _DeviceLogsScreenState extends State<DeviceLogsScreen> {
|
||||
thingID = value!;
|
||||
setState(() {});
|
||||
},
|
||||
onSaved: (value) {
|
||||
log("On Saved");
|
||||
},
|
||||
onSaved: (value) {},
|
||||
iconStyleData: const IconStyleData(
|
||||
icon: Icon(
|
||||
Icons.arrow_drop_down,
|
||||
@@ -217,17 +216,24 @@ class _DeviceLogsScreenState extends State<DeviceLogsScreen> {
|
||||
height: context.lowValue,
|
||||
),
|
||||
Expanded(
|
||||
child: sensorsSnapshot.data?.isEmpty ?? false
|
||||
? Center(
|
||||
child: Text(appLocalization(context)
|
||||
.no_data_message),
|
||||
)
|
||||
: RefreshIndicator(
|
||||
child: (() {
|
||||
if (sensorsSnapshot.data?.isEmpty ?? false) {
|
||||
return StreamBuilder<String>(
|
||||
stream: deviceLogsBloc.streammessage,
|
||||
builder: (context, messageSnapshot) {
|
||||
return Center(
|
||||
child: Text(getMessageData(
|
||||
messageSnapshot.data ?? '',
|
||||
)),
|
||||
);
|
||||
},
|
||||
);
|
||||
} else {
|
||||
return RefreshIndicator(
|
||||
onRefresh: refresh,
|
||||
child: ListView.builder(
|
||||
controller: controller,
|
||||
itemCount:
|
||||
sensorsSnapshot.data!.length + 1,
|
||||
itemCount: sensorsSnapshot.data!.length + 1,
|
||||
itemBuilder: (context, index) {
|
||||
if (index <
|
||||
sensorsSnapshot.data!.length) {
|
||||
@@ -247,8 +253,8 @@ class _DeviceLogsScreenState extends State<DeviceLogsScreen> {
|
||||
child: hasMoreSnapshot.data ??
|
||||
hasMore
|
||||
? const CircularProgressIndicator()
|
||||
: Text(appLocalization(
|
||||
context)
|
||||
: Text(
|
||||
appLocalization(context)
|
||||
.main_no_data),
|
||||
);
|
||||
},
|
||||
@@ -257,7 +263,9 @@ class _DeviceLogsScreenState extends State<DeviceLogsScreen> {
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
})(),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -272,13 +280,22 @@ class _DeviceLogsScreenState extends State<DeviceLogsScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
String getMessageData(String data) {
|
||||
if (data == ApplicationConstants.LOADING) {
|
||||
return appLocalization(context).loading_message;
|
||||
} else if (data == ApplicationConstants.NO_DATA) {
|
||||
return appLocalization(context).main_no_data;
|
||||
} else {
|
||||
return appLocalization(context).no_data_message;
|
||||
}
|
||||
}
|
||||
|
||||
Widget logDetail(SensorLogs sensor, int index) {
|
||||
return Column(
|
||||
children: [
|
||||
ListTile(
|
||||
subtitle:
|
||||
Text(DeviceUtils.instance.getDeviceSensorsLog(context, sensor)),
|
||||
// leading: leadingList(sensor),
|
||||
title: Text(
|
||||
DateTimeUtils.instance
|
||||
.convertCurrentMillisToDateTimeString(sensor.time ?? 0),
|
||||
|
||||
Reference in New Issue
Block a user