mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-11 07:38:05 +00:00
Compare commits
32 Commits
upgrade-fl
...
hide_aqi_o
Author | SHA1 | Date | |
---|---|---|---|
921da20d3f | |||
4d9145a953 | |||
a2f897c3a6 | |||
249c2fb172 | |||
7a8537d39c | |||
1da0cdad4b | |||
d10df2ffb8 | |||
6ff9c602f1 | |||
5f20d52e57 | |||
362557d0d0 | |||
312d185932 | |||
89e12e47da | |||
a0d9819532 | |||
1316820954 | |||
5591c78d88 | |||
eaff7c4a52 | |||
5b3152e833 | |||
c1d3296b59 | |||
b3069ab749 | |||
37b21ecdfb | |||
8d408867bb | |||
57508fe17e | |||
13360fe6f3 | |||
3e5b501167 | |||
4d9f08af31 | |||
28aa3bc406 | |||
51ad74b2be | |||
994e9f4e57 | |||
c642ba2644 | |||
218f43bacb | |||
04250ebc98 | |||
29959f567e |
@ -25,3 +25,8 @@ linter:
|
|||||||
prefer_int_literals: false
|
prefer_int_literals: false
|
||||||
sort_constructors_first: false
|
sort_constructors_first: false
|
||||||
avoid_redundant_argument_values: false
|
avoid_redundant_argument_values: false
|
||||||
|
always_put_required_named_parameters_first: false
|
||||||
|
unnecessary_breaks: false
|
||||||
|
avoid_catches_without_on_clauses: false
|
||||||
|
cascade_invocations: false
|
||||||
|
overridden_fields: false
|
||||||
|
@ -15,7 +15,9 @@ class AirQualityDataModel extends Equatable {
|
|||||||
return AirQualityDataModel(
|
return AirQualityDataModel(
|
||||||
date: DateTime.parse(json['date'] as String),
|
date: DateTime.parse(json['date'] as String),
|
||||||
data: (json['data'] as List<dynamic>)
|
data: (json['data'] as List<dynamic>)
|
||||||
.map((e) => AirQualityPercentageData.fromJson(e as Map<String, dynamic>))
|
.map(
|
||||||
|
(e) => AirQualityPercentageData.fromJson(e as Map<String, dynamic>),
|
||||||
|
)
|
||||||
.toList(),
|
.toList(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -23,9 +25,9 @@ class AirQualityDataModel extends Equatable {
|
|||||||
static final Map<String, Color> metricColors = {
|
static final Map<String, Color> metricColors = {
|
||||||
'good': ColorsManager.goodGreen.withValues(alpha: 0.7),
|
'good': ColorsManager.goodGreen.withValues(alpha: 0.7),
|
||||||
'moderate': ColorsManager.moderateYellow.withValues(alpha: 0.7),
|
'moderate': ColorsManager.moderateYellow.withValues(alpha: 0.7),
|
||||||
'poor': ColorsManager.poorOrange.withValues(alpha: 0.7),
|
'unhealthy_sensitive': ColorsManager.poorOrange.withValues(alpha: 0.7),
|
||||||
'unhealthy': ColorsManager.unhealthyRed.withValues(alpha: 0.7),
|
'unhealthy': ColorsManager.unhealthyRed.withValues(alpha: 0.7),
|
||||||
'severe': ColorsManager.severePink.withValues(alpha: 0.7),
|
'very_unhealthy': ColorsManager.severePink.withValues(alpha: 0.7),
|
||||||
'hazardous': ColorsManager.hazardousPurple.withValues(alpha: 0.7),
|
'hazardous': ColorsManager.hazardousPurple.withValues(alpha: 0.7),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -36,22 +38,19 @@ class AirQualityDataModel extends Equatable {
|
|||||||
class AirQualityPercentageData extends Equatable {
|
class AirQualityPercentageData extends Equatable {
|
||||||
const AirQualityPercentageData({
|
const AirQualityPercentageData({
|
||||||
required this.type,
|
required this.type,
|
||||||
required this.name,
|
|
||||||
required this.percentage,
|
required this.percentage,
|
||||||
});
|
});
|
||||||
|
|
||||||
final String type;
|
final String type;
|
||||||
final String name;
|
|
||||||
final double percentage;
|
final double percentage;
|
||||||
|
|
||||||
factory AirQualityPercentageData.fromJson(Map<String, dynamic> json) {
|
factory AirQualityPercentageData.fromJson(Map<String, dynamic> json) {
|
||||||
return AirQualityPercentageData(
|
return AirQualityPercentageData(
|
||||||
type: json['type'] as String? ?? '',
|
type: json['type'] as String? ?? '',
|
||||||
name: json['name'] as String? ?? '',
|
|
||||||
percentage: (json['percentage'] as num?)?.toDouble() ?? 0,
|
percentage: (json['percentage'] as num?)?.toDouble() ?? 0,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [type, name, percentage];
|
List<Object?> get props => [type, percentage];
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,6 @@ class AirQualityDistributionBloc
|
|||||||
state.copyWith(
|
state.copyWith(
|
||||||
status: AirQualityDistributionStatus.success,
|
status: AirQualityDistributionStatus.success,
|
||||||
chartData: result,
|
chartData: result,
|
||||||
filteredChartData: _arrangeChartDataByType(result, state.selectedAqiType),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -58,24 +57,6 @@ class AirQualityDistributionBloc
|
|||||||
UpdateAqiTypeEvent event,
|
UpdateAqiTypeEvent event,
|
||||||
Emitter<AirQualityDistributionState> emit,
|
Emitter<AirQualityDistributionState> emit,
|
||||||
) {
|
) {
|
||||||
emit(
|
emit(state.copyWith(selectedAqiType: event.aqiType));
|
||||||
state.copyWith(
|
|
||||||
selectedAqiType: event.aqiType,
|
|
||||||
filteredChartData: _arrangeChartDataByType(state.chartData, event.aqiType),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<AirQualityDataModel> _arrangeChartDataByType(
|
|
||||||
List<AirQualityDataModel> data,
|
|
||||||
AqiType aqiType,
|
|
||||||
) {
|
|
||||||
final filteredData = data.map(
|
|
||||||
(data) => AirQualityDataModel(
|
|
||||||
date: data.date,
|
|
||||||
data: data.data.where((value) => value.type == aqiType.code).toList(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
return filteredData.toList();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,28 +11,24 @@ class AirQualityDistributionState extends Equatable {
|
|||||||
const AirQualityDistributionState({
|
const AirQualityDistributionState({
|
||||||
this.status = AirQualityDistributionStatus.initial,
|
this.status = AirQualityDistributionStatus.initial,
|
||||||
this.chartData = const [],
|
this.chartData = const [],
|
||||||
this.filteredChartData = const [],
|
|
||||||
this.errorMessage,
|
this.errorMessage,
|
||||||
this.selectedAqiType = AqiType.aqi,
|
this.selectedAqiType = AqiType.aqi,
|
||||||
});
|
});
|
||||||
|
|
||||||
final AirQualityDistributionStatus status;
|
final AirQualityDistributionStatus status;
|
||||||
final List<AirQualityDataModel> chartData;
|
final List<AirQualityDataModel> chartData;
|
||||||
final List<AirQualityDataModel> filteredChartData;
|
|
||||||
final String? errorMessage;
|
final String? errorMessage;
|
||||||
final AqiType selectedAqiType;
|
final AqiType selectedAqiType;
|
||||||
|
|
||||||
AirQualityDistributionState copyWith({
|
AirQualityDistributionState copyWith({
|
||||||
AirQualityDistributionStatus? status,
|
AirQualityDistributionStatus? status,
|
||||||
List<AirQualityDataModel>? chartData,
|
List<AirQualityDataModel>? chartData,
|
||||||
List<AirQualityDataModel>? filteredChartData,
|
|
||||||
String? errorMessage,
|
String? errorMessage,
|
||||||
AqiType? selectedAqiType,
|
AqiType? selectedAqiType,
|
||||||
}) {
|
}) {
|
||||||
return AirQualityDistributionState(
|
return AirQualityDistributionState(
|
||||||
status: status ?? this.status,
|
status: status ?? this.status,
|
||||||
chartData: chartData ?? this.chartData,
|
chartData: chartData ?? this.chartData,
|
||||||
filteredChartData: filteredChartData ?? this.filteredChartData,
|
|
||||||
errorMessage: errorMessage ?? this.errorMessage,
|
errorMessage: errorMessage ?? this.errorMessage,
|
||||||
selectedAqiType: selectedAqiType ?? this.selectedAqiType,
|
selectedAqiType: selectedAqiType ?? this.selectedAqiType,
|
||||||
);
|
);
|
||||||
|
@ -3,6 +3,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
|||||||
import 'package:syncrow_web/pages/analytics/modules/air_quality/blocs/air_quality_distribution/air_quality_distribution_bloc.dart';
|
import 'package:syncrow_web/pages/analytics/modules/air_quality/blocs/air_quality_distribution/air_quality_distribution_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/modules/air_quality/blocs/device_location/device_location_bloc.dart';
|
import 'package:syncrow_web/pages/analytics/modules/air_quality/blocs/device_location/device_location_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/modules/air_quality/blocs/range_of_aqi/range_of_aqi_bloc.dart';
|
import 'package:syncrow_web/pages/analytics/modules/air_quality/blocs/range_of_aqi/range_of_aqi_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/analytics/modules/air_quality/widgets/aqi_type_dropdown.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/modules/analytics/blocs/analytics_date_picker_bloc/analytics_date_picker_bloc.dart';
|
import 'package:syncrow_web/pages/analytics/modules/analytics/blocs/analytics_date_picker_bloc/analytics_date_picker_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/modules/analytics/blocs/analytics_devices/analytics_devices_bloc.dart';
|
import 'package:syncrow_web/pages/analytics/modules/analytics/blocs/analytics_devices/analytics_devices_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/modules/energy_management/blocs/realtime_device_changes/realtime_device_changes_bloc.dart';
|
import 'package:syncrow_web/pages/analytics/modules/energy_management/blocs/realtime_device_changes/realtime_device_changes_bloc.dart';
|
||||||
@ -22,6 +23,7 @@ abstract final class FetchAirQualityDataHelper {
|
|||||||
bool shouldFetchAnalyticsDevices = true,
|
bool shouldFetchAnalyticsDevices = true,
|
||||||
}) {
|
}) {
|
||||||
final date = context.read<AnalyticsDatePickerBloc>().state.monthlyDate;
|
final date = context.read<AnalyticsDatePickerBloc>().state.monthlyDate;
|
||||||
|
final aqiType = context.read<AirQualityDistributionBloc>().state.selectedAqiType;
|
||||||
loadAnalyticsDevices(
|
loadAnalyticsDevices(
|
||||||
context,
|
context,
|
||||||
communityUuid: communityUuid,
|
communityUuid: communityUuid,
|
||||||
@ -36,6 +38,7 @@ abstract final class FetchAirQualityDataHelper {
|
|||||||
context,
|
context,
|
||||||
spaceUuid: spaceUuid,
|
spaceUuid: spaceUuid,
|
||||||
date: date,
|
date: date,
|
||||||
|
aqiType: aqiType,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,10 +107,15 @@ abstract final class FetchAirQualityDataHelper {
|
|||||||
BuildContext context, {
|
BuildContext context, {
|
||||||
required String spaceUuid,
|
required String spaceUuid,
|
||||||
required DateTime date,
|
required DateTime date,
|
||||||
|
required AqiType aqiType,
|
||||||
}) {
|
}) {
|
||||||
context.read<AirQualityDistributionBloc>().add(
|
context.read<AirQualityDistributionBloc>().add(
|
||||||
LoadAirQualityDistribution(
|
LoadAirQualityDistribution(
|
||||||
GetAirQualityDistributionParam(spaceUuid: spaceUuid, date: date),
|
GetAirQualityDistributionParam(
|
||||||
|
spaceUuid: spaceUuid,
|
||||||
|
date: date,
|
||||||
|
aqiType: aqiType,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -16,11 +16,6 @@ class AqiDistributionChart extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final sortedData = List<AirQualityDataModel>.from(chartData)
|
|
||||||
..sort(
|
|
||||||
(a, b) => a.date.compareTo(b.date),
|
|
||||||
);
|
|
||||||
|
|
||||||
return BarChart(
|
return BarChart(
|
||||||
BarChartData(
|
BarChartData(
|
||||||
maxY: 100.1,
|
maxY: 100.1,
|
||||||
@ -30,29 +25,25 @@ class AqiDistributionChart extends StatelessWidget {
|
|||||||
borderData: EnergyManagementChartsHelper.borderData(),
|
borderData: EnergyManagementChartsHelper.borderData(),
|
||||||
barTouchData: _barTouchData(context),
|
barTouchData: _barTouchData(context),
|
||||||
titlesData: _titlesData(context),
|
titlesData: _titlesData(context),
|
||||||
barGroups: _buildBarGroups(sortedData),
|
barGroups: _buildBarGroups(),
|
||||||
),
|
),
|
||||||
duration: Duration.zero,
|
duration: Duration.zero,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<BarChartGroupData> _buildBarGroups(List<AirQualityDataModel> sortedData) {
|
List<BarChartGroupData> _buildBarGroups() {
|
||||||
return List.generate(sortedData.length, (index) {
|
return List.generate(chartData.length, (index) {
|
||||||
final data = sortedData[index];
|
final data = chartData[index];
|
||||||
final stackItems = <BarChartRodData>[];
|
final stackItems = <BarChartRodData>[];
|
||||||
double currentY = 0;
|
double currentY = 0;
|
||||||
bool isFirstElement = true;
|
var isFirstElement = true;
|
||||||
|
|
||||||
// Sort data by type to ensure consistent order
|
for (final percentageData in data.data) {
|
||||||
final sortedPercentageData = List<AirQualityPercentageData>.from(data.data)
|
|
||||||
..sort((a, b) => a.type.compareTo(b.type));
|
|
||||||
|
|
||||||
for (final percentageData in sortedPercentageData) {
|
|
||||||
stackItems.add(
|
stackItems.add(
|
||||||
BarChartRodData(
|
BarChartRodData(
|
||||||
fromY: currentY,
|
fromY: currentY,
|
||||||
toY: currentY + percentageData.percentage ,
|
toY: currentY + percentageData.percentage,
|
||||||
color: AirQualityDataModel.metricColors[percentageData.name]!,
|
color: AirQualityDataModel.metricColors[percentageData.type],
|
||||||
borderRadius: isFirstElement
|
borderRadius: isFirstElement
|
||||||
? const BorderRadius.only(
|
? const BorderRadius.only(
|
||||||
topLeft: Radius.circular(22),
|
topLeft: Radius.circular(22),
|
||||||
@ -84,23 +75,21 @@ class AqiDistributionChart extends StatelessWidget {
|
|||||||
tooltipRoundedRadius: 16,
|
tooltipRoundedRadius: 16,
|
||||||
tooltipPadding: const EdgeInsets.all(8),
|
tooltipPadding: const EdgeInsets.all(8),
|
||||||
getTooltipItem: (group, groupIndex, rod, rodIndex) {
|
getTooltipItem: (group, groupIndex, rod, rodIndex) {
|
||||||
final data = chartData[group.x.toInt()];
|
final data = chartData[group.x];
|
||||||
|
|
||||||
final List<TextSpan> children = [];
|
final children = <TextSpan>[];
|
||||||
|
|
||||||
final textStyle = context.textTheme.bodySmall?.copyWith(
|
final textStyle = context.textTheme.bodySmall?.copyWith(
|
||||||
color: ColorsManager.blackColor,
|
color: ColorsManager.blackColor,
|
||||||
fontSize: 12,
|
fontSize: 8,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Sort data by type to ensure consistent order
|
for (final percentageData in data.data) {
|
||||||
final sortedPercentageData = List<AirQualityPercentageData>.from(data.data)
|
final percentage = percentageData.percentage.toStringAsFixed(1);
|
||||||
..sort((a, b) => a.type.compareTo(b.type));
|
final type = percentageData.type[0].toUpperCase() +
|
||||||
|
percentageData.type.substring(1).replaceAll('_', ' ');
|
||||||
for (final percentageData in sortedPercentageData) {
|
|
||||||
children.add(TextSpan(
|
children.add(TextSpan(
|
||||||
text:
|
text: '\n$type: $percentage%',
|
||||||
'\n${percentageData.type.toUpperCase()}: ${percentageData.percentage.toStringAsFixed(1)}%',
|
|
||||||
style: textStyle,
|
style: textStyle,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -109,9 +98,10 @@ class AqiDistributionChart extends StatelessWidget {
|
|||||||
DateFormat('dd/MM/yyyy').format(data.date),
|
DateFormat('dd/MM/yyyy').format(data.date),
|
||||||
context.textTheme.bodyMedium!.copyWith(
|
context.textTheme.bodyMedium!.copyWith(
|
||||||
color: ColorsManager.blackColor,
|
color: ColorsManager.blackColor,
|
||||||
fontSize: 16,
|
fontSize: 9,
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
),
|
),
|
||||||
|
textAlign: TextAlign.start,
|
||||||
children: children,
|
children: children,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -33,7 +33,7 @@ class AqiDistributionChartBox extends StatelessWidget {
|
|||||||
const Divider(),
|
const Divider(),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: AqiDistributionChart(chartData: state.filteredChartData),
|
child: AqiDistributionChart(chartData: state.chartData),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -2,8 +2,11 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/modules/air_quality/blocs/air_quality_distribution/air_quality_distribution_bloc.dart';
|
import 'package:syncrow_web/pages/analytics/modules/air_quality/blocs/air_quality_distribution/air_quality_distribution_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/modules/air_quality/widgets/aqi_type_dropdown.dart';
|
import 'package:syncrow_web/pages/analytics/modules/air_quality/widgets/aqi_type_dropdown.dart';
|
||||||
|
import 'package:syncrow_web/pages/analytics/modules/analytics/blocs/analytics_date_picker_bloc/analytics_date_picker_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/modules/energy_management/widgets/chart_title.dart';
|
import 'package:syncrow_web/pages/analytics/modules/energy_management/widgets/chart_title.dart';
|
||||||
|
import 'package:syncrow_web/pages/analytics/params/get_air_quality_distribution_param.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/widgets/charts_loading_widget.dart';
|
import 'package:syncrow_web/pages/analytics/widgets/charts_loading_widget.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
||||||
|
|
||||||
class AqiDistributionChartTitle extends StatelessWidget {
|
class AqiDistributionChartTitle extends StatelessWidget {
|
||||||
const AqiDistributionChartTitle({required this.isLoading, super.key});
|
const AqiDistributionChartTitle({required this.isLoading, super.key});
|
||||||
@ -31,9 +34,15 @@ class AqiDistributionChartTitle extends StatelessWidget {
|
|||||||
child: AqiTypeDropdown(
|
child: AqiTypeDropdown(
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
context
|
final bloc = context.read<AirQualityDistributionBloc>();
|
||||||
.read<AirQualityDistributionBloc>()
|
try {
|
||||||
.add(UpdateAqiTypeEvent(value));
|
final param = _makeLoadAqiDistributionParam(context, value);
|
||||||
|
bloc.add(LoadAirQualityDistribution(param));
|
||||||
|
} catch (_) {
|
||||||
|
return;
|
||||||
|
} finally {
|
||||||
|
bloc.add(UpdateAqiTypeEvent(value));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@ -41,4 +50,19 @@ class AqiDistributionChartTitle extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GetAirQualityDistributionParam _makeLoadAqiDistributionParam(
|
||||||
|
BuildContext context,
|
||||||
|
AqiType aqiType,
|
||||||
|
) {
|
||||||
|
final date = context.read<AnalyticsDatePickerBloc>().state.monthlyDate;
|
||||||
|
final spaceUuid =
|
||||||
|
context.read<SpaceTreeBloc>().state.selectedSpaces.firstOrNull ?? '';
|
||||||
|
if (spaceUuid.isEmpty) throw Exception('Space UUID is empty');
|
||||||
|
return GetAirQualityDistributionParam(
|
||||||
|
date: date,
|
||||||
|
spaceUuid: spaceUuid,
|
||||||
|
aqiType: aqiType,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,8 @@ enum AqiType {
|
|||||||
aqi('AQI', '', 'aqi'),
|
aqi('AQI', '', 'aqi'),
|
||||||
pm25('PM2.5', 'µg/m³', 'pm25'),
|
pm25('PM2.5', 'µg/m³', 'pm25'),
|
||||||
pm10('PM10', 'µg/m³', 'pm10'),
|
pm10('PM10', 'µg/m³', 'pm10'),
|
||||||
hcho('HCHO', 'mg/m³', 'hcho'),
|
hcho('HCHO', 'mg/m³', 'cho2'),
|
||||||
tvoc('TVOC', 'µg/m³', 'tvoc'),
|
tvoc('TVOC', 'µg/m³', 'voc'),
|
||||||
co2('CO2', 'ppm', 'co2');
|
co2('CO2', 'ppm', 'co2');
|
||||||
|
|
||||||
const AqiType(this.value, this.unit, this.code);
|
const AqiType(this.value, this.unit, this.code);
|
||||||
|
@ -63,7 +63,7 @@ class RangeOfAqiChart extends StatelessWidget {
|
|||||||
gradient: LinearGradient(
|
gradient: LinearGradient(
|
||||||
begin: Alignment.bottomCenter,
|
begin: Alignment.bottomCenter,
|
||||||
end: Alignment.topCenter,
|
end: Alignment.topCenter,
|
||||||
stops: [0.0, 0.2, 0.4, 0.6, 0.8, 1.0],
|
stops: const [0.0, 0.2, 0.4, 0.6, 0.8, 1.0],
|
||||||
colors: RangeOfAqiChartsHelper.gradientData.map((e) {
|
colors: RangeOfAqiChartsHelper.gradientData.map((e) {
|
||||||
final (color, _) = e;
|
final (color, _) = e;
|
||||||
return color.withValues(alpha: 0.6);
|
return color.withValues(alpha: 0.6);
|
||||||
|
@ -16,7 +16,7 @@ import 'package:syncrow_web/pages/analytics/modules/energy_management/blocs/real
|
|||||||
import 'package:syncrow_web/pages/analytics/modules/energy_management/blocs/total_energy_consumption/total_energy_consumption_bloc.dart';
|
import 'package:syncrow_web/pages/analytics/modules/energy_management/blocs/total_energy_consumption/total_energy_consumption_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/modules/occupancy/blocs/occupancy/occupancy_bloc.dart';
|
import 'package:syncrow_web/pages/analytics/modules/occupancy/blocs/occupancy/occupancy_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/modules/occupancy/blocs/occupancy_heat_map/occupancy_heat_map_bloc.dart';
|
import 'package:syncrow_web/pages/analytics/modules/occupancy/blocs/occupancy_heat_map/occupancy_heat_map_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/services/air_quality_distribution/fake_air_quality_distribution_service.dart';
|
import 'package:syncrow_web/pages/analytics/services/air_quality_distribution/remote_air_quality_distribution_service.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/services/analytics_devices/analytics_devices_service_delagate.dart';
|
import 'package:syncrow_web/pages/analytics/services/analytics_devices/analytics_devices_service_delagate.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/services/analytics_devices/remote_energy_management_analytics_devices_service.dart';
|
import 'package:syncrow_web/pages/analytics/services/analytics_devices/remote_energy_management_analytics_devices_service.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/services/analytics_devices/remote_occupancy_analytics_devices_service.dart';
|
import 'package:syncrow_web/pages/analytics/services/analytics_devices/remote_occupancy_analytics_devices_service.dart';
|
||||||
@ -27,7 +27,7 @@ import 'package:syncrow_web/pages/analytics/services/energy_consumption_per_devi
|
|||||||
import 'package:syncrow_web/pages/analytics/services/occupacy/remote_occupancy_service.dart';
|
import 'package:syncrow_web/pages/analytics/services/occupacy/remote_occupancy_service.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/services/occupancy_heat_map/remote_occupancy_heat_map_service.dart';
|
import 'package:syncrow_web/pages/analytics/services/occupancy_heat_map/remote_occupancy_heat_map_service.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/services/power_clamp_info/remote_power_clamp_info_service.dart';
|
import 'package:syncrow_web/pages/analytics/services/power_clamp_info/remote_power_clamp_info_service.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/services/range_of_aqi/fake_range_of_aqi_service.dart';
|
import 'package:syncrow_web/pages/analytics/services/range_of_aqi/remote_range_of_aqi_service.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/services/realtime_device_service/firebase_realtime_device_service.dart';
|
import 'package:syncrow_web/pages/analytics/services/realtime_device_service/firebase_realtime_device_service.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/services/total_energy_consumption/remote_total_energy_consumption_service.dart';
|
import 'package:syncrow_web/pages/analytics/services/total_energy_consumption/remote_total_energy_consumption_service.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/shared/navigate_home_grid_view.dart';
|
import 'package:syncrow_web/pages/device_managment/shared/navigate_home_grid_view.dart';
|
||||||
@ -104,12 +104,12 @@ class _AnalyticsPageState extends State<AnalyticsPage> {
|
|||||||
),
|
),
|
||||||
BlocProvider(
|
BlocProvider(
|
||||||
create: (context) => RangeOfAqiBloc(
|
create: (context) => RangeOfAqiBloc(
|
||||||
FakeRangeOfAqiService(),
|
RemoteRangeOfAqiService(_httpService),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
BlocProvider(
|
BlocProvider(
|
||||||
create: (context) => AirQualityDistributionBloc(
|
create: (context) => AirQualityDistributionBloc(
|
||||||
FakeAirQualityDistributionService(),
|
RemoteAirQualityDistributionService(_httpService),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
BlocProvider(
|
BlocProvider(
|
||||||
|
@ -20,7 +20,7 @@ class AnalyticsDateFilterButton extends StatefulWidget {
|
|||||||
final void Function(DateTime)? onDateSelected;
|
final void Function(DateTime)? onDateSelected;
|
||||||
final DatePickerType datePickerType;
|
final DatePickerType datePickerType;
|
||||||
|
|
||||||
static final _color = ColorsManager.blackColor.withValues(alpha: 0.8);
|
static final Color _color = ColorsManager.blackColor.withValues(alpha: 0.8);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<AnalyticsDateFilterButton> createState() =>
|
State<AnalyticsDateFilterButton> createState() =>
|
||||||
@ -60,23 +60,21 @@ class _AnalyticsDateFilterButtonState extends State<AnalyticsDateFilterButton> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
showDialog(
|
showDialog<void>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (_) {
|
builder: (_) => switch (widget.datePickerType) {
|
||||||
return switch (widget.datePickerType) {
|
DatePickerType.month => MonthPickerWidget(
|
||||||
DatePickerType.month => MonthPickerWidget(
|
selectedDate: widget.selectedDate,
|
||||||
selectedDate: widget.selectedDate,
|
onDateSelected: (value) {
|
||||||
onDateSelected: (value) {
|
widget.onDateSelected?.call(value);
|
||||||
widget.onDateSelected?.call(value);
|
},
|
||||||
},
|
),
|
||||||
),
|
DatePickerType.year => YearPickerWidget(
|
||||||
DatePickerType.year => YearPickerWidget(
|
selectedDate: widget.selectedDate,
|
||||||
selectedDate: widget.selectedDate,
|
onDateSelected: (value) {
|
||||||
onDateSelected: (value) {
|
widget.onDateSelected?.call(value);
|
||||||
widget.onDateSelected?.call(value);
|
},
|
||||||
},
|
),
|
||||||
),
|
|
||||||
};
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -41,15 +41,19 @@ class AnalyticsPageTabsAndChildren extends StatelessWidget {
|
|||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
...AnalyticsPageTab.values.map(
|
...AnalyticsPageTab.values
|
||||||
(tab) => _buildAnimation(
|
.where(
|
||||||
child: AnalyticsPageTabButton(
|
(tab) => tab != AnalyticsPageTab.airQuality,
|
||||||
key: ValueKey(selectedTab),
|
)
|
||||||
tab: tab,
|
.map(
|
||||||
isSelected: tab == selectedTab,
|
(tab) => _buildAnimation(
|
||||||
|
child: AnalyticsPageTabButton(
|
||||||
|
key: ValueKey(selectedTab),
|
||||||
|
tab: tab,
|
||||||
|
isSelected: tab == selectedTab,
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -118,7 +122,7 @@ class AnalyticsPageTabsAndChildren extends StatelessWidget {
|
|||||||
communityUuid: communities.firstOrNull ?? '',
|
communityUuid: communities.firstOrNull ?? '',
|
||||||
spaceUuid: spaces.firstOrNull ?? '',
|
spaceUuid: spaces.firstOrNull ?? '',
|
||||||
);
|
);
|
||||||
break;
|
return;
|
||||||
case AnalyticsPageTab.airQuality:
|
case AnalyticsPageTab.airQuality:
|
||||||
_onAirQualityDateChanged(
|
_onAirQualityDateChanged(
|
||||||
context,
|
context,
|
||||||
@ -126,8 +130,9 @@ class AnalyticsPageTabsAndChildren extends StatelessWidget {
|
|||||||
communityUuid: communities.firstOrNull ?? '',
|
communityUuid: communities.firstOrNull ?? '',
|
||||||
spaceUuid: spaces.firstOrNull ?? '',
|
spaceUuid: spaces.firstOrNull ?? '',
|
||||||
);
|
);
|
||||||
|
return;
|
||||||
default:
|
default:
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -157,6 +162,7 @@ class AnalyticsPageTabsAndChildren extends StatelessWidget {
|
|||||||
required String communityUuid,
|
required String communityUuid,
|
||||||
required String spaceUuid,
|
required String spaceUuid,
|
||||||
}) {
|
}) {
|
||||||
|
if (spaceUuid.isEmpty) return;
|
||||||
FetchAirQualityDataHelper.loadAirQualityData(
|
FetchAirQualityDataHelper.loadAirQualityData(
|
||||||
context,
|
context,
|
||||||
date: date,
|
date: date,
|
||||||
|
@ -38,7 +38,7 @@ abstract final class EnergyManagementChartsHelper {
|
|||||||
sideTitles: SideTitles(
|
sideTitles: SideTitles(
|
||||||
showTitles: true,
|
showTitles: true,
|
||||||
maxIncluded: false,
|
maxIncluded: false,
|
||||||
minIncluded: true,
|
minIncluded: false,
|
||||||
interval: leftTitlesInterval,
|
interval: leftTitlesInterval,
|
||||||
reservedSize: 110,
|
reservedSize: 110,
|
||||||
getTitlesWidget: (value, meta) => Padding(
|
getTitlesWidget: (value, meta) => Padding(
|
||||||
|
@ -34,8 +34,8 @@ class OccupancyHeatMapGradient extends StatelessWidget {
|
|||||||
width: 1,
|
width: 1,
|
||||||
),
|
),
|
||||||
gradient: LinearGradient(
|
gradient: LinearGradient(
|
||||||
begin: AlignmentDirectional.centerEnd,
|
begin: AlignmentDirectional.centerStart,
|
||||||
end: AlignmentDirectional.centerStart,
|
end: AlignmentDirectional.centerEnd,
|
||||||
colors: _heatMapColors(),
|
colors: _heatMapColors(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -28,11 +28,11 @@ class OccupancyPainter extends CustomPainter {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void paint(Canvas canvas, Size size) {
|
void paint(Canvas canvas, Size size) {
|
||||||
final Paint fillPaint = Paint();
|
final fillPaint = Paint();
|
||||||
final Paint borderPaint = Paint()
|
final borderPaint = Paint()
|
||||||
..color = ColorsManager.grayBorder.withValues(alpha: 0.4)
|
..color = ColorsManager.grayBorder.withValues(alpha: 0.4)
|
||||||
..style = PaintingStyle.stroke;
|
..style = PaintingStyle.stroke;
|
||||||
final Paint hoveredBorderPaint = Paint()
|
final hoveredBorderPaint = Paint()
|
||||||
..color = Colors.black
|
..color = Colors.black
|
||||||
..style = PaintingStyle.stroke
|
..style = PaintingStyle.stroke
|
||||||
..strokeWidth = 1.5;
|
..strokeWidth = 1.5;
|
||||||
@ -48,7 +48,6 @@ class OccupancyPainter extends CustomPainter {
|
|||||||
final rect = Rect.fromLTWH(x, y, cellSize, cellSize);
|
final rect = Rect.fromLTWH(x, y, cellSize, cellSize);
|
||||||
canvas.drawRect(rect, fillPaint);
|
canvas.drawRect(rect, fillPaint);
|
||||||
|
|
||||||
// Highlight the hovered item
|
|
||||||
if (hoveredItem != null && hoveredItem!.index == item.index) {
|
if (hoveredItem != null && hoveredItem!.index == item.index) {
|
||||||
canvas.drawRect(rect, hoveredBorderPaint);
|
canvas.drawRect(rect, hoveredBorderPaint);
|
||||||
} else {
|
} else {
|
||||||
@ -73,16 +72,16 @@ class OccupancyPainter extends CustomPainter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _drawDashedLine(Canvas canvas, Offset start, Offset end, Paint paint) {
|
void _drawDashedLine(Canvas canvas, Offset start, Offset end, Paint paint) {
|
||||||
const double dashWidth = 2.0;
|
const dashWidth = 2.0;
|
||||||
const double dashSpace = 4.0;
|
const dashSpace = 4.0;
|
||||||
final double totalLength = (end - start).distance;
|
final totalLength = (end - start).distance;
|
||||||
final Offset direction = (end - start) / (end - start).distance;
|
final direction = (end - start) / (end - start).distance;
|
||||||
|
|
||||||
double currentLength = 0.0;
|
var currentLength = 0.0;
|
||||||
while (currentLength < totalLength) {
|
while (currentLength < totalLength) {
|
||||||
final Offset dashStart = start + direction * currentLength;
|
final dashStart = start + direction * currentLength;
|
||||||
final double nextLength = currentLength + dashWidth;
|
final nextLength = currentLength + dashWidth;
|
||||||
final Offset dashEnd =
|
final dashEnd =
|
||||||
start + direction * (nextLength < totalLength ? nextLength : totalLength);
|
start + direction * (nextLength < totalLength ? nextLength : totalLength);
|
||||||
canvas.drawLine(dashStart, dashEnd, paint);
|
canvas.drawLine(dashStart, dashEnd, paint);
|
||||||
currentLength = nextLength + dashSpace;
|
currentLength = nextLength + dashSpace;
|
||||||
@ -91,8 +90,9 @@ class OccupancyPainter extends CustomPainter {
|
|||||||
|
|
||||||
Color _getColor(int value) {
|
Color _getColor(int value) {
|
||||||
if (maxValue == 0) return ColorsManager.vividBlue.withValues(alpha: 0);
|
if (maxValue == 0) return ColorsManager.vividBlue.withValues(alpha: 0);
|
||||||
final opacity = value.clamp(0, maxValue) / maxValue;
|
final clampedValue = 0.075 + (1 * value.clamp(0, maxValue) / maxValue);
|
||||||
return ColorsManager.vividBlue.withValues(alpha: opacity);
|
final opacity = value == 0 ? 0 : clampedValue;
|
||||||
|
return ColorsManager.vividBlue.withValues(alpha: opacity.toDouble());
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
|
import 'package:syncrow_web/pages/analytics/modules/air_quality/widgets/aqi_type_dropdown.dart';
|
||||||
|
|
||||||
class GetAirQualityDistributionParam {
|
class GetAirQualityDistributionParam {
|
||||||
final DateTime date;
|
final DateTime date;
|
||||||
final String spaceUuid;
|
final String spaceUuid;
|
||||||
|
final AqiType aqiType;
|
||||||
|
|
||||||
const GetAirQualityDistributionParam({
|
const GetAirQualityDistributionParam(
|
||||||
|
{
|
||||||
required this.date,
|
required this.date,
|
||||||
required this.spaceUuid,
|
required this.spaceUuid,
|
||||||
|
required this.aqiType,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,95 +0,0 @@
|
|||||||
import 'dart:math';
|
|
||||||
|
|
||||||
import 'package:syncrow_web/pages/analytics/models/air_quality_data_model.dart';
|
|
||||||
import 'package:syncrow_web/pages/analytics/modules/air_quality/widgets/aqi_type_dropdown.dart';
|
|
||||||
import 'package:syncrow_web/pages/analytics/params/get_air_quality_distribution_param.dart';
|
|
||||||
import 'package:syncrow_web/pages/analytics/services/air_quality_distribution/air_quality_distribution_service.dart';
|
|
||||||
|
|
||||||
class FakeAirQualityDistributionService implements AirQualityDistributionService {
|
|
||||||
final _random = Random();
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<List<AirQualityDataModel>> getAirQualityDistribution(
|
|
||||||
GetAirQualityDistributionParam param,
|
|
||||||
) async {
|
|
||||||
return Future.delayed(
|
|
||||||
const Duration(milliseconds: 400),
|
|
||||||
() => List.generate(30, (index) {
|
|
||||||
final date = DateTime(2025, 5, 1).add(Duration(days: index));
|
|
||||||
|
|
||||||
final values = _generateRandomPercentages();
|
|
||||||
final nullMask = List.generate(6, (_) => _shouldBeNull());
|
|
||||||
|
|
||||||
if (nullMask.every((isNull) => isNull)) {
|
|
||||||
nullMask[_random.nextInt(6)] = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
final nonNullValues = _redistributePercentages(values, nullMask);
|
|
||||||
|
|
||||||
return AirQualityDataModel(
|
|
||||||
date: date,
|
|
||||||
data: [
|
|
||||||
AirQualityPercentageData(
|
|
||||||
type: AqiType.aqi.code,
|
|
||||||
percentage: nonNullValues[0],
|
|
||||||
name: 'good',
|
|
||||||
),
|
|
||||||
AirQualityPercentageData(
|
|
||||||
name: 'moderate',
|
|
||||||
type: AqiType.co2.code,
|
|
||||||
percentage: nonNullValues[1],
|
|
||||||
),
|
|
||||||
AirQualityPercentageData(
|
|
||||||
name: 'poor',
|
|
||||||
percentage: nonNullValues[2],
|
|
||||||
type: AqiType.hcho.code,
|
|
||||||
|
|
||||||
),
|
|
||||||
AirQualityPercentageData(
|
|
||||||
name: 'unhealthy',
|
|
||||||
percentage: nonNullValues[3],
|
|
||||||
type: AqiType.pm10.code,
|
|
||||||
),
|
|
||||||
AirQualityPercentageData(
|
|
||||||
name: 'severe',
|
|
||||||
type: AqiType.pm25.code,
|
|
||||||
percentage: nonNullValues[4],
|
|
||||||
),
|
|
||||||
AirQualityPercentageData(
|
|
||||||
name: 'hazardous',
|
|
||||||
percentage: nonNullValues[5],
|
|
||||||
type: AqiType.co2.code,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<double> _redistributePercentages(
|
|
||||||
List<double> originalValues,
|
|
||||||
List<bool> nullMask,
|
|
||||||
) {
|
|
||||||
double nonNullSum = 0;
|
|
||||||
for (int i = 0; i < originalValues.length; i++) {
|
|
||||||
if (!nullMask[i]) {
|
|
||||||
nonNullSum += originalValues[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return List.generate(originalValues.length, (i) {
|
|
||||||
if (nullMask[i]) return 0;
|
|
||||||
return (originalValues[i] / nonNullSum * 100).roundToDouble();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
bool _shouldBeNull() => _random.nextDouble() < 0.6;
|
|
||||||
|
|
||||||
List<double> _generateRandomPercentages() {
|
|
||||||
final values = List.generate(6, (_) => _random.nextDouble());
|
|
||||||
|
|
||||||
final sum = values.reduce((a, b) => a + b);
|
|
||||||
|
|
||||||
return values.map((value) => (value / sum * 100).roundToDouble()).toList();
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,7 +3,8 @@ import 'package:syncrow_web/pages/analytics/params/get_air_quality_distribution_
|
|||||||
import 'package:syncrow_web/pages/analytics/services/air_quality_distribution/air_quality_distribution_service.dart';
|
import 'package:syncrow_web/pages/analytics/services/air_quality_distribution/air_quality_distribution_service.dart';
|
||||||
import 'package:syncrow_web/services/api/http_service.dart';
|
import 'package:syncrow_web/services/api/http_service.dart';
|
||||||
|
|
||||||
class RemoteAirQualityDistributionService implements AirQualityDistributionService {
|
final class RemoteAirQualityDistributionService
|
||||||
|
implements AirQualityDistributionService {
|
||||||
RemoteAirQualityDistributionService(this._httpService);
|
RemoteAirQualityDistributionService(this._httpService);
|
||||||
|
|
||||||
final HTTPService _httpService;
|
final HTTPService _httpService;
|
||||||
@ -14,10 +15,10 @@ class RemoteAirQualityDistributionService implements AirQualityDistributionServi
|
|||||||
) async {
|
) async {
|
||||||
try {
|
try {
|
||||||
final response = await _httpService.get(
|
final response = await _httpService.get(
|
||||||
path: 'endpoint',
|
path: '/aqi/distribution/space/${param.spaceUuid}',
|
||||||
queryParameters: {
|
queryParameters: {
|
||||||
'spaceUuid': param.spaceUuid,
|
'monthDate': _formatDate(param.date),
|
||||||
'date': param.date.toIso8601String(),
|
'pollutantType': param.aqiType.code,
|
||||||
},
|
},
|
||||||
expectedResponseModel: (data) {
|
expectedResponseModel: (data) {
|
||||||
final json = data as Map<String, dynamic>? ?? {};
|
final json = data as Map<String, dynamic>? ?? {};
|
||||||
@ -33,4 +34,8 @@ class RemoteAirQualityDistributionService implements AirQualityDistributionServi
|
|||||||
throw Exception('Failed to load energy consumption per phase: $e');
|
throw Exception('Failed to load energy consumption per phase: $e');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static String _formatDate(DateTime date) {
|
||||||
|
return '${date.year}-${date.month.toString().padLeft(2, '0')}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,15 +26,15 @@ class DeviceLocationDetailsServiceDecorator implements DeviceLocationService {
|
|||||||
if (data != null) {
|
if (data != null) {
|
||||||
final addressData = data['address'] as Map<String, dynamic>;
|
final addressData = data['address'] as Map<String, dynamic>;
|
||||||
return deviceLocationInfo.copyWith(
|
return deviceLocationInfo.copyWith(
|
||||||
city: addressData['city'],
|
city: addressData['city'] as String?,
|
||||||
country: addressData['country_code'].toString().toUpperCase(),
|
country: addressData['country_code']?.toString().toUpperCase(),
|
||||||
address: addressData['state'],
|
address: addressData['state'] as String?,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return deviceLocationInfo;
|
return deviceLocationInfo;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw Exception('Failed to load device location info: ${e.toString()}');
|
throw Exception('Failed to load device location info: $e');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,36 +0,0 @@
|
|||||||
import 'package:syncrow_web/pages/analytics/models/range_of_aqi.dart';
|
|
||||||
import 'package:syncrow_web/pages/analytics/modules/air_quality/widgets/aqi_type_dropdown.dart';
|
|
||||||
import 'package:syncrow_web/pages/analytics/params/get_range_of_aqi_param.dart';
|
|
||||||
import 'package:syncrow_web/pages/analytics/services/range_of_aqi/range_of_aqi_service.dart';
|
|
||||||
|
|
||||||
class FakeRangeOfAqiService implements RangeOfAqiService {
|
|
||||||
@override
|
|
||||||
Future<List<RangeOfAqi>> load(GetRangeOfAqiParam param) async {
|
|
||||||
return await Future.delayed(const Duration(milliseconds: 800), () {
|
|
||||||
final random = DateTime.now().millisecondsSinceEpoch;
|
|
||||||
|
|
||||||
return List.generate(30, (index) {
|
|
||||||
final date = DateTime(2025, 5, 1).add(Duration(days: index));
|
|
||||||
|
|
||||||
final min = ((random + index * 17) % 200).toDouble();
|
|
||||||
final avgDelta = ((random + index * 23) % 50).toDouble() + 20;
|
|
||||||
final maxDelta = ((random + index * 31) % 50).toDouble() + 30;
|
|
||||||
|
|
||||||
final avg = (min + avgDelta).clamp(0.0, 301.0);
|
|
||||||
final max = (avg + maxDelta).clamp(0.0, 301.0);
|
|
||||||
|
|
||||||
return RangeOfAqi(
|
|
||||||
data: [
|
|
||||||
RangeOfAqiValue(type: AqiType.aqi.code, min: min, average: avg, max: max),
|
|
||||||
RangeOfAqiValue(type: AqiType.pm25.code, min: min, average: avg, max: max),
|
|
||||||
RangeOfAqiValue(type: AqiType.pm10.code, min: min, average: avg, max: max),
|
|
||||||
RangeOfAqiValue(type: AqiType.hcho.code, min: min, average: avg, max: max),
|
|
||||||
RangeOfAqiValue(type: AqiType.tvoc.code, min: min, average: avg, max: max),
|
|
||||||
RangeOfAqiValue(type: AqiType.co2.code, min: min, average: avg, max: max),
|
|
||||||
],
|
|
||||||
date: date,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -12,11 +12,8 @@ final class RemoteRangeOfAqiService implements RangeOfAqiService {
|
|||||||
Future<List<RangeOfAqi>> load(GetRangeOfAqiParam param) async {
|
Future<List<RangeOfAqi>> load(GetRangeOfAqiParam param) async {
|
||||||
try {
|
try {
|
||||||
final response = await _httpService.get(
|
final response = await _httpService.get(
|
||||||
path: 'endpoint',
|
path: '/aqi/range/space/${param.spaceUuid}',
|
||||||
queryParameters: {
|
queryParameters: {'monthDate': _formatDate(param.date)},
|
||||||
'spaceUuid': param.spaceUuid,
|
|
||||||
'date': param.date.toIso8601String(),
|
|
||||||
},
|
|
||||||
expectedResponseModel: (data) {
|
expectedResponseModel: (data) {
|
||||||
final json = data as Map<String, dynamic>? ?? {};
|
final json = data as Map<String, dynamic>? ?? {};
|
||||||
final mappedData = json['data'] as List<dynamic>? ?? [];
|
final mappedData = json['data'] as List<dynamic>? ?? [];
|
||||||
@ -28,7 +25,11 @@ final class RemoteRangeOfAqiService implements RangeOfAqiService {
|
|||||||
);
|
);
|
||||||
return response;
|
return response;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw Exception('Failed to load energy consumption per phase: $e');
|
throw Exception('Failed to load range of aqi: $e');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static String _formatDate(DateTime date) {
|
||||||
|
return '${date.year}-${date.month.toString().padLeft(2, '0')}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ class CustomWebTextField extends StatelessWidget {
|
|||||||
controller: controller,
|
controller: controller,
|
||||||
style: const TextStyle(color: Colors.black),
|
style: const TextStyle(color: Colors.black),
|
||||||
decoration: textBoxDecoration()!.copyWith(
|
decoration: textBoxDecoration()!.copyWith(
|
||||||
errorStyle: const TextStyle(height: 0),
|
errorStyle: const TextStyle(height: 0.01),
|
||||||
hintStyle: context.textTheme.titleSmall!
|
hintStyle: context.textTheme.titleSmall!
|
||||||
.copyWith(color: Colors.grey, fontSize: 12),
|
.copyWith(color: Colors.grey, fontSize: 12),
|
||||||
hintText: hintText ?? 'Please enter'),
|
hintText: hintText ?? 'Please enter'),
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_svg/svg.dart';
|
import 'package:flutter_svg/svg.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/all_devices/bloc/device_mgmt_bloc/device_managment_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/device_setting/bloc/setting_bloc_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/device_setting/settings_model/device_info_model.dart';
|
import 'package:syncrow_web/pages/device_managment/device_setting/settings_model/device_info_model.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/device_setting/settings_model/sub_space_model.dart';
|
import 'package:syncrow_web/pages/device_managment/device_setting/settings_model/sub_space_model.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/device_setting/sub_space_dialog.dart';
|
import 'package:syncrow_web/pages/device_managment/device_setting/sub_space_dialog.dart';
|
||||||
@ -66,14 +69,25 @@ class DeviceManagementContent extends StatelessWidget {
|
|||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.all(10.0),
|
padding: const EdgeInsets.all(10.0),
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () {
|
onTap: () async {
|
||||||
showSubSpaceDialog(
|
final selectedSubSpace = await showSubSpaceDialog(
|
||||||
context,
|
context,
|
||||||
communityUuid: device.community!.uuid!,
|
communityUuid: device.community!.uuid!,
|
||||||
spaceUuid: device.spaces!.first.uuid!,
|
spaceUuid: device.spaces!.first.uuid!,
|
||||||
subSpaces: subSpaces,
|
subSpaces: subSpaces,
|
||||||
selected: device.subspace!.uuid,
|
selected: deviceInfo.subspace.uuid,
|
||||||
);
|
);
|
||||||
|
if (selectedSubSpace != null) {
|
||||||
|
Future.delayed(const Duration(milliseconds: 500), () {
|
||||||
|
context.read<SettingDeviceBloc>().add(
|
||||||
|
SettingBlocAssignRoom(
|
||||||
|
communityUuid: device.community!.uuid!,
|
||||||
|
spaceUuid: device.spaces!.first.uuid!,
|
||||||
|
subSpaceUuid: selectedSubSpace.id ?? '',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
child: infoRow(
|
child: infoRow(
|
||||||
label: 'Sub-Space:',
|
label: 'Sub-Space:',
|
||||||
|
@ -9,13 +9,11 @@ import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
|||||||
class SubSpaceDialog extends StatefulWidget {
|
class SubSpaceDialog extends StatefulWidget {
|
||||||
final List<SubSpaceModel> subSpaces;
|
final List<SubSpaceModel> subSpaces;
|
||||||
final String? selected;
|
final String? selected;
|
||||||
final void Function(SubSpaceModel?) onConfirmed;
|
|
||||||
|
|
||||||
const SubSpaceDialog({
|
const SubSpaceDialog({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.subSpaces,
|
required this.subSpaces,
|
||||||
this.selected,
|
this.selected,
|
||||||
required this.onConfirmed,
|
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -86,30 +84,21 @@ class _SubSpaceDialogState extends State<SubSpaceDialog> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void showSubSpaceDialog(
|
Future<SubSpaceModel?> showSubSpaceDialog(
|
||||||
BuildContext context, {
|
BuildContext context, {
|
||||||
required List<SubSpaceModel> subSpaces,
|
required List<SubSpaceModel> subSpaces,
|
||||||
String? selected,
|
String? selected,
|
||||||
required String communityUuid,
|
required String communityUuid,
|
||||||
required String spaceUuid,
|
required String spaceUuid,
|
||||||
}) {
|
}) {
|
||||||
showDialog(
|
return showDialog<SubSpaceModel>(
|
||||||
context: context,
|
context: context,
|
||||||
barrierDismissible: true,
|
builder: (ctx) => BlocProvider.value(
|
||||||
builder: (ctx) => SubSpaceDialog(
|
value: BlocProvider.of<SettingDeviceBloc>(context),
|
||||||
subSpaces: subSpaces,
|
child: SubSpaceDialog(
|
||||||
selected: selected,
|
subSpaces: subSpaces,
|
||||||
onConfirmed: (selectedModel) {
|
selected: selected,
|
||||||
if (selectedModel != null) {
|
),
|
||||||
context.read<SettingDeviceBloc>().add(
|
|
||||||
SettingBlocAssignRoom(
|
|
||||||
communityUuid: communityUuid,
|
|
||||||
spaceUuid: spaceUuid,
|
|
||||||
subSpaceUuid: selectedModel.id ?? '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
||||||
import 'package:syncrow_web/pages/device_managment/device_setting/bloc/setting_bloc_bloc.dart';
|
|
||||||
import 'package:syncrow_web/pages/device_managment/device_setting/settings_model/sub_space_model.dart';
|
import 'package:syncrow_web/pages/device_managment/device_setting/settings_model/sub_space_model.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/device_setting/sub_space_dialog.dart';
|
import 'package:syncrow_web/pages/device_managment/device_setting/sub_space_dialog.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
@ -62,11 +60,12 @@ class SubSpaceDialogButtons extends StatelessWidget {
|
|||||||
? null
|
? null
|
||||||
: () {
|
: () {
|
||||||
final selectedModel = widget.subSpaces.firstWhere(
|
final selectedModel = widget.subSpaces.firstWhere(
|
||||||
(space) => space.id == _selectedId,
|
(space) => space.id == _selectedId,
|
||||||
orElse: () =>
|
orElse: () =>
|
||||||
SubSpaceModel(id: null, name: '', devices: []));
|
SubSpaceModel(id: null, name: '', devices: []),
|
||||||
widget.onConfirmed(selectedModel);
|
);
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context)
|
||||||
|
.pop(selectedModel);
|
||||||
},
|
},
|
||||||
child: Text(
|
child: Text(
|
||||||
'Confirm',
|
'Confirm',
|
||||||
@ -84,31 +83,3 @@ class SubSpaceDialogButtons extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void showSubSpaceDialog(
|
|
||||||
BuildContext context, {
|
|
||||||
required List<SubSpaceModel> subSpaces,
|
|
||||||
String? selected,
|
|
||||||
required String communityUuid,
|
|
||||||
required String spaceUuid,
|
|
||||||
}) {
|
|
||||||
showDialog(
|
|
||||||
context: context,
|
|
||||||
barrierDismissible: true,
|
|
||||||
builder: (ctx) => SubSpaceDialog(
|
|
||||||
subSpaces: subSpaces,
|
|
||||||
selected: selected,
|
|
||||||
onConfirmed: (selectedModel) {
|
|
||||||
if (selectedModel != null) {
|
|
||||||
context.read<SettingDeviceBloc>().add(
|
|
||||||
SettingBlocAssignRoom(
|
|
||||||
communityUuid: communityUuid,
|
|
||||||
spaceUuid: spaceUuid,
|
|
||||||
subSpaceUuid: selectedModel.id ?? '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
@ -40,7 +40,7 @@ class HomeCard extends StatelessWidget {
|
|||||||
child: Text(
|
child: Text(
|
||||||
name,
|
name,
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 20,
|
fontSize: 30,
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
|
@ -97,7 +97,7 @@ class _HomeWebPageState extends State<HomeWebPage> {
|
|||||||
itemCount: homeBloc.homeItems.length,
|
itemCount: homeBloc.homeItems.length,
|
||||||
gridDelegate:
|
gridDelegate:
|
||||||
const SliverGridDelegateWithFixedCrossAxisCount(
|
const SliverGridDelegateWithFixedCrossAxisCount(
|
||||||
crossAxisCount: 3, // Adjust as needed.
|
crossAxisCount: 4, // Adjust as needed.
|
||||||
crossAxisSpacing: 20.0,
|
crossAxisSpacing: 20.0,
|
||||||
mainAxisSpacing: 20.0,
|
mainAxisSpacing: 20.0,
|
||||||
childAspectRatio: 1.5,
|
childAspectRatio: 1.5,
|
||||||
|
@ -11,7 +11,6 @@ class CreateRoutineBloc extends Bloc<CreateRoutineEvent, CreateRoutineState> {
|
|||||||
on<SpaceOnlyWithDevicesEvent>(_fetchSpaceOnlyWithDevices);
|
on<SpaceOnlyWithDevicesEvent>(_fetchSpaceOnlyWithDevices);
|
||||||
on<SaveCommunityIdAndSpaceIdEvent>(saveSpaceIdCommunityId);
|
on<SaveCommunityIdAndSpaceIdEvent>(saveSpaceIdCommunityId);
|
||||||
on<ResetSelectedEvent>(resetSelected);
|
on<ResetSelectedEvent>(resetSelected);
|
||||||
on<FetchCommunityEvent>(_fetchCommunity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String selectedSpaceId = '';
|
String selectedSpaceId = '';
|
||||||
@ -50,18 +49,4 @@ class CreateRoutineBloc extends Bloc<CreateRoutineEvent, CreateRoutineState> {
|
|||||||
selectedCommunityId = '';
|
selectedCommunityId = '';
|
||||||
emit(const ResetSelectedState());
|
emit(const ResetSelectedState());
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _fetchCommunity(
|
|
||||||
FetchCommunityEvent event, Emitter<CreateRoutineState> emit) async {
|
|
||||||
emit(const CommunitiesLoadingState());
|
|
||||||
|
|
||||||
try {
|
|
||||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
|
||||||
communities =
|
|
||||||
await CommunitySpaceManagementApi().fetchCommunities(projectUuid);
|
|
||||||
emit(const CommunityLoadedState());
|
|
||||||
} catch (e) {
|
|
||||||
emit(SpaceTreeErrorState('Error loading communities $e'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -43,9 +43,3 @@ class ResetSelectedEvent extends CreateRoutineEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class FetchCommunityEvent extends CreateRoutineEvent {
|
|
||||||
const FetchCommunityEvent();
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [];
|
|
||||||
}
|
|
@ -1,13 +1,11 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routines/create_new_routines/dropdown_menu_content.dart';
|
import 'package:syncrow_web/pages/routines/create_new_routines/dropdown_menu_content.dart';
|
||||||
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_state.dart';
|
|
||||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
import 'space_tree_dropdown_bloc.dart';
|
import 'space_tree_dropdown_bloc.dart';
|
||||||
|
|
||||||
class SpaceTreeDropdown extends StatefulWidget {
|
class SpaceTreeDropdown extends StatelessWidget {
|
||||||
final String? selectedSpaceId;
|
final String? selectedSpaceId;
|
||||||
final Function(String?)? onChanged;
|
final Function(String?)? onChanged;
|
||||||
|
|
||||||
@ -18,23 +16,33 @@ class SpaceTreeDropdown extends StatefulWidget {
|
|||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<SpaceTreeDropdown> createState() => _SpaceTreeDropdownState();
|
Widget build(BuildContext context) {
|
||||||
|
return BlocProvider(
|
||||||
|
create: (context) {
|
||||||
|
final bloc = SpaceTreeDropdownBloc(selectedSpaceId);
|
||||||
|
bloc.add(FetchSpacesEvent());
|
||||||
|
return bloc;
|
||||||
|
},
|
||||||
|
child: _DropdownContent(onChanged: onChanged),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _SpaceTreeDropdownState extends State<SpaceTreeDropdown> {
|
class _DropdownContent extends StatefulWidget {
|
||||||
late SpaceTreeDropdownBloc _dropdownBloc;
|
final Function(String?)? onChanged;
|
||||||
|
|
||||||
|
const _DropdownContent({this.onChanged});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<_DropdownContent> createState() => _DropdownContentState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _DropdownContentState extends State<_DropdownContent> {
|
||||||
final LayerLink _layerLink = LayerLink();
|
final LayerLink _layerLink = LayerLink();
|
||||||
OverlayEntry? _overlayEntry;
|
OverlayEntry? _overlayEntry;
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
_dropdownBloc = SpaceTreeDropdownBloc(widget.selectedSpaceId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_dropdownBloc.close();
|
|
||||||
_removeOverlay();
|
_removeOverlay();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
@ -46,100 +54,120 @@ class _SpaceTreeDropdownState extends State<SpaceTreeDropdown> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider.value(
|
return Column(
|
||||||
value: _dropdownBloc,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
child: BlocBuilder<SpaceTreeBloc, SpaceTreeState>(
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
builder: (context, spaceTreeState) {
|
children: [
|
||||||
final communities = spaceTreeState.searchQuery.isNotEmpty
|
Padding(
|
||||||
? spaceTreeState.filteredCommunity
|
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||||
: spaceTreeState.communityList;
|
child: Text(
|
||||||
|
"Community",
|
||||||
|
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
|
||||||
|
fontWeight: FontWeight.w400,
|
||||||
|
fontSize: 13,
|
||||||
|
color: ColorsManager.blackColor,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
CompositedTransformTarget(
|
||||||
|
link: _layerLink,
|
||||||
|
child: GestureDetector(
|
||||||
|
onTap: () => _toggleDropdown(context),
|
||||||
|
child: BlocBuilder<SpaceTreeDropdownBloc, SpaceTreeDropdownState>(
|
||||||
|
builder: (context, state) {
|
||||||
|
return _buildDropdownTrigger(state);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return BlocBuilder<SpaceTreeDropdownBloc, SpaceTreeDropdownState>(
|
Widget _buildDropdownTrigger(SpaceTreeDropdownState state) {
|
||||||
builder: (context, dropdownState) {
|
if (state.status == SpaceTreeDropdownStatus.loading) {
|
||||||
final selectedCommunity = _findCommunity(
|
return Container(
|
||||||
communities,
|
height: 46,
|
||||||
dropdownState.selectedSpaceId,
|
decoration: BoxDecoration(
|
||||||
);
|
border: Border.all(color: Colors.grey.shade300),
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
margin: const EdgeInsets.symmetric(horizontal: 10),
|
||||||
|
child: const Center(child: CircularProgressIndicator()),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return Column(
|
if (state.status == SpaceTreeDropdownStatus.failure) {
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
return Container(
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
height: 46,
|
||||||
children: [
|
decoration: BoxDecoration(
|
||||||
Padding(
|
border: Border.all(color: Colors.grey.shade300),
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 10),
|
borderRadius: BorderRadius.circular(12),
|
||||||
child: Text(
|
),
|
||||||
"Community",
|
margin: const EdgeInsets.symmetric(horizontal: 10),
|
||||||
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
|
child: Center(
|
||||||
fontWeight: FontWeight.w400,
|
child: Text(
|
||||||
fontSize: 13,
|
'Error: ${state.errorMessage}',
|
||||||
color: ColorsManager.blackColor,
|
style: const TextStyle(color: Colors.red),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
);
|
||||||
CompositedTransformTarget(
|
}
|
||||||
link: _layerLink,
|
|
||||||
child: GestureDetector(
|
final selectedCommunity = _findCommunity(state, state.selectedSpaceId);
|
||||||
onTap: () => _toggleDropdown(context, communities),
|
|
||||||
child: Container(
|
return Container(
|
||||||
height: 46,
|
height: 46,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
border: Border.all(color: Colors.grey.shade300),
|
border: Border.all(color: Colors.grey.shade300),
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
),
|
),
|
||||||
margin: const EdgeInsets.symmetric(horizontal: 10),
|
margin: const EdgeInsets.symmetric(horizontal: 10),
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
Padding(
|
Padding(
|
||||||
padding:
|
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||||
const EdgeInsets.symmetric(horizontal: 10),
|
child: Text(
|
||||||
child: Text(
|
selectedCommunity?.name ?? 'Please Select',
|
||||||
selectedCommunity?.name ?? 'Please Select',
|
style: TextStyle(
|
||||||
style: TextStyle(
|
color: selectedCommunity != null
|
||||||
color: selectedCommunity != null
|
? ColorsManager.blackColor
|
||||||
? ColorsManager.blackColor
|
: ColorsManager.textGray,
|
||||||
: ColorsManager.textGray,
|
overflow: TextOverflow.ellipsis,
|
||||||
overflow: TextOverflow.ellipsis,
|
fontWeight: FontWeight.w400,
|
||||||
fontWeight: FontWeight.w400,
|
fontSize: 13,
|
||||||
fontSize: 13,
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
Container(
|
||||||
Container(
|
decoration: BoxDecoration(
|
||||||
decoration: BoxDecoration(
|
color: Colors.grey[200],
|
||||||
color: Colors.grey[200],
|
borderRadius: const BorderRadius.only(
|
||||||
borderRadius: const BorderRadius.only(
|
topRight: Radius.circular(10),
|
||||||
topRight: Radius.circular(10),
|
bottomRight: Radius.circular(10),
|
||||||
bottomRight: Radius.circular(10),
|
),
|
||||||
),
|
),
|
||||||
),
|
height: 45,
|
||||||
height: 45,
|
width: 33,
|
||||||
width: 33,
|
child: const Icon(
|
||||||
child: const Icon(
|
Icons.keyboard_arrow_down,
|
||||||
Icons.keyboard_arrow_down,
|
color: ColorsManager.textGray,
|
||||||
color: ColorsManager.textGray,
|
),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _toggleDropdown(BuildContext context, List<CommunityModel> communities) {
|
void _toggleDropdown(BuildContext context) {
|
||||||
if (_overlayEntry != null) {
|
if (_overlayEntry != null) {
|
||||||
_removeOverlay();
|
_removeOverlay();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final bloc = context.read<SpaceTreeDropdownBloc>();
|
||||||
|
|
||||||
_overlayEntry = OverlayEntry(
|
_overlayEntry = OverlayEntry(
|
||||||
builder: (context) => Positioned(
|
builder: (context) => Positioned(
|
||||||
width: 300,
|
width: 300,
|
||||||
@ -148,18 +176,22 @@ class _SpaceTreeDropdownState extends State<SpaceTreeDropdown> {
|
|||||||
showWhenUnlinked: false,
|
showWhenUnlinked: false,
|
||||||
offset: const Offset(0, 48),
|
offset: const Offset(0, 48),
|
||||||
child: Material(
|
child: Material(
|
||||||
|
color: ColorsManager.whiteColors,
|
||||||
elevation: 8,
|
elevation: 8,
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
child: DropdownMenuContent(
|
child: BlocProvider.value(
|
||||||
selectedSpaceId: _dropdownBloc.state.selectedSpaceId,
|
value: bloc,
|
||||||
onChanged: (id) {
|
child: DropdownMenuContent(
|
||||||
if (id != null && mounted) {
|
selectedSpaceId: bloc.state.selectedSpaceId,
|
||||||
_dropdownBloc.add(SpaceTreeDropdownSelectEvent(id));
|
onChanged: (id) {
|
||||||
widget.onChanged?.call(id);
|
if (id != null && mounted) {
|
||||||
_removeOverlay();
|
bloc.add(SpaceTreeDropdownSelectEvent(id));
|
||||||
}
|
widget.onChanged?.call(id);
|
||||||
},
|
_removeOverlay();
|
||||||
onClose: _removeOverlay,
|
}
|
||||||
|
},
|
||||||
|
onClose: _removeOverlay,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -170,10 +202,13 @@ class _SpaceTreeDropdownState extends State<SpaceTreeDropdown> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CommunityModel? _findCommunity(
|
CommunityModel? _findCommunity(
|
||||||
List<CommunityModel> communities, String? communityId) {
|
SpaceTreeDropdownState state, String? communityId) {
|
||||||
if (communityId == null) return null;
|
if (communityId == null) return null;
|
||||||
try {
|
try {
|
||||||
return communities.firstWhere((c) => c.uuid == communityId);
|
return state.filteredCommunities.firstWhere((c) => c.uuid == communityId);
|
||||||
|
} catch (_) {}
|
||||||
|
try {
|
||||||
|
return state.communities.firstWhere((c) => c.uuid == communityId);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,7 @@ class _CreateNewRoutinesDialogState extends State<CreateNewRoutinesDialog> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
create: (BuildContext context) =>
|
create: (BuildContext context) => CreateRoutineBloc(),
|
||||||
CreateRoutineBloc()..add(const FetchCommunityEvent()),
|
|
||||||
child: BlocBuilder<CreateRoutineBloc, CreateRoutineState>(
|
child: BlocBuilder<CreateRoutineBloc, CreateRoutineState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
final _bloc = BlocProvider.of<CreateRoutineBloc>(context);
|
final _bloc = BlocProvider.of<CreateRoutineBloc>(context);
|
||||||
|
@ -1,12 +1,7 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
import 'space_tree_dropdown_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_event.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_state.dart';
|
|
||||||
|
|
||||||
class DropdownMenuContent extends StatefulWidget {
|
class DropdownMenuContent extends StatefulWidget {
|
||||||
final String? selectedSpaceId;
|
final String? selectedSpaceId;
|
||||||
@ -14,6 +9,7 @@ class DropdownMenuContent extends StatefulWidget {
|
|||||||
final VoidCallback onClose;
|
final VoidCallback onClose;
|
||||||
|
|
||||||
const DropdownMenuContent({
|
const DropdownMenuContent({
|
||||||
|
super.key,
|
||||||
required this.selectedSpaceId,
|
required this.selectedSpaceId,
|
||||||
required this.onChanged,
|
required this.onChanged,
|
||||||
required this.onClose,
|
required this.onClose,
|
||||||
@ -26,6 +22,7 @@ class DropdownMenuContent extends StatefulWidget {
|
|||||||
class _DropdownMenuContentState extends State<DropdownMenuContent> {
|
class _DropdownMenuContentState extends State<DropdownMenuContent> {
|
||||||
final ScrollController _scrollController = ScrollController();
|
final ScrollController _scrollController = ScrollController();
|
||||||
final TextEditingController _searchController = TextEditingController();
|
final TextEditingController _searchController = TextEditingController();
|
||||||
|
Timer? _debounceTimer;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -35,43 +32,49 @@ class _DropdownMenuContentState extends State<DropdownMenuContent> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
|
_debounceTimer?.cancel();
|
||||||
_scrollController.dispose();
|
_scrollController.dispose();
|
||||||
_searchController.dispose();
|
_searchController.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onScroll() {
|
void _onScroll() {
|
||||||
final bloc = context.read<SpaceTreeBloc>();
|
final bloc = context.read<SpaceTreeDropdownBloc>();
|
||||||
final state = bloc.state;
|
final state = bloc.state;
|
||||||
if (_scrollController.position.pixels >=
|
if (_scrollController.position.pixels >=
|
||||||
_scrollController.position.maxScrollExtent - 30) {
|
_scrollController.position.maxScrollExtent - 30) {
|
||||||
if (state is SpaceTreeState && !state.paginationIsLoading) {
|
if (state.paginationModel?.hasNext == true &&
|
||||||
bloc.add(PaginationEvent(state.paginationModel, state.communityList));
|
!state.paginationIsLoading) {
|
||||||
|
bloc.add(PaginationEvent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _handleSearch(String query) {
|
||||||
|
_debounceTimer?.cancel();
|
||||||
|
_debounceTimer = Timer(const Duration(milliseconds: 500), () {
|
||||||
|
context.read<SpaceTreeDropdownBloc>().add(SearchQueryEvent(query));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ConstrainedBox(
|
return ConstrainedBox(
|
||||||
constraints: const BoxConstraints(maxHeight: 300),
|
constraints: const BoxConstraints(maxHeight: 300),
|
||||||
child: BlocBuilder<SpaceTreeBloc, SpaceTreeState>(
|
child: BlocBuilder<SpaceTreeDropdownBloc, SpaceTreeDropdownState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
final communities = state.searchQuery.isNotEmpty
|
final communities = state.searchQuery.isNotEmpty
|
||||||
? state.filteredCommunity
|
? state.filteredCommunities
|
||||||
: state.communityList;
|
: state.communities;
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
// Search bar
|
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: TextFormField(
|
child: TextFormField(
|
||||||
controller: _searchController,
|
controller: _searchController,
|
||||||
onChanged: (query) {
|
onChanged: _handleSearch,
|
||||||
context.read<SpaceTreeBloc>().add(SearchQueryEvent(query));
|
|
||||||
},
|
|
||||||
style: const TextStyle(fontSize: 14, color: Colors.black),
|
style: const TextStyle(fontSize: 14, color: Colors.black),
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText: 'Search for space...',
|
hintText: 'Search for space...',
|
||||||
@ -85,7 +88,6 @@ class _DropdownMenuContentState extends State<DropdownMenuContent> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
// Community list
|
|
||||||
Expanded(
|
Expanded(
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
controller: _scrollController,
|
controller: _scrollController,
|
||||||
@ -121,19 +123,12 @@ class _DropdownMenuContentState extends State<DropdownMenuContent> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
setState(() {
|
context
|
||||||
_searchController.clear();
|
.read<SpaceTreeDropdownBloc>()
|
||||||
_searchController.text.isEmpty
|
.add(SearchQueryEvent(''));
|
||||||
? context
|
|
||||||
.read<SpaceTreeBloc>()
|
|
||||||
.add(SearchQueryEvent(''))
|
|
||||||
: context.read<SpaceTreeBloc>().add(
|
|
||||||
SearchQueryEvent(_searchController.text));
|
|
||||||
});
|
|
||||||
// Future.delayed(const Duration(seconds: 1), () {
|
|
||||||
widget.onChanged(community.uuid);
|
widget.onChanged(community.uuid);
|
||||||
widget.onClose();
|
widget.onClose();
|
||||||
// });
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
|
import 'dart:async';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_tree/model/pagination_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
|
||||||
|
import 'package:syncrow_web/services/space_mana_api.dart';
|
||||||
part 'space_tree_dropdown_event.dart';
|
part 'space_tree_dropdown_event.dart';
|
||||||
part 'space_tree_dropdown_state.dart';
|
part 'space_tree_dropdown_state.dart';
|
||||||
|
|
||||||
@ -9,19 +13,158 @@ class SpaceTreeDropdownBloc
|
|||||||
: super(SpaceTreeDropdownState(selectedSpaceId: initialId)) {
|
: super(SpaceTreeDropdownState(selectedSpaceId: initialId)) {
|
||||||
on<SpaceTreeDropdownSelectEvent>(_onSelect);
|
on<SpaceTreeDropdownSelectEvent>(_onSelect);
|
||||||
on<SpaceTreeDropdownResetEvent>(_onReset);
|
on<SpaceTreeDropdownResetEvent>(_onReset);
|
||||||
|
on<FetchSpacesEvent>(_fetchSpaces);
|
||||||
|
on<SearchQueryEvent>(_onSearch);
|
||||||
|
on<PaginationEvent>(_onPagination);
|
||||||
|
on<DebouncedSearchEvent>(_onDebouncedSearch);
|
||||||
}
|
}
|
||||||
|
Timer? _debounceTimer;
|
||||||
|
|
||||||
void _onSelect(
|
void _onSelect(
|
||||||
SpaceTreeDropdownSelectEvent event,
|
SpaceTreeDropdownSelectEvent event,
|
||||||
Emitter<SpaceTreeDropdownState> emit,
|
Emitter<SpaceTreeDropdownState> emit,
|
||||||
) {
|
) {
|
||||||
emit(SpaceTreeDropdownState(selectedSpaceId: event.spaceId));
|
final exists = state.communities.any((c) => c.uuid == event.spaceId);
|
||||||
|
|
||||||
|
if (!exists) {
|
||||||
|
final community = state.filteredCommunities.firstWhere(
|
||||||
|
(c) => c.uuid == event.spaceId,
|
||||||
|
orElse: () => CommunityModel(
|
||||||
|
uuid: event.spaceId!,
|
||||||
|
name: 'Loading...',
|
||||||
|
createdAt: DateTime.now(),
|
||||||
|
updatedAt: DateTime.now(),
|
||||||
|
spaces: [],
|
||||||
|
description: ''),
|
||||||
|
);
|
||||||
|
|
||||||
|
emit(state.copyWith(
|
||||||
|
selectedSpaceId: event.spaceId,
|
||||||
|
communities: [...state.communities, community],
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
emit(state.copyWith(selectedSpaceId: event.spaceId));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onReset(
|
void _onReset(
|
||||||
SpaceTreeDropdownResetEvent event,
|
SpaceTreeDropdownResetEvent event,
|
||||||
Emitter<SpaceTreeDropdownState> emit,
|
Emitter<SpaceTreeDropdownState> emit,
|
||||||
) {
|
) {
|
||||||
emit(SpaceTreeDropdownState(selectedSpaceId: event.initialId));
|
emit(state.copyWith(selectedSpaceId: event.initialId));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
Future<void> _fetchSpaces(
|
||||||
|
FetchSpacesEvent event,
|
||||||
|
Emitter<SpaceTreeDropdownState> emit,
|
||||||
|
) async {
|
||||||
|
if (state.status != SpaceTreeDropdownStatus.initial) return;
|
||||||
|
emit(state.copyWith(status: SpaceTreeDropdownStatus.loading));
|
||||||
|
try {
|
||||||
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
final paginationModel = await CommunitySpaceManagementApi()
|
||||||
|
.fetchCommunitiesAndSpaces(projectId: projectUuid, page: 1);
|
||||||
|
|
||||||
|
emit(state.copyWith(
|
||||||
|
status: SpaceTreeDropdownStatus.success,
|
||||||
|
communities: paginationModel.communities,
|
||||||
|
filteredCommunities: paginationModel.communities,
|
||||||
|
paginationModel: paginationModel,
|
||||||
|
));
|
||||||
|
} catch (e) {
|
||||||
|
emit(state.copyWith(
|
||||||
|
status: SpaceTreeDropdownStatus.failure,
|
||||||
|
errorMessage: 'Error loading communities: $e',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onSearch(
|
||||||
|
SearchQueryEvent event,
|
||||||
|
Emitter<SpaceTreeDropdownState> emit,
|
||||||
|
) {
|
||||||
|
_debounceTimer?.cancel();
|
||||||
|
_debounceTimer = Timer(const Duration(seconds: 1), () {
|
||||||
|
add(DebouncedSearchEvent(event.searchQuery));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _onDebouncedSearch(
|
||||||
|
DebouncedSearchEvent event,
|
||||||
|
Emitter<SpaceTreeDropdownState> emit,
|
||||||
|
) async {
|
||||||
|
emit(state.copyWith(isSearching: true));
|
||||||
|
|
||||||
|
try {
|
||||||
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
final paginationModel =
|
||||||
|
await CommunitySpaceManagementApi().fetchCommunitiesAndSpaces(
|
||||||
|
projectId: projectUuid,
|
||||||
|
page: 1,
|
||||||
|
search: event.searchQuery,
|
||||||
|
);
|
||||||
|
|
||||||
|
emit(state.copyWith(
|
||||||
|
filteredCommunities: paginationModel.communities,
|
||||||
|
isSearching: false,
|
||||||
|
searchQuery: event.searchQuery,
|
||||||
|
paginationModel: paginationModel,
|
||||||
|
));
|
||||||
|
} catch (e) {
|
||||||
|
emit(state.copyWith(
|
||||||
|
isSearching: false,
|
||||||
|
errorMessage: 'Error searching communities: $e',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> close() {
|
||||||
|
_debounceTimer?.cancel();
|
||||||
|
return super.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _onPagination(
|
||||||
|
PaginationEvent event,
|
||||||
|
Emitter<SpaceTreeDropdownState> emit,
|
||||||
|
) async {
|
||||||
|
if (state.paginationIsLoading || state.paginationModel?.hasNext != true) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
emit(state.copyWith(paginationIsLoading: true));
|
||||||
|
|
||||||
|
try {
|
||||||
|
final nextPage = state.paginationModel!.pageNum;
|
||||||
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
final newPagination = await CommunitySpaceManagementApi()
|
||||||
|
.fetchCommunitiesAndSpaces(projectId: projectUuid, page: nextPage);
|
||||||
|
|
||||||
|
final combinedCommunities = [
|
||||||
|
...state.communities,
|
||||||
|
...newPagination.communities
|
||||||
|
];
|
||||||
|
List<CommunityModel> filteredCommunities;
|
||||||
|
if (state.searchQuery.isNotEmpty) {
|
||||||
|
final query = state.searchQuery.toLowerCase();
|
||||||
|
filteredCommunities = combinedCommunities.where((community) {
|
||||||
|
return community.name.toLowerCase().contains(query);
|
||||||
|
}).toList();
|
||||||
|
} else {
|
||||||
|
filteredCommunities = combinedCommunities;
|
||||||
|
}
|
||||||
|
|
||||||
|
emit(state.copyWith(
|
||||||
|
communities: combinedCommunities,
|
||||||
|
filteredCommunities: filteredCommunities,
|
||||||
|
paginationModel: newPagination,
|
||||||
|
paginationIsLoading: false,
|
||||||
|
));
|
||||||
|
} catch (e) {
|
||||||
|
emit(state.copyWith(
|
||||||
|
paginationIsLoading: false,
|
||||||
|
errorMessage: 'Error loading more communities: $e',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -12,4 +12,20 @@ class SpaceTreeDropdownResetEvent extends SpaceTreeDropdownEvent {
|
|||||||
final String? initialId;
|
final String? initialId;
|
||||||
|
|
||||||
SpaceTreeDropdownResetEvent(this.initialId);
|
SpaceTreeDropdownResetEvent(this.initialId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class FetchSpacesEvent extends SpaceTreeDropdownEvent {}
|
||||||
|
|
||||||
|
class SearchQueryEvent extends SpaceTreeDropdownEvent {
|
||||||
|
final String searchQuery;
|
||||||
|
|
||||||
|
SearchQueryEvent(this.searchQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
class DebouncedSearchEvent extends SpaceTreeDropdownEvent {
|
||||||
|
final String searchQuery;
|
||||||
|
|
||||||
|
DebouncedSearchEvent(this.searchQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
class PaginationEvent extends SpaceTreeDropdownEvent {}
|
@ -1,7 +1,51 @@
|
|||||||
part of 'space_tree_dropdown_bloc.dart';
|
part of 'space_tree_dropdown_bloc.dart';
|
||||||
|
|
||||||
|
enum SpaceTreeDropdownStatus { initial, loading, success, failure }
|
||||||
|
|
||||||
class SpaceTreeDropdownState {
|
class SpaceTreeDropdownState {
|
||||||
final String? selectedSpaceId;
|
final String? selectedSpaceId;
|
||||||
|
final List<CommunityModel> communities;
|
||||||
|
final List<CommunityModel> filteredCommunities;
|
||||||
|
final SpaceTreeDropdownStatus status;
|
||||||
|
final String? errorMessage;
|
||||||
|
final String searchQuery;
|
||||||
|
final bool paginationIsLoading;
|
||||||
|
final PaginationModel? paginationModel;
|
||||||
|
final bool isSearching;
|
||||||
|
|
||||||
SpaceTreeDropdownState({this.selectedSpaceId});
|
SpaceTreeDropdownState({
|
||||||
|
this.selectedSpaceId,
|
||||||
|
this.communities = const [],
|
||||||
|
this.filteredCommunities = const [],
|
||||||
|
this.status = SpaceTreeDropdownStatus.initial,
|
||||||
|
this.errorMessage,
|
||||||
|
this.searchQuery = '',
|
||||||
|
this.paginationIsLoading = false,
|
||||||
|
this.paginationModel,
|
||||||
|
this.isSearching = false,
|
||||||
|
});
|
||||||
|
|
||||||
|
SpaceTreeDropdownState copyWith({
|
||||||
|
String? selectedSpaceId,
|
||||||
|
List<CommunityModel>? communities,
|
||||||
|
List<CommunityModel>? filteredCommunities,
|
||||||
|
SpaceTreeDropdownStatus? status,
|
||||||
|
String? errorMessage,
|
||||||
|
String? searchQuery,
|
||||||
|
bool? paginationIsLoading,
|
||||||
|
PaginationModel? paginationModel,
|
||||||
|
bool? isSearching,
|
||||||
|
}) {
|
||||||
|
return SpaceTreeDropdownState(
|
||||||
|
selectedSpaceId: selectedSpaceId ?? this.selectedSpaceId,
|
||||||
|
communities: communities ?? this.communities,
|
||||||
|
filteredCommunities: filteredCommunities ?? this.filteredCommunities,
|
||||||
|
status: status ?? this.status,
|
||||||
|
errorMessage: errorMessage ?? this.errorMessage,
|
||||||
|
searchQuery: searchQuery ?? this.searchQuery,
|
||||||
|
paginationIsLoading: paginationIsLoading ?? this.paginationIsLoading,
|
||||||
|
paginationModel: paginationModel ?? this.paginationModel,
|
||||||
|
isSearching: isSearching ?? this.isSearching,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
@ -118,6 +118,7 @@ class DeviceDialogHelper {
|
|||||||
uniqueCustomId: data['uniqueCustomId'],
|
uniqueCustomId: data['uniqueCustomId'],
|
||||||
deviceSelectedFunctions: deviceSelectedFunctions,
|
deviceSelectedFunctions: deviceSelectedFunctions,
|
||||||
device: data['device'],
|
device: data['device'],
|
||||||
|
dialogType: dialogType,
|
||||||
);
|
);
|
||||||
case 'NCPS':
|
case 'NCPS':
|
||||||
return FlushPresenceSensor.showFlushFunctionsDialog(
|
return FlushPresenceSensor.showFlushFunctionsDialog(
|
||||||
|
@ -65,7 +65,9 @@ class ACHelper {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
const DialogHeader('AC Functions'),
|
DialogHeader(dialogType == 'THEN'
|
||||||
|
? 'AC Functions'
|
||||||
|
: 'AC Conditions'),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Row(
|
child: Row(
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
@ -96,7 +96,9 @@ class _WallPresenceSensorState extends State<FlushPresenceSensor> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
const DialogHeader('Presence Sensor Condition'),
|
DialogHeader(widget.dialogType == 'THEN'
|
||||||
|
? 'Presence Sensor Functions'
|
||||||
|
: 'Presence Sensor Condition'),
|
||||||
Expanded(child: _buildMainContent(context, state)),
|
Expanded(child: _buildMainContent(context, state)),
|
||||||
_buildDialogFooter(context, state),
|
_buildDialogFooter(context, state),
|
||||||
],
|
],
|
||||||
|
@ -16,9 +16,10 @@ class GatewayDialog extends StatefulWidget {
|
|||||||
required this.functions,
|
required this.functions,
|
||||||
required this.deviceSelectedFunctions,
|
required this.deviceSelectedFunctions,
|
||||||
required this.device,
|
required this.device,
|
||||||
|
required this.dialogType,
|
||||||
super.key,
|
super.key,
|
||||||
});
|
});
|
||||||
|
final String dialogType;
|
||||||
final String? uniqueCustomId;
|
final String? uniqueCustomId;
|
||||||
final List<DeviceFunction> functions;
|
final List<DeviceFunction> functions;
|
||||||
final List<DeviceFunctionData> deviceSelectedFunctions;
|
final List<DeviceFunctionData> deviceSelectedFunctions;
|
||||||
@ -55,7 +56,9 @@ class _GatewayDialogState extends State<GatewayDialog> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
const DialogHeader('Gateway Conditions'),
|
DialogHeader(widget.dialogType == 'THEN'
|
||||||
|
? 'Gateway Functions'
|
||||||
|
: 'Gateway Conditions'),
|
||||||
Expanded(child: _buildMainContent(context, state)),
|
Expanded(child: _buildMainContent(context, state)),
|
||||||
_buildDialogFooter(context, state),
|
_buildDialogFooter(context, state),
|
||||||
],
|
],
|
||||||
|
@ -14,6 +14,7 @@ abstract final class GatewayHelper {
|
|||||||
required String? uniqueCustomId,
|
required String? uniqueCustomId,
|
||||||
required List<DeviceFunctionData> deviceSelectedFunctions,
|
required List<DeviceFunctionData> deviceSelectedFunctions,
|
||||||
required AllDevicesModel? device,
|
required AllDevicesModel? device,
|
||||||
|
required String dialogType,
|
||||||
}) async {
|
}) async {
|
||||||
return showDialog(
|
return showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
@ -27,6 +28,7 @@ abstract final class GatewayHelper {
|
|||||||
functions: functions,
|
functions: functions,
|
||||||
deviceSelectedFunctions: deviceSelectedFunctions,
|
deviceSelectedFunctions: deviceSelectedFunctions,
|
||||||
device: device,
|
device: device,
|
||||||
|
dialogType:dialogType,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -59,7 +59,9 @@ class OneGangSwitchHelper {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
const DialogHeader('1 Gang Light Switch Condition'),
|
DialogHeader(dialogType == 'THEN'
|
||||||
|
? '1 Gang Light Switch Functions'
|
||||||
|
: '1 Gang Light Switch Condition'),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
@ -246,9 +248,9 @@ class OneGangSwitchHelper {
|
|||||||
withSpecialChar: false,
|
withSpecialChar: false,
|
||||||
currentCondition: selectedFunctionData?.condition,
|
currentCondition: selectedFunctionData?.condition,
|
||||||
dialogType: dialogType,
|
dialogType: dialogType,
|
||||||
sliderRange: (0, 43200),
|
sliderRange: (0, 43200),
|
||||||
displayedValue: (initialValue ?? 0).toString(),
|
displayedValue: (initialValue ?? 0).toString(),
|
||||||
initialValue: (initialValue ?? 0).toString(),
|
initialValue: (initialValue ?? 0).toString(),
|
||||||
onConditionChanged: (condition) {
|
onConditionChanged: (condition) {
|
||||||
context.read<FunctionBloc>().add(
|
context.read<FunctionBloc>().add(
|
||||||
AddFunction(
|
AddFunction(
|
||||||
|
@ -98,7 +98,9 @@ class _EnergyClampDialogState extends State<EnergyClampDialog> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
const DialogHeader('Energy Clamp Conditions'),
|
DialogHeader(widget.dialogType == 'THEN'
|
||||||
|
? 'Energy Clamp Functions'
|
||||||
|
: 'Energy Clamp Conditions'),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Visibility(
|
child: Visibility(
|
||||||
visible: _functions.isNotEmpty,
|
visible: _functions.isNotEmpty,
|
||||||
|
@ -58,7 +58,9 @@ class ThreeGangSwitchHelper {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
const DialogHeader('3 Gangs Light Switch Condition'),
|
DialogHeader(dialogType == 'THEN'
|
||||||
|
? '3 Gangs Light Switch Functions'
|
||||||
|
: '3 Gangs Light Switch Condition'),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
|
@ -59,7 +59,9 @@ class TwoGangSwitchHelper {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
const DialogHeader('2 Gangs Light Switch Condition'),
|
DialogHeader(dialogType == 'THEN'
|
||||||
|
? '2 Gangs Light Switch Functions'
|
||||||
|
: '2 Gangs Light Switch Condition'),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
|
@ -63,7 +63,8 @@ class _WallPresenceSensorState extends State<WallPresenceSensor> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_wpsFunctions = widget.functions.whereType<WpsFunctions>().where((function) {
|
_wpsFunctions =
|
||||||
|
widget.functions.whereType<WpsFunctions>().where((function) {
|
||||||
if (widget.dialogType == 'THEN') {
|
if (widget.dialogType == 'THEN') {
|
||||||
return function.type == 'THEN' || function.type == 'BOTH';
|
return function.type == 'THEN' || function.type == 'BOTH';
|
||||||
}
|
}
|
||||||
@ -97,7 +98,9 @@ class _WallPresenceSensorState extends State<WallPresenceSensor> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
const DialogHeader('Presence Sensor Condition'),
|
DialogHeader(widget.dialogType == 'THEN'
|
||||||
|
? 'Presence Sensor Functions'
|
||||||
|
: 'Presence Sensor Condition'),
|
||||||
Expanded(child: _buildMainContent(context, state)),
|
Expanded(child: _buildMainContent(context, state)),
|
||||||
_buildDialogFooter(context, state),
|
_buildDialogFooter(context, state),
|
||||||
],
|
],
|
||||||
|
@ -93,7 +93,9 @@ class _WaterHeaterDialogRoutinesState extends State<WaterHeaterDialogRoutines> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
const DialogHeader('Water Heater Condition'),
|
DialogHeader(widget.dialogType == 'THEN'
|
||||||
|
? 'Water Heater Funtions'
|
||||||
|
: 'Water Heater Condition'),
|
||||||
Expanded(child: _buildMainContent(context, state)),
|
Expanded(child: _buildMainContent(context, state)),
|
||||||
_buildDialogFooter(context, state),
|
_buildDialogFooter(context, state),
|
||||||
],
|
],
|
||||||
|
@ -1,26 +0,0 @@
|
|||||||
//
|
|
||||||
// Generated file. Do not edit.
|
|
||||||
//
|
|
||||||
|
|
||||||
import FlutterMacOS
|
|
||||||
import Foundation
|
|
||||||
|
|
||||||
import firebase_analytics
|
|
||||||
import firebase_core
|
|
||||||
import firebase_crashlytics
|
|
||||||
import firebase_database
|
|
||||||
import flutter_secure_storage_macos
|
|
||||||
import path_provider_foundation
|
|
||||||
import shared_preferences_foundation
|
|
||||||
import url_launcher_macos
|
|
||||||
|
|
||||||
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
|
||||||
FirebaseAnalyticsPlugin.register(with: registry.registrar(forPlugin: "FirebaseAnalyticsPlugin"))
|
|
||||||
FLTFirebaseCorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseCorePlugin"))
|
|
||||||
FLTFirebaseCrashlyticsPlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseCrashlyticsPlugin"))
|
|
||||||
FLTFirebaseDatabasePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseDatabasePlugin"))
|
|
||||||
FlutterSecureStoragePlugin.register(with: registry.registrar(forPlugin: "FlutterSecureStoragePlugin"))
|
|
||||||
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
|
|
||||||
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
|
|
||||||
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
|
|
||||||
}
|
|
Reference in New Issue
Block a user