mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-15 17:47:53 +00:00
Compare commits
144 Commits
SP-1620-FE
...
Cancel-but
Author | SHA1 | Date | |
---|---|---|---|
c6e98fa245 | |||
db9e856bca | |||
07435ec89e | |||
2a2fb7ffca | |||
5a2299ea2f | |||
90f8305aa1 | |||
329b2ba472 | |||
0fb9149613 | |||
87b45fff1d | |||
95ae50d12d | |||
479aa4a091 | |||
75efc595b4 | |||
8bc7a3daa2 | |||
03a6c5474b | |||
ada7daf179 | |||
4bdb487094 | |||
f8e4c89cdb | |||
7d4cdba0ef | |||
a78b5993a9 | |||
0e7109a19e | |||
ff3d5cd996 | |||
5f30a5a61b | |||
0712e6d64b | |||
a493ae08ce | |||
27349a6cc0 | |||
d17d4184be | |||
41d4fbb555 | |||
fccb5cbbab | |||
48d7ab430f | |||
28ac911f3f | |||
a793cc3967 | |||
09446844b0 | |||
f02788eaa5 | |||
614db4333c | |||
b79ab06d95 | |||
0a424300aa | |||
8494f0a8f1 | |||
ec12b970b0 | |||
65ed94eb08 | |||
51c088d998 | |||
2f233db332 | |||
1f82e84115 | |||
5da25d8ecb | |||
23c3bf11f9 | |||
5201a65a97 | |||
e4cc5fce50 | |||
8dea89db0e | |||
ad5ada9d55 | |||
7172a0e3fb | |||
78898968e8 | |||
666c64231f | |||
5b5a94cf65 | |||
d45fa4c957 | |||
e39c6abd32 | |||
fc6ea640a7 | |||
09c44f8a5f | |||
c178c36824 | |||
ce96afd7af | |||
27dfa0a05a | |||
78979a4375 | |||
ea19387605 | |||
5b33a8617e | |||
34565a7dab | |||
caf1ff5c7e | |||
01e8002c43 | |||
63da660ece | |||
567d0e2d20 | |||
45e6ea3259 | |||
e942957a47 | |||
b9a3b9c719 | |||
f5500dfe50 | |||
20d044f2e5 | |||
8caee32822 | |||
6c4bc0d634 | |||
1ba1aba54e | |||
09f2123946 | |||
8fc6e54ecc | |||
5d3380ef82 | |||
5b0710957d | |||
056a1daadc | |||
0132805713 | |||
35f975b261 | |||
9600f4fb8b | |||
5cd1384000 | |||
0260523121 | |||
6af96fadbd | |||
737762bbaf | |||
6bcfb77a06 | |||
6b76827f21 | |||
519285fa7c | |||
3eb38d28f7 | |||
2108622b5b | |||
ac44af54a3 | |||
aa141ef54d | |||
b0aea94b91 | |||
96f463229c | |||
4d9145a953 | |||
a2f897c3a6 | |||
249c2fb172 | |||
7a8537d39c | |||
1da0cdad4b | |||
d10df2ffb8 | |||
6ff9c602f1 | |||
5f20d52e57 | |||
362557d0d0 | |||
312d185932 | |||
89e12e47da | |||
a0d9819532 | |||
1316820954 | |||
5591c78d88 | |||
eaff7c4a52 | |||
37b21ecdfb | |||
1567f10827 | |||
cdbd90b54c | |||
03f5c869c6 | |||
4f98891902 | |||
7002bbfa04 | |||
f19120c754 | |||
6b3eca23af | |||
4f4f11c330 | |||
8a25fa798c | |||
584845ffdc | |||
6612e91430 | |||
56c613fb0c | |||
8d2d9dd0bb | |||
cfc68f1568 | |||
02e08ad92f | |||
d7899a24f5 | |||
800c0ba47f | |||
fe4e775902 | |||
5247856cb4 | |||
4a8b8a32ba | |||
2abce77eb5 | |||
7efd1c3c87 | |||
7a0d9aefb7 | |||
21cc25cfc4 | |||
e2ec4bbf31 | |||
51b46ae197 | |||
36ee22603a | |||
b0abd42b0c | |||
ba4da78846 | |||
dc20d69f20 | |||
cf6ec231dc | |||
d0530f7fc3 |
10
.github/.github/dependabot.yaml
vendored
Normal file
10
.github/.github/dependabot.yaml
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: "github-actions"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "daily"
|
||||||
|
- package-ecosystem: "pub"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "daily"
|
BIN
assets/images/autocad_occupancy_image.png
Normal file
BIN
assets/images/autocad_occupancy_image.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 290 KiB |
10
lib/common/widgets/app_loading_indicator.dart
Normal file
10
lib/common/widgets/app_loading_indicator.dart
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class AppLoadingIndicator extends StatelessWidget {
|
||||||
|
const AppLoadingIndicator({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return const Center(child: CircularProgressIndicator());
|
||||||
|
}
|
||||||
|
}
|
@ -11,7 +11,6 @@ import 'package:syncrow_web/pages/home/bloc/home_event.dart';
|
|||||||
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_bloc.dart';
|
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_event.dart';
|
|
||||||
import 'package:syncrow_web/pages/visitor_password/bloc/visitor_password_bloc.dart';
|
import 'package:syncrow_web/pages/visitor_password/bloc/visitor_password_bloc.dart';
|
||||||
import 'package:syncrow_web/services/locator.dart';
|
import 'package:syncrow_web/services/locator.dart';
|
||||||
import 'package:syncrow_web/utils/app_routes.dart';
|
import 'package:syncrow_web/utils/app_routes.dart';
|
||||||
@ -21,8 +20,10 @@ import 'package:syncrow_web/utils/theme/theme.dart';
|
|||||||
|
|
||||||
Future<void> main() async {
|
Future<void> main() async {
|
||||||
try {
|
try {
|
||||||
const environment =
|
const environment = String.fromEnvironment(
|
||||||
String.fromEnvironment('FLAVOR', defaultValue: 'production');
|
'FLAVOR',
|
||||||
|
defaultValue: 'production',
|
||||||
|
);
|
||||||
await dotenv.load(fileName: '.env.$environment');
|
await dotenv.load(fileName: '.env.$environment');
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
await Firebase.initializeApp(
|
await Firebase.initializeApp(
|
||||||
@ -40,7 +41,7 @@ class MyApp extends StatelessWidget {
|
|||||||
initialLocation: RoutesConst.auth,
|
initialLocation: RoutesConst.auth,
|
||||||
routes: AppRoutes.getRoutes(),
|
routes: AppRoutes.getRoutes(),
|
||||||
redirect: (context, state) async {
|
redirect: (context, state) async {
|
||||||
String checkToken = await AuthBloc.getTokenAndValidate();
|
final checkToken = await AuthBloc.getTokenAndValidate();
|
||||||
final loggedIn = checkToken == 'Success';
|
final loggedIn = checkToken == 'Success';
|
||||||
final goingToLogin = state.uri.toString() == RoutesConst.auth;
|
final goingToLogin = state.uri.toString() == RoutesConst.auth;
|
||||||
|
|
||||||
@ -58,8 +59,7 @@ class MyApp extends StatelessWidget {
|
|||||||
BlocProvider<CreateRoutineBloc>(
|
BlocProvider<CreateRoutineBloc>(
|
||||||
create: (context) => CreateRoutineBloc(),
|
create: (context) => CreateRoutineBloc(),
|
||||||
),
|
),
|
||||||
BlocProvider(
|
BlocProvider(create: (context) => HomeBloc()..add(FetchUserInfo())),
|
||||||
create: (context) => HomeBloc()..add(const FetchUserInfo())),
|
|
||||||
BlocProvider<VisitorPasswordBloc>(
|
BlocProvider<VisitorPasswordBloc>(
|
||||||
create: (context) => VisitorPasswordBloc(),
|
create: (context) => VisitorPasswordBloc(),
|
||||||
),
|
),
|
||||||
@ -67,7 +67,7 @@ class MyApp extends StatelessWidget {
|
|||||||
create: (context) => RoutineBloc(),
|
create: (context) => RoutineBloc(),
|
||||||
),
|
),
|
||||||
BlocProvider<SpaceTreeBloc>(
|
BlocProvider<SpaceTreeBloc>(
|
||||||
create: (context) => SpaceTreeBloc()..add(InitialEvent()),
|
create: (context) => SpaceTreeBloc(),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
child: MaterialApp.router(
|
child: MaterialApp.router(
|
||||||
|
@ -11,7 +11,6 @@ import 'package:syncrow_web/pages/home/bloc/home_event.dart';
|
|||||||
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_bloc.dart';
|
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_event.dart';
|
|
||||||
import 'package:syncrow_web/pages/visitor_password/bloc/visitor_password_bloc.dart';
|
import 'package:syncrow_web/pages/visitor_password/bloc/visitor_password_bloc.dart';
|
||||||
import 'package:syncrow_web/services/locator.dart';
|
import 'package:syncrow_web/services/locator.dart';
|
||||||
import 'package:syncrow_web/utils/app_routes.dart';
|
import 'package:syncrow_web/utils/app_routes.dart';
|
||||||
@ -21,7 +20,10 @@ import 'package:syncrow_web/utils/theme/theme.dart';
|
|||||||
|
|
||||||
Future<void> main() async {
|
Future<void> main() async {
|
||||||
try {
|
try {
|
||||||
const environment = String.fromEnvironment('FLAVOR', defaultValue: 'development');
|
const environment = String.fromEnvironment(
|
||||||
|
'FLAVOR',
|
||||||
|
defaultValue: 'development',
|
||||||
|
);
|
||||||
await dotenv.load(fileName: '.env.$environment');
|
await dotenv.load(fileName: '.env.$environment');
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
await Firebase.initializeApp(
|
await Firebase.initializeApp(
|
||||||
@ -39,7 +41,7 @@ class MyApp extends StatelessWidget {
|
|||||||
initialLocation: RoutesConst.auth,
|
initialLocation: RoutesConst.auth,
|
||||||
routes: AppRoutes.getRoutes(),
|
routes: AppRoutes.getRoutes(),
|
||||||
redirect: (context, state) async {
|
redirect: (context, state) async {
|
||||||
String checkToken = await AuthBloc.getTokenAndValidate();
|
final checkToken = await AuthBloc.getTokenAndValidate();
|
||||||
final loggedIn = checkToken == 'Success';
|
final loggedIn = checkToken == 'Success';
|
||||||
final goingToLogin = state.uri.toString() == RoutesConst.auth;
|
final goingToLogin = state.uri.toString() == RoutesConst.auth;
|
||||||
|
|
||||||
@ -57,7 +59,7 @@ class MyApp extends StatelessWidget {
|
|||||||
BlocProvider<CreateRoutineBloc>(
|
BlocProvider<CreateRoutineBloc>(
|
||||||
create: (context) => CreateRoutineBloc(),
|
create: (context) => CreateRoutineBloc(),
|
||||||
),
|
),
|
||||||
BlocProvider(create: (context) => HomeBloc()..add(const FetchUserInfo())),
|
BlocProvider(create: (context) => HomeBloc()..add(FetchUserInfo())),
|
||||||
BlocProvider<VisitorPasswordBloc>(
|
BlocProvider<VisitorPasswordBloc>(
|
||||||
create: (context) => VisitorPasswordBloc(),
|
create: (context) => VisitorPasswordBloc(),
|
||||||
),
|
),
|
||||||
@ -65,7 +67,7 @@ class MyApp extends StatelessWidget {
|
|||||||
create: (context) => RoutineBloc(),
|
create: (context) => RoutineBloc(),
|
||||||
),
|
),
|
||||||
BlocProvider<SpaceTreeBloc>(
|
BlocProvider<SpaceTreeBloc>(
|
||||||
create: (context) => SpaceTreeBloc()..add(InitialEvent()),
|
create: (context) => SpaceTreeBloc(),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
child: MaterialApp.router(
|
child: MaterialApp.router(
|
||||||
|
@ -11,7 +11,6 @@ import 'package:syncrow_web/pages/home/bloc/home_event.dart';
|
|||||||
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_bloc.dart';
|
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_event.dart';
|
|
||||||
import 'package:syncrow_web/pages/visitor_password/bloc/visitor_password_bloc.dart';
|
import 'package:syncrow_web/pages/visitor_password/bloc/visitor_password_bloc.dart';
|
||||||
import 'package:syncrow_web/services/locator.dart';
|
import 'package:syncrow_web/services/locator.dart';
|
||||||
import 'package:syncrow_web/utils/app_routes.dart';
|
import 'package:syncrow_web/utils/app_routes.dart';
|
||||||
@ -39,7 +38,7 @@ class MyApp extends StatelessWidget {
|
|||||||
initialLocation: RoutesConst.auth,
|
initialLocation: RoutesConst.auth,
|
||||||
routes: AppRoutes.getRoutes(),
|
routes: AppRoutes.getRoutes(),
|
||||||
redirect: (context, state) async {
|
redirect: (context, state) async {
|
||||||
String checkToken = await AuthBloc.getTokenAndValidate();
|
final checkToken = await AuthBloc.getTokenAndValidate();
|
||||||
final loggedIn = checkToken == 'Success';
|
final loggedIn = checkToken == 'Success';
|
||||||
final goingToLogin = state.uri.toString() == RoutesConst.auth;
|
final goingToLogin = state.uri.toString() == RoutesConst.auth;
|
||||||
|
|
||||||
@ -57,7 +56,7 @@ class MyApp extends StatelessWidget {
|
|||||||
BlocProvider<CreateRoutineBloc>(
|
BlocProvider<CreateRoutineBloc>(
|
||||||
create: (context) => CreateRoutineBloc(),
|
create: (context) => CreateRoutineBloc(),
|
||||||
),
|
),
|
||||||
BlocProvider(create: (context) => HomeBloc()..add(const FetchUserInfo())),
|
BlocProvider(create: (context) => HomeBloc()..add(FetchUserInfo())),
|
||||||
BlocProvider<VisitorPasswordBloc>(
|
BlocProvider<VisitorPasswordBloc>(
|
||||||
create: (context) => VisitorPasswordBloc(),
|
create: (context) => VisitorPasswordBloc(),
|
||||||
),
|
),
|
||||||
@ -65,7 +64,7 @@ class MyApp extends StatelessWidget {
|
|||||||
create: (context) => RoutineBloc(),
|
create: (context) => RoutineBloc(),
|
||||||
),
|
),
|
||||||
BlocProvider<SpaceTreeBloc>(
|
BlocProvider<SpaceTreeBloc>(
|
||||||
create: (context) => SpaceTreeBloc()..add(InitialEvent()),
|
create: (context) => SpaceTreeBloc(),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
child: MaterialApp.router(
|
child: MaterialApp.router(
|
||||||
|
@ -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];
|
||||||
}
|
}
|
||||||
|
@ -38,9 +38,9 @@ class RangeOfAqiValue extends Equatable {
|
|||||||
factory RangeOfAqiValue.fromJson(Map<String, dynamic> json) {
|
factory RangeOfAqiValue.fromJson(Map<String, dynamic> json) {
|
||||||
return RangeOfAqiValue(
|
return RangeOfAqiValue(
|
||||||
type: json['type'] as String,
|
type: json['type'] as String,
|
||||||
min: (json['min'] as num).toDouble(),
|
min: (json['min'] as num? ?? 0).toDouble(),
|
||||||
average: (json['average'] as num).toDouble(),
|
average: (json['average'] as num? ?? 0).toDouble(),
|
||||||
max: (json['max'] as num).toDouble(),
|
max: (json['max'] as num? ?? 0).toDouble(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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,11 +23,14 @@ 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;
|
||||||
|
if (shouldFetchAnalyticsDevices) {
|
||||||
loadAnalyticsDevices(
|
loadAnalyticsDevices(
|
||||||
context,
|
context,
|
||||||
communityUuid: communityUuid,
|
communityUuid: communityUuid,
|
||||||
spaceUuid: spaceUuid,
|
spaceUuid: spaceUuid,
|
||||||
);
|
);
|
||||||
|
}
|
||||||
loadRangeOfAqi(
|
loadRangeOfAqi(
|
||||||
context,
|
context,
|
||||||
spaceUuid: spaceUuid,
|
spaceUuid: spaceUuid,
|
||||||
@ -36,6 +40,7 @@ abstract final class FetchAirQualityDataHelper {
|
|||||||
context,
|
context,
|
||||||
spaceUuid: spaceUuid,
|
spaceUuid: spaceUuid,
|
||||||
date: date,
|
date: date,
|
||||||
|
aqiType: aqiType,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,10 +109,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,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ abstract final class RangeOfAqiChartsHelper {
|
|||||||
return titlesData.copyWith(
|
return titlesData.copyWith(
|
||||||
bottomTitles: titlesData.bottomTitles.copyWith(
|
bottomTitles: titlesData.bottomTitles.copyWith(
|
||||||
sideTitles: titlesData.bottomTitles.sideTitles.copyWith(
|
sideTitles: titlesData.bottomTitles.sideTitles.copyWith(
|
||||||
|
reservedSize: 36,
|
||||||
getTitlesWidget: (value, meta) => Padding(
|
getTitlesWidget: (value, meta) => Padding(
|
||||||
padding: const EdgeInsetsDirectional.only(top: 20.0),
|
padding: const EdgeInsetsDirectional.only(top: 20.0),
|
||||||
child: Text(
|
child: Text(
|
||||||
@ -40,6 +41,7 @@ abstract final class RangeOfAqiChartsHelper {
|
|||||||
reservedSize: 70,
|
reservedSize: 70,
|
||||||
interval: 50,
|
interval: 50,
|
||||||
maxIncluded: false,
|
maxIncluded: false,
|
||||||
|
minIncluded: true,
|
||||||
getTitlesWidget: (value, meta) {
|
getTitlesWidget: (value, meta) {
|
||||||
final text = value >= 300 ? '301+' : value.toInt().toString();
|
final text = value >= 300 ? '301+' : value.toInt().toString();
|
||||||
return Padding(
|
return Padding(
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/modules/air_quality/widgets/air_quality_end_side_widget.dart';
|
import 'package:syncrow_web/pages/analytics/modules/air_quality/widgets/air_quality_end_side_widget.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/modules/air_quality/widgets/aqi_distribution_chart_box.dart';
|
import 'package:syncrow_web/pages/analytics/modules/air_quality/widgets/aqi_distribution_chart_box.dart';
|
||||||
|
import 'package:syncrow_web/pages/analytics/modules/air_quality/widgets/aqi_legend.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/modules/air_quality/widgets/range_of_aqi_chart_box.dart';
|
import 'package:syncrow_web/pages/analytics/modules/air_quality/widgets/range_of_aqi_chart_box.dart';
|
||||||
|
|
||||||
class AirQualityView extends StatelessWidget {
|
class AirQualityView extends StatelessWidget {
|
||||||
@ -20,6 +21,10 @@ class AirQualityView extends StatelessWidget {
|
|||||||
child: Column(
|
child: Column(
|
||||||
spacing: 32,
|
spacing: 32,
|
||||||
children: [
|
children: [
|
||||||
|
SizedBox(
|
||||||
|
height: height * 0.1,
|
||||||
|
child: const AqiLegend(),
|
||||||
|
),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
height: height * 1.2,
|
height: height * 1.2,
|
||||||
child: const AirQualityEndSideWidget(),
|
child: const AirQualityEndSideWidget(),
|
||||||
@ -40,7 +45,7 @@ class AirQualityView extends StatelessWidget {
|
|||||||
return SingleChildScrollView(
|
return SingleChildScrollView(
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: _padding,
|
padding: _padding,
|
||||||
height: height * 1.1,
|
height: height * 1.2,
|
||||||
child: const Column(
|
child: const Column(
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
@ -52,8 +57,9 @@ class AirQualityView extends StatelessWidget {
|
|||||||
child: Column(
|
child: Column(
|
||||||
spacing: 20,
|
spacing: 20,
|
||||||
children: [
|
children: [
|
||||||
Expanded(child: RangeOfAqiChartBox()),
|
Expanded(flex: 2, child: AqiLegend()),
|
||||||
Expanded(child: AqiDistributionChartBox()),
|
Expanded(flex: 12, child: RangeOfAqiChartBox()),
|
||||||
|
Expanded(flex: 12, child: AqiDistributionChartBox()),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -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,30 @@ 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) {
|
final groups = <BarChartGroupData>[];
|
||||||
final data = sortedData[index];
|
for (var i = 0; i < chartData.length; i++) {
|
||||||
|
final data = chartData[i];
|
||||||
|
final isAllZero = data.data.every((d) => d.percentage == 0);
|
||||||
|
if (isAllZero) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
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),
|
||||||
@ -65,13 +61,15 @@ class AqiDistributionChart extends StatelessWidget {
|
|||||||
currentY += percentageData.percentage + _rodStackItemsSpacing;
|
currentY += percentageData.percentage + _rodStackItemsSpacing;
|
||||||
isFirstElement = false;
|
isFirstElement = false;
|
||||||
}
|
}
|
||||||
|
groups.add(
|
||||||
return BarChartGroupData(
|
BarChartGroupData(
|
||||||
x: index,
|
x: i,
|
||||||
barRods: stackItems,
|
barRods: stackItems,
|
||||||
groupVertically: true,
|
groupVertically: true,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
});
|
}
|
||||||
|
return groups;
|
||||||
}
|
}
|
||||||
|
|
||||||
BarTouchData _barTouchData(BuildContext context) {
|
BarTouchData _barTouchData(BuildContext context) {
|
||||||
@ -82,25 +80,27 @@ class AqiDistributionChart extends StatelessWidget {
|
|||||||
color: ColorsManager.semiTransparentBlack,
|
color: ColorsManager.semiTransparentBlack,
|
||||||
),
|
),
|
||||||
tooltipRoundedRadius: 16,
|
tooltipRoundedRadius: 16,
|
||||||
|
maxContentWidth: 500,
|
||||||
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: 11,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Sort data by type to ensure consistent order
|
for (final percentageData in data.data) {
|
||||||
final sortedPercentageData = List<AirQualityPercentageData>.from(data.data)
|
if (percentageData.percentage == 0) {
|
||||||
..sort((a, b) => a.type.compareTo(b.type));
|
continue;
|
||||||
|
}
|
||||||
for (final percentageData in sortedPercentageData) {
|
final percentage = percentageData.percentage.toStringAsFixed(1);
|
||||||
|
final type = percentageData.type[0].toUpperCase() +
|
||||||
|
percentageData.type.substring(1).replaceAll('_', ' ');
|
||||||
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 +109,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: 12,
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
),
|
),
|
||||||
|
textAlign: TextAlign.start,
|
||||||
children: children,
|
children: children,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -128,7 +129,6 @@ class AqiDistributionChart extends StatelessWidget {
|
|||||||
final leftTitles = titlesData.leftTitles.copyWith(
|
final leftTitles = titlesData.leftTitles.copyWith(
|
||||||
sideTitles: titlesData.leftTitles.sideTitles.copyWith(
|
sideTitles: titlesData.leftTitles.sideTitles.copyWith(
|
||||||
reservedSize: 70,
|
reservedSize: 70,
|
||||||
interval: 20,
|
|
||||||
maxIncluded: false,
|
maxIncluded: false,
|
||||||
minIncluded: true,
|
minIncluded: true,
|
||||||
getTitlesWidget: (value, meta) => Padding(
|
getTitlesWidget: (value, meta) => Padding(
|
||||||
@ -150,7 +150,7 @@ class AqiDistributionChart extends StatelessWidget {
|
|||||||
|
|
||||||
final bottomTitles = AxisTitles(
|
final bottomTitles = AxisTitles(
|
||||||
sideTitles: SideTitles(
|
sideTitles: SideTitles(
|
||||||
showTitles: true,
|
showTitles: chartData.isNotEmpty,
|
||||||
getTitlesWidget: (value, _) => FittedBox(
|
getTitlesWidget: (value, _) => FittedBox(
|
||||||
alignment: AlignmentDirectional.bottomCenter,
|
alignment: AlignmentDirectional.bottomCenter,
|
||||||
fit: BoxFit.scaleDown,
|
fit: BoxFit.scaleDown,
|
||||||
@ -158,7 +158,7 @@ class AqiDistributionChart extends StatelessWidget {
|
|||||||
chartData[value.toInt()].date.day.toString(),
|
chartData[value.toInt()].date.day.toString(),
|
||||||
style: context.textTheme.bodySmall?.copyWith(
|
style: context.textTheme.bodySmall?.copyWith(
|
||||||
color: ColorsManager.lightGreyColor,
|
color: ColorsManager.lightGreyColor,
|
||||||
fontSize: 8,
|
fontSize: 12,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -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});
|
||||||
@ -16,7 +19,7 @@ class AqiDistributionChartTitle extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
ChartsLoadingWidget(isLoading: isLoading),
|
ChartsLoadingWidget(isLoading: isLoading),
|
||||||
const Expanded(
|
const Expanded(
|
||||||
flex: 3,
|
flex: 4,
|
||||||
child: FittedBox(
|
child: FittedBox(
|
||||||
fit: BoxFit.scaleDown,
|
fit: BoxFit.scaleDown,
|
||||||
alignment: AlignmentDirectional.centerStart,
|
alignment: AlignmentDirectional.centerStart,
|
||||||
@ -25,20 +28,44 @@ class AqiDistributionChartTitle extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
FittedBox(
|
Expanded(
|
||||||
|
flex: 2,
|
||||||
|
child: FittedBox(
|
||||||
alignment: AlignmentDirectional.centerEnd,
|
alignment: AlignmentDirectional.centerEnd,
|
||||||
fit: BoxFit.scaleDown,
|
fit: BoxFit.scaleDown,
|
||||||
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:syncrow_web/pages/analytics/modules/air_quality/helpers/range_of_aqi_charts_helper.dart';
|
||||||
|
import 'package:syncrow_web/pages/analytics/modules/analytics/widgets/chart_informative_cell.dart';
|
||||||
|
import 'package:syncrow_web/utils/style.dart';
|
||||||
|
|
||||||
|
class AqiLegend extends StatelessWidget {
|
||||||
|
const AqiLegend({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Container(
|
||||||
|
padding: const EdgeInsetsDirectional.all(20),
|
||||||
|
decoration: subSectionContainerDecoration.copyWith(
|
||||||
|
borderRadius: BorderRadius.circular(20),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
spacing: 16,
|
||||||
|
children: RangeOfAqiChartsHelper.gradientData.map((e) {
|
||||||
|
return Flexible(
|
||||||
|
flex: 4,
|
||||||
|
child: FittedBox(
|
||||||
|
fit: BoxFit.fill,
|
||||||
|
child: ChartInformativeCell(
|
||||||
|
color: e.$1,
|
||||||
|
title: FittedBox(
|
||||||
|
fit: BoxFit.fill,
|
||||||
|
child: Text(e.$2),
|
||||||
|
),
|
||||||
|
height: null,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -47,19 +47,29 @@ class AqiLocationInfoCell extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Align(
|
Align(
|
||||||
alignment: AlignmentDirectional.bottomEnd,
|
alignment: AlignmentDirectional.bottomCenter,
|
||||||
child: Padding(
|
child: Row(
|
||||||
padding: const EdgeInsetsDirectional.all(10),
|
crossAxisAlignment: CrossAxisAlignment.end,
|
||||||
child: SizedBox(
|
children: [
|
||||||
height: 40,
|
Expanded(
|
||||||
width: 120,
|
child: SvgPicture.asset(
|
||||||
|
svgPath,
|
||||||
|
fit: BoxFit.scaleDown,
|
||||||
|
alignment: AlignmentDirectional.bottomStart,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
child: FittedBox(
|
child: FittedBox(
|
||||||
fit: BoxFit.scaleDown,
|
fit: BoxFit.scaleDown,
|
||||||
alignment: AlignmentDirectional.bottomEnd,
|
alignment: AlignmentDirectional.bottomEnd,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsetsDirectional.all(10),
|
||||||
child: Text(
|
child: Text(
|
||||||
value,
|
value,
|
||||||
style: context.textTheme.bodySmall?.copyWith(
|
style: context.textTheme.bodySmall?.copyWith(
|
||||||
color: ColorsManager.vividBlue.withValues(alpha: 0.7),
|
color: ColorsManager.vividBlue.withValues(
|
||||||
|
alpha: 0.7,
|
||||||
|
),
|
||||||
fontWeight: FontWeight.w700,
|
fontWeight: FontWeight.w700,
|
||||||
fontSize: 24,
|
fontSize: 24,
|
||||||
),
|
),
|
||||||
@ -67,16 +77,7 @@ class AqiLocationInfoCell extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
Align(
|
|
||||||
alignment: AlignmentDirectional.bottomStart,
|
|
||||||
child: SizedBox.square(
|
|
||||||
dimension: MediaQuery.sizeOf(context).width * 0.45,
|
|
||||||
child: FittedBox(
|
|
||||||
fit: BoxFit.scaleDown,
|
|
||||||
alignment: AlignmentDirectional.bottomStart,
|
|
||||||
child: SvgPicture.asset(svgPath),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
@ -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,10 +27,12 @@ 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';
|
||||||
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_event.dart';
|
||||||
import 'package:syncrow_web/services/api/http_service.dart';
|
import 'package:syncrow_web/services/api/http_service.dart';
|
||||||
import 'package:syncrow_web/utils/theme/responsive_text_theme.dart';
|
import 'package:syncrow_web/utils/theme/responsive_text_theme.dart';
|
||||||
import 'package:syncrow_web/web_layout/web_scaffold.dart';
|
import 'package:syncrow_web/web_layout/web_scaffold.dart';
|
||||||
@ -104,12 +106,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(
|
||||||
@ -130,9 +132,19 @@ class _AnalyticsPageState extends State<AnalyticsPage> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class AnalyticsPageForm extends StatelessWidget {
|
class AnalyticsPageForm extends StatefulWidget {
|
||||||
const AnalyticsPageForm({super.key});
|
const AnalyticsPageForm({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<AnalyticsPageForm> createState() => _AnalyticsPageFormState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _AnalyticsPageFormState extends State<AnalyticsPageForm> {
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
context.read<SpaceTreeBloc>().add(InitialEvent());
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return WebScaffold(
|
return WebScaffold(
|
||||||
|
@ -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,10 +60,9 @@ 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) {
|
||||||
@ -76,7 +75,6 @@ class _AnalyticsDateFilterButtonState extends State<AnalyticsDateFilterButton> {
|
|||||||
widget.onDateSelected?.call(value);
|
widget.onDateSelected?.call(value);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
};
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -118,7 +118,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 +126,9 @@ class AnalyticsPageTabsAndChildren extends StatelessWidget {
|
|||||||
communityUuid: communities.firstOrNull ?? '',
|
communityUuid: communities.firstOrNull ?? '',
|
||||||
spaceUuid: spaces.firstOrNull ?? '',
|
spaceUuid: spaces.firstOrNull ?? '',
|
||||||
);
|
);
|
||||||
|
return;
|
||||||
default:
|
default:
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -157,6 +158,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,
|
||||||
|
@ -7,16 +7,18 @@ class ChartInformativeCell extends StatelessWidget {
|
|||||||
required this.title,
|
required this.title,
|
||||||
required this.color,
|
required this.color,
|
||||||
this.hasBorder = false,
|
this.hasBorder = false,
|
||||||
|
this.height,
|
||||||
});
|
});
|
||||||
|
|
||||||
final Widget title;
|
final Widget title;
|
||||||
final Color color;
|
final Color color;
|
||||||
final bool hasBorder;
|
final bool hasBorder;
|
||||||
|
final double? height;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Container(
|
||||||
height: MediaQuery.sizeOf(context).height * 0.0385,
|
height: height ?? MediaQuery.sizeOf(context).height * 0.0385,
|
||||||
padding: const EdgeInsetsDirectional.symmetric(
|
padding: const EdgeInsetsDirectional.symmetric(
|
||||||
vertical: 8,
|
vertical: 8,
|
||||||
horizontal: 12,
|
horizontal: 12,
|
||||||
|
@ -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(
|
||||||
|
@ -46,7 +46,7 @@ class AnalyticsEnergyManagementView extends StatelessWidget {
|
|||||||
spacing: 32,
|
spacing: 32,
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
flex: 2,
|
flex: 7,
|
||||||
child: Column(
|
child: Column(
|
||||||
spacing: 20,
|
spacing: 20,
|
||||||
children: [
|
children: [
|
||||||
@ -55,7 +55,7 @@ class AnalyticsEnergyManagementView extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Expanded(child: PowerClampEnergyDataWidget()),
|
Expanded(flex: 4, child: PowerClampEnergyDataWidget()),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -31,12 +31,12 @@ class AnalyticsOccupancyView extends StatelessWidget {
|
|||||||
return SingleChildScrollView(
|
return SingleChildScrollView(
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: _padding,
|
padding: _padding,
|
||||||
height: height * 0.9,
|
height: height * 1,
|
||||||
child: const Row(
|
child: const Row(
|
||||||
spacing: 32,
|
spacing: 32,
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
flex: 5,
|
flex: 7,
|
||||||
child: Column(
|
child: Column(
|
||||||
spacing: 20,
|
spacing: 20,
|
||||||
children: [
|
children: [
|
||||||
@ -45,7 +45,7 @@ class AnalyticsOccupancyView extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Expanded(flex: 2, child: OccupancyEndSideBar()),
|
Expanded(flex: 4, child: OccupancyEndSideBar()),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -24,8 +24,9 @@ class OccupancyEndSideBar extends StatelessWidget {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
const AnalyticsSidebarHeader(title: 'Presnce Sensor'),
|
const AnalyticsSidebarHeader(title: 'Presnce Sensor'),
|
||||||
SizedBox(
|
Expanded(
|
||||||
height: MediaQuery.sizeOf(context).height * 0.2,
|
child: SizedBox(
|
||||||
|
// height: MediaQuery.sizeOf(context).height * 0.2,
|
||||||
child: PowerClampEnergyStatusWidget(
|
child: PowerClampEnergyStatusWidget(
|
||||||
status: [
|
status: [
|
||||||
PowerClampEnergyStatus(
|
PowerClampEnergyStatus(
|
||||||
@ -54,7 +55,14 @@ class OccupancyEndSideBar extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
|
Expanded(
|
||||||
|
flex: 2,
|
||||||
|
child: FittedBox(
|
||||||
|
child: Image.asset(Assets.autocadOccupancyImage),
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -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')}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,20 +50,11 @@ class _DynamicTableState extends State<DynamicTable> {
|
|||||||
bool _selectAll = false;
|
bool _selectAll = false;
|
||||||
final ScrollController _verticalScrollController = ScrollController();
|
final ScrollController _verticalScrollController = ScrollController();
|
||||||
final ScrollController _horizontalScrollController = ScrollController();
|
final ScrollController _horizontalScrollController = ScrollController();
|
||||||
late ScrollController _horizontalHeaderScrollController;
|
|
||||||
late ScrollController _horizontalBodyScrollController;
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_initializeSelection();
|
_initializeSelection();
|
||||||
_horizontalHeaderScrollController = ScrollController();
|
|
||||||
_horizontalBodyScrollController = ScrollController();
|
|
||||||
|
|
||||||
// Synchronize horizontal scrolling
|
|
||||||
_horizontalBodyScrollController.addListener(() {
|
|
||||||
_horizontalHeaderScrollController
|
|
||||||
.jumpTo(_horizontalBodyScrollController.offset);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -113,70 +104,58 @@ class _DynamicTableState extends State<DynamicTable> {
|
|||||||
context.read<DeviceManagementBloc>().add(UpdateSelection(_selectedRows));
|
context.read<DeviceManagementBloc>().add(UpdateSelection(_selectedRows));
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
_horizontalHeaderScrollController.dispose();
|
|
||||||
_horizontalBodyScrollController.dispose();
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Container(
|
||||||
decoration: widget.cellDecoration,
|
decoration: widget.cellDecoration,
|
||||||
|
child: Scrollbar(
|
||||||
|
controller: _verticalScrollController,
|
||||||
|
thumbVisibility: true,
|
||||||
|
trackVisibility: true,
|
||||||
|
child: Scrollbar(
|
||||||
|
//fixed the horizontal scrollbar issue
|
||||||
|
controller: _horizontalScrollController,
|
||||||
|
thumbVisibility: true,
|
||||||
|
trackVisibility: true,
|
||||||
|
notificationPredicate: (notif) => notif.depth == 1,
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
controller: _verticalScrollController,
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
controller: _horizontalScrollController,
|
||||||
|
scrollDirection: Axis.horizontal,
|
||||||
|
child: SizedBox(
|
||||||
|
width: widget.size.width,
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
Container(
|
Container(
|
||||||
decoration: widget.headerDecoration ??
|
decoration: widget.headerDecoration ??
|
||||||
const BoxDecoration(color: ColorsManager.boxColor),
|
const BoxDecoration(
|
||||||
child: SingleChildScrollView(
|
color: ColorsManager.boxColor,
|
||||||
scrollDirection: Axis.horizontal,
|
),
|
||||||
physics: const NeverScrollableScrollPhysics(),
|
|
||||||
controller: _horizontalHeaderScrollController,
|
|
||||||
child: SizedBox(
|
|
||||||
width: widget.size.width,
|
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
if (widget.withCheckBox) _buildSelectAllCheckbox(),
|
if (widget.withCheckBox) _buildSelectAllCheckbox(),
|
||||||
...List.generate(widget.headers.length, (index) {
|
...List.generate(widget.headers.length, (index) {
|
||||||
return _buildTableHeaderCell(
|
return _buildTableHeaderCell(
|
||||||
widget.headers[index], index);
|
widget.headers[index], index);
|
||||||
}),
|
})
|
||||||
|
//...widget.headers.map((header) => _buildTableHeaderCell(header)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
SizedBox(
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
child: Scrollbar(
|
|
||||||
controller: _verticalScrollController,
|
|
||||||
thumbVisibility: true,
|
|
||||||
trackVisibility: true,
|
|
||||||
child: SingleChildScrollView(
|
|
||||||
controller: _verticalScrollController,
|
|
||||||
child: Scrollbar(
|
|
||||||
controller: _horizontalBodyScrollController,
|
|
||||||
thumbVisibility: false,
|
|
||||||
trackVisibility: false,
|
|
||||||
notificationPredicate: (notif) => notif.depth == 1,
|
|
||||||
child: SingleChildScrollView(
|
|
||||||
scrollDirection: Axis.horizontal,
|
|
||||||
controller: _horizontalBodyScrollController,
|
|
||||||
child: Container(
|
|
||||||
color: ColorsManager.whiteColors,
|
|
||||||
child: SizedBox(
|
|
||||||
width: widget.size.width,
|
width: widget.size.width,
|
||||||
child: widget.isEmpty
|
child: widget.isEmpty
|
||||||
? _buildEmptyState()
|
? _buildEmptyState()
|
||||||
: Column(
|
: Column(
|
||||||
children: List.generate(widget.data.length,
|
children:
|
||||||
(rowIndex) {
|
List.generate(widget.data.length, (rowIndex) {
|
||||||
final row = widget.data[rowIndex];
|
final row = widget.data[rowIndex];
|
||||||
return Row(
|
return Row(
|
||||||
children: [
|
children: [
|
||||||
if (widget.withCheckBox)
|
if (widget.withCheckBox)
|
||||||
_buildRowCheckbox(rowIndex,
|
_buildRowCheckbox(
|
||||||
widget.size.height * 0.08),
|
rowIndex, widget.size.height * 0.08),
|
||||||
...row.asMap().entries.map((entry) {
|
...row.asMap().entries.map((entry) {
|
||||||
return _buildTableCell(
|
return _buildTableCell(
|
||||||
entry.value.toString(),
|
entry.value.toString(),
|
||||||
@ -190,35 +169,20 @@ class _DynamicTableState extends State<DynamicTable> {
|
|||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildSelectAllCheckbox() {
|
|
||||||
return Container(
|
|
||||||
width: 50,
|
|
||||||
decoration: const BoxDecoration(
|
|
||||||
border: Border.symmetric(
|
|
||||||
vertical: BorderSide(color: ColorsManager.boxDivider),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: Checkbox(
|
),
|
||||||
value: _selectAll,
|
),
|
||||||
onChanged: widget.withSelectAll && widget.data.isNotEmpty
|
|
||||||
? _toggleSelectAll
|
|
||||||
: null,
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildEmptyState() => Column(
|
Widget _buildEmptyState() => Container(
|
||||||
|
height: widget.size.height,
|
||||||
|
color: ColorsManager.whiteColors,
|
||||||
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Row(
|
Row(
|
||||||
@ -242,8 +206,27 @@ class _DynamicTableState extends State<DynamicTable> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
SizedBox(height: widget.size.height * 0.5),
|
||||||
],
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
Widget _buildSelectAllCheckbox() {
|
||||||
|
return Container(
|
||||||
|
width: 50,
|
||||||
|
decoration: const BoxDecoration(
|
||||||
|
border: Border.symmetric(
|
||||||
|
vertical: BorderSide(color: ColorsManager.boxDivider),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Checkbox(
|
||||||
|
value: _selectAll,
|
||||||
|
onChanged: widget.withSelectAll && widget.data.isNotEmpty
|
||||||
|
? _toggleSelectAll
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Widget _buildRowCheckbox(int index, double size) {
|
Widget _buildRowCheckbox(int index, double size) {
|
||||||
return Container(
|
return Container(
|
||||||
width: 50,
|
width: 50,
|
||||||
@ -298,12 +281,8 @@ class _DynamicTableState extends State<DynamicTable> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildTableCell(
|
Widget _buildTableCell(String content, double size,
|
||||||
String content,
|
{required int rowIndex, required int columnIndex}) {
|
||||||
double size, {
|
|
||||||
required int rowIndex,
|
|
||||||
required int columnIndex,
|
|
||||||
}) {
|
|
||||||
bool isBatteryLevel = content.endsWith('%');
|
bool isBatteryLevel = content.endsWith('%');
|
||||||
double? batteryLevel;
|
double? batteryLevel;
|
||||||
|
|
||||||
@ -311,7 +290,6 @@ class _DynamicTableState extends State<DynamicTable> {
|
|||||||
batteryLevel = double.tryParse(content.replaceAll('%', '').trim());
|
batteryLevel = double.tryParse(content.replaceAll('%', '').trim());
|
||||||
}
|
}
|
||||||
bool isSettingsColumn = widget.headers[columnIndex] == 'Settings';
|
bool isSettingsColumn = widget.headers[columnIndex] == 'Settings';
|
||||||
|
|
||||||
if (isSettingsColumn) {
|
if (isSettingsColumn) {
|
||||||
return buildSettingsIcon(
|
return buildSettingsIcon(
|
||||||
width: 120,
|
width: 120,
|
||||||
@ -416,11 +394,10 @@ class _DynamicTableState extends State<DynamicTable> {
|
|||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: Center(
|
child: Center(
|
||||||
child: SvgPicture.asset(
|
child: SvgPicture.asset(
|
||||||
Assets.settings, // ضع المسار الصحيح هنا
|
Assets.settings,
|
||||||
width: 40,
|
width: 40,
|
||||||
height: 22,
|
height: 22,
|
||||||
color: ColorsManager
|
color: ColorsManager.primaryColor,
|
||||||
.primaryColor, // نفس لون الأيقونة في الصورة
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -43,14 +43,15 @@ class DeviceManagementBloc
|
|||||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
if (spaceBloc.state.selectedCommunities.isEmpty) {
|
if (spaceBloc.state.selectedCommunities.isEmpty) {
|
||||||
devices = await DevicesManagementApi().fetchDevices('', '', projectUuid);
|
devices =
|
||||||
|
await DevicesManagementApi().fetchDevices('', '', projectUuid);
|
||||||
} else {
|
} else {
|
||||||
for (var community in spaceBloc.state.selectedCommunities) {
|
for (var community in spaceBloc.state.selectedCommunities) {
|
||||||
List<String> spacesList =
|
List<String> spacesList =
|
||||||
spaceBloc.state.selectedCommunityAndSpaces[community] ?? [];
|
spaceBloc.state.selectedCommunityAndSpaces[community] ?? [];
|
||||||
for (var space in spacesList) {
|
for (var space in spacesList) {
|
||||||
devices.addAll(await DevicesManagementApi().fetchDevices(
|
devices.addAll(await DevicesManagementApi()
|
||||||
community, space, projectUuid));
|
.fetchDevices(community, space, projectUuid));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -100,7 +101,7 @@ class DeviceManagementBloc
|
|||||||
));
|
));
|
||||||
|
|
||||||
if (currentProductName.isNotEmpty) {
|
if (currentProductName.isNotEmpty) {
|
||||||
add(SearchDevices(productName: currentProductName));
|
add(SearchDevices(deviceNameOrProductName: currentProductName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -269,34 +270,41 @@ class DeviceManagementBloc
|
|||||||
return 'All';
|
return 'All';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onSearchDevices(
|
void _onSearchDevices(
|
||||||
SearchDevices event, Emitter<DeviceManagementState> emit) {
|
SearchDevices event, Emitter<DeviceManagementState> emit) {
|
||||||
if ((event.community == null || event.community!.isEmpty) &&
|
if ((event.community == null || event.community!.isEmpty) &&
|
||||||
(event.unitName == null || event.unitName!.isEmpty) &&
|
(event.unitName == null || event.unitName!.isEmpty) &&
|
||||||
(event.productName == null || event.productName!.isEmpty)) {
|
(event.deviceNameOrProductName == null ||
|
||||||
|
event.deviceNameOrProductName!.isEmpty)) {
|
||||||
currentProductName = '';
|
currentProductName = '';
|
||||||
if (state is DeviceManagementFiltered) {
|
_filteredDevices = List.from(_devices);
|
||||||
add(FilterDevices(_getFilterFromIndex(_selectedIndex)));
|
emit(DeviceManagementLoaded(
|
||||||
} else {
|
devices: _devices,
|
||||||
|
selectedIndex: _selectedIndex,
|
||||||
|
onlineCount: _onlineCount,
|
||||||
|
offlineCount: _offlineCount,
|
||||||
|
lowBatteryCount: _lowBatteryCount,
|
||||||
|
selectedDevice: null,
|
||||||
|
isControlButtonEnabled: false,
|
||||||
|
));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
if (event.deviceNameOrProductName == currentProductName &&
|
||||||
|
|
||||||
if (event.productName == currentProductName &&
|
|
||||||
event.community == currentCommunity &&
|
event.community == currentCommunity &&
|
||||||
event.unitName == currentUnitName &&
|
event.unitName == currentUnitName &&
|
||||||
event.searchField) {
|
event.searchField) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
currentProductName = event.productName ?? '';
|
currentProductName = event.deviceNameOrProductName ?? '';
|
||||||
currentCommunity = event.community;
|
currentCommunity = event.community;
|
||||||
currentUnitName = event.unitName;
|
currentUnitName = event.unitName;
|
||||||
|
|
||||||
List<AllDevicesModel> devicesToSearch = _filteredDevices;
|
List<AllDevicesModel> devicesToSearch = _devices;
|
||||||
|
|
||||||
if (devicesToSearch.isNotEmpty) {
|
if (devicesToSearch.isNotEmpty) {
|
||||||
|
final searchText = event.deviceNameOrProductName?.toLowerCase() ?? '';
|
||||||
|
|
||||||
final filteredDevices = devicesToSearch.where((device) {
|
final filteredDevices = devicesToSearch.where((device) {
|
||||||
final matchesCommunity = event.community == null ||
|
final matchesCommunity = event.community == null ||
|
||||||
event.community!.isEmpty ||
|
event.community!.isEmpty ||
|
||||||
@ -304,31 +312,25 @@ class DeviceManagementBloc
|
|||||||
?.toLowerCase()
|
?.toLowerCase()
|
||||||
.contains(event.community!.toLowerCase()) ??
|
.contains(event.community!.toLowerCase()) ??
|
||||||
false);
|
false);
|
||||||
|
|
||||||
final matchesUnit = event.unitName == null ||
|
final matchesUnit = event.unitName == null ||
|
||||||
event.unitName!.isEmpty ||
|
event.unitName!.isEmpty ||
|
||||||
(device.spaces != null &&
|
(device.spaces != null &&
|
||||||
device.spaces!.isNotEmpty &&
|
device.spaces!.any((space) =>
|
||||||
device.spaces![0].spaceName!
|
space.spaceName != null &&
|
||||||
|
space.spaceName!
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.contains(event.unitName!.toLowerCase()));
|
.contains(event.unitName!.toLowerCase())));
|
||||||
final matchesProductName = event.productName == null ||
|
|
||||||
event.productName!.isEmpty ||
|
|
||||||
(device.name
|
|
||||||
?.toLowerCase()
|
|
||||||
.contains(event.productName!.toLowerCase()) ??
|
|
||||||
false);
|
|
||||||
final matchesDeviceName = event.productName == null ||
|
|
||||||
event.productName!.isEmpty ||
|
|
||||||
(device.categoryName
|
|
||||||
?.toLowerCase()
|
|
||||||
.contains(event.productName!.toLowerCase()) ??
|
|
||||||
false);
|
|
||||||
|
|
||||||
return matchesCommunity &&
|
final matchesSearchText = searchText.isEmpty ||
|
||||||
matchesUnit &&
|
(device.name?.toLowerCase().contains(searchText) ?? false) ||
|
||||||
(matchesProductName || matchesDeviceName);
|
(device.productName?.toLowerCase().contains(searchText) ?? false);
|
||||||
|
|
||||||
|
return matchesCommunity && matchesUnit && matchesSearchText;
|
||||||
}).toList();
|
}).toList();
|
||||||
|
|
||||||
|
_filteredDevices = filteredDevices;
|
||||||
|
|
||||||
emit(DeviceManagementFiltered(
|
emit(DeviceManagementFiltered(
|
||||||
filteredDevices: filteredDevices,
|
filteredDevices: filteredDevices,
|
||||||
selectedIndex: _selectedIndex,
|
selectedIndex: _selectedIndex,
|
||||||
|
@ -38,18 +38,18 @@ class SelectedFilterChanged extends DeviceManagementEvent {
|
|||||||
class SearchDevices extends DeviceManagementEvent {
|
class SearchDevices extends DeviceManagementEvent {
|
||||||
final String? community;
|
final String? community;
|
||||||
final String? unitName;
|
final String? unitName;
|
||||||
final String? productName;
|
final String? deviceNameOrProductName;
|
||||||
final bool searchField;
|
final bool searchField;
|
||||||
|
|
||||||
const SearchDevices({
|
const SearchDevices({
|
||||||
this.community,
|
this.community,
|
||||||
this.unitName,
|
this.unitName,
|
||||||
this.productName,
|
this.deviceNameOrProductName,
|
||||||
this.searchField = false,
|
this.searchField = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [community, unitName, productName];
|
List<Object?> get props => [community, unitName, deviceNameOrProductName];
|
||||||
}
|
}
|
||||||
|
|
||||||
class SelectDevice extends DeviceManagementEvent {
|
class SelectDevice extends DeviceManagementEvent {
|
||||||
|
@ -6,6 +6,7 @@ import 'package:syncrow_web/pages/device_managment/all_devices/models/device_tag
|
|||||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/room.dart';
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/room.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/unit.dart';
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/unit.dart';
|
||||||
import 'package:syncrow_web/pages/routines/models/ac/ac_function.dart';
|
import 'package:syncrow_web/pages/routines/models/ac/ac_function.dart';
|
||||||
|
import 'package:syncrow_web/pages/routines/models/curtain/curtain_function.dart';
|
||||||
import 'package:syncrow_web/pages/routines/models/device_functions.dart';
|
import 'package:syncrow_web/pages/routines/models/device_functions.dart';
|
||||||
import 'package:syncrow_web/pages/routines/models/flush/flush_functions.dart';
|
import 'package:syncrow_web/pages/routines/models/flush/flush_functions.dart';
|
||||||
import 'package:syncrow_web/pages/routines/models/gang_switches/one_gang_switch/one_gang_switch.dart';
|
import 'package:syncrow_web/pages/routines/models/gang_switches/one_gang_switch/one_gang_switch.dart';
|
||||||
@ -359,6 +360,14 @@ SOS
|
|||||||
uuid: uuid ?? '',
|
uuid: uuid ?? '',
|
||||||
name: name ?? '',
|
name: name ?? '',
|
||||||
);
|
);
|
||||||
|
case 'CUR':
|
||||||
|
return [
|
||||||
|
ControlCurtainFunction(
|
||||||
|
deviceId: uuid ?? '',
|
||||||
|
deviceName: name ?? '',
|
||||||
|
type: 'BOTH',
|
||||||
|
)
|
||||||
|
];
|
||||||
case 'NCPS':
|
case 'NCPS':
|
||||||
return [
|
return [
|
||||||
FlushPresenceDelayFunction(
|
FlushPresenceDelayFunction(
|
||||||
@ -441,15 +450,10 @@ SOS
|
|||||||
VoltageCStatusFunction(
|
VoltageCStatusFunction(
|
||||||
deviceId: uuid ?? '', deviceName: name ?? '', type: 'IF'),
|
deviceId: uuid ?? '', deviceName: name ?? '', type: 'IF'),
|
||||||
CurrentCStatusFunction(
|
CurrentCStatusFunction(
|
||||||
deviceId: uuid ?? '',
|
deviceId: uuid ?? '', deviceName: name ?? '', type: 'IF'),
|
||||||
deviceName: name ?? '',
|
|
||||||
type: 'IF'),
|
|
||||||
PowerFactorCStatusFunction(
|
PowerFactorCStatusFunction(
|
||||||
deviceId: uuid ?? '',
|
deviceId: uuid ?? '', deviceName: name ?? '', type: 'IF'),
|
||||||
deviceName: name ?? '',
|
|
||||||
type: 'IF'),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
@ -8,15 +8,28 @@ import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routi
|
|||||||
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routines/view/create_new_routine_view.dart';
|
import 'package:syncrow_web/pages/routines/view/create_new_routine_view.dart';
|
||||||
import 'package:syncrow_web/pages/routines/view/routines_view.dart';
|
import 'package:syncrow_web/pages/routines/view/routines_view.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_event.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||||
import 'package:syncrow_web/utils/theme/responsive_text_theme.dart';
|
import 'package:syncrow_web/utils/theme/responsive_text_theme.dart';
|
||||||
import 'package:syncrow_web/web_layout/web_scaffold.dart';
|
import 'package:syncrow_web/web_layout/web_scaffold.dart';
|
||||||
|
|
||||||
class DeviceManagementPage extends StatelessWidget with HelperResponsiveLayout {
|
class DeviceManagementPage extends StatefulWidget with HelperResponsiveLayout {
|
||||||
const DeviceManagementPage({super.key});
|
const DeviceManagementPage({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<DeviceManagementPage> createState() => _DeviceManagementPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _DeviceManagementPageState extends State<DeviceManagementPage> {
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
context.read<SpaceTreeBloc>().add(InitialEvent());
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MultiBlocProvider(
|
return MultiBlocProvider(
|
||||||
|
@ -53,7 +53,7 @@ class _DeviceSearchFiltersState extends State<DeviceSearchFilters>
|
|||||||
controller: controller,
|
controller: controller,
|
||||||
onSubmitted: () {
|
onSubmitted: () {
|
||||||
final searchDevicesEvent = SearchDevices(
|
final searchDevicesEvent = SearchDevices(
|
||||||
productName: _productNameController.text,
|
deviceNameOrProductName: _productNameController.text,
|
||||||
unitName: _unitNameController.text,
|
unitName: _unitNameController.text,
|
||||||
searchField: true,
|
searchField: true,
|
||||||
);
|
);
|
||||||
@ -68,7 +68,7 @@ class _DeviceSearchFiltersState extends State<DeviceSearchFilters>
|
|||||||
onSearch: () => context.read<DeviceManagementBloc>().add(
|
onSearch: () => context.read<DeviceManagementBloc>().add(
|
||||||
SearchDevices(
|
SearchDevices(
|
||||||
unitName: _unitNameController.text,
|
unitName: _unitNameController.text,
|
||||||
productName: _productNameController.text,
|
deviceNameOrProductName: _productNameController.text,
|
||||||
searchField: true,
|
searchField: true,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -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),
|
||||||
|
child: SubSpaceDialog(
|
||||||
subSpaces: subSpaces,
|
subSpaces: subSpaces,
|
||||||
selected: selected,
|
selected: selected,
|
||||||
onConfirmed: (selectedModel) {
|
|
||||||
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';
|
||||||
@ -64,9 +62,10 @@ class SubSpaceDialogButtons extends StatelessWidget {
|
|||||||
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 ?? '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
// ignore_for_file: invalid_use_of_visible_for_testing_member
|
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:firebase_database/firebase_database.dart';
|
import 'package:firebase_database/firebase_database.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
@ -16,45 +14,38 @@ class DoorLockBloc extends Bloc<DoorLockEvent, DoorLockState> {
|
|||||||
|
|
||||||
DoorLockBloc({required this.deviceId}) : super(DoorLockInitial()) {
|
DoorLockBloc({required this.deviceId}) : super(DoorLockInitial()) {
|
||||||
on<DoorLockFetchStatus>(_onFetchDeviceStatus);
|
on<DoorLockFetchStatus>(_onFetchDeviceStatus);
|
||||||
//on<DoorLockControl>(_onDoorLockControl);
|
|
||||||
on<UpdateLockEvent>(_updateLock);
|
on<UpdateLockEvent>(_updateLock);
|
||||||
on<DoorLockFactoryReset>(_onFactoryReset);
|
on<DoorLockFactoryReset>(_onFactoryReset);
|
||||||
on<StatusUpdated>(_onStatusUpdated);
|
on<StatusUpdated>(_onStatusUpdated);
|
||||||
}
|
}
|
||||||
|
|
||||||
_listenToChanges(deviceId) {
|
void _listenToChanges(String deviceId) {
|
||||||
try {
|
try {
|
||||||
DatabaseReference ref =
|
final ref = FirebaseDatabase.instance.ref('device-status/$deviceId');
|
||||||
FirebaseDatabase.instance.ref('device-status/$deviceId');
|
ref.onValue.listen((event) {
|
||||||
Stream<DatabaseEvent> stream = ref.onValue;
|
final data = event.snapshot.value;
|
||||||
|
if (data is Map) {
|
||||||
|
final statusData = data['status'] as List<dynamic>? ?? [];
|
||||||
|
final statusList = statusData.map((item) {
|
||||||
|
return Status(code: item['code'], value: item['value']);
|
||||||
|
}).toList();
|
||||||
|
|
||||||
stream.listen((DatabaseEvent event) {
|
final model =
|
||||||
Map<dynamic, dynamic> usersMap =
|
DoorLockStatusModel.fromJson(data['productUuid'], statusList);
|
||||||
event.snapshot.value as Map<dynamic, dynamic>;
|
|
||||||
|
|
||||||
List<Status> statusList = [];
|
|
||||||
usersMap['status'].forEach((element) {
|
|
||||||
statusList
|
|
||||||
.add(Status(code: element['code'], value: element['value']));
|
|
||||||
});
|
|
||||||
|
|
||||||
deviceStatus =
|
|
||||||
DoorLockStatusModel.fromJson(usersMap['productUuid'], statusList);
|
|
||||||
if (!isClosed) {
|
if (!isClosed) {
|
||||||
add(StatusUpdated(deviceStatus));
|
add(StatusUpdated(model));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onStatusUpdated(StatusUpdated event, Emitter<DoorLockState> emit) {
|
void _onStatusUpdated(StatusUpdated event, Emitter<DoorLockState> emit) {
|
||||||
emit(DoorLockStatusLoading());
|
|
||||||
|
|
||||||
deviceStatus = event.deviceStatus;
|
deviceStatus = event.deviceStatus;
|
||||||
emit(DoorLockStatusLoaded(deviceStatus));
|
emit(DoorLockStatusLoaded(deviceStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<void> _onFetchDeviceStatus(
|
Future<void> _onFetchDeviceStatus(
|
||||||
DoorLockFetchStatus event, Emitter<DoorLockState> emit) async {
|
DoorLockFetchStatus event, Emitter<DoorLockState> emit) async {
|
||||||
emit(DoorLockStatusLoading());
|
emit(DoorLockStatusLoading());
|
||||||
try {
|
try {
|
||||||
@ -63,14 +54,13 @@ class DoorLockBloc extends Bloc<DoorLockEvent, DoorLockState> {
|
|||||||
deviceStatus =
|
deviceStatus =
|
||||||
DoorLockStatusModel.fromJson(event.deviceId, status.status);
|
DoorLockStatusModel.fromJson(event.deviceId, status.status);
|
||||||
_listenToChanges(event.deviceId);
|
_listenToChanges(event.deviceId);
|
||||||
|
|
||||||
emit(DoorLockStatusLoaded(deviceStatus));
|
emit(DoorLockStatusLoaded(deviceStatus));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(DoorLockControlError(e.toString()));
|
emit(DoorLockControlError(e.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<void> _updateLock(
|
Future<void> _updateLock(
|
||||||
UpdateLockEvent event, Emitter<DoorLockState> emit) async {
|
UpdateLockEvent event, Emitter<DoorLockState> emit) async {
|
||||||
final oldValue = deviceStatus.normalOpenSwitch;
|
final oldValue = deviceStatus.normalOpenSwitch;
|
||||||
deviceStatus = deviceStatus.copyWith(normalOpenSwitch: !oldValue);
|
deviceStatus = deviceStatus.copyWith(normalOpenSwitch: !oldValue);
|
||||||
@ -78,7 +68,6 @@ class DoorLockBloc extends Bloc<DoorLockEvent, DoorLockState> {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
final response = await DevicesManagementApi.openDoorLock(deviceId);
|
final response = await DevicesManagementApi.openDoorLock(deviceId);
|
||||||
|
|
||||||
if (!response) {
|
if (!response) {
|
||||||
_revertValueAndEmit(deviceId, 'normal_open_switch', oldValue, emit);
|
_revertValueAndEmit(deviceId, 'normal_open_switch', oldValue, emit);
|
||||||
}
|
}
|
||||||
@ -88,35 +77,8 @@ class DoorLockBloc extends Bloc<DoorLockEvent, DoorLockState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _runDebounce({
|
void _revertValueAndEmit(String deviceId, String code, dynamic oldValue,
|
||||||
required String deviceId,
|
Emitter<DoorLockState> emit) {
|
||||||
required String code,
|
|
||||||
required dynamic value,
|
|
||||||
required dynamic oldValue,
|
|
||||||
required Emitter<DoorLockState> emit,
|
|
||||||
}) async {
|
|
||||||
if (_timer != null) {
|
|
||||||
_timer!.cancel();
|
|
||||||
}
|
|
||||||
_timer = Timer(const Duration(seconds: 1), () async {
|
|
||||||
try {
|
|
||||||
final response = await DevicesManagementApi()
|
|
||||||
.deviceControl(deviceId, Status(code: code, value: value));
|
|
||||||
if (!response) {
|
|
||||||
_revertValueAndEmit(deviceId, code, oldValue, emit);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
_revertValueAndEmit(deviceId, code, oldValue, emit);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void _revertValueAndEmit(
|
|
||||||
String deviceId,
|
|
||||||
String code,
|
|
||||||
dynamic oldValue,
|
|
||||||
Emitter<DoorLockState> emit,
|
|
||||||
) {
|
|
||||||
_updateLocalValue(code, oldValue);
|
_updateLocalValue(code, oldValue);
|
||||||
emit(DoorLockStatusLoaded(deviceStatus));
|
emit(DoorLockStatusLoaded(deviceStatus));
|
||||||
emit(const DoorLockControlError('Failed to control the device.'));
|
emit(const DoorLockControlError('Failed to control the device.'));
|
||||||
@ -124,34 +86,23 @@ class DoorLockBloc extends Bloc<DoorLockEvent, DoorLockState> {
|
|||||||
|
|
||||||
void _updateLocalValue(String code, dynamic value) {
|
void _updateLocalValue(String code, dynamic value) {
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case 'reverse_lock':
|
|
||||||
if (value is bool) {
|
|
||||||
deviceStatus = deviceStatus.copyWith(reverseLock: value);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'normal_open_switch':
|
case 'normal_open_switch':
|
||||||
if (value is bool) {
|
if (value is bool) {
|
||||||
deviceStatus = deviceStatus.copyWith(normalOpenSwitch: value);
|
deviceStatus = deviceStatus.copyWith(normalOpenSwitch: value);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'reverse_lock':
|
||||||
|
if (value is bool) {
|
||||||
|
deviceStatus = deviceStatus.copyWith(reverseLock: value);
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
emit(DoorLockStatusLoaded(deviceStatus));
|
emit(DoorLockStatusLoaded(deviceStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
dynamic _getValueByCode(String code) {
|
Future<void> _onFactoryReset(
|
||||||
switch (code) {
|
|
||||||
case 'reverse_lock':
|
|
||||||
return deviceStatus.reverseLock;
|
|
||||||
case 'normal_open_switch':
|
|
||||||
return deviceStatus.normalOpenSwitch;
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FutureOr<void> _onFactoryReset(
|
|
||||||
DoorLockFactoryReset event, Emitter<DoorLockState> emit) async {
|
DoorLockFactoryReset event, Emitter<DoorLockState> emit) async {
|
||||||
emit(DoorLockStatusLoading());
|
emit(DoorLockStatusLoading());
|
||||||
try {
|
try {
|
||||||
|
@ -8,7 +8,7 @@ import 'package:syncrow_web/pages/device_managment/door_lock/models/door_lock_st
|
|||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
|
|
||||||
class DoorLockButton extends StatefulWidget {
|
class DoorLockButton extends StatelessWidget {
|
||||||
const DoorLockButton({
|
const DoorLockButton({
|
||||||
super.key,
|
super.key,
|
||||||
required this.doorLock,
|
required this.doorLock,
|
||||||
@ -18,70 +18,28 @@ class DoorLockButton extends StatefulWidget {
|
|||||||
final AllDevicesModel doorLock;
|
final AllDevicesModel doorLock;
|
||||||
final DoorLockStatusModel smartDoorModel;
|
final DoorLockStatusModel smartDoorModel;
|
||||||
|
|
||||||
@override
|
double _calculateProgress() {
|
||||||
State<DoorLockButton> createState() =>
|
final value = smartDoorModel.unlockRequest;
|
||||||
_DoorLockButtonState(smartDoorModel: smartDoorModel);
|
if (value <= 0 || value > 30) return 0;
|
||||||
}
|
return value / 30.0;
|
||||||
|
|
||||||
class _DoorLockButtonState extends State<DoorLockButton>
|
|
||||||
with SingleTickerProviderStateMixin {
|
|
||||||
late AnimationController _animationController;
|
|
||||||
late Animation<double> _animation;
|
|
||||||
DoorLockStatusModel smartDoorModel;
|
|
||||||
|
|
||||||
_DoorLockButtonState({required this.smartDoorModel});
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
_animationController = AnimationController(
|
|
||||||
vsync: this,
|
|
||||||
duration: const Duration(milliseconds: 500),
|
|
||||||
);
|
|
||||||
_animation = Tween<double>(begin: 0, end: 1).animate(_animationController)
|
|
||||||
..addListener(() {
|
|
||||||
setState(() {});
|
|
||||||
});
|
|
||||||
|
|
||||||
if (smartDoorModel.unlockRequest > 0) {
|
|
||||||
_animationController.reverse(from: 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void didUpdateWidget(covariant DoorLockButton oldWidget) {
|
|
||||||
super.didUpdateWidget(oldWidget);
|
|
||||||
if (oldWidget.smartDoorModel.normalOpenSwitch !=
|
|
||||||
widget.smartDoorModel.normalOpenSwitch) {
|
|
||||||
setState(() {
|
|
||||||
smartDoorModel = widget.smartDoorModel;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (smartDoorModel.unlockRequest > 0) {
|
|
||||||
_animationController.forward(from: 0);
|
|
||||||
} else {
|
|
||||||
_animationController.reverse(from: 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
_animationController.dispose();
|
|
||||||
super.dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final progress = _calculateProgress();
|
||||||
|
final isEnabled = smartDoorModel.unlockRequest > 0;
|
||||||
|
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
width: 255,
|
width: 255,
|
||||||
height: 255,
|
height: 255,
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () {
|
onTap: isEnabled
|
||||||
_animationController.forward(from: 0);
|
? () {
|
||||||
BlocProvider.of<DoorLockBloc>(context)
|
BlocProvider.of<DoorLockBloc>(context).add(
|
||||||
.add(UpdateLockEvent(value: !smartDoorModel.normalOpenSwitch));
|
UpdateLockEvent(value: !smartDoorModel.normalOpenSwitch),
|
||||||
},
|
);
|
||||||
|
}
|
||||||
|
: null,
|
||||||
child: Container(
|
child: Container(
|
||||||
width: 255,
|
width: 255,
|
||||||
height: 255,
|
height: 255,
|
||||||
@ -115,9 +73,10 @@ class _DoorLockButtonState extends State<DoorLockButton>
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
if (progress > 0)
|
||||||
SizedBox.expand(
|
SizedBox.expand(
|
||||||
child: CircularProgressIndicator(
|
child: CircularProgressIndicator(
|
||||||
value: _animation.value,
|
value: progress,
|
||||||
strokeWidth: 8,
|
strokeWidth: 8,
|
||||||
backgroundColor: Colors.transparent,
|
backgroundColor: Colors.transparent,
|
||||||
valueColor: const AlwaysStoppedAnimation<Color>(
|
valueColor: const AlwaysStoppedAnimation<Color>(
|
||||||
|
@ -13,30 +13,32 @@ import 'package:syncrow_web/pages/space_tree/bloc/space_tree_event.dart';
|
|||||||
import 'package:syncrow_web/services/home_api.dart';
|
import 'package:syncrow_web/services/home_api.dart';
|
||||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
import 'package:syncrow_web/utils/constants/routes_const.dart';
|
import 'package:syncrow_web/utils/constants/routes_const.dart';
|
||||||
import 'package:syncrow_web/utils/navigation_service.dart';
|
|
||||||
|
|
||||||
class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
||||||
UserModel? user;
|
UserModel? user;
|
||||||
String terms = '';
|
String terms = '';
|
||||||
String policy = '';
|
String policy = '';
|
||||||
|
|
||||||
HomeBloc() : super((HomeInitial())) {
|
HomeBloc() : super(HomeInitial()) {
|
||||||
// on<CreateNewNode>(_createNode);
|
|
||||||
on<FetchUserInfo>(_fetchUserInfo);
|
on<FetchUserInfo>(_fetchUserInfo);
|
||||||
on<FetchTermEvent>(_fetchTerms);
|
on<FetchTermEvent>(_fetchTerms);
|
||||||
on<FetchPolicyEvent>(_fetchPolicy);
|
on<FetchPolicyEvent>(_fetchPolicy);
|
||||||
on<ConfirmUserAgreementEvent>(_confirmUserAgreement);
|
on<ConfirmUserAgreementEvent>(_confirmUserAgreement);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future _fetchUserInfo(FetchUserInfo event, Emitter<HomeState> emit) async {
|
Future<void> _fetchUserInfo(
|
||||||
|
FetchUserInfo event,
|
||||||
|
Emitter<HomeState> emit,
|
||||||
|
) async {
|
||||||
try {
|
try {
|
||||||
var uuid =
|
final uuid =
|
||||||
await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
|
await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
|
||||||
|
if (uuid != null) {
|
||||||
user = await HomeApi().fetchUserInfo(uuid);
|
user = await HomeApi().fetchUserInfo(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
if (user != null && user!.project != null) {
|
if (user != null && user?.project != null) {
|
||||||
await ProjectManager.setProjectUUID(user!.project!.uuid);
|
await ProjectManager.setProjectUUID(user!.project!.uuid);
|
||||||
|
|
||||||
}
|
}
|
||||||
add(FetchTermEvent());
|
add(FetchTermEvent());
|
||||||
add(FetchPolicyEvent());
|
add(FetchPolicyEvent());
|
||||||
@ -47,7 +49,7 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future _fetchTerms(FetchTermEvent event, Emitter<HomeState> emit) async {
|
Future<void> _fetchTerms(FetchTermEvent event, Emitter<HomeState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingHome());
|
emit(LoadingHome());
|
||||||
terms = await HomeApi().fetchTerms();
|
terms = await HomeApi().fetchTerms();
|
||||||
@ -57,22 +59,22 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future _fetchPolicy(FetchPolicyEvent event, Emitter<HomeState> emit) async {
|
Future<void> _fetchPolicy(FetchPolicyEvent event, Emitter<HomeState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingHome());
|
emit(LoadingHome());
|
||||||
policy = await HomeApi().fetchPolicy();
|
policy = await HomeApi().fetchPolicy();
|
||||||
emit(HomeInitial());
|
emit(HomeInitial());
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugPrint("Error fetching policy: $e");
|
debugPrint('Error fetching policy: $e');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future _confirmUserAgreement(
|
Future<void> _confirmUserAgreement(
|
||||||
ConfirmUserAgreementEvent event, Emitter<HomeState> emit) async {
|
ConfirmUserAgreementEvent event, Emitter<HomeState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingHome());
|
emit(LoadingHome());
|
||||||
var uuid =
|
final uuid =
|
||||||
await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
|
await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
|
||||||
policy = await HomeApi().confirmUserAgreements(uuid);
|
policy = await HomeApi().confirmUserAgreements(uuid);
|
||||||
emit(PolicyAgreement());
|
emit(PolicyAgreement());
|
||||||
@ -81,7 +83,7 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<HomeItemModel> homeItems = [
|
final List<HomeItemModel> homeItems = [
|
||||||
HomeItemModel(
|
HomeItemModel(
|
||||||
title: 'Access Management',
|
title: 'Access Management',
|
||||||
icon: Assets.accessIcon,
|
icon: Assets.accessIcon,
|
||||||
@ -126,41 +128,5 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
|||||||
},
|
},
|
||||||
color: const Color(0xFF023DFE),
|
color: const Color(0xFF023DFE),
|
||||||
),
|
),
|
||||||
|
|
||||||
// HomeItemModel(
|
|
||||||
// title: 'Move in',
|
|
||||||
// icon: Assets.moveinIcon,
|
|
||||||
// active: false,
|
|
||||||
// onPress: (context) {},
|
|
||||||
// color: ColorsManager.primaryColor,
|
|
||||||
// ),
|
|
||||||
// HomeItemModel(
|
|
||||||
// title: 'Construction',
|
|
||||||
// icon: Assets.constructionIcon,
|
|
||||||
// active: false,
|
|
||||||
// onPress: (context) {},
|
|
||||||
// color: ColorsManager.primaryColor,
|
|
||||||
// ),
|
|
||||||
// HomeItemModel(
|
|
||||||
// title: 'Energy',
|
|
||||||
// icon: Assets.energyIcon,
|
|
||||||
// active: false,
|
|
||||||
// onPress: (context) {},
|
|
||||||
// color: ColorsManager.slidingBlueColor.withOpacity(0.2),
|
|
||||||
// ),
|
|
||||||
// HomeItemModel(
|
|
||||||
// title: 'Integrations',
|
|
||||||
// icon: Assets.integrationsIcon,
|
|
||||||
// active: false,
|
|
||||||
// onPress: (context) {},
|
|
||||||
// color: ColorsManager.slidingBlueColor.withOpacity(0.2),
|
|
||||||
// ),
|
|
||||||
// HomeItemModel(
|
|
||||||
// title: 'Asset',
|
|
||||||
// icon: Assets.assetIcon,
|
|
||||||
// active: false,
|
|
||||||
// onPress: (context) {},
|
|
||||||
// color: ColorsManager.slidingBlueColor.withOpacity(0.2),
|
|
||||||
// ),
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -34,17 +34,9 @@ class HomeCard extends StatelessWidget {
|
|||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Flexible(
|
Expanded(
|
||||||
child: FittedBox(
|
child: SpliteNameHelperWidget(
|
||||||
fit: BoxFit.scaleDown,
|
name: name,
|
||||||
child: Text(
|
|
||||||
name,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 30,
|
|
||||||
color: Colors.white,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -63,3 +55,72 @@ class HomeCard extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class SpliteNameHelperWidget extends StatelessWidget {
|
||||||
|
final String name;
|
||||||
|
const SpliteNameHelperWidget({
|
||||||
|
super.key,
|
||||||
|
required this.name,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
List<String> parts = name.split(' ');
|
||||||
|
|
||||||
|
if (parts.length == 2) {
|
||||||
|
// Two-word string
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsetsGeometry.only(top: 10, left: 10),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: FittedBox(
|
||||||
|
fit: BoxFit.scaleDown,
|
||||||
|
child: Text(
|
||||||
|
parts[0],
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 30,
|
||||||
|
color: Colors.white,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: FittedBox(
|
||||||
|
fit: BoxFit.scaleDown,
|
||||||
|
child: Text(
|
||||||
|
parts[1],
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 30,
|
||||||
|
color: Colors.white,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// One-word string
|
||||||
|
return Text(
|
||||||
|
name,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 30,
|
||||||
|
color: Colors.white,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Text(
|
||||||
|
// name,
|
||||||
|
// style: const TextStyle(
|
||||||
|
// fontSize: 32,
|
||||||
|
// color: Colors.white,
|
||||||
|
// fontWeight: FontWeight.bold,
|
||||||
|
// ),
|
||||||
|
// )
|
||||||
|
@ -1,17 +1,37 @@
|
|||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/home/bloc/home_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/home/bloc/home_event.dart';
|
||||||
import 'package:syncrow_web/pages/home/view/home_page_mobile.dart';
|
import 'package:syncrow_web/pages/home/view/home_page_mobile.dart';
|
||||||
import 'package:syncrow_web/pages/home/view/home_page_web.dart';
|
import 'package:syncrow_web/pages/home/view/home_page_web.dart';
|
||||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||||
|
|
||||||
class HomePage extends StatelessWidget with HelperResponsiveLayout {
|
class HomePage extends StatefulWidget {
|
||||||
const HomePage({super.key});
|
const HomePage({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<HomePage> createState() => _HomePageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _HomePageState extends State<HomePage> with HelperResponsiveLayout {
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
_fetchUserInfo();
|
||||||
|
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final isSmallScreen = isSmallScreenSize(context);
|
if (isSmallScreenSize(context) || isMediumScreenSize(context)) {
|
||||||
final isMediumScreen = isMediumScreenSize(context);
|
return HomeMobilePage();
|
||||||
return isSmallScreen || isMediumScreen
|
}
|
||||||
? HomeMobilePage()
|
|
||||||
: const HomeWebPage();
|
return const HomeWebPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _fetchUserInfo() {
|
||||||
|
final bloc = context.read<HomeBloc>();
|
||||||
|
if (bloc.user == null) bloc.add(const FetchUserInfo());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ class _HomeWebPageState extends State<HomeWebPage> {
|
|||||||
flex: 4,
|
flex: 4,
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
height: size.height * 0.6,
|
height: size.height * 0.6,
|
||||||
width: size.width * 0.68,
|
width: size.width * 0.8,
|
||||||
child: GridView.builder(
|
child: GridView.builder(
|
||||||
itemCount: homeBloc.homeItems.length,
|
itemCount: homeBloc.homeItems.length,
|
||||||
gridDelegate:
|
gridDelegate:
|
||||||
|
@ -19,7 +19,6 @@ import 'package:syncrow_web/utils/color_manager.dart';
|
|||||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||||
import 'package:syncrow_web/utils/style.dart';
|
import 'package:syncrow_web/utils/style.dart';
|
||||||
|
|
||||||
class UsersPage extends StatelessWidget {
|
class UsersPage extends StatelessWidget {
|
||||||
UsersPage({super.key});
|
UsersPage({super.key});
|
||||||
|
|
||||||
|
@ -13,6 +13,35 @@ class FunctionBloc extends Bloc<FunctionBlocEvent, FunctionBlocState> {
|
|||||||
on<AddFunction>(_onAddFunction);
|
on<AddFunction>(_onAddFunction);
|
||||||
on<SelectFunction>(_onSelectFunction);
|
on<SelectFunction>(_onSelectFunction);
|
||||||
}
|
}
|
||||||
|
// void _onAddFunction(AddFunction event, Emitter<FunctionBlocState> emit) {
|
||||||
|
// final functions = List<DeviceFunctionData>.from(state.addedFunctions);
|
||||||
|
// final existingIndex = functions.indexWhere(
|
||||||
|
// (f) => f.functionCode == event.functionData.functionCode,
|
||||||
|
// );
|
||||||
|
|
||||||
|
// if (existingIndex != -1) {
|
||||||
|
// final existingData = functions[existingIndex];
|
||||||
|
// functions[existingIndex] = DeviceFunctionData(
|
||||||
|
// entityId: event.functionData.entityId,
|
||||||
|
// functionCode: event.functionData.functionCode,
|
||||||
|
// operationName: event.functionData.operationName,
|
||||||
|
// value: event.functionData.value ?? existingData.value,
|
||||||
|
// valueDescription: event.functionData.valueDescription ??
|
||||||
|
// existingData.valueDescription,
|
||||||
|
// condition: event.functionData.condition ?? existingData.condition,
|
||||||
|
// step: event.functionData.step ?? existingData.step,
|
||||||
|
// );
|
||||||
|
// } else {
|
||||||
|
// functions.clear();
|
||||||
|
// functions.add(event.functionData);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// emit(state.copyWith(
|
||||||
|
// addedFunctions: functions,
|
||||||
|
// selectedFunction: event.functionData.functionCode,
|
||||||
|
// ));
|
||||||
|
// }
|
||||||
|
|
||||||
void _onAddFunction(AddFunction event, Emitter<FunctionBlocState> emit) {
|
void _onAddFunction(AddFunction event, Emitter<FunctionBlocState> emit) {
|
||||||
final functions = List<DeviceFunctionData>.from(state.addedFunctions);
|
final functions = List<DeviceFunctionData>.from(state.addedFunctions);
|
||||||
final existingIndex = functions.indexWhere(
|
final existingIndex = functions.indexWhere(
|
||||||
@ -20,19 +49,10 @@ class FunctionBloc extends Bloc<FunctionBlocEvent, FunctionBlocState> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (existingIndex != -1) {
|
if (existingIndex != -1) {
|
||||||
final existingData = functions[existingIndex];
|
// Update the function value
|
||||||
functions[existingIndex] = DeviceFunctionData(
|
functions[existingIndex] = event.functionData;
|
||||||
entityId: event.functionData.entityId,
|
|
||||||
functionCode: event.functionData.functionCode,
|
|
||||||
operationName: event.functionData.operationName,
|
|
||||||
value: event.functionData.value ?? existingData.value,
|
|
||||||
valueDescription: event.functionData.valueDescription ??
|
|
||||||
existingData.valueDescription,
|
|
||||||
condition: event.functionData.condition ?? existingData.condition,
|
|
||||||
step: event.functionData.step ?? existingData.step,
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
functions.clear();
|
// Add new function value
|
||||||
functions.add(event.functionData);
|
functions.add(event.functionData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,8 +4,8 @@ import 'package:bloc/bloc.dart';
|
|||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
|
||||||
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/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/routines/bloc/automation_scene_trigger_bloc/automation_status_update.dart';
|
import 'package:syncrow_web/pages/routines/bloc/automation_scene_trigger_bloc/automation_status_update.dart';
|
||||||
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_bloc.dart';
|
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_bloc.dart';
|
||||||
@ -27,9 +27,6 @@ import 'package:uuid/uuid.dart';
|
|||||||
part 'routine_event.dart';
|
part 'routine_event.dart';
|
||||||
part 'routine_state.dart';
|
part 'routine_state.dart';
|
||||||
|
|
||||||
// String spaceId = '25c96044-fadf-44bb-93c7-3c079e527ce6';
|
|
||||||
// String communityId = 'aff21a57-2f91-4e5c-b99b-0182c3ab65a9';
|
|
||||||
|
|
||||||
class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||||
RoutineBloc() : super(const RoutineState()) {
|
RoutineBloc() : super(const RoutineState()) {
|
||||||
on<AddToIfContainer>(_onAddToIfContainer);
|
on<AddToIfContainer>(_onAddToIfContainer);
|
||||||
@ -173,7 +170,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onLoadScenes(
|
Future<void> _onLoadScenes(
|
||||||
LoadScenes event, Emitter<RoutineState> emit) async {
|
LoadScenes event, Emitter<RoutineState> emit) async {
|
||||||
emit(state.copyWith(isLoading: true, errorMessage: null));
|
emit(state.copyWith(isLoading: true, errorMessage: null));
|
||||||
List<ScenesModel> scenes = [];
|
List<ScenesModel> scenes = [];
|
||||||
@ -211,7 +208,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
loadAutomationErrorMessage: '',
|
loadAutomationErrorMessage: '',
|
||||||
scenes: scenes));
|
scenes: scenes));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onLoadAutomation(
|
Future<void> _onLoadAutomation(
|
||||||
LoadAutomation event, Emitter<RoutineState> emit) async {
|
LoadAutomation event, Emitter<RoutineState> emit) async {
|
||||||
@ -1163,8 +1160,8 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
|
|
||||||
if (result['success']) {
|
if (result['success']) {
|
||||||
add(ResetRoutineState());
|
add(ResetRoutineState());
|
||||||
add(LoadAutomation());
|
add(const LoadAutomation());
|
||||||
add(LoadScenes());
|
add(const LoadScenes());
|
||||||
} else {
|
} else {
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
@ -1422,15 +1419,17 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
event.automationId, event.automationStatusUpdate, projectId);
|
event.automationId, event.automationStatusUpdate, projectId);
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
final updatedAutomations = await SceneApi.getAutomationByUnitId(
|
// await SceneApi.getAutomationByUnitId(
|
||||||
event.automationStatusUpdate.spaceUuid,
|
// event.automationStatusUpdate.spaceUuid,
|
||||||
event.communityId,
|
// event.communityId,
|
||||||
projectId);
|
// projectId);
|
||||||
|
|
||||||
// Remove from loading set safely
|
// Remove from loading set safely
|
||||||
|
|
||||||
final updatedLoadingIds = {...state.loadingAutomationIds!}
|
final updatedLoadingIds = {...state.loadingAutomationIds!}
|
||||||
..remove(event.automationId);
|
..remove(event.automationId);
|
||||||
|
final updatedAutomations = changeItemStateOnToggelingSceen(
|
||||||
|
state.automations, event.automationId);
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
automations: updatedAutomations,
|
automations: updatedAutomations,
|
||||||
loadingAutomationIds: updatedLoadingIds,
|
loadingAutomationIds: updatedLoadingIds,
|
||||||
@ -1452,4 +1451,24 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<ScenesModel> changeItemStateOnToggelingSceen(
|
||||||
|
List<ScenesModel> oldSceen, String automationId) {
|
||||||
|
return oldSceen.map((scene) {
|
||||||
|
if (scene.id == automationId) {
|
||||||
|
return ScenesModel(
|
||||||
|
id: scene.id,
|
||||||
|
sceneTuyaId: scene.sceneTuyaId,
|
||||||
|
name: scene.name,
|
||||||
|
status: scene.status == 'enable' ? 'disable' : 'enable',
|
||||||
|
type: scene.type,
|
||||||
|
spaceName: scene.spaceName,
|
||||||
|
spaceId: scene.spaceId,
|
||||||
|
communityId: scene.communityId,
|
||||||
|
icon: scene.icon,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return scene;
|
||||||
|
}).toList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ class _DropdownContentState extends State<_DropdownContent> {
|
|||||||
final selectedCommunity = _findCommunity(state, state.selectedSpaceId);
|
final selectedCommunity = _findCommunity(state, state.selectedSpaceId);
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
height: 46,
|
height: 40,
|
||||||
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),
|
||||||
@ -149,7 +149,7 @@ class _DropdownContentState extends State<_DropdownContent> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
height: 45,
|
height: 45,
|
||||||
width: 33,
|
width: 44,
|
||||||
child: const Icon(
|
child: const Icon(
|
||||||
Icons.keyboard_arrow_down,
|
Icons.keyboard_arrow_down,
|
||||||
color: ColorsManager.textGray,
|
color: ColorsManager.textGray,
|
||||||
|
@ -44,51 +44,60 @@ class _CreateNewRoutinesDialogState extends State<CreateNewRoutinesDialog> {
|
|||||||
_selectedSpace = null;
|
_selectedSpace = null;
|
||||||
_selectedCommunity = _selectedId;
|
_selectedCommunity = _selectedId;
|
||||||
}
|
}
|
||||||
return AlertDialog(
|
return Dialog(
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
insetPadding: EdgeInsets.zero,
|
insetPadding: const EdgeInsets.symmetric(
|
||||||
contentPadding: EdgeInsets.zero,
|
horizontal: 20,
|
||||||
|
),
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(12)),
|
borderRadius: BorderRadius.circular(12)),
|
||||||
title: Text(
|
child: Container(
|
||||||
|
width: 450,
|
||||||
|
child: Stack(
|
||||||
|
children: [
|
||||||
|
Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
Text(
|
||||||
'Create New Routines',
|
'Create New Routines',
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
|
style:
|
||||||
|
Theme.of(context).textTheme.bodyMedium!.copyWith(
|
||||||
color: ColorsManager.spaceColor,
|
color: ColorsManager.spaceColor,
|
||||||
fontSize: 20,
|
fontSize: 20,
|
||||||
fontWeight: FontWeight.w700,
|
fontWeight: FontWeight.w700,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
content: Stack(
|
|
||||||
children: [
|
|
||||||
Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
const Divider(),
|
const Divider(),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
|
Column(
|
||||||
|
children: [
|
||||||
Column(
|
Column(
|
||||||
children: [
|
children: [
|
||||||
Padding(
|
Padding(
|
||||||
padding:
|
padding: const EdgeInsets.only(
|
||||||
const EdgeInsets.only(left: 13, right: 8),
|
left: 13, right: 10),
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
SpaceTreeDropdown(
|
SpaceTreeDropdown(
|
||||||
selectedSpaceId: _selectedId,
|
selectedSpaceId: _selectedId,
|
||||||
onChanged: (String? newValue) {
|
onChanged: (String? newValue) {
|
||||||
setState(() => _selectedId = newValue!);
|
setState(
|
||||||
|
() => _selectedId = newValue!);
|
||||||
if (_selectedId != null) {
|
if (_selectedId != null) {
|
||||||
_bloc.add(SpaceOnlyWithDevicesEvent(
|
_bloc.add(
|
||||||
|
SpaceOnlyWithDevicesEvent(
|
||||||
_selectedId!));
|
_selectedId!));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)),
|
)),
|
||||||
const SizedBox(height: 5),
|
const SizedBox(height: 21),
|
||||||
const SizedBox(height: 8),
|
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(left: 15, right: 15),
|
padding: const EdgeInsets.only(
|
||||||
|
left: 15, right: 20),
|
||||||
child: SpaceDropdown(
|
child: SpaceDropdown(
|
||||||
hintMessage: spaceHint,
|
hintMessage: spaceHint,
|
||||||
spaces: spaces,
|
spaces: spaces,
|
||||||
@ -102,6 +111,8 @@ class _CreateNewRoutinesDialogState extends State<CreateNewRoutinesDialog> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
const Divider(),
|
const Divider(),
|
||||||
Row(
|
Row(
|
||||||
@ -183,6 +194,7 @@ class _CreateNewRoutinesDialogState extends State<CreateNewRoutinesDialog> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
|
@ -34,7 +34,9 @@ class SpaceDropdown extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
child: Container(
|
child: Container(
|
||||||
|
height: 40,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
|
color: ColorsManager.whiteColors,
|
||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(10),
|
||||||
),
|
),
|
||||||
child: DropdownButton2<String>(
|
child: DropdownButton2<String>(
|
||||||
@ -45,7 +47,7 @@ class SpaceDropdown extends StatelessWidget {
|
|||||||
value: space.uuid,
|
value: space.uuid,
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
' ${space.name}',
|
' ${space.name}',
|
||||||
@ -88,7 +90,7 @@ class SpaceDropdown extends StatelessWidget {
|
|||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
flex: 6,
|
flex: 8,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.only(left: 10),
|
padding: const EdgeInsets.only(left: 10),
|
||||||
child: Text(
|
child: Text(
|
||||||
@ -129,6 +131,7 @@ class SpaceDropdown extends StatelessWidget {
|
|||||||
dropdownStyleData: DropdownStyleData(
|
dropdownStyleData: DropdownStyleData(
|
||||||
maxHeight: MediaQuery.of(context).size.height * 0.4,
|
maxHeight: MediaQuery.of(context).size.height * 0.4,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
|
color: ColorsManager.whiteColors,
|
||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(10),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -4,6 +4,7 @@ import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
|||||||
import 'package:syncrow_web/pages/routines/models/device_functions.dart';
|
import 'package:syncrow_web/pages/routines/models/device_functions.dart';
|
||||||
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/ac_dialog.dart';
|
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/ac_dialog.dart';
|
||||||
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/ceiling_sensor/ceiling_sensor_helper.dart';
|
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/ceiling_sensor/ceiling_sensor_helper.dart';
|
||||||
|
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/curtain_dialog.dart';
|
||||||
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/flush_presence_sensor/flush_presence_sensor.dart';
|
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/flush_presence_sensor/flush_presence_sensor.dart';
|
||||||
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/gateway/gateway_helper.dart';
|
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/gateway/gateway_helper.dart';
|
||||||
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/one_gang_switch_dialog.dart';
|
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/one_gang_switch_dialog.dart';
|
||||||
@ -26,7 +27,7 @@ class DeviceDialogHelper {
|
|||||||
final result = await _getDialogForDeviceType(
|
final result = await _getDialogForDeviceType(
|
||||||
dialogType: dialogType,
|
dialogType: dialogType,
|
||||||
context: context,
|
context: context,
|
||||||
productType: data['productType'],
|
productType: data['productType'] as String,
|
||||||
data: data,
|
data: data,
|
||||||
functions: functions,
|
functions: functions,
|
||||||
removeComparetors: removeComparetors,
|
removeComparetors: removeComparetors,
|
||||||
@ -65,7 +66,14 @@ class DeviceDialogHelper {
|
|||||||
removeComparetors: removeComparetors,
|
removeComparetors: removeComparetors,
|
||||||
dialogType: dialogType,
|
dialogType: dialogType,
|
||||||
);
|
);
|
||||||
|
case 'CUR':
|
||||||
|
return CurtainHelper.showControlDialog(
|
||||||
|
dialogType: dialogType,
|
||||||
|
context: context,
|
||||||
|
functions: functions,
|
||||||
|
uniqueCustomId: data['uniqueCustomId'],
|
||||||
|
device: data['device'],
|
||||||
|
);
|
||||||
case '1G':
|
case '1G':
|
||||||
return OneGangSwitchHelper.showSwitchFunctionsDialog(
|
return OneGangSwitchHelper.showSwitchFunctionsDialog(
|
||||||
dialogType: dialogType,
|
dialogType: dialogType,
|
||||||
|
@ -17,7 +17,8 @@ class SaveRoutineHelper {
|
|||||||
builder: (context) {
|
builder: (context) {
|
||||||
return BlocBuilder<RoutineBloc, RoutineState>(
|
return BlocBuilder<RoutineBloc, RoutineState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
final selectedConditionLabel = state.selectedAutomationOperator == 'and'
|
final selectedConditionLabel =
|
||||||
|
state.selectedAutomationOperator == 'and'
|
||||||
? 'All Conditions are met'
|
? 'All Conditions are met'
|
||||||
: 'Any Condition is met';
|
: 'Any Condition is met';
|
||||||
|
|
||||||
@ -37,7 +38,8 @@ class SaveRoutineHelper {
|
|||||||
Text(
|
Text(
|
||||||
'Create a scene: ${state.routineName ?? ""}',
|
'Create a scene: ${state.routineName ?? ""}',
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: Theme.of(context).textTheme.headlineMedium!.copyWith(
|
style:
|
||||||
|
Theme.of(context).textTheme.headlineMedium!.copyWith(
|
||||||
color: ColorsManager.primaryColorWithOpacity,
|
color: ColorsManager.primaryColorWithOpacity,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
@ -58,7 +60,8 @@ class SaveRoutineHelper {
|
|||||||
_buildIfConditions(state, context),
|
_buildIfConditions(state, context),
|
||||||
Container(
|
Container(
|
||||||
width: 1,
|
width: 1,
|
||||||
color: ColorsManager.greyColor.withValues(alpha: 0.8),
|
color: ColorsManager.greyColor
|
||||||
|
.withValues(alpha: 0.8),
|
||||||
),
|
),
|
||||||
_buildThenActions(state, context),
|
_buildThenActions(state, context),
|
||||||
],
|
],
|
||||||
@ -97,7 +100,8 @@ class SaveRoutineHelper {
|
|||||||
child: Row(
|
child: Row(
|
||||||
spacing: 16,
|
spacing: 16,
|
||||||
children: [
|
children: [
|
||||||
Expanded(child: Text('IF: $selectedConditionLabel', style: textStyle)),
|
Expanded(
|
||||||
|
child: Text('IF: $selectedConditionLabel', style: textStyle)),
|
||||||
const Expanded(child: Text('THEN:', style: textStyle)),
|
const Expanded(child: Text('THEN:', style: textStyle)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@ -143,7 +147,8 @@ class SaveRoutineHelper {
|
|||||||
child: ListView(
|
child: ListView(
|
||||||
// shrinkWrap: true,
|
// shrinkWrap: true,
|
||||||
children: state.thenItems.map((item) {
|
children: state.thenItems.map((item) {
|
||||||
final functions = state.selectedFunctions[item['uniqueCustomId']] ?? [];
|
final functions =
|
||||||
|
state.selectedFunctions[item['uniqueCustomId']] ?? [];
|
||||||
return functionRow(item, context, functions);
|
return functionRow(item, context, functions);
|
||||||
}).toList(),
|
}).toList(),
|
||||||
),
|
),
|
||||||
@ -203,7 +208,8 @@ class SaveRoutineHelper {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: Center(
|
child: Center(
|
||||||
child: item['type'] == 'tap_to_run' || item['type'] == 'scene'
|
child:
|
||||||
|
item['type'] == 'tap_to_run' || item['type'] == 'scene'
|
||||||
? Image.memory(
|
? Image.memory(
|
||||||
base64Decode(item['icon']),
|
base64Decode(item['icon']),
|
||||||
width: 12,
|
width: 12,
|
||||||
|
49
lib/pages/routines/models/curtain/curtain_function.dart
Normal file
49
lib/pages/routines/models/curtain/curtain_function.dart
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import 'package:syncrow_web/pages/device_managment/curtain/model/curtain_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/routines/models/curtain/curtain_opertion_value.dart';
|
||||||
|
import 'package:syncrow_web/pages/routines/models/device_functions.dart'
|
||||||
|
show DeviceFunction;
|
||||||
|
import 'package:syncrow_web/utils/constants/app_enum.dart';
|
||||||
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
|
|
||||||
|
abstract class CurtainFunction extends DeviceFunction<CurtainModel> {
|
||||||
|
final String type;
|
||||||
|
CurtainFunction({
|
||||||
|
required super.deviceId,
|
||||||
|
required super.deviceName,
|
||||||
|
required this.type,
|
||||||
|
required super.code,
|
||||||
|
required super.operationName,
|
||||||
|
required super.icon,
|
||||||
|
});
|
||||||
|
List<CurtainOperationalValue> getOperationalValues();
|
||||||
|
}
|
||||||
|
|
||||||
|
class ControlCurtainFunction extends CurtainFunction {
|
||||||
|
ControlCurtainFunction({
|
||||||
|
required super.deviceId,
|
||||||
|
required super.deviceName,
|
||||||
|
required super.type,
|
||||||
|
super.code = 'control',
|
||||||
|
super.operationName = 'Control',
|
||||||
|
super.icon = Assets.curtain,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<CurtainOperationalValue> getOperationalValues() => [
|
||||||
|
CurtainOperationalValue(
|
||||||
|
icon: Assets.curtain,
|
||||||
|
description: 'OPEN',
|
||||||
|
value: 'open',
|
||||||
|
),
|
||||||
|
CurtainOperationalValue(
|
||||||
|
icon: Assets.curtain,
|
||||||
|
description: 'STOP',
|
||||||
|
value: 'stop',
|
||||||
|
),
|
||||||
|
CurtainOperationalValue(
|
||||||
|
icon: Assets.curtain,
|
||||||
|
description: 'CLOSE',
|
||||||
|
value: 'close',
|
||||||
|
)
|
||||||
|
];
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
class CurtainOperationalValue {
|
||||||
|
final String icon;
|
||||||
|
final String description;
|
||||||
|
final String value;
|
||||||
|
|
||||||
|
CurtainOperationalValue({
|
||||||
|
required this.icon,
|
||||||
|
required this.description,
|
||||||
|
required this.value,
|
||||||
|
});
|
||||||
|
}
|
@ -405,8 +405,8 @@ class PowerFactorCStatusFunction extends EnergyClampFunctions {
|
|||||||
code: 'PowerFactorC',
|
code: 'PowerFactorC',
|
||||||
operationName: 'Power Factor C',
|
operationName: 'Power Factor C',
|
||||||
icon: Assets.speedoMeter,
|
icon: Assets.speedoMeter,
|
||||||
min: 0.00,
|
min: 0.0,
|
||||||
max: 1.00,
|
max: 1.0,
|
||||||
step: 0.1,
|
step: 0.1,
|
||||||
unit: "",
|
unit: "",
|
||||||
);
|
);
|
||||||
|
@ -148,6 +148,7 @@ class IfContainer extends StatelessWidget {
|
|||||||
'NCPS',
|
'NCPS',
|
||||||
'WH',
|
'WH',
|
||||||
'PC',
|
'PC',
|
||||||
|
'CUR',
|
||||||
].contains(mutableData['productType'])) {
|
].contains(mutableData['productType'])) {
|
||||||
context
|
context
|
||||||
.read<RoutineBloc>()
|
.read<RoutineBloc>()
|
||||||
|
@ -28,6 +28,7 @@ class _RoutineDevicesState extends State<RoutineDevices> {
|
|||||||
'NCPS',
|
'NCPS',
|
||||||
'WH',
|
'WH',
|
||||||
'PC',
|
'PC',
|
||||||
|
'CUR',
|
||||||
};
|
};
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -117,10 +117,22 @@ class ACHelper {
|
|||||||
},
|
},
|
||||||
onConfirm: state.addedFunctions.isNotEmpty
|
onConfirm: state.addedFunctions.isNotEmpty
|
||||||
? () {
|
? () {
|
||||||
|
final selectedFunctionData =
|
||||||
|
state.addedFunctions.firstWhere(
|
||||||
|
(f) =>
|
||||||
|
f.functionCode == state.selectedFunction,
|
||||||
|
orElse: () => DeviceFunctionData(
|
||||||
|
entityId: '',
|
||||||
|
functionCode: state.selectedFunction ?? '',
|
||||||
|
operationName: '',
|
||||||
|
value: null,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
/// add the functions to the routine bloc
|
/// add the functions to the routine bloc
|
||||||
context.read<RoutineBloc>().add(
|
context.read<RoutineBloc>().add(
|
||||||
AddFunctionToRoutine(
|
AddFunctionToRoutine(
|
||||||
state.addedFunctions,
|
[selectedFunctionData],
|
||||||
uniqueCustomId,
|
uniqueCustomId,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -78,12 +78,22 @@ class _CeilingSensorDialogState extends State<CeilingSensorDialog> {
|
|||||||
onCancel: () => Navigator.pop(context),
|
onCancel: () => Navigator.pop(context),
|
||||||
onConfirm: state.addedFunctions.isNotEmpty
|
onConfirm: state.addedFunctions.isNotEmpty
|
||||||
? () {
|
? () {
|
||||||
|
final selectedFunctionData =
|
||||||
|
state.addedFunctions.firstWhere(
|
||||||
|
(f) => f.functionCode == state.selectedFunction,
|
||||||
|
orElse: () => DeviceFunctionData(
|
||||||
|
entityId: '',
|
||||||
|
functionCode: state.selectedFunction ?? '',
|
||||||
|
operationName: '',
|
||||||
|
value: null,
|
||||||
|
),
|
||||||
|
);
|
||||||
final functions = _updateValuesForAddedFunctions(
|
final functions = _updateValuesForAddedFunctions(
|
||||||
state.addedFunctions,
|
state.addedFunctions,
|
||||||
);
|
);
|
||||||
context.read<RoutineBloc>().add(
|
context.read<RoutineBloc>().add(
|
||||||
AddFunctionToRoutine(
|
AddFunctionToRoutine(
|
||||||
functions,
|
[selectedFunctionData],
|
||||||
'${widget.uniqueCustomId}',
|
'${widget.uniqueCustomId}',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
270
lib/pages/routines/widgets/routine_dialogs/curtain_dialog.dart
Normal file
270
lib/pages/routines/widgets/routine_dialogs/curtain_dialog.dart
Normal file
@ -0,0 +1,270 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:flutter_svg/svg.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/routines/bloc/functions_bloc/functions_bloc_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/routines/models/curtain/curtain_function.dart';
|
||||||
|
import 'package:syncrow_web/pages/routines/models/curtain/curtain_opertion_value.dart';
|
||||||
|
import 'package:syncrow_web/pages/routines/models/device_functions.dart';
|
||||||
|
import 'package:syncrow_web/pages/routines/widgets/dialog_footer.dart';
|
||||||
|
import 'package:syncrow_web/pages/routines/widgets/dialog_header.dart';
|
||||||
|
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/helpers/routine_tap_function_helper.dart';
|
||||||
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||||
|
|
||||||
|
class CurtainHelper {
|
||||||
|
static Future<Map<String, dynamic>?> showControlDialog({
|
||||||
|
required String dialogType,
|
||||||
|
required BuildContext context,
|
||||||
|
required List<DeviceFunction> functions,
|
||||||
|
required String uniqueCustomId,
|
||||||
|
required AllDevicesModel? device,
|
||||||
|
}) async {
|
||||||
|
List<ControlCurtainFunction> curtainFunctions =
|
||||||
|
functions.whereType<ControlCurtainFunction>().where((function) {
|
||||||
|
if (dialogType == 'THEN') {
|
||||||
|
return function.type == 'THEN' || function.type == 'BOTH';
|
||||||
|
}
|
||||||
|
return function.type == 'IF' || function.type == 'BOTH';
|
||||||
|
}).toList();
|
||||||
|
return showDialog<Map<String, dynamic>?>(
|
||||||
|
context: context,
|
||||||
|
builder: (context) => BlocProvider(
|
||||||
|
create: (_) => FunctionBloc()..add(const InitializeFunctions([])),
|
||||||
|
child: AlertDialog(
|
||||||
|
contentPadding: EdgeInsets.zero,
|
||||||
|
content: BlocBuilder<FunctionBloc, FunctionBlocState>(
|
||||||
|
builder: (context, state) {
|
||||||
|
final selectedFunction = state.selectedFunction;
|
||||||
|
final selectedOperationName = state.selectedOperationName;
|
||||||
|
final selectedFunctionData = state.addedFunctions
|
||||||
|
.firstWhere((f) => f.functionCode == selectedFunction,
|
||||||
|
orElse: () => DeviceFunctionData(
|
||||||
|
entityId: '',
|
||||||
|
functionCode: selectedFunction ?? '',
|
||||||
|
operationName: '',
|
||||||
|
value: null,
|
||||||
|
));
|
||||||
|
|
||||||
|
return Container(
|
||||||
|
width: selectedFunction != null ? 600 : 360,
|
||||||
|
height: 450,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.white,
|
||||||
|
borderRadius: BorderRadius.circular(20),
|
||||||
|
),
|
||||||
|
padding: const EdgeInsets.only(top: 20),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
const DialogHeader('AC Functions'),
|
||||||
|
Expanded(
|
||||||
|
child: Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
// Function list
|
||||||
|
SizedBox(
|
||||||
|
width: selectedFunction != null ? 320 : 360,
|
||||||
|
child: _buildFunctionsList(
|
||||||
|
context: context,
|
||||||
|
curtainFunctions: curtainFunctions,
|
||||||
|
onFunctionSelected:
|
||||||
|
(functionCode, operationName) {
|
||||||
|
RoutineTapFunctionHelper.onTapFunction(
|
||||||
|
context,
|
||||||
|
functionCode: functionCode,
|
||||||
|
functionOperationName: operationName,
|
||||||
|
functionValueDescription:
|
||||||
|
selectedFunctionData.valueDescription,
|
||||||
|
deviceUuid: device?.uuid,
|
||||||
|
codesToAddIntoFunctionsWithDefaultValue: [
|
||||||
|
'temp_set',
|
||||||
|
'temp_current',
|
||||||
|
],
|
||||||
|
defaultValue: 0);
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
// Value selector
|
||||||
|
if (selectedFunction != null)
|
||||||
|
Expanded(
|
||||||
|
child: _buildValueSelector(
|
||||||
|
context: context,
|
||||||
|
selectedFunction: selectedFunction,
|
||||||
|
selectedFunctionData: selectedFunctionData,
|
||||||
|
controlFunctions: curtainFunctions,
|
||||||
|
device: device,
|
||||||
|
operationName: selectedOperationName ?? '',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
DialogFooter(
|
||||||
|
onCancel: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
onConfirm: state.addedFunctions.isNotEmpty
|
||||||
|
? () {
|
||||||
|
/// add the functions to the routine bloc
|
||||||
|
context.read<RoutineBloc>().add(
|
||||||
|
AddFunctionToRoutine(
|
||||||
|
state.addedFunctions,
|
||||||
|
uniqueCustomId,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Return the device data to be added to the container
|
||||||
|
Navigator.pop(context, {
|
||||||
|
'deviceId': functions.first.deviceId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
isConfirmEnabled: selectedFunction != null,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
).then((value) {
|
||||||
|
return value;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static Widget _buildFunctionsList({
|
||||||
|
required BuildContext context,
|
||||||
|
required List<ControlCurtainFunction> curtainFunctions,
|
||||||
|
required Function(String, String) onFunctionSelected,
|
||||||
|
}) {
|
||||||
|
return ListView.separated(
|
||||||
|
shrinkWrap: false,
|
||||||
|
physics: const AlwaysScrollableScrollPhysics(),
|
||||||
|
itemCount: curtainFunctions.length,
|
||||||
|
separatorBuilder: (context, index) => const Padding(
|
||||||
|
padding: EdgeInsets.symmetric(horizontal: 40.0),
|
||||||
|
child: Divider(
|
||||||
|
color: ColorsManager.dividerColor,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final function = curtainFunctions[index];
|
||||||
|
return ListTile(
|
||||||
|
leading: SvgPicture.asset(
|
||||||
|
function.icon,
|
||||||
|
width: 24,
|
||||||
|
height: 24,
|
||||||
|
placeholderBuilder: (BuildContext context) => Container(
|
||||||
|
width: 24,
|
||||||
|
height: 24,
|
||||||
|
color: Colors.transparent,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
title: Text(
|
||||||
|
function.operationName,
|
||||||
|
style: context.textTheme.bodyMedium,
|
||||||
|
),
|
||||||
|
trailing: const Icon(
|
||||||
|
Icons.arrow_forward_ios,
|
||||||
|
size: 16,
|
||||||
|
color: ColorsManager.textGray,
|
||||||
|
),
|
||||||
|
onTap: () => onFunctionSelected(
|
||||||
|
function.code,
|
||||||
|
function.operationName,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Widget _buildValueSelector({
|
||||||
|
required BuildContext context,
|
||||||
|
required String selectedFunction,
|
||||||
|
required DeviceFunctionData? selectedFunctionData,
|
||||||
|
required List<ControlCurtainFunction> controlFunctions,
|
||||||
|
AllDevicesModel? device,
|
||||||
|
required String operationName,
|
||||||
|
}) {
|
||||||
|
final selectedFn =
|
||||||
|
controlFunctions.firstWhere((f) => f.code == selectedFunction);
|
||||||
|
|
||||||
|
// Rest of your existing code for other value selectors
|
||||||
|
final values = selectedFn.getOperationalValues();
|
||||||
|
return _buildOperationalValuesList(
|
||||||
|
context: context,
|
||||||
|
values: values,
|
||||||
|
selectedValue: selectedFunctionData?.value,
|
||||||
|
device: device,
|
||||||
|
operationName: operationName,
|
||||||
|
selectCode: selectedFunction,
|
||||||
|
selectedFunctionData: selectedFunctionData,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Widget _buildOperationalValuesList({
|
||||||
|
required BuildContext context,
|
||||||
|
required List<CurtainOperationalValue> values,
|
||||||
|
required dynamic selectedValue,
|
||||||
|
AllDevicesModel? device,
|
||||||
|
required String operationName,
|
||||||
|
required String selectCode,
|
||||||
|
DeviceFunctionData? selectedFunctionData,
|
||||||
|
|
||||||
|
// required Function(dynamic) onValueChanged,
|
||||||
|
}) {
|
||||||
|
return ListView.builder(
|
||||||
|
shrinkWrap: false,
|
||||||
|
physics: const AlwaysScrollableScrollPhysics(),
|
||||||
|
itemCount: values.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final value = values[index];
|
||||||
|
final isSelected = selectedValue == value.value;
|
||||||
|
return ListTile(
|
||||||
|
leading: SvgPicture.asset(
|
||||||
|
value.icon,
|
||||||
|
width: 24,
|
||||||
|
height: 24,
|
||||||
|
placeholderBuilder: (BuildContext context) => Container(
|
||||||
|
width: 24,
|
||||||
|
height: 24,
|
||||||
|
color: Colors.transparent,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
title: Text(
|
||||||
|
value.description,
|
||||||
|
style: context.textTheme.bodyMedium,
|
||||||
|
),
|
||||||
|
trailing: Icon(
|
||||||
|
isSelected
|
||||||
|
? Icons.radio_button_checked
|
||||||
|
: Icons.radio_button_unchecked,
|
||||||
|
size: 24,
|
||||||
|
color: isSelected
|
||||||
|
? ColorsManager.primaryColorWithOpacity
|
||||||
|
: ColorsManager.textGray,
|
||||||
|
),
|
||||||
|
onTap: () {
|
||||||
|
if (!isSelected) {
|
||||||
|
context.read<FunctionBloc>().add(
|
||||||
|
AddFunction(
|
||||||
|
functionData: DeviceFunctionData(
|
||||||
|
entityId: device?.uuid ?? '',
|
||||||
|
functionCode: selectCode,
|
||||||
|
operationName: operationName,
|
||||||
|
value: value.value,
|
||||||
|
condition: selectedFunctionData?.condition,
|
||||||
|
valueDescription:
|
||||||
|
selectedFunctionData?.valueDescription,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -192,9 +192,18 @@ class _WallPresenceSensorState extends State<FlushPresenceSensor> {
|
|||||||
onCancel: () => Navigator.pop(context),
|
onCancel: () => Navigator.pop(context),
|
||||||
onConfirm: state.addedFunctions.isNotEmpty
|
onConfirm: state.addedFunctions.isNotEmpty
|
||||||
? () {
|
? () {
|
||||||
|
final selectedFunctionData = state.addedFunctions.firstWhere(
|
||||||
|
(f) => f.functionCode == state.selectedFunction,
|
||||||
|
orElse: () => DeviceFunctionData(
|
||||||
|
entityId: '',
|
||||||
|
functionCode: state.selectedFunction ?? '',
|
||||||
|
operationName: '',
|
||||||
|
value: null,
|
||||||
|
),
|
||||||
|
);
|
||||||
context.read<RoutineBloc>().add(
|
context.read<RoutineBloc>().add(
|
||||||
AddFunctionToRoutine(
|
AddFunctionToRoutine(
|
||||||
state.addedFunctions,
|
[selectedFunctionData],
|
||||||
widget.uniqueCustomId!,
|
widget.uniqueCustomId!,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -115,9 +115,18 @@ class _GatewayDialogState extends State<GatewayDialog> {
|
|||||||
onCancel: () => Navigator.pop(context),
|
onCancel: () => Navigator.pop(context),
|
||||||
onConfirm: state.addedFunctions.isNotEmpty
|
onConfirm: state.addedFunctions.isNotEmpty
|
||||||
? () {
|
? () {
|
||||||
|
final selectedFunctionData = state.addedFunctions.firstWhere(
|
||||||
|
(f) => f.functionCode == state.selectedFunction,
|
||||||
|
orElse: () => DeviceFunctionData(
|
||||||
|
entityId: '',
|
||||||
|
functionCode: state.selectedFunction ?? '',
|
||||||
|
operationName: '',
|
||||||
|
value: null,
|
||||||
|
),
|
||||||
|
);
|
||||||
context.read<RoutineBloc>().add(
|
context.read<RoutineBloc>().add(
|
||||||
AddFunctionToRoutine(
|
AddFunctionToRoutine(
|
||||||
state.addedFunctions,
|
[selectedFunctionData],
|
||||||
widget.uniqueCustomId ?? '-1',
|
widget.uniqueCustomId ?? '-1',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -147,7 +147,7 @@ class OneGangSwitchHelper {
|
|||||||
// }
|
// }
|
||||||
context.read<RoutineBloc>().add(
|
context.read<RoutineBloc>().add(
|
||||||
AddFunctionToRoutine(
|
AddFunctionToRoutine(
|
||||||
state.addedFunctions,
|
[selectedFunctionData],
|
||||||
uniqueCustomId,
|
uniqueCustomId,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -250,9 +250,18 @@ class _EnergyClampDialogState extends State<EnergyClampDialog> {
|
|||||||
onCancel: () => Navigator.pop(context),
|
onCancel: () => Navigator.pop(context),
|
||||||
onConfirm: state.addedFunctions.isNotEmpty
|
onConfirm: state.addedFunctions.isNotEmpty
|
||||||
? () {
|
? () {
|
||||||
|
final selectedFunctionData = state.addedFunctions.firstWhere(
|
||||||
|
(f) => f.functionCode == state.selectedFunction,
|
||||||
|
orElse: () => DeviceFunctionData(
|
||||||
|
entityId: '',
|
||||||
|
functionCode: state.selectedFunction ?? '',
|
||||||
|
operationName: '',
|
||||||
|
value: null,
|
||||||
|
),
|
||||||
|
);
|
||||||
context.read<RoutineBloc>().add(
|
context.read<RoutineBloc>().add(
|
||||||
AddFunctionToRoutine(
|
AddFunctionToRoutine(
|
||||||
state.addedFunctions,
|
[selectedFunctionData],
|
||||||
widget.uniqueCustomId!,
|
widget.uniqueCustomId!,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -27,17 +27,16 @@ class EnergyValueSelectorWidget extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final selectedFn =
|
final selectedFn = functions.firstWhere((f) => f.code == selectedFunction);
|
||||||
functions.firstWhere((f) => f.code == selectedFunction);
|
|
||||||
final values = selectedFn.getOperationalValues();
|
final values = selectedFn.getOperationalValues();
|
||||||
final step = selectedFn.step ?? 1.0;
|
final step = selectedFn.step;
|
||||||
final _unit = selectedFn.unit ?? '';
|
final _unit = selectedFn.unit ?? '';
|
||||||
final (double, double) sliderRange =
|
final (double, double) sliderRange =
|
||||||
(selectedFn.min ?? 0.0, selectedFn.max ?? 100.0);
|
(selectedFn.min ?? 0.0, selectedFn.max ?? 100.0);
|
||||||
|
|
||||||
if (_isSliderFunction(selectedFunction)) {
|
if (_isSliderFunction(selectedFunction)) {
|
||||||
return CustomRoutinesTextbox(
|
return CustomRoutinesTextbox(
|
||||||
withSpecialChar: false,
|
withSpecialChar: true,
|
||||||
currentCondition: functionData.condition,
|
currentCondition: functionData.condition,
|
||||||
dialogType: dialogType,
|
dialogType: dialogType,
|
||||||
sliderRange: sliderRange,
|
sliderRange: sliderRange,
|
||||||
@ -60,14 +59,14 @@ class EnergyValueSelectorWidget extends StatelessWidget {
|
|||||||
entityId: device?.uuid ?? '',
|
entityId: device?.uuid ?? '',
|
||||||
functionCode: selectedFunction,
|
functionCode: selectedFunction,
|
||||||
operationName: functionData.operationName,
|
operationName: functionData.operationName,
|
||||||
value: value.toInt(),
|
value: value,
|
||||||
condition: functionData.condition,
|
condition: functionData.condition,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
unit: _unit,
|
unit: _unit,
|
||||||
dividendOfRange: 1,
|
dividendOfRange: 1,
|
||||||
stepIncreaseAmount: step,
|
stepIncreaseAmount: step!,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,9 +145,22 @@ class TwoGangSwitchHelper {
|
|||||||
// ),
|
// ),
|
||||||
// );
|
// );
|
||||||
// }
|
// }
|
||||||
|
final selectedFunctionData =
|
||||||
|
state.addedFunctions.firstWhere(
|
||||||
|
(f) =>
|
||||||
|
f.functionCode ==
|
||||||
|
state.selectedFunction,
|
||||||
|
orElse: () => DeviceFunctionData(
|
||||||
|
entityId: '',
|
||||||
|
functionCode:
|
||||||
|
state.selectedFunction ?? '',
|
||||||
|
operationName: '',
|
||||||
|
value: null,
|
||||||
|
),
|
||||||
|
);
|
||||||
context.read<RoutineBloc>().add(
|
context.read<RoutineBloc>().add(
|
||||||
AddFunctionToRoutine(
|
AddFunctionToRoutine(
|
||||||
state.addedFunctions,
|
[selectedFunctionData],
|
||||||
uniqueCustomId,
|
uniqueCustomId,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -210,9 +210,18 @@ class _WallPresenceSensorState extends State<WallPresenceSensor> {
|
|||||||
onCancel: () => Navigator.pop(context),
|
onCancel: () => Navigator.pop(context),
|
||||||
onConfirm: state.addedFunctions.isNotEmpty
|
onConfirm: state.addedFunctions.isNotEmpty
|
||||||
? () {
|
? () {
|
||||||
|
final selectedFunctionData = state.addedFunctions.firstWhere(
|
||||||
|
(f) => f.functionCode == state.selectedFunction,
|
||||||
|
orElse: () => DeviceFunctionData(
|
||||||
|
entityId: '',
|
||||||
|
functionCode: state.selectedFunction ?? '',
|
||||||
|
operationName: '',
|
||||||
|
value: null,
|
||||||
|
),
|
||||||
|
);
|
||||||
context.read<RoutineBloc>().add(
|
context.read<RoutineBloc>().add(
|
||||||
AddFunctionToRoutine(
|
AddFunctionToRoutine(
|
||||||
state.addedFunctions,
|
[selectedFunctionData],
|
||||||
widget.uniqueCustomId!,
|
widget.uniqueCustomId!,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -188,9 +188,18 @@ class _WaterHeaterDialogRoutinesState extends State<WaterHeaterDialogRoutines> {
|
|||||||
onCancel: () => Navigator.pop(context),
|
onCancel: () => Navigator.pop(context),
|
||||||
onConfirm: state.addedFunctions.isNotEmpty
|
onConfirm: state.addedFunctions.isNotEmpty
|
||||||
? () {
|
? () {
|
||||||
|
final selectedFunctionData = state.addedFunctions.firstWhere(
|
||||||
|
(f) => f.functionCode == state.selectedFunction,
|
||||||
|
orElse: () => DeviceFunctionData(
|
||||||
|
entityId: '',
|
||||||
|
functionCode: state.selectedFunction ?? '',
|
||||||
|
operationName: '',
|
||||||
|
value: null,
|
||||||
|
),
|
||||||
|
);
|
||||||
context.read<RoutineBloc>().add(
|
context.read<RoutineBloc>().add(
|
||||||
AddFunctionToRoutine(
|
AddFunctionToRoutine(
|
||||||
state.addedFunctions,
|
[selectedFunctionData],
|
||||||
widget.uniqueCustomId!,
|
widget.uniqueCustomId!,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -30,19 +30,19 @@ class ThenContainer extends StatelessWidget {
|
|||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 18, fontWeight: FontWeight.bold)),
|
fontSize: 18, fontWeight: FontWeight.bold)),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
state.isLoading && state.isUpdate == true
|
if (state.isLoading && state.isUpdate == true)
|
||||||
? const Center(
|
const Center(
|
||||||
child: CircularProgressIndicator(),
|
child: CircularProgressIndicator(),
|
||||||
)
|
)
|
||||||
: Wrap(
|
else
|
||||||
|
Wrap(
|
||||||
spacing: 8,
|
spacing: 8,
|
||||||
runSpacing: 8,
|
runSpacing: 8,
|
||||||
children: List.generate(
|
children: List.generate(
|
||||||
state.thenItems.length,
|
state.thenItems.length,
|
||||||
(index) => GestureDetector(
|
(index) => GestureDetector(
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
if (state.thenItems[index]
|
if (state.thenItems[index]['deviceId'] ==
|
||||||
['deviceId'] ==
|
|
||||||
'delay') {
|
'delay') {
|
||||||
final result = await DelayHelper
|
final result = await DelayHelper
|
||||||
.showDelayPickerDialog(context,
|
.showDelayPickerDialog(context,
|
||||||
@ -67,16 +67,15 @@ class ThenContainer extends StatelessWidget {
|
|||||||
builder: (BuildContext context) =>
|
builder: (BuildContext context) =>
|
||||||
AutomationDialog(
|
AutomationDialog(
|
||||||
automationName:
|
automationName:
|
||||||
state.thenItems[index]
|
state.thenItems[index]['name']
|
||||||
['name'] ??
|
as String? ??
|
||||||
'Automation',
|
'Automation',
|
||||||
automationId:
|
automationId: state.thenItems[index]
|
||||||
state.thenItems[index]
|
['deviceId'] as String? ??
|
||||||
['deviceId'] ??
|
|
||||||
'',
|
'',
|
||||||
uniqueCustomId:
|
uniqueCustomId: state
|
||||||
state.thenItems[index]
|
.thenItems[index]
|
||||||
['uniqueCustomId'],
|
['uniqueCustomId'] as String,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -85,10 +84,8 @@ class ThenContainer extends StatelessWidget {
|
|||||||
.read<RoutineBloc>()
|
.read<RoutineBloc>()
|
||||||
.add(AddToThenContainer({
|
.add(AddToThenContainer({
|
||||||
...state.thenItems[index],
|
...state.thenItems[index],
|
||||||
'imagePath':
|
'imagePath': Assets.automation,
|
||||||
Assets.automation,
|
'title': state.thenItems[index]
|
||||||
'title':
|
|
||||||
state.thenItems[index]
|
|
||||||
['name'] ??
|
['name'] ??
|
||||||
state.thenItems[index]
|
state.thenItems[index]
|
||||||
['title'],
|
['title'],
|
||||||
@ -102,8 +99,7 @@ class ThenContainer extends StatelessWidget {
|
|||||||
context: context,
|
context: context,
|
||||||
data: state.thenItems[index],
|
data: state.thenItems[index],
|
||||||
removeComparetors: true,
|
removeComparetors: true,
|
||||||
dialogType: "THEN");
|
dialogType: 'THEN');
|
||||||
|
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
context.read<RoutineBloc>().add(
|
context.read<RoutineBloc>().add(
|
||||||
AddToThenContainer(
|
AddToThenContainer(
|
||||||
@ -115,9 +111,10 @@ class ThenContainer extends StatelessWidget {
|
|||||||
'3G',
|
'3G',
|
||||||
'WPS',
|
'WPS',
|
||||||
'CPS',
|
'CPS',
|
||||||
"GW",
|
'GW',
|
||||||
"NCPS",
|
'NCPS',
|
||||||
'WH',
|
'WH',
|
||||||
|
'CUR',
|
||||||
].contains(state.thenItems[index]
|
].contains(state.thenItems[index]
|
||||||
['productType'])) {
|
['productType'])) {
|
||||||
context.read<RoutineBloc>().add(
|
context.read<RoutineBloc>().add(
|
||||||
@ -127,10 +124,10 @@ class ThenContainer extends StatelessWidget {
|
|||||||
},
|
},
|
||||||
child: DraggableCard(
|
child: DraggableCard(
|
||||||
imagePath: state.thenItems[index]
|
imagePath: state.thenItems[index]
|
||||||
['imagePath'] ??
|
['imagePath'] as String? ??
|
||||||
'',
|
'',
|
||||||
title: state.thenItems[index]
|
title: state.thenItems[index]['title']
|
||||||
['title'] ??
|
as String? ??
|
||||||
'',
|
'',
|
||||||
deviceData: state.thenItems[index],
|
deviceData: state.thenItems[index],
|
||||||
padding: const EdgeInsets.symmetric(
|
padding: const EdgeInsets.symmetric(
|
||||||
@ -143,7 +140,8 @@ class ThenContainer extends StatelessWidget {
|
|||||||
index: index,
|
index: index,
|
||||||
isFromThen: true,
|
isFromThen: true,
|
||||||
key: state.thenItems[index]
|
key: state.thenItems[index]
|
||||||
['uniqueCustomId']));
|
['uniqueCustomId']
|
||||||
|
as String));
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
))),
|
))),
|
||||||
@ -230,7 +228,7 @@ class ThenContainer extends StatelessWidget {
|
|||||||
context: context,
|
context: context,
|
||||||
data: mutableData,
|
data: mutableData,
|
||||||
removeComparetors: true,
|
removeComparetors: true,
|
||||||
dialogType: "THEN");
|
dialogType: 'THEN');
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
context.read<RoutineBloc>().add(AddToThenContainer(mutableData));
|
context.read<RoutineBloc>().add(AddToThenContainer(mutableData));
|
||||||
} else if (![
|
} else if (![
|
||||||
@ -241,9 +239,10 @@ class ThenContainer extends StatelessWidget {
|
|||||||
'WPS',
|
'WPS',
|
||||||
'GW',
|
'GW',
|
||||||
'CPS',
|
'CPS',
|
||||||
"NCPS",
|
'NCPS',
|
||||||
"WH",
|
'WH',
|
||||||
'PC',
|
'PC',
|
||||||
|
'CUR',
|
||||||
].contains(mutableData['productType'])) {
|
].contains(mutableData['productType'])) {
|
||||||
context.read<RoutineBloc>().add(AddToThenContainer(mutableData));
|
context.read<RoutineBloc>().add(AddToThenContainer(mutableData));
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
class SpaceConnectionModel {
|
||||||
|
final String from;
|
||||||
|
final String to;
|
||||||
|
|
||||||
|
const SpaceConnectionModel({required this.from, required this.to});
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/main_module/models/space_connection_model.dart';
|
||||||
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
|
||||||
|
class SpacesConnectionsArrowPainter extends CustomPainter {
|
||||||
|
final List<SpaceConnectionModel> connections;
|
||||||
|
final Map<String, Offset> positions;
|
||||||
|
final double cardWidth = 150.0;
|
||||||
|
final double cardHeight = 90.0;
|
||||||
|
final Set<String> highlightedUuids;
|
||||||
|
|
||||||
|
SpacesConnectionsArrowPainter({
|
||||||
|
required this.connections,
|
||||||
|
required this.positions,
|
||||||
|
required this.highlightedUuids,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
void paint(Canvas canvas, Size size) {
|
||||||
|
for (final connection in connections) {
|
||||||
|
final isSelected = highlightedUuids.contains(connection.from) ||
|
||||||
|
highlightedUuids.contains(connection.to);
|
||||||
|
final paint = Paint()
|
||||||
|
..color = isSelected
|
||||||
|
? ColorsManager.blackColor
|
||||||
|
: ColorsManager.blackColor.withValues(alpha: 0.5)
|
||||||
|
..strokeWidth = 2.0
|
||||||
|
..style = PaintingStyle.stroke;
|
||||||
|
|
||||||
|
final from = positions[connection.from];
|
||||||
|
final to = positions[connection.to];
|
||||||
|
|
||||||
|
if (from != null && to != null) {
|
||||||
|
final startPoint =
|
||||||
|
Offset(from.dx + cardWidth / 2, from.dy + cardHeight - 10);
|
||||||
|
final endPoint = Offset(to.dx + cardWidth / 2, to.dy);
|
||||||
|
|
||||||
|
final path = Path()..moveTo(startPoint.dx, startPoint.dy);
|
||||||
|
|
||||||
|
final controlPoint1 = Offset(startPoint.dx, startPoint.dy + 20);
|
||||||
|
final controlPoint2 = Offset(endPoint.dx, endPoint.dy - 60);
|
||||||
|
|
||||||
|
path.cubicTo(controlPoint1.dx, controlPoint1.dy, controlPoint2.dx,
|
||||||
|
controlPoint2.dy, endPoint.dx, endPoint.dy);
|
||||||
|
|
||||||
|
canvas.drawPath(path, paint);
|
||||||
|
|
||||||
|
final circlePaint = Paint()
|
||||||
|
..color = isSelected
|
||||||
|
? ColorsManager.blackColor
|
||||||
|
: ColorsManager.blackColor.withValues(alpha: 0.5)
|
||||||
|
..style = PaintingStyle.fill
|
||||||
|
..blendMode = BlendMode.srcIn;
|
||||||
|
canvas.drawCircle(endPoint, 4, circlePaint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool shouldRepaint(covariant CustomPainter oldDelegate) => true;
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/presentation/bloc/communities_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/presentation/communities_tree_selection_bloc/communities_tree_selection_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/create_community/presentation/create_community_dialog.dart';
|
||||||
|
|
||||||
|
abstract final class SpaceManagementCommunityDialogHelper {
|
||||||
|
static void showCreateDialog(BuildContext context) {
|
||||||
|
showDialog<void>(
|
||||||
|
context: context,
|
||||||
|
builder: (_) => CreateCommunityDialog(
|
||||||
|
title: const SelectableText('Community Name'),
|
||||||
|
onCreateCommunity: (community) {
|
||||||
|
context.read<CommunitiesBloc>().add(
|
||||||
|
InsertCommunity(community),
|
||||||
|
);
|
||||||
|
context.read<CommunitiesTreeSelectionBloc>().add(
|
||||||
|
SelectCommunityEvent(community: community),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
import 'package:equatable/equatable.dart';
|
||||||
|
|
||||||
|
class PaginatedDataModel<T> extends Equatable {
|
||||||
|
const PaginatedDataModel({
|
||||||
|
required this.data,
|
||||||
|
required this.page,
|
||||||
|
required this.size,
|
||||||
|
required this.hasNext,
|
||||||
|
required this.totalItems,
|
||||||
|
required this.totalPages,
|
||||||
|
});
|
||||||
|
|
||||||
|
final List<T> data;
|
||||||
|
final int page;
|
||||||
|
final int size;
|
||||||
|
final bool hasNext;
|
||||||
|
final int totalItems;
|
||||||
|
final int totalPages;
|
||||||
|
|
||||||
|
factory PaginatedDataModel.fromJson(
|
||||||
|
Map<String, dynamic> json,
|
||||||
|
List<T> Function(List<dynamic>) fromJsonList,
|
||||||
|
) {
|
||||||
|
return PaginatedDataModel<T>(
|
||||||
|
data: fromJsonList(json['data'] as List<dynamic>),
|
||||||
|
page: json['page'] as int? ?? 1,
|
||||||
|
size: json['size'] as int? ?? 25,
|
||||||
|
hasNext: json['hasNext'] as bool? ?? false,
|
||||||
|
totalItems: json['totalItem'] as int? ?? 0,
|
||||||
|
totalPages: json['totalPage'] as int? ?? 0,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [
|
||||||
|
data,
|
||||||
|
page,
|
||||||
|
size,
|
||||||
|
hasNext,
|
||||||
|
totalItems,
|
||||||
|
totalPages,
|
||||||
|
];
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/shared/navigate_home_grid_view.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/main_module/widgets/space_management_body.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/data/services/debounced_communities_service.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/data/services/remote_communities_service.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/params/load_communities_param.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/presentation/bloc/communities_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/presentation/communities_tree_selection_bloc/communities_tree_selection_bloc.dart';
|
||||||
|
import 'package:syncrow_web/services/api/http_service.dart';
|
||||||
|
import 'package:syncrow_web/utils/theme/responsive_text_theme.dart';
|
||||||
|
import 'package:syncrow_web/web_layout/web_scaffold.dart';
|
||||||
|
|
||||||
|
class SpaceManagementPage extends StatelessWidget {
|
||||||
|
const SpaceManagementPage({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return MultiBlocProvider(
|
||||||
|
providers: [
|
||||||
|
BlocProvider(
|
||||||
|
create: (context) => CommunitiesBloc(
|
||||||
|
communitiesService: DebouncedCommunitiesService(
|
||||||
|
RemoteCommunitiesService(HTTPService()),
|
||||||
|
),
|
||||||
|
)..add(const LoadCommunities(LoadCommunitiesParam())),
|
||||||
|
),
|
||||||
|
BlocProvider(create: (context) => CommunitiesTreeSelectionBloc()),
|
||||||
|
],
|
||||||
|
child: WebScaffold(
|
||||||
|
appBarTitle: Text(
|
||||||
|
'Space Management',
|
||||||
|
style: ResponsiveTextTheme.of(context).deviceManagementTitle,
|
||||||
|
),
|
||||||
|
enableMenuSidebar: false,
|
||||||
|
centerBody: Text(
|
||||||
|
'Community Structure',
|
||||||
|
style: Theme.of(context).textTheme.bodyLarge!.copyWith(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
rightBody: const NavigateHomeGridView(),
|
||||||
|
scaffoldBody: const SpaceManagementBody(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,280 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/main_module/models/space_connection_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/main_module/painters/spaces_connections_arrow_painter.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/main_module/widgets/space_card_widget.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/main_module/widgets/space_cell.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/models/community_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/models/space_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/presentation/communities_tree_selection_bloc/communities_tree_selection_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/presentation/helpers/space_details_dialog_helper.dart';
|
||||||
|
|
||||||
|
class CommunityStructureCanvas extends StatefulWidget {
|
||||||
|
const CommunityStructureCanvas({
|
||||||
|
required this.community,
|
||||||
|
required this.selectedSpace,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
final CommunityModel community;
|
||||||
|
final SpaceModel? selectedSpace;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<CommunityStructureCanvas> createState() => _CommunityStructureCanvasState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _CommunityStructureCanvasState extends State<CommunityStructureCanvas>
|
||||||
|
with SingleTickerProviderStateMixin {
|
||||||
|
final Map<String, Offset> _positions = {};
|
||||||
|
final double _cardWidth = 150.0;
|
||||||
|
final double _cardHeight = 90.0;
|
||||||
|
final double _horizontalSpacing = 150.0;
|
||||||
|
final double _verticalSpacing = 120.0;
|
||||||
|
|
||||||
|
late TransformationController _transformationController;
|
||||||
|
late AnimationController _animationController;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
_transformationController = TransformationController();
|
||||||
|
_animationController = AnimationController(
|
||||||
|
vsync: this,
|
||||||
|
duration: const Duration(milliseconds: 150),
|
||||||
|
);
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didUpdateWidget(covariant CommunityStructureCanvas oldWidget) {
|
||||||
|
super.didUpdateWidget(oldWidget);
|
||||||
|
if (widget.selectedSpace?.uuid != oldWidget.selectedSpace?.uuid) {
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
if (mounted) {
|
||||||
|
_animateToSpace(widget.selectedSpace);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_transformationController.dispose();
|
||||||
|
_animationController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<String> _getAllDescendantUuids(SpaceModel space) {
|
||||||
|
final uuids = <String>{};
|
||||||
|
for (final child in space.children) {
|
||||||
|
uuids.add(child.uuid);
|
||||||
|
uuids.addAll(_getAllDescendantUuids(child));
|
||||||
|
}
|
||||||
|
return uuids;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _runAnimation(Matrix4 target) {
|
||||||
|
final animation = Matrix4Tween(
|
||||||
|
begin: _transformationController.value,
|
||||||
|
end: target,
|
||||||
|
).animate(_animationController);
|
||||||
|
|
||||||
|
void listener() {
|
||||||
|
_transformationController.value = animation.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
animation.addListener(listener);
|
||||||
|
_animationController.forward(from: 0).whenCompleteOrCancel(() {
|
||||||
|
animation.removeListener(listener);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void _animateToSpace(SpaceModel? space) {
|
||||||
|
if (space == null) {
|
||||||
|
_runAnimation(Matrix4.identity());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final position = _positions[space.uuid];
|
||||||
|
if (position == null) return;
|
||||||
|
|
||||||
|
const scale = 1.5;
|
||||||
|
final viewSize = context.size;
|
||||||
|
if (viewSize == null) return;
|
||||||
|
|
||||||
|
final x = -position.dx * scale + (viewSize.width / 2) - (_cardWidth * scale / 2);
|
||||||
|
final y =
|
||||||
|
-position.dy * scale + (viewSize.height / 2) - (_cardHeight * scale / 2);
|
||||||
|
|
||||||
|
final matrix = Matrix4.identity()
|
||||||
|
..translate(x, y)
|
||||||
|
..scale(scale);
|
||||||
|
|
||||||
|
_runAnimation(matrix);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onSpaceTapped(SpaceModel? space) {
|
||||||
|
context.read<CommunitiesTreeSelectionBloc>().add(
|
||||||
|
SelectSpaceEvent(community: widget.community, space: space),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _resetSelectionAndZoom() {
|
||||||
|
context.read<CommunitiesTreeSelectionBloc>().add(
|
||||||
|
SelectSpaceEvent(
|
||||||
|
community: widget.community,
|
||||||
|
space: null,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _calculateLayout(
|
||||||
|
List<SpaceModel> spaces,
|
||||||
|
int depth,
|
||||||
|
Map<int, double> levelXOffset,
|
||||||
|
) {
|
||||||
|
for (final space in spaces) {
|
||||||
|
double childSubtreeWidth = 0;
|
||||||
|
if (space.children.isNotEmpty) {
|
||||||
|
_calculateLayout(space.children, depth + 1, levelXOffset);
|
||||||
|
final firstChildPos = _positions[space.children.first.uuid];
|
||||||
|
final lastChildPos = _positions[space.children.last.uuid];
|
||||||
|
if (firstChildPos != null && lastChildPos != null) {
|
||||||
|
childSubtreeWidth = (lastChildPos.dx + _cardWidth) - firstChildPos.dx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final currentX = levelXOffset.putIfAbsent(depth, () => 0.0);
|
||||||
|
double? x;
|
||||||
|
|
||||||
|
if (space.children.isNotEmpty) {
|
||||||
|
final firstChildPos = _positions[space.children.first.uuid]!;
|
||||||
|
x = firstChildPos.dx + (childSubtreeWidth - _cardWidth) / 2;
|
||||||
|
} else {
|
||||||
|
x = currentX;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x < currentX) {
|
||||||
|
final shiftX = currentX - x;
|
||||||
|
_shiftSubtree(space, shiftX);
|
||||||
|
final keysToShift = levelXOffset.keys.where((d) => d > depth).toList();
|
||||||
|
for (final key in keysToShift) {
|
||||||
|
levelXOffset[key] = levelXOffset[key]! + shiftX;
|
||||||
|
}
|
||||||
|
x += shiftX;
|
||||||
|
}
|
||||||
|
|
||||||
|
final y = depth * (_verticalSpacing + _cardHeight);
|
||||||
|
_positions[space.uuid] = Offset(x, y);
|
||||||
|
levelXOffset[depth] = x + _cardWidth + _horizontalSpacing;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _shiftSubtree(SpaceModel space, double shiftX) {
|
||||||
|
if (_positions.containsKey(space.uuid)) {
|
||||||
|
_positions[space.uuid] = _positions[space.uuid]!.translate(shiftX, 0);
|
||||||
|
}
|
||||||
|
for (final child in space.children) {
|
||||||
|
_shiftSubtree(child, shiftX);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Widget> _buildTreeWidgets() {
|
||||||
|
_positions.clear();
|
||||||
|
final community = widget.community;
|
||||||
|
|
||||||
|
_calculateLayout(community.spaces, 0, {});
|
||||||
|
|
||||||
|
final selectedSpace = widget.selectedSpace;
|
||||||
|
final highlightedUuids = <String>{};
|
||||||
|
if (selectedSpace != null) {
|
||||||
|
highlightedUuids.add(selectedSpace.uuid);
|
||||||
|
highlightedUuids.addAll(_getAllDescendantUuids(selectedSpace));
|
||||||
|
}
|
||||||
|
|
||||||
|
final widgets = <Widget>[];
|
||||||
|
final connections = <SpaceConnectionModel>[];
|
||||||
|
_generateWidgets(community.spaces, widgets, connections, highlightedUuids);
|
||||||
|
|
||||||
|
return [
|
||||||
|
CustomPaint(
|
||||||
|
painter: SpacesConnectionsArrowPainter(
|
||||||
|
connections: connections,
|
||||||
|
positions: _positions,
|
||||||
|
highlightedUuids: highlightedUuids,
|
||||||
|
),
|
||||||
|
child: Stack(alignment: AlignmentDirectional.center, children: widgets),
|
||||||
|
),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
void _generateWidgets(
|
||||||
|
List<SpaceModel> spaces,
|
||||||
|
List<Widget> widgets,
|
||||||
|
List<SpaceConnectionModel> connections,
|
||||||
|
Set<String> highlightedUuids,
|
||||||
|
) {
|
||||||
|
for (final space in spaces) {
|
||||||
|
final position = _positions[space.uuid];
|
||||||
|
if (position == null) continue;
|
||||||
|
|
||||||
|
final isHighlighted = highlightedUuids.contains(space.uuid);
|
||||||
|
final hasNoSelectedSpace = widget.selectedSpace == null;
|
||||||
|
|
||||||
|
widgets.add(
|
||||||
|
Positioned(
|
||||||
|
left: position.dx,
|
||||||
|
top: position.dy,
|
||||||
|
width: _cardWidth,
|
||||||
|
height: _cardHeight,
|
||||||
|
child: SpaceCardWidget(
|
||||||
|
buildSpaceContainer: () {
|
||||||
|
return Opacity(
|
||||||
|
opacity: hasNoSelectedSpace || isHighlighted ? 1.0 : 0.5,
|
||||||
|
child: Tooltip(
|
||||||
|
message: space.spaceName,
|
||||||
|
preferBelow: false,
|
||||||
|
child: SpaceCell(
|
||||||
|
onTap: () => _onSpaceTapped(space),
|
||||||
|
icon: space.icon,
|
||||||
|
name: space.spaceName,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
onTap: () => SpaceDetailsDialogHelper.showCreate(context),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
for (final child in space.children) {
|
||||||
|
connections.add(
|
||||||
|
SpaceConnectionModel(from: space.uuid, to: child.uuid),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
_generateWidgets(space.children, widgets, connections, highlightedUuids);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final treeWidgets = _buildTreeWidgets();
|
||||||
|
return InteractiveViewer(
|
||||||
|
transformationController: _transformationController,
|
||||||
|
boundaryMargin: EdgeInsets.symmetric(
|
||||||
|
horizontal: MediaQuery.sizeOf(context).width * 0.3,
|
||||||
|
vertical: MediaQuery.sizeOf(context).height * 0.3,
|
||||||
|
),
|
||||||
|
minScale: 0.5,
|
||||||
|
maxScale: 3.0,
|
||||||
|
constrained: false,
|
||||||
|
child: GestureDetector(
|
||||||
|
onTap: _resetSelectionAndZoom,
|
||||||
|
child: SizedBox(
|
||||||
|
width: MediaQuery.sizeOf(context).width * 5,
|
||||||
|
height: MediaQuery.sizeOf(context).height * 5,
|
||||||
|
child: Stack(children: treeWidgets),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||||
|
|
||||||
|
class CommunityTemplateCell extends StatelessWidget {
|
||||||
|
const CommunityTemplateCell({
|
||||||
|
super.key,
|
||||||
|
required this.onTap,
|
||||||
|
required this.title,
|
||||||
|
});
|
||||||
|
|
||||||
|
final void Function() onTap;
|
||||||
|
final Widget title;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: onTap,
|
||||||
|
child: Column(
|
||||||
|
spacing: 8,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: AspectRatio(
|
||||||
|
aspectRatio: 2.0,
|
||||||
|
child: Container(
|
||||||
|
decoration: ShapeDecoration(
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
side: const BorderSide(
|
||||||
|
width: 4,
|
||||||
|
strokeAlign: BorderSide.strokeAlignOutside,
|
||||||
|
color: ColorsManager.borderColor,
|
||||||
|
),
|
||||||
|
borderRadius: BorderRadius.circular(5),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
DefaultTextStyle(
|
||||||
|
style: context.textTheme.bodyLarge!.copyWith(
|
||||||
|
color: ColorsManager.blackColor,
|
||||||
|
),
|
||||||
|
child: title,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/presentation/helpers/space_details_dialog_helper.dart';
|
||||||
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
|
||||||
|
class CreateSpaceButton extends StatelessWidget {
|
||||||
|
const CreateSpaceButton({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: () => SpaceDetailsDialogHelper.showCreate(context),
|
||||||
|
child: Container(
|
||||||
|
height: 60,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.white,
|
||||||
|
borderRadius: BorderRadius.circular(20),
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: Colors.grey.withValues(alpha: 0.5),
|
||||||
|
spreadRadius: 5,
|
||||||
|
blurRadius: 7,
|
||||||
|
offset: const Offset(0, 3),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: Center(
|
||||||
|
child: Container(
|
||||||
|
width: 40,
|
||||||
|
height: 40,
|
||||||
|
decoration: const BoxDecoration(
|
||||||
|
color: ColorsManager.boxColor,
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
),
|
||||||
|
child: const Icon(
|
||||||
|
Icons.add,
|
||||||
|
color: Colors.blue,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
|
||||||
|
class PlusButtonWidget extends StatelessWidget {
|
||||||
|
final Offset offset;
|
||||||
|
final void Function() onButtonTap;
|
||||||
|
|
||||||
|
const PlusButtonWidget({
|
||||||
|
super.key,
|
||||||
|
required this.offset,
|
||||||
|
required this.onButtonTap,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: onButtonTap,
|
||||||
|
child: Container(
|
||||||
|
width: 30,
|
||||||
|
height: 30,
|
||||||
|
decoration: const BoxDecoration(
|
||||||
|
color: ColorsManager.spaceColor,
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
),
|
||||||
|
child: const Icon(
|
||||||
|
Icons.add,
|
||||||
|
color: ColorsManager.whiteColors,
|
||||||
|
size: 20,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/main_module/widgets/plus_button_widget.dart';
|
||||||
|
|
||||||
|
class SpaceCardWidget extends StatefulWidget {
|
||||||
|
final void Function() onTap;
|
||||||
|
final Widget Function() buildSpaceContainer;
|
||||||
|
|
||||||
|
const SpaceCardWidget({
|
||||||
|
required this.onTap,
|
||||||
|
required this.buildSpaceContainer,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<SpaceCardWidget> createState() => _SpaceCardWidgetState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SpaceCardWidgetState extends State<SpaceCardWidget> {
|
||||||
|
bool isHovered = false;
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return MouseRegion(
|
||||||
|
onEnter: (_) => setState(() => isHovered = true),
|
||||||
|
onExit: (_) => setState(() => isHovered = false),
|
||||||
|
child: SizedBox(
|
||||||
|
child: Stack(
|
||||||
|
clipBehavior: Clip.none,
|
||||||
|
alignment: Alignment.center,
|
||||||
|
children: [
|
||||||
|
widget.buildSpaceContainer(),
|
||||||
|
if (isHovered)
|
||||||
|
Positioned(
|
||||||
|
bottom: 0,
|
||||||
|
child: PlusButtonWidget(
|
||||||
|
offset: Offset.zero,
|
||||||
|
onButtonTap: widget.onTap,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,85 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_svg/svg.dart';
|
||||||
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||||
|
|
||||||
|
class SpaceCell extends StatelessWidget {
|
||||||
|
final String icon;
|
||||||
|
final String name;
|
||||||
|
final VoidCallback? onTap;
|
||||||
|
|
||||||
|
const SpaceCell({
|
||||||
|
super.key,
|
||||||
|
required this.icon,
|
||||||
|
required this.name,
|
||||||
|
required this.onTap,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: onTap,
|
||||||
|
child: Container(
|
||||||
|
width: 150,
|
||||||
|
height: 70,
|
||||||
|
decoration: _containerDecoration(),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
_buildIconContainer(),
|
||||||
|
const SizedBox(width: 10),
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
name,
|
||||||
|
style: context.textTheme.bodyLarge?.copyWith(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: ColorsManager.blackColor,
|
||||||
|
),
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildIconContainer() {
|
||||||
|
return Container(
|
||||||
|
width: 40,
|
||||||
|
height: double.infinity,
|
||||||
|
decoration: const BoxDecoration(
|
||||||
|
color: ColorsManager.spaceColor,
|
||||||
|
borderRadius: BorderRadius.only(
|
||||||
|
topLeft: Radius.circular(15),
|
||||||
|
bottomLeft: Radius.circular(15),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Center(
|
||||||
|
child: SvgPicture.asset(
|
||||||
|
icon,
|
||||||
|
colorFilter: const ColorFilter.mode(
|
||||||
|
ColorsManager.whiteColors,
|
||||||
|
BlendMode.srcIn,
|
||||||
|
),
|
||||||
|
width: 24,
|
||||||
|
height: 24,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
BoxDecoration _containerDecoration() {
|
||||||
|
return BoxDecoration(
|
||||||
|
color: ColorsManager.whiteColors,
|
||||||
|
borderRadius: BorderRadius.circular(15),
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: ColorsManager.lightGrayColor.withValues(alpha: 0.5),
|
||||||
|
spreadRadius: 2,
|
||||||
|
blurRadius: 5,
|
||||||
|
offset: const Offset(0, 3),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/main_module/widgets/space_management_community_structure.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/main_module/widgets/space_management_templates_view.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/presentation/communities_tree_selection_bloc/communities_tree_selection_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/presentation/widgets/space_management_communities_tree.dart';
|
||||||
|
|
||||||
|
class SpaceManagementBody extends StatelessWidget {
|
||||||
|
const SpaceManagementBody({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Row(
|
||||||
|
children: [
|
||||||
|
const SpaceManagementCommunitiesTree(),
|
||||||
|
Expanded(
|
||||||
|
child: BlocBuilder<CommunitiesTreeSelectionBloc,
|
||||||
|
CommunitiesTreeSelectionState>(
|
||||||
|
buildWhen: (previous, current) =>
|
||||||
|
previous.selectedCommunity != current.selectedCommunity,
|
||||||
|
builder: (context, state) => Visibility(
|
||||||
|
visible: state.selectedCommunity == null,
|
||||||
|
replacement: const SpaceManagementCommunityStructure(),
|
||||||
|
child: const SpaceManagementTemplatesView(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/main_module/widgets/community_structure_canvas.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/main_module/widgets/create_space_button.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/presentation/communities_tree_selection_bloc/communities_tree_selection_bloc.dart';
|
||||||
|
|
||||||
|
class SpaceManagementCommunityStructure extends StatelessWidget {
|
||||||
|
const SpaceManagementCommunityStructure({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final selectionBloc = context.watch<CommunitiesTreeSelectionBloc>().state;
|
||||||
|
final selectedCommunity = selectionBloc.selectedCommunity;
|
||||||
|
final selectedSpace = selectionBloc.selectedSpace;
|
||||||
|
const spacer = Spacer(flex: 10);
|
||||||
|
return Visibility(
|
||||||
|
visible: selectedCommunity!.spaces.isNotEmpty,
|
||||||
|
replacement: const Row(
|
||||||
|
children: [spacer, Expanded(child: CreateSpaceButton()), spacer],
|
||||||
|
),
|
||||||
|
child: CommunityStructureCanvas(
|
||||||
|
community: selectedCommunity,
|
||||||
|
selectedSpace: selectedSpace,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/main_module/shared/helpers/space_management_community_dialog_helper.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/main_module/widgets/community_template_cell.dart';
|
||||||
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
|
||||||
|
class SpaceManagementTemplatesView extends StatelessWidget {
|
||||||
|
const SpaceManagementTemplatesView({super.key});
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return ColoredBox(
|
||||||
|
color: ColorsManager.whiteColors,
|
||||||
|
child: GridView.builder(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 40, vertical: 20),
|
||||||
|
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
|
||||||
|
maxCrossAxisExtent: 400,
|
||||||
|
mainAxisSpacing: 10,
|
||||||
|
crossAxisSpacing: 10,
|
||||||
|
childAspectRatio: 2.0,
|
||||||
|
),
|
||||||
|
itemCount: _gridItems(context).length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final model = _gridItems(context)[index];
|
||||||
|
return CommunityTemplateCell(
|
||||||
|
onTap: model.onTap,
|
||||||
|
title: model.title,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<_CommunityTemplateModel> _gridItems(BuildContext context) {
|
||||||
|
return [
|
||||||
|
_CommunityTemplateModel(
|
||||||
|
title: const Text('Blank'),
|
||||||
|
onTap: () => SpaceManagementCommunityDialogHelper.showCreateDialog(context),
|
||||||
|
),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _CommunityTemplateModel {
|
||||||
|
final Widget title;
|
||||||
|
final void Function() onTap;
|
||||||
|
|
||||||
|
_CommunityTemplateModel({
|
||||||
|
required this.title,
|
||||||
|
required this.onTap,
|
||||||
|
});
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/params/load_communities_param.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/services/communities_service.dart';
|
||||||
|
|
||||||
|
final class DebouncedCommunitiesService implements CommunitiesService {
|
||||||
|
DebouncedCommunitiesService(
|
||||||
|
this._decoratee, {
|
||||||
|
this.debounceDuration = const Duration(milliseconds: 500),
|
||||||
|
});
|
||||||
|
|
||||||
|
final CommunitiesService _decoratee;
|
||||||
|
final Duration debounceDuration;
|
||||||
|
|
||||||
|
Timer? _debounceTimer;
|
||||||
|
late Completer<CommunitiesPaginationModel>? _completer;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<CommunitiesPaginationModel> getCommunity(
|
||||||
|
LoadCommunitiesParam param,
|
||||||
|
) async {
|
||||||
|
_debounceTimer?.cancel();
|
||||||
|
|
||||||
|
_completer = Completer<CommunitiesPaginationModel>();
|
||||||
|
final currentCompleter = _completer!;
|
||||||
|
|
||||||
|
_debounceTimer = Timer(debounceDuration, () async {
|
||||||
|
try {
|
||||||
|
final result = await _decoratee.getCommunity(param);
|
||||||
|
if (!currentCompleter.isCompleted) {
|
||||||
|
currentCompleter.complete(result);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (!currentCompleter.isCompleted) {
|
||||||
|
currentCompleter.completeError(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return currentCompleter.future;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/models/community_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/params/load_communities_param.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/services/communities_service.dart';
|
||||||
|
import 'package:syncrow_web/services/api/api_exception.dart';
|
||||||
|
import 'package:syncrow_web/services/api/http_service.dart';
|
||||||
|
import 'package:syncrow_web/utils/constants/api_const.dart';
|
||||||
|
|
||||||
|
class RemoteCommunitiesService implements CommunitiesService {
|
||||||
|
const RemoteCommunitiesService(this._httpService);
|
||||||
|
|
||||||
|
final HTTPService _httpService;
|
||||||
|
|
||||||
|
static const _defaultErrorMessage = 'Failed to load communities';
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<CommunitiesPaginationModel> getCommunity(
|
||||||
|
LoadCommunitiesParam param,
|
||||||
|
) async {
|
||||||
|
try {
|
||||||
|
final response = await _httpService.get(
|
||||||
|
path: await _makeUrl(),
|
||||||
|
queryParameters: {
|
||||||
|
'page': param.page,
|
||||||
|
'size': param.size,
|
||||||
|
'includeSpaces': param.includeSpaces,
|
||||||
|
if (param.search.isNotEmpty && param.search != 'null')
|
||||||
|
'search': param.search,
|
||||||
|
},
|
||||||
|
expectedResponseModel: (json) => CommunitiesPaginationModel.fromJson(
|
||||||
|
json as Map<String, dynamic>,
|
||||||
|
CommunityModel.fromJsonList,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
return response;
|
||||||
|
} on DioException catch (e) {
|
||||||
|
final message = e.response?.data as Map<String, dynamic>?;
|
||||||
|
final error = message?['error'] as Map<String, dynamic>?;
|
||||||
|
final errorMessage = error?['error'] as String? ?? '';
|
||||||
|
throw APIException(errorMessage);
|
||||||
|
} catch (e) {
|
||||||
|
final formattedErrorMessage = [_defaultErrorMessage, '$e'].join(': ');
|
||||||
|
throw APIException(formattedErrorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<String> _makeUrl() async {
|
||||||
|
final projectUuid = await ProjectManager.getProjectUUID();
|
||||||
|
if (projectUuid == null) throw APIException('Project UUID is required');
|
||||||
|
return ApiEndpoints.getCommunityListv2.replaceAll(
|
||||||
|
'{projectId}',
|
||||||
|
projectUuid,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/models/space_model.dart';
|
||||||
|
|
||||||
|
class CommunityModel extends Equatable {
|
||||||
|
final String uuid;
|
||||||
|
final String name;
|
||||||
|
final DateTime createdAt;
|
||||||
|
final DateTime updatedAt;
|
||||||
|
final String description;
|
||||||
|
final String externalId;
|
||||||
|
final List<SpaceModel> spaces;
|
||||||
|
|
||||||
|
const CommunityModel({
|
||||||
|
required this.uuid,
|
||||||
|
required this.name,
|
||||||
|
required this.createdAt,
|
||||||
|
required this.updatedAt,
|
||||||
|
required this.description,
|
||||||
|
required this.externalId,
|
||||||
|
required this.spaces,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory CommunityModel.fromJson(Map<String, dynamic> json) {
|
||||||
|
return CommunityModel(
|
||||||
|
uuid: json['uuid'] as String,
|
||||||
|
name: json['name'] as String,
|
||||||
|
createdAt: DateTime.parse(json['createdAt'] as String),
|
||||||
|
updatedAt: DateTime.parse(json['updatedAt'] as String),
|
||||||
|
description: json['description'] as String,
|
||||||
|
externalId: json['externalId']?.toString() ?? '',
|
||||||
|
spaces: (json['spaces'] as List<dynamic>? ?? <dynamic>[])
|
||||||
|
.map((e) => SpaceModel.fromJson(e as Map<String, dynamic>))
|
||||||
|
.toList(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
static List<CommunityModel> fromJsonList(List<dynamic> json) {
|
||||||
|
return json
|
||||||
|
.map((e) => CommunityModel.fromJson(e as Map<String, dynamic>))
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [uuid, name, spaces];
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
import 'package:equatable/equatable.dart';
|
||||||
|
|
||||||
|
class SpaceModel extends Equatable {
|
||||||
|
final String uuid;
|
||||||
|
final DateTime? createdAt;
|
||||||
|
final DateTime? updatedAt;
|
||||||
|
final String spaceName;
|
||||||
|
final String icon;
|
||||||
|
final List<SpaceModel> children;
|
||||||
|
final SpaceModel? parent;
|
||||||
|
|
||||||
|
const SpaceModel({
|
||||||
|
required this.uuid,
|
||||||
|
required this.createdAt,
|
||||||
|
required this.updatedAt,
|
||||||
|
required this.spaceName,
|
||||||
|
required this.icon,
|
||||||
|
required this.children,
|
||||||
|
required this.parent,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory SpaceModel.fromJson(Map<String, dynamic> json) {
|
||||||
|
return SpaceModel(
|
||||||
|
uuid: json['uuid'] as String? ?? '',
|
||||||
|
createdAt: DateTime.tryParse(json['createdAt'] as String? ?? ''),
|
||||||
|
updatedAt: DateTime.tryParse(json['updatedAt'] as String? ?? ''),
|
||||||
|
spaceName: json['spaceName'] as String? ?? '',
|
||||||
|
icon: json['icon'] as String? ?? 'assets/icons/location_icon.svg',
|
||||||
|
children: (json['children'] as List<dynamic>?)
|
||||||
|
?.map((e) => SpaceModel.fromJson(e as Map<String, dynamic>))
|
||||||
|
.toList() ??
|
||||||
|
[],
|
||||||
|
parent: json['parent'] != null
|
||||||
|
? SpaceModel.fromJson(json['parent'] as Map<String, dynamic>)
|
||||||
|
: null,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [uuid, spaceName, icon, children];
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
import 'package:equatable/equatable.dart';
|
||||||
|
|
||||||
|
class LoadCommunitiesParam extends Equatable {
|
||||||
|
const LoadCommunitiesParam({
|
||||||
|
this.page = 1,
|
||||||
|
this.size = 25,
|
||||||
|
this.search = '',
|
||||||
|
this.includeSpaces = true,
|
||||||
|
});
|
||||||
|
|
||||||
|
final int page;
|
||||||
|
final int size;
|
||||||
|
final String search;
|
||||||
|
final bool includeSpaces;
|
||||||
|
|
||||||
|
LoadCommunitiesParam copyWith({
|
||||||
|
int? page,
|
||||||
|
int? size,
|
||||||
|
String? search,
|
||||||
|
bool? includeSpaces,
|
||||||
|
}) {
|
||||||
|
return LoadCommunitiesParam(
|
||||||
|
page: page ?? this.page,
|
||||||
|
size: size ?? this.size,
|
||||||
|
search: search ?? this.search,
|
||||||
|
includeSpaces: includeSpaces ?? this.includeSpaces,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [page, size, search, includeSpaces];
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
import 'package:syncrow_web/pages/space_management_v2/main_module/shared/models/paginated_data_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/models/community_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/params/load_communities_param.dart';
|
||||||
|
|
||||||
|
typedef CommunitiesPaginationModel = PaginatedDataModel<CommunityModel>;
|
||||||
|
|
||||||
|
abstract class CommunitiesService {
|
||||||
|
Future<CommunitiesPaginationModel> getCommunity(LoadCommunitiesParam param);
|
||||||
|
}
|
@ -0,0 +1,117 @@
|
|||||||
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/models/community_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/params/load_communities_param.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/services/communities_service.dart';
|
||||||
|
import 'package:syncrow_web/services/api/api_exception.dart';
|
||||||
|
|
||||||
|
part 'communities_event.dart';
|
||||||
|
part 'communities_state.dart';
|
||||||
|
|
||||||
|
class CommunitiesBloc extends Bloc<CommunitiesEvent, CommunitiesState> {
|
||||||
|
CommunitiesBloc({
|
||||||
|
required CommunitiesService communitiesService,
|
||||||
|
}) : _communitiesService = communitiesService,
|
||||||
|
super(const CommunitiesState()) {
|
||||||
|
on<LoadCommunities>(_onLoadCommunities);
|
||||||
|
on<LoadMoreCommunities>(_onLoadMoreCommunities);
|
||||||
|
on<InsertCommunity>(_onInsertCommunity);
|
||||||
|
}
|
||||||
|
|
||||||
|
final CommunitiesService _communitiesService;
|
||||||
|
|
||||||
|
Future<void> _onLoadCommunities(
|
||||||
|
LoadCommunities event,
|
||||||
|
Emitter<CommunitiesState> emit,
|
||||||
|
) async {
|
||||||
|
try {
|
||||||
|
emit(
|
||||||
|
state.copyWith(status: CommunitiesStatus.loading),
|
||||||
|
);
|
||||||
|
|
||||||
|
final paginationResponse = await _communitiesService.getCommunity(
|
||||||
|
event.param,
|
||||||
|
);
|
||||||
|
|
||||||
|
emit(
|
||||||
|
CommunitiesState(
|
||||||
|
status: CommunitiesStatus.success,
|
||||||
|
communities: paginationResponse.data,
|
||||||
|
hasNext: paginationResponse.hasNext,
|
||||||
|
currentPage: paginationResponse.page,
|
||||||
|
searchQuery: event.param.search,
|
||||||
|
isLoadingMore: false,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} on APIException catch (e) {
|
||||||
|
_onApiException(e, emit);
|
||||||
|
} catch (e) {
|
||||||
|
_onError(e, emit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _onLoadMoreCommunities(
|
||||||
|
LoadMoreCommunities event,
|
||||||
|
Emitter<CommunitiesState> emit,
|
||||||
|
) async {
|
||||||
|
if (!state.hasNext || state.isLoadingMore) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
emit(state.copyWith(isLoadingMore: true));
|
||||||
|
|
||||||
|
final param = LoadCommunitiesParam(
|
||||||
|
page: state.currentPage + 1,
|
||||||
|
search: state.searchQuery,
|
||||||
|
);
|
||||||
|
|
||||||
|
final paginationResponse = await _communitiesService.getCommunity(param);
|
||||||
|
|
||||||
|
final updatedCommunities = List<CommunityModel>.from(state.communities)
|
||||||
|
..addAll(paginationResponse.data);
|
||||||
|
|
||||||
|
emit(
|
||||||
|
state.copyWith(
|
||||||
|
status: CommunitiesStatus.success,
|
||||||
|
communities: updatedCommunities,
|
||||||
|
hasNext: paginationResponse.hasNext,
|
||||||
|
currentPage: paginationResponse.page,
|
||||||
|
isLoadingMore: false,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} on APIException catch (e) {
|
||||||
|
_onApiException(e, emit);
|
||||||
|
} catch (e) {
|
||||||
|
_onError(e, emit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onApiException(
|
||||||
|
APIException e,
|
||||||
|
Emitter<CommunitiesState> emit,
|
||||||
|
) {
|
||||||
|
emit(
|
||||||
|
state.copyWith(
|
||||||
|
status: CommunitiesStatus.failure,
|
||||||
|
isLoadingMore: false,
|
||||||
|
errorMessage: e.message,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onError(Object e, Emitter<CommunitiesState> emit) {
|
||||||
|
emit(
|
||||||
|
state.copyWith(
|
||||||
|
status: CommunitiesStatus.failure,
|
||||||
|
isLoadingMore: false,
|
||||||
|
errorMessage: e.toString(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onInsertCommunity(
|
||||||
|
InsertCommunity event,
|
||||||
|
Emitter<CommunitiesState> emit,
|
||||||
|
) {
|
||||||
|
emit(state.copyWith(communities: [event.community, ...state.communities]));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
part of 'communities_bloc.dart';
|
||||||
|
|
||||||
|
sealed class CommunitiesEvent extends Equatable {
|
||||||
|
const CommunitiesEvent();
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [];
|
||||||
|
}
|
||||||
|
|
||||||
|
class LoadCommunities extends CommunitiesEvent {
|
||||||
|
const LoadCommunities(this.param);
|
||||||
|
|
||||||
|
final LoadCommunitiesParam param;
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [param];
|
||||||
|
}
|
||||||
|
|
||||||
|
class LoadMoreCommunities extends CommunitiesEvent {
|
||||||
|
const LoadMoreCommunities();
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [];
|
||||||
|
}
|
||||||
|
|
||||||
|
final class InsertCommunity extends CommunitiesEvent {
|
||||||
|
const InsertCommunity(this.community);
|
||||||
|
|
||||||
|
final CommunityModel community;
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [community];
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
part of 'communities_bloc.dart';
|
||||||
|
|
||||||
|
enum CommunitiesStatus { initial, loading, success, failure }
|
||||||
|
|
||||||
|
final class CommunitiesState extends Equatable {
|
||||||
|
const CommunitiesState({
|
||||||
|
this.status = CommunitiesStatus.initial,
|
||||||
|
this.communities = const [],
|
||||||
|
this.errorMessage,
|
||||||
|
this.isLoadingMore = false,
|
||||||
|
this.hasNext = false,
|
||||||
|
this.currentPage = 1,
|
||||||
|
this.searchQuery = '',
|
||||||
|
});
|
||||||
|
|
||||||
|
final CommunitiesStatus status;
|
||||||
|
final List<CommunityModel> communities;
|
||||||
|
final String? errorMessage;
|
||||||
|
final bool isLoadingMore;
|
||||||
|
final bool hasNext;
|
||||||
|
final int currentPage;
|
||||||
|
final String searchQuery;
|
||||||
|
|
||||||
|
CommunitiesState copyWith({
|
||||||
|
CommunitiesStatus? status,
|
||||||
|
List<CommunityModel>? communities,
|
||||||
|
String? errorMessage,
|
||||||
|
bool? isLoadingMore,
|
||||||
|
bool? hasNext,
|
||||||
|
int? currentPage,
|
||||||
|
String? searchQuery,
|
||||||
|
}) {
|
||||||
|
return CommunitiesState(
|
||||||
|
status: status ?? this.status,
|
||||||
|
communities: communities ?? this.communities,
|
||||||
|
errorMessage: errorMessage ?? this.errorMessage,
|
||||||
|
isLoadingMore: isLoadingMore ?? this.isLoadingMore,
|
||||||
|
hasNext: hasNext ?? this.hasNext,
|
||||||
|
currentPage: currentPage ?? this.currentPage,
|
||||||
|
searchQuery: searchQuery ?? this.searchQuery,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [
|
||||||
|
status,
|
||||||
|
communities,
|
||||||
|
errorMessage,
|
||||||
|
isLoadingMore,
|
||||||
|
hasNext,
|
||||||
|
currentPage,
|
||||||
|
searchQuery,
|
||||||
|
];
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
import 'package:bloc/bloc.dart';
|
||||||
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/models/community_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/models/space_model.dart';
|
||||||
|
|
||||||
|
part 'communities_tree_selection_event.dart';
|
||||||
|
part 'communities_tree_selection_state.dart';
|
||||||
|
|
||||||
|
class CommunitiesTreeSelectionBloc
|
||||||
|
extends Bloc<CommunitiesTreeSelectionEvent, CommunitiesTreeSelectionState> {
|
||||||
|
CommunitiesTreeSelectionBloc() : super(const CommunitiesTreeSelectionState()) {
|
||||||
|
on<SelectCommunityEvent>(_onSelectCommunity);
|
||||||
|
on<SelectSpaceEvent>(_onSelectSpace);
|
||||||
|
on<ClearCommunitiesTreeSelectionEvent>(_onClearSelection);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onSelectCommunity(
|
||||||
|
SelectCommunityEvent event,
|
||||||
|
Emitter<CommunitiesTreeSelectionState> emit,
|
||||||
|
) {
|
||||||
|
emit(
|
||||||
|
CommunitiesTreeSelectionState(
|
||||||
|
selectedCommunity: event.community,
|
||||||
|
selectedSpace: null,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onSelectSpace(
|
||||||
|
SelectSpaceEvent event,
|
||||||
|
Emitter<CommunitiesTreeSelectionState> emit,
|
||||||
|
) {
|
||||||
|
emit(
|
||||||
|
CommunitiesTreeSelectionState(
|
||||||
|
selectedCommunity: event.community,
|
||||||
|
selectedSpace: event.space,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onClearSelection(
|
||||||
|
ClearCommunitiesTreeSelectionEvent event,
|
||||||
|
Emitter<CommunitiesTreeSelectionState> emit,
|
||||||
|
) {
|
||||||
|
emit(const CommunitiesTreeSelectionState());
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user