mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 14:47:23 +00:00
@ -1,6 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||
|
||||
class DialogDropdown extends StatefulWidget {
|
||||
final List<String> items;
|
||||
@ -8,14 +7,14 @@ class DialogDropdown extends StatefulWidget {
|
||||
final String? selectedValue;
|
||||
|
||||
const DialogDropdown({
|
||||
super.key,
|
||||
Key? key,
|
||||
required this.items,
|
||||
required this.onSelected,
|
||||
this.selectedValue,
|
||||
});
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<DialogDropdown> createState() => _DialogDropdownState();
|
||||
_DialogDropdownState createState() => _DialogDropdownState();
|
||||
}
|
||||
|
||||
class _DialogDropdownState extends State<DialogDropdown> {
|
||||
@ -47,14 +46,16 @@ class _DialogDropdownState extends State<DialogDropdown> {
|
||||
}
|
||||
|
||||
OverlayEntry _createOverlayEntry() {
|
||||
final renderBox = context.findRenderObject()! as RenderBox;
|
||||
final renderBox = context.findRenderObject() as RenderBox;
|
||||
final size = renderBox.size;
|
||||
final offset = renderBox.localToGlobal(Offset.zero);
|
||||
|
||||
return OverlayEntry(
|
||||
builder: (context) {
|
||||
return GestureDetector(
|
||||
onTap: _closeDropdown,
|
||||
onTap: () {
|
||||
_closeDropdown();
|
||||
},
|
||||
behavior: HitTestBehavior.translucent,
|
||||
child: Stack(
|
||||
children: [
|
||||
@ -86,7 +87,10 @@ class _DialogDropdownState extends State<DialogDropdown> {
|
||||
child: ListTile(
|
||||
title: Text(
|
||||
item,
|
||||
style: context.textTheme.bodyMedium?.copyWith(
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodyMedium
|
||||
?.copyWith(
|
||||
color: ColorsManager.textPrimaryColor,
|
||||
),
|
||||
),
|
||||
|
@ -10,25 +10,24 @@ class EditChip extends StatelessWidget {
|
||||
final double borderRadius;
|
||||
|
||||
const EditChip({
|
||||
super.key,
|
||||
Key? key,
|
||||
this.label = 'Edit',
|
||||
required this.onTap,
|
||||
this.labelColor = ColorsManager.spaceColor,
|
||||
this.backgroundColor = ColorsManager.whiteColors,
|
||||
this.borderColor = ColorsManager.spaceColor,
|
||||
this.borderRadius = 16.0,
|
||||
});
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Chip(
|
||||
label: Text(label,
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall!
|
||||
.copyWith(color: labelColor)),
|
||||
label: Text(
|
||||
label,
|
||||
style: Theme.of(context).textTheme.bodySmall!.copyWith(color: labelColor)
|
||||
),
|
||||
backgroundColor: backgroundColor,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(borderRadius),
|
||||
|
@ -9,12 +9,12 @@ class TagDialogTextfieldDropdown extends StatefulWidget {
|
||||
final String product;
|
||||
|
||||
const TagDialogTextfieldDropdown({
|
||||
super.key,
|
||||
Key? key,
|
||||
required this.items,
|
||||
required this.onSelected,
|
||||
this.initialValue,
|
||||
required this.product,
|
||||
});
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
_DialogTextfieldDropdownState createState() =>
|
||||
@ -79,7 +79,7 @@ class _DialogTextfieldDropdownState extends State<TagDialogTextfieldDropdown> {
|
||||
}
|
||||
|
||||
OverlayEntry _createOverlayEntry() {
|
||||
final renderBox = context.findRenderObject()! as RenderBox;
|
||||
final renderBox = context.findRenderObject() as RenderBox;
|
||||
final size = renderBox.size;
|
||||
final offset = renderBox.localToGlobal(Offset.zero);
|
||||
|
||||
|
@ -10,8 +10,7 @@ class CustomExpansionTile extends StatefulWidget {
|
||||
final ValueChanged<bool>? onExpansionChanged; // Notify when expansion changes
|
||||
final VoidCallback? onItemSelected; // Callback for selecting the item
|
||||
|
||||
const CustomExpansionTile({
|
||||
super.key,
|
||||
CustomExpansionTile({
|
||||
required this.title,
|
||||
this.children,
|
||||
this.initiallyExpanded = false,
|
||||
|
@ -7,7 +7,7 @@ class CustomSearchBar extends StatefulWidget {
|
||||
final TextEditingController? controller;
|
||||
final String hintText;
|
||||
final String? searchQuery;
|
||||
final void Function(String)? onSearchChanged;
|
||||
final Function(String)? onSearchChanged; // Callback for search input changes
|
||||
|
||||
const CustomSearchBar({
|
||||
super.key,
|
||||
@ -37,7 +37,7 @@ class _CustomSearchBarState extends State<CustomSearchBar> {
|
||||
color: ColorsManager.whiteColors,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withValues(alpha: 0.2),
|
||||
color: Colors.black.withOpacity(0.2),
|
||||
spreadRadius: 0,
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 4),
|
||||
@ -57,7 +57,7 @@ class _CustomSearchBarState extends State<CustomSearchBar> {
|
||||
style: const TextStyle(
|
||||
color: Colors.black,
|
||||
),
|
||||
onChanged: widget.onSearchChanged,
|
||||
onChanged: widget.onSearchChanged, // Call the callback on text change
|
||||
decoration: InputDecoration(
|
||||
filled: true,
|
||||
fillColor: ColorsManager.textFieldGreyColor,
|
||||
|
@ -1,8 +1,7 @@
|
||||
// File generated by FlutterFire CLI.
|
||||
// ignore_for_file: type=lint
|
||||
import 'package:firebase_core/firebase_core.dart' show FirebaseOptions;
|
||||
import 'package:flutter/foundation.dart'
|
||||
show defaultTargetPlatform, kIsWeb, TargetPlatform;
|
||||
import 'package:flutter/foundation.dart' show defaultTargetPlatform, kIsWeb, TargetPlatform;
|
||||
|
||||
/// Default [FirebaseOptions] for use with your Firebase apps.
|
||||
///
|
||||
|
@ -40,7 +40,7 @@ class MyApp extends StatelessWidget {
|
||||
initialLocation: RoutesConst.auth,
|
||||
routes: AppRoutes.getRoutes(),
|
||||
redirect: (context, state) async {
|
||||
final checkToken = await AuthBloc.getTokenAndValidate();
|
||||
String checkToken = await AuthBloc.getTokenAndValidate();
|
||||
final loggedIn = checkToken == 'Success';
|
||||
final goingToLogin = state.uri.toString() == RoutesConst.auth;
|
||||
|
||||
|
@ -21,8 +21,7 @@ import 'package:syncrow_web/utils/theme/theme.dart';
|
||||
|
||||
Future<void> main() async {
|
||||
try {
|
||||
const environment =
|
||||
String.fromEnvironment('FLAVOR', defaultValue: 'development');
|
||||
const environment = String.fromEnvironment('FLAVOR', defaultValue: 'development');
|
||||
await dotenv.load(fileName: '.env.$environment');
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await Firebase.initializeApp(
|
||||
@ -40,7 +39,7 @@ class MyApp extends StatelessWidget {
|
||||
initialLocation: RoutesConst.auth,
|
||||
routes: AppRoutes.getRoutes(),
|
||||
redirect: (context, state) async {
|
||||
final checkToken = await AuthBloc.getTokenAndValidate();
|
||||
String checkToken = await AuthBloc.getTokenAndValidate();
|
||||
final loggedIn = checkToken == 'Success';
|
||||
final goingToLogin = state.uri.toString() == RoutesConst.auth;
|
||||
|
||||
@ -58,8 +57,7 @@ class MyApp extends StatelessWidget {
|
||||
BlocProvider<CreateRoutineBloc>(
|
||||
create: (context) => CreateRoutineBloc(),
|
||||
),
|
||||
BlocProvider(
|
||||
create: (context) => HomeBloc()..add(const FetchUserInfo())),
|
||||
BlocProvider(create: (context) => HomeBloc()..add(const FetchUserInfo())),
|
||||
BlocProvider<VisitorPasswordBloc>(
|
||||
create: (context) => VisitorPasswordBloc(),
|
||||
),
|
||||
|
@ -21,8 +21,7 @@ import 'package:syncrow_web/utils/theme/theme.dart';
|
||||
|
||||
Future<void> main() async {
|
||||
try {
|
||||
const environment =
|
||||
String.fromEnvironment('FLAVOR', defaultValue: 'staging');
|
||||
const environment = String.fromEnvironment('FLAVOR', defaultValue: 'staging');
|
||||
await dotenv.load(fileName: '.env.$environment');
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await Firebase.initializeApp(
|
||||
@ -40,7 +39,7 @@ class MyApp extends StatelessWidget {
|
||||
initialLocation: RoutesConst.auth,
|
||||
routes: AppRoutes.getRoutes(),
|
||||
redirect: (context, state) async {
|
||||
final checkToken = await AuthBloc.getTokenAndValidate();
|
||||
String checkToken = await AuthBloc.getTokenAndValidate();
|
||||
final loggedIn = checkToken == 'Success';
|
||||
final goingToLogin = state.uri.toString() == RoutesConst.auth;
|
||||
|
||||
@ -58,8 +57,7 @@ class MyApp extends StatelessWidget {
|
||||
BlocProvider<CreateRoutineBloc>(
|
||||
create: (context) => CreateRoutineBloc(),
|
||||
),
|
||||
BlocProvider(
|
||||
create: (context) => HomeBloc()..add(const FetchUserInfo())),
|
||||
BlocProvider(create: (context) => HomeBloc()..add(const FetchUserInfo())),
|
||||
BlocProvider<VisitorPasswordBloc>(
|
||||
create: (context) => VisitorPasswordBloc(),
|
||||
),
|
||||
|
@ -11,7 +11,7 @@ import 'package:syncrow_web/utils/constants/app_enum.dart';
|
||||
import 'package:syncrow_web/utils/snack_bar.dart';
|
||||
|
||||
class AccessBloc extends Bloc<AccessEvent, AccessState> {
|
||||
AccessBloc() : super(AccessInitial()) {
|
||||
AccessBloc() : super((AccessInitial())) {
|
||||
on<FetchTableData>(_onFetchTableData);
|
||||
on<SelectTime>(selectTime);
|
||||
on<FilterDataEvent>(_filterData);
|
||||
@ -43,12 +43,12 @@ class AccessBloc extends Bloc<AccessEvent, AccessState> {
|
||||
}
|
||||
|
||||
void updateTabsCount() {
|
||||
final toBeEffectiveCount = data
|
||||
int toBeEffectiveCount = data
|
||||
.where((item) => item.passwordStatus.value == 'To be effective')
|
||||
.length;
|
||||
final effectiveCount =
|
||||
int effectiveCount =
|
||||
data.where((item) => item.passwordStatus.value == 'Effective').length;
|
||||
final expiredCount =
|
||||
int expiredCount =
|
||||
data.where((item) => item.passwordStatus.value == 'Expired').length;
|
||||
tabs[1] = 'To Be Effective ($toBeEffectiveCount)';
|
||||
tabs[2] = 'Effective ($effectiveCount)';
|
||||
@ -81,7 +81,7 @@ class AccessBloc extends Bloc<AccessEvent, AccessState> {
|
||||
Emitter<AccessState> emit,
|
||||
) async {
|
||||
emit(AccessLoaded());
|
||||
final picked = await showDatePicker(
|
||||
final DateTime? picked = await showDatePicker(
|
||||
context: event.context,
|
||||
initialDate: DateTime.now(),
|
||||
firstDate: DateTime.now().add(const Duration(days: -5095)),
|
||||
@ -89,7 +89,7 @@ class AccessBloc extends Bloc<AccessEvent, AccessState> {
|
||||
builder: (BuildContext context, Widget? child) {
|
||||
return Theme(
|
||||
data: ThemeData.light().copyWith(
|
||||
colorScheme: const ColorScheme.light(
|
||||
colorScheme: ColorScheme.light(
|
||||
primary: ColorsManager.blackColor,
|
||||
onPrimary: Colors.white,
|
||||
onSurface: ColorsManager.grayColor,
|
||||
@ -105,20 +105,20 @@ class AccessBloc extends Bloc<AccessEvent, AccessState> {
|
||||
},
|
||||
);
|
||||
if (picked != null) {
|
||||
final timePicked = await showHourPicker(
|
||||
final TimeOfDay? timePicked = await showHourPicker(
|
||||
context: event.context,
|
||||
initialTime: TimeOfDay.now(),
|
||||
);
|
||||
|
||||
if (timePicked != null) {
|
||||
final selectedDateTime = DateTime(
|
||||
final DateTime selectedDateTime = DateTime(
|
||||
picked.year,
|
||||
picked.month,
|
||||
picked.day,
|
||||
timePicked.hour,
|
||||
timePicked.minute,
|
||||
);
|
||||
final selectedTimestamp =
|
||||
final int selectedTimestamp =
|
||||
selectedDateTime.millisecondsSinceEpoch ~/ 1000;
|
||||
if (event.isStart) {
|
||||
if (expirationTimeTimeStamp != null &&
|
||||
@ -152,35 +152,39 @@ class AccessBloc extends Bloc<AccessEvent, AccessState> {
|
||||
final searchText = event.passwordName?.toLowerCase() ?? '';
|
||||
final searchEmailText = event.emailAuthorizer?.toLowerCase() ?? '';
|
||||
filteredData = data.where((item) {
|
||||
var matchesCriteria = true;
|
||||
bool matchesCriteria = true;
|
||||
// Convert timestamp to DateTime and extract date component
|
||||
final effectiveDate = DateTime.fromMillisecondsSinceEpoch(
|
||||
DateTime effectiveDate = DateTime.fromMillisecondsSinceEpoch(
|
||||
int.parse(item.effectiveTime.toString()) * 1000)
|
||||
.toUtc()
|
||||
.toLocal();
|
||||
final invalidDate = DateTime.fromMillisecondsSinceEpoch(
|
||||
DateTime invalidDate = DateTime.fromMillisecondsSinceEpoch(
|
||||
int.parse(item.invalidTime.toString()) * 1000)
|
||||
.toUtc()
|
||||
.toLocal();
|
||||
final effectiveDateAndTime = DateTime(
|
||||
DateTime effectiveDateAndTime = DateTime(
|
||||
effectiveDate.year,
|
||||
effectiveDate.month,
|
||||
effectiveDate.day,
|
||||
effectiveDate.hour,
|
||||
effectiveDate.minute);
|
||||
final invalidDateAndTime = DateTime(invalidDate.year, invalidDate.month,
|
||||
invalidDate.day, invalidDate.hour, invalidDate.minute);
|
||||
DateTime invalidDateAndTime = DateTime(
|
||||
invalidDate.year,
|
||||
invalidDate.month,
|
||||
invalidDate.day,
|
||||
invalidDate.hour,
|
||||
invalidDate.minute);
|
||||
|
||||
// Filter by password name, making the search case-insensitive
|
||||
if (searchText.isNotEmpty) {
|
||||
final matchesName =
|
||||
final bool matchesName =
|
||||
item.passwordName.toString().toLowerCase().contains(searchText);
|
||||
if (!matchesName) {
|
||||
matchesCriteria = false;
|
||||
}
|
||||
}
|
||||
if (searchEmailText.isNotEmpty) {
|
||||
final matchesName = item.authorizerEmail
|
||||
final bool matchesName = item.authorizerEmail
|
||||
.toString()
|
||||
.toLowerCase()
|
||||
.contains(searchEmailText);
|
||||
@ -190,7 +194,7 @@ class AccessBloc extends Bloc<AccessEvent, AccessState> {
|
||||
}
|
||||
// Filter by start date only
|
||||
if (event.startTime != null && event.endTime == null) {
|
||||
var startDateTime =
|
||||
DateTime startDateTime =
|
||||
DateTime.fromMillisecondsSinceEpoch(event.startTime! * 1000)
|
||||
.toUtc()
|
||||
.toLocal();
|
||||
@ -202,7 +206,7 @@ class AccessBloc extends Bloc<AccessEvent, AccessState> {
|
||||
}
|
||||
// Filter by end date only
|
||||
if (event.endTime != null && event.startTime == null) {
|
||||
var startDateTime =
|
||||
DateTime startDateTime =
|
||||
DateTime.fromMillisecondsSinceEpoch(event.endTime! * 1000)
|
||||
.toUtc()
|
||||
.toLocal();
|
||||
@ -215,11 +219,11 @@ class AccessBloc extends Bloc<AccessEvent, AccessState> {
|
||||
|
||||
// Filter by both start date and end date
|
||||
if (event.startTime != null && event.endTime != null) {
|
||||
var startDateTime =
|
||||
DateTime startDateTime =
|
||||
DateTime.fromMillisecondsSinceEpoch(event.startTime! * 1000)
|
||||
.toUtc()
|
||||
.toLocal();
|
||||
var endDateTime =
|
||||
DateTime endDateTime =
|
||||
DateTime.fromMillisecondsSinceEpoch(event.endTime! * 1000)
|
||||
.toUtc()
|
||||
.toLocal();
|
||||
@ -254,7 +258,7 @@ class AccessBloc extends Bloc<AccessEvent, AccessState> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> resetSearch(ResetSearch event, Emitter<AccessState> emit) async {
|
||||
resetSearch(ResetSearch event, Emitter<AccessState> emit) async {
|
||||
emit(AccessLoaded());
|
||||
startTime = 'Start Time';
|
||||
endTime = 'End Time';
|
||||
@ -268,7 +272,7 @@ class AccessBloc extends Bloc<AccessEvent, AccessState> {
|
||||
}
|
||||
|
||||
String timestampToDate(dynamic timestamp) {
|
||||
final dateTime =
|
||||
DateTime dateTime =
|
||||
DateTime.fromMillisecondsSinceEpoch(int.parse(timestamp) * 1000);
|
||||
return "${dateTime.year}/${dateTime.month.toString().padLeft(2, '0')}/${dateTime.day.toString().padLeft(2, '0')} "
|
||||
" ${dateTime.hour.toString().padLeft(2, '0')}:${dateTime.minute.toString().padLeft(2, '0')}";
|
||||
@ -285,17 +289,17 @@ class AccessBloc extends Bloc<AccessEvent, AccessState> {
|
||||
break;
|
||||
case 1: // To Be Effective
|
||||
filteredData = data
|
||||
.where((item) => item.passwordStatus.value == 'To Be Effective')
|
||||
.where((item) => item.passwordStatus.value == "To Be Effective")
|
||||
.toList();
|
||||
break;
|
||||
case 2: // Effective
|
||||
filteredData = data
|
||||
.where((item) => item.passwordStatus.value == 'Effective')
|
||||
.where((item) => item.passwordStatus.value == "Effective")
|
||||
.toList();
|
||||
break;
|
||||
case 3: // Expired
|
||||
filteredData = data
|
||||
.where((item) => item.passwordStatus.value == 'Expired')
|
||||
.where((item) => item.passwordStatus.value == "Expired")
|
||||
.toList();
|
||||
break;
|
||||
default:
|
||||
|
@ -15,7 +15,7 @@ class AccessLoaded extends AccessState {}
|
||||
class FailedState extends AccessState {
|
||||
final String message;
|
||||
|
||||
const FailedState(this.message);
|
||||
FailedState(this.message);
|
||||
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
|
@ -36,7 +36,7 @@ class PasswordModel {
|
||||
effectiveTime: json['effectiveTime'],
|
||||
passwordCreated: json['passwordCreated'],
|
||||
createdTime: json['createdTime'],
|
||||
passwordName: json['passwordName'] ?? 'No Name',
|
||||
passwordName: json['passwordName']??'No Name',
|
||||
passwordStatus: AccessStatusExtension.fromString(json['passwordStatus']),
|
||||
passwordType: AccessTypeExtension.fromString(json['passwordType']),
|
||||
deviceUuid: json['deviceUuid'],
|
||||
|
@ -1,3 +1,5 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class DashedBorderPainter extends CustomPainter {
|
||||
@ -18,28 +20,27 @@ class DashedBorderPainter extends CustomPainter {
|
||||
..strokeWidth = 0.5
|
||||
..style = PaintingStyle.stroke;
|
||||
|
||||
final topPath = Path()
|
||||
final Path topPath = Path()
|
||||
..moveTo(0, 0)
|
||||
..lineTo(size.width, 0);
|
||||
|
||||
final bottomPath = Path()
|
||||
final Path bottomPath = Path()
|
||||
..moveTo(0, size.height)
|
||||
..lineTo(size.width, size.height);
|
||||
|
||||
final dashedTopPath = _createDashedPath(topPath, dashWidth, dashSpace);
|
||||
final dashedBottomPath =
|
||||
_createDashedPath(bottomPath, dashWidth, dashSpace);
|
||||
final dashedBottomPath = _createDashedPath(bottomPath, dashWidth, dashSpace);
|
||||
|
||||
canvas.drawPath(dashedTopPath, paint);
|
||||
canvas.drawPath(dashedBottomPath, paint);
|
||||
}
|
||||
|
||||
Path _createDashedPath(Path source, double dashWidth, double dashSpace) {
|
||||
final dashedPath = Path();
|
||||
for (final pathMetric in source.computeMetrics()) {
|
||||
var distance = 0.0;
|
||||
final Path dashedPath = Path();
|
||||
for (PathMetric pathMetric in source.computeMetrics()) {
|
||||
double distance = 0.0;
|
||||
while (distance < pathMetric.length) {
|
||||
final nextDistance = distance + dashWidth;
|
||||
final double nextDistance = distance + dashWidth;
|
||||
dashedPath.addPath(
|
||||
pathMetric.extractPath(distance, nextDistance),
|
||||
Offset.zero,
|
||||
|
@ -15,8 +15,7 @@ class AirQualityDataModel extends Equatable {
|
||||
return AirQualityDataModel(
|
||||
date: DateTime.parse(json['date'] as String),
|
||||
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(),
|
||||
);
|
||||
}
|
||||
|
@ -36,14 +36,11 @@ class AnalyticsDevice {
|
||||
deviceTuyaUuid: json['deviceTuyaUuid'] as String?,
|
||||
isActive: json['isActive'] as bool?,
|
||||
productDevice: json['productDevice'] != null
|
||||
? ProductDevice.fromJson(
|
||||
json['productDevice'] as Map<String, dynamic>)
|
||||
? ProductDevice.fromJson(json['productDevice'] as Map<String, dynamic>)
|
||||
: null,
|
||||
spaceUuid: json['spaceUuid'] as String?,
|
||||
latitude:
|
||||
json['lat'] != null ? double.parse(json['lat'] as String) : null,
|
||||
longitude:
|
||||
json['lon'] != null ? double.parse(json['lon'] as String) : null,
|
||||
latitude: json['lat'] != null ? double.parse(json['lat'] as String) : null,
|
||||
longitude: json['lon'] != null ? double.parse(json['lon'] as String) : null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -15,8 +15,7 @@ class Occupacy extends Equatable {
|
||||
|
||||
factory Occupacy.fromJson(Map<String, dynamic> json) {
|
||||
return Occupacy(
|
||||
date:
|
||||
DateTime.parse(json['event_date'] as String? ?? '${DateTime.now()}'),
|
||||
date: DateTime.parse(json['event_date'] as String? ?? '${DateTime.now()}'),
|
||||
occupancy: (json['occupancy_percentage'] ?? 0).toString(),
|
||||
spaceUuid: json['space_uuid'] as String? ?? '',
|
||||
occupiedSeconds: json['occupied_seconds'] as int? ?? 0,
|
||||
|
@ -19,8 +19,7 @@ class OccupancyHeatMapModel extends Equatable {
|
||||
eventDate: DateTime.parse(
|
||||
json['event_date'] as String? ?? '${DateTime.now()}',
|
||||
),
|
||||
countTotalPresenceDetected:
|
||||
json['count_total_presence_detected'] as int? ?? 0,
|
||||
countTotalPresenceDetected: json['count_total_presence_detected'] as int? ?? 0,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -33,8 +33,7 @@ class AirQualityDistributionBloc
|
||||
state.copyWith(
|
||||
status: AirQualityDistributionStatus.success,
|
||||
chartData: result,
|
||||
filteredChartData:
|
||||
_arrangeChartDataByType(result, state.selectedAqiType),
|
||||
filteredChartData: _arrangeChartDataByType(result, state.selectedAqiType),
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
@ -62,8 +61,7 @@ class AirQualityDistributionBloc
|
||||
emit(
|
||||
state.copyWith(
|
||||
selectedAqiType: event.aqiType,
|
||||
filteredChartData:
|
||||
_arrangeChartDataByType(state.chartData, event.aqiType),
|
||||
filteredChartData: _arrangeChartDataByType(state.chartData, event.aqiType),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -7,8 +7,7 @@ import 'package:syncrow_web/pages/analytics/services/device_location/device_loca
|
||||
part 'device_location_event.dart';
|
||||
part 'device_location_state.dart';
|
||||
|
||||
class DeviceLocationBloc
|
||||
extends Bloc<DeviceLocationEvent, DeviceLocationState> {
|
||||
class DeviceLocationBloc extends Bloc<DeviceLocationEvent, DeviceLocationState> {
|
||||
DeviceLocationBloc(
|
||||
this._deviceLocationService,
|
||||
) : super(const DeviceLocationState()) {
|
||||
|
@ -53,8 +53,7 @@ class RangeOfAqiBloc extends Bloc<RangeOfAqiEvent, RangeOfAqiState> {
|
||||
emit(
|
||||
state.copyWith(
|
||||
selectedAqiType: event.aqiType,
|
||||
filteredRangeOfAqi:
|
||||
_arrangeChartDataByType(state.rangeOfAqi, event.aqiType),
|
||||
filteredRangeOfAqi: _arrangeChartDataByType(state.rangeOfAqi, event.aqiType),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -105,8 +105,7 @@ abstract final class RangeOfAqiChartsHelper {
|
||||
tooltipRoundedRadius: 16,
|
||||
showOnTopOfTheChartBoxArea: false,
|
||||
tooltipPadding: const EdgeInsets.all(8),
|
||||
getTooltipItems: (touchedSpots) =>
|
||||
RangeOfAqiChartsHelper.getTooltipItems(
|
||||
getTooltipItems: (touchedSpots) => RangeOfAqiChartsHelper.getTooltipItems(
|
||||
touchedSpots,
|
||||
chartData,
|
||||
),
|
||||
|
@ -81,8 +81,7 @@ class AqiDeviceInfo extends StatelessWidget {
|
||||
aqiLevel: status
|
||||
.firstWhere(
|
||||
(e) => e.code == 'air_quality_index',
|
||||
orElse: () =>
|
||||
Status(code: 'air_quality_index', value: ''),
|
||||
orElse: () => Status(code: 'air_quality_index', value: ''),
|
||||
)
|
||||
.value
|
||||
.toString(),
|
||||
|
@ -36,25 +36,23 @@ class AqiDistributionChart extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
List<BarChartGroupData> _buildBarGroups(
|
||||
List<AirQualityDataModel> sortedData) {
|
||||
List<BarChartGroupData> _buildBarGroups(List<AirQualityDataModel> sortedData) {
|
||||
return List.generate(sortedData.length, (index) {
|
||||
final data = sortedData[index];
|
||||
final stackItems = <BarChartRodData>[];
|
||||
double currentY = 0;
|
||||
var isFirstElement = true;
|
||||
bool isFirstElement = true;
|
||||
|
||||
// Sort data by type to ensure consistent order
|
||||
final sortedPercentageData =
|
||||
List<AirQualityPercentageData>.from(data.data)
|
||||
final sortedPercentageData = List<AirQualityPercentageData>.from(data.data)
|
||||
..sort((a, b) => a.type.compareTo(b.type));
|
||||
|
||||
for (final percentageData in sortedPercentageData) {
|
||||
stackItems.add(
|
||||
BarChartRodData(
|
||||
fromY: currentY,
|
||||
toY: currentY + percentageData.percentage,
|
||||
color: AirQualityDataModel.metricColors[percentageData.name],
|
||||
toY: currentY + percentageData.percentage ,
|
||||
color: AirQualityDataModel.metricColors[percentageData.name]!,
|
||||
borderRadius: isFirstElement
|
||||
? const BorderRadius.only(
|
||||
topLeft: Radius.circular(22),
|
||||
@ -86,9 +84,9 @@ class AqiDistributionChart extends StatelessWidget {
|
||||
tooltipRoundedRadius: 16,
|
||||
tooltipPadding: const EdgeInsets.all(8),
|
||||
getTooltipItem: (group, groupIndex, rod, rodIndex) {
|
||||
final data = chartData[group.x];
|
||||
final data = chartData[group.x.toInt()];
|
||||
|
||||
final children = <TextSpan>[];
|
||||
final List<TextSpan> children = [];
|
||||
|
||||
final textStyle = context.textTheme.bodySmall?.copyWith(
|
||||
color: ColorsManager.blackColor,
|
||||
@ -96,8 +94,7 @@ class AqiDistributionChart extends StatelessWidget {
|
||||
);
|
||||
|
||||
// Sort data by type to ensure consistent order
|
||||
final sortedPercentageData =
|
||||
List<AirQualityPercentageData>.from(data.data)
|
||||
final sortedPercentageData = List<AirQualityPercentageData>.from(data.data)
|
||||
..sort((a, b) => a.type.compareTo(b.type));
|
||||
|
||||
for (final percentageData in sortedPercentageData) {
|
||||
|
@ -49,7 +49,7 @@ class AqiSubValueWidget extends StatelessWidget {
|
||||
|
||||
int _getActiveSegmentByRange(double value, (double min, double max) range) {
|
||||
final ranges = _getRangesForValue(range);
|
||||
for (var i = 0; i < ranges.length; i++) {
|
||||
for (int i = 0; i < ranges.length; i++) {
|
||||
if (value <= ranges[i].max) return i;
|
||||
}
|
||||
return ranges.length - 1;
|
||||
|
@ -29,8 +29,7 @@ class AqiTypeDropdown extends StatefulWidget {
|
||||
class _AqiTypeDropdownState extends State<AqiTypeDropdown> {
|
||||
AqiType? _selectedItem = AqiType.aqi;
|
||||
|
||||
void _updateSelectedItem(AqiType? item) =>
|
||||
setState(() => _selectedItem = item);
|
||||
void _updateSelectedItem(AqiType? item) => setState(() => _selectedItem = item);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -63,7 +63,7 @@ class RangeOfAqiChart extends StatelessWidget {
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.bottomCenter,
|
||||
end: Alignment.topCenter,
|
||||
stops: const [0.0, 0.2, 0.4, 0.6, 0.8, 1.0],
|
||||
stops: [0.0, 0.2, 0.4, 0.6, 0.8, 1.0],
|
||||
colors: RangeOfAqiChartsHelper.gradientData.map((e) {
|
||||
final (color, _) = e;
|
||||
return color.withValues(alpha: 0.6);
|
||||
@ -99,8 +99,7 @@ class RangeOfAqiChart extends StatelessWidget {
|
||||
}) {
|
||||
const invisibleDot = FlDotData(show: false);
|
||||
return LineChartBarData(
|
||||
spots:
|
||||
List.generate(values.length, (i) => FlSpot(i.toDouble(), values[i])),
|
||||
spots: List.generate(values.length, (i) => FlSpot(i.toDouble(), values[i])),
|
||||
isCurved: true,
|
||||
color: color,
|
||||
barWidth: 4,
|
||||
|
@ -32,8 +32,7 @@ class RangeOfAqiChartBox extends StatelessWidget {
|
||||
const SizedBox(height: 10),
|
||||
const Divider(),
|
||||
const SizedBox(height: 20),
|
||||
Expanded(
|
||||
child: RangeOfAqiChart(chartData: state.filteredRangeOfAqi)),
|
||||
Expanded(child: RangeOfAqiChart(chartData: state.filteredRangeOfAqi)),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
@ -8,8 +8,7 @@ sealed class AnalyticsDevicesEvent extends Equatable {
|
||||
}
|
||||
|
||||
final class LoadAnalyticsDevicesEvent extends AnalyticsDevicesEvent {
|
||||
const LoadAnalyticsDevicesEvent(
|
||||
{required this.param, required this.onSuccess});
|
||||
const LoadAnalyticsDevicesEvent({required this.param, required this.onSuccess});
|
||||
|
||||
final GetAnalyticsDevicesParam param;
|
||||
final void Function(AnalyticsDevice device) onSuccess;
|
||||
|
@ -8,8 +8,7 @@ import 'package:syncrow_web/pages/space_tree/bloc/space_tree_event.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart';
|
||||
|
||||
final class AirQualityDataLoadingStrategy
|
||||
implements AnalyticsDataLoadingStrategy {
|
||||
final class AirQualityDataLoadingStrategy implements AnalyticsDataLoadingStrategy {
|
||||
@override
|
||||
void onCommunitySelected(
|
||||
BuildContext context,
|
||||
@ -26,8 +25,7 @@ final class AirQualityDataLoadingStrategy
|
||||
SpaceModel space,
|
||||
) {
|
||||
final spaceTreeBloc = context.read<SpaceTreeBloc>();
|
||||
final isSpaceSelected =
|
||||
spaceTreeBloc.state.selectedSpaces.contains(space.uuid);
|
||||
final isSpaceSelected = spaceTreeBloc.state.selectedSpaces.contains(space.uuid);
|
||||
|
||||
final hasSelectedSpaces = spaceTreeBloc.state.selectedSpaces.isNotEmpty;
|
||||
if (hasSelectedSpaces) clearData(context);
|
||||
@ -36,7 +34,7 @@ final class AirQualityDataLoadingStrategy
|
||||
|
||||
spaceTreeBloc
|
||||
..add(const SpaceTreeClearSelectionEvent())
|
||||
..add(OnSpaceSelected(community, space.uuid ?? '', const []));
|
||||
..add(OnSpaceSelected(community, space.uuid ?? '', []));
|
||||
|
||||
FetchAirQualityDataHelper.loadAirQualityData(
|
||||
context,
|
||||
|
@ -8,8 +8,7 @@ abstract final class AnalyticsDataLoadingStrategyFactory {
|
||||
const AnalyticsDataLoadingStrategyFactory._();
|
||||
static AnalyticsDataLoadingStrategy getStrategy(AnalyticsPageTab tab) {
|
||||
return switch (tab) {
|
||||
AnalyticsPageTab.energyManagement =>
|
||||
EnergyManagementDataLoadingStrategy(),
|
||||
AnalyticsPageTab.energyManagement => EnergyManagementDataLoadingStrategy(),
|
||||
AnalyticsPageTab.occupancy => OccupancyDataLoadingStrategy(),
|
||||
AnalyticsPageTab.airQuality => AirQualityDataLoadingStrategy(),
|
||||
};
|
||||
|
@ -7,8 +7,7 @@ import 'package:syncrow_web/pages/space_tree/bloc/space_tree_event.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart';
|
||||
|
||||
class EnergyManagementDataLoadingStrategy
|
||||
implements AnalyticsDataLoadingStrategy {
|
||||
class EnergyManagementDataLoadingStrategy implements AnalyticsDataLoadingStrategy {
|
||||
@override
|
||||
void onCommunitySelected(
|
||||
BuildContext context,
|
||||
@ -32,8 +31,7 @@ class EnergyManagementDataLoadingStrategy
|
||||
SpaceModel space,
|
||||
) {
|
||||
final spaceTreeBloc = context.read<SpaceTreeBloc>();
|
||||
final isSpaceSelected =
|
||||
spaceTreeBloc.state.selectedSpaces.contains(space.uuid);
|
||||
final isSpaceSelected = spaceTreeBloc.state.selectedSpaces.contains(space.uuid);
|
||||
final hasSelectedSpaces = spaceTreeBloc.state.selectedSpaces.isNotEmpty;
|
||||
|
||||
if (isSpaceSelected) {
|
||||
|
@ -24,8 +24,7 @@ class OccupancyDataLoadingStrategy implements AnalyticsDataLoadingStrategy {
|
||||
SpaceModel space,
|
||||
) {
|
||||
final spaceTreeBloc = context.read<SpaceTreeBloc>();
|
||||
final isSpaceSelected =
|
||||
spaceTreeBloc.state.selectedSpaces.contains(space.uuid);
|
||||
final isSpaceSelected = spaceTreeBloc.state.selectedSpaces.contains(space.uuid);
|
||||
|
||||
final hasSelectedSpaces = spaceTreeBloc.state.selectedSpaces.isNotEmpty;
|
||||
if (hasSelectedSpaces) clearData(context);
|
||||
@ -34,7 +33,7 @@ class OccupancyDataLoadingStrategy implements AnalyticsDataLoadingStrategy {
|
||||
|
||||
spaceTreeBloc
|
||||
..add(const SpaceTreeClearSelectionEvent())
|
||||
..add(OnSpaceSelected(community, space.uuid ?? '', const []));
|
||||
..add(OnSpaceSelected(community, space.uuid ?? '', []));
|
||||
|
||||
FetchOccupancyDataHelper.loadOccupancyData(
|
||||
context,
|
||||
|
@ -10,8 +10,7 @@ class AnalyticsCommunitiesSidebar extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final selectedTab = context.watch<AnalyticsTabBloc>().state;
|
||||
final strategy =
|
||||
AnalyticsDataLoadingStrategyFactory.getStrategy(selectedTab);
|
||||
final strategy = AnalyticsDataLoadingStrategyFactory.getStrategy(selectedTab);
|
||||
|
||||
return Expanded(
|
||||
child: AnalyticsSpaceTreeView(
|
||||
|
@ -20,7 +20,7 @@ class AnalyticsDateFilterButton extends StatefulWidget {
|
||||
final void Function(DateTime)? onDateSelected;
|
||||
final DatePickerType datePickerType;
|
||||
|
||||
static final Color _color = ColorsManager.blackColor.withValues(alpha: 0.8);
|
||||
static final _color = ColorsManager.blackColor.withValues(alpha: 0.8);
|
||||
|
||||
@override
|
||||
State<AnalyticsDateFilterButton> createState() =>
|
||||
|
@ -33,9 +33,8 @@ class AnalyticsPageTabButton extends StatelessWidget {
|
||||
style: TextStyle(
|
||||
fontWeight: isSelected ? FontWeight.w700 : FontWeight.w400,
|
||||
fontSize: 16,
|
||||
color: isSelected
|
||||
? ColorsManager.slidingBlueColor
|
||||
: ColorsManager.textGray,
|
||||
color:
|
||||
isSelected ? ColorsManager.slidingBlueColor : ColorsManager.textGray,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
@ -21,18 +21,18 @@ class _MonthPickerWidgetState extends State<MonthPickerWidget> {
|
||||
int? _selectedMonth;
|
||||
|
||||
static const _monthNames = [
|
||||
'January',
|
||||
'February',
|
||||
'March',
|
||||
'April',
|
||||
'May',
|
||||
'June',
|
||||
'July',
|
||||
'August',
|
||||
'September',
|
||||
'October',
|
||||
'November',
|
||||
'December',
|
||||
"January",
|
||||
"February",
|
||||
"March",
|
||||
"April",
|
||||
"May",
|
||||
"June",
|
||||
"July",
|
||||
"August",
|
||||
"September",
|
||||
"October",
|
||||
"November",
|
||||
"December",
|
||||
];
|
||||
|
||||
@override
|
||||
@ -189,19 +189,14 @@ class _MonthPickerWidgetState extends State<MonthPickerWidget> {
|
||||
final isFutureMonth = isCurrentYear && index > currentDate.month - 1;
|
||||
|
||||
return InkWell(
|
||||
onTap: isFutureMonth
|
||||
? null
|
||||
: () => setState(() => _selectedMonth = index),
|
||||
onTap: isFutureMonth ? null : () => setState(() => _selectedMonth = index),
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFEDF2F7),
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft:
|
||||
index % 3 == 0 ? const Radius.circular(16) : Radius.zero,
|
||||
bottomLeft:
|
||||
index % 3 == 0 ? const Radius.circular(16) : Radius.zero,
|
||||
topRight:
|
||||
index % 3 == 2 ? const Radius.circular(16) : Radius.zero,
|
||||
topLeft: index % 3 == 0 ? const Radius.circular(16) : Radius.zero,
|
||||
bottomLeft: index % 3 == 0 ? const Radius.circular(16) : Radius.zero,
|
||||
topRight: index % 3 == 2 ? const Radius.circular(16) : Radius.zero,
|
||||
bottomRight:
|
||||
index % 3 == 2 ? const Radius.circular(16) : Radius.zero,
|
||||
),
|
||||
|
@ -53,8 +53,7 @@ class _AnalyticsSpaceTreeViewState extends State<AnalyticsSpaceTreeView> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<SpaceTreeBloc, SpaceTreeState>(
|
||||
builder: (context, state) {
|
||||
return BlocBuilder<SpaceTreeBloc, SpaceTreeState>(builder: (context, state) {
|
||||
final communities = state.searchQuery.isNotEmpty
|
||||
? state.filteredCommunity
|
||||
: state.communityList;
|
||||
@ -77,8 +76,7 @@ class _AnalyticsSpaceTreeViewState extends State<AnalyticsSpaceTreeView> {
|
||||
),
|
||||
),
|
||||
CustomSearchBar(
|
||||
onSearchChanged: (query) =>
|
||||
context.read<SpaceTreeBloc>().add(
|
||||
onSearchChanged: (query) => context.read<SpaceTreeBloc>().add(
|
||||
SearchQueryEvent(query),
|
||||
),
|
||||
),
|
||||
@ -115,8 +113,7 @@ class _AnalyticsSpaceTreeViewState extends State<AnalyticsSpaceTreeView> {
|
||||
isExpanded: state.expandedCommunities.contains(
|
||||
communities[index].uuid,
|
||||
),
|
||||
onItemSelected: () =>
|
||||
widget.onSelectCommunity?.call(
|
||||
onItemSelected: () => widget.onSelectCommunity?.call(
|
||||
communities[index],
|
||||
communities[index].spaces,
|
||||
),
|
||||
@ -124,8 +121,8 @@ class _AnalyticsSpaceTreeViewState extends State<AnalyticsSpaceTreeView> {
|
||||
(space) {
|
||||
return CustomExpansionTileSpaceTree(
|
||||
title: space.name,
|
||||
isExpanded: state.expandedSpaces
|
||||
.contains(space.uuid),
|
||||
isExpanded:
|
||||
state.expandedSpaces.contains(space.uuid),
|
||||
onItemSelected: () =>
|
||||
widget.onSelectSpace?.call(
|
||||
communities[index],
|
||||
@ -156,8 +153,7 @@ class _AnalyticsSpaceTreeViewState extends State<AnalyticsSpaceTreeView> {
|
||||
},
|
||||
),
|
||||
),
|
||||
if (state.paginationIsLoading)
|
||||
const CircularProgressIndicator(),
|
||||
if (state.paginationIsLoading) const CircularProgressIndicator(),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
@ -19,9 +19,9 @@ class YearPickerWidget extends StatefulWidget {
|
||||
class _YearPickerWidgetState extends State<YearPickerWidget> {
|
||||
late int _currentYear;
|
||||
|
||||
static final List<int> years = List.generate(
|
||||
static final years = List.generate(
|
||||
DateTime.now().year - (DateTime.now().year - 5) + 1,
|
||||
(index) => 2020 + index,
|
||||
(index) => (2020 + index),
|
||||
).where((year) => year <= DateTime.now().year).toList();
|
||||
|
||||
@override
|
||||
@ -123,12 +123,9 @@ class _YearPickerWidgetState extends State<YearPickerWidget> {
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFEDF2F7),
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft:
|
||||
index % 3 == 0 ? const Radius.circular(16) : Radius.zero,
|
||||
bottomLeft:
|
||||
index % 3 == 0 ? const Radius.circular(16) : Radius.zero,
|
||||
topRight:
|
||||
index % 3 == 2 ? const Radius.circular(16) : Radius.zero,
|
||||
topLeft: index % 3 == 0 ? const Radius.circular(16) : Radius.zero,
|
||||
bottomLeft: index % 3 == 0 ? const Radius.circular(16) : Radius.zero,
|
||||
topRight: index % 3 == 2 ? const Radius.circular(16) : Radius.zero,
|
||||
bottomRight:
|
||||
index % 3 == 2 ? const Radius.circular(16) : Radius.zero,
|
||||
),
|
||||
|
@ -8,15 +8,13 @@ import 'package:syncrow_web/services/api/api_exception.dart';
|
||||
part 'energy_consumption_by_phases_event.dart';
|
||||
part 'energy_consumption_by_phases_state.dart';
|
||||
|
||||
class EnergyConsumptionByPhasesBloc extends Bloc<EnergyConsumptionByPhasesEvent,
|
||||
EnergyConsumptionByPhasesState> {
|
||||
class EnergyConsumptionByPhasesBloc
|
||||
extends Bloc<EnergyConsumptionByPhasesEvent, EnergyConsumptionByPhasesState> {
|
||||
EnergyConsumptionByPhasesBloc(
|
||||
this._energyConsumptionByPhasesService,
|
||||
) : super(const EnergyConsumptionByPhasesState()) {
|
||||
on<LoadEnergyConsumptionByPhasesEvent>(
|
||||
_onLoadEnergyConsumptionByPhasesEvent);
|
||||
on<ClearEnergyConsumptionByPhasesEvent>(
|
||||
_onClearEnergyConsumptionByPhasesEvent);
|
||||
on<LoadEnergyConsumptionByPhasesEvent>(_onLoadEnergyConsumptionByPhasesEvent);
|
||||
on<ClearEnergyConsumptionByPhasesEvent>(_onClearEnergyConsumptionByPhasesEvent);
|
||||
}
|
||||
|
||||
final EnergyConsumptionByPhasesService _energyConsumptionByPhasesService;
|
||||
@ -27,8 +25,7 @@ class EnergyConsumptionByPhasesBloc extends Bloc<EnergyConsumptionByPhasesEvent,
|
||||
) async {
|
||||
emit(state.copyWith(status: EnergyConsumptionByPhasesStatus.loading));
|
||||
try {
|
||||
final chartData =
|
||||
await _energyConsumptionByPhasesService.load(event.param);
|
||||
final chartData = await _energyConsumptionByPhasesService.load(event.param);
|
||||
emit(
|
||||
state.copyWith(
|
||||
status: EnergyConsumptionByPhasesStatus.loaded,
|
||||
@ -52,7 +49,7 @@ class EnergyConsumptionByPhasesBloc extends Bloc<EnergyConsumptionByPhasesEvent,
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onClearEnergyConsumptionByPhasesEvent(
|
||||
void _onClearEnergyConsumptionByPhasesEvent(
|
||||
ClearEnergyConsumptionByPhasesEvent event,
|
||||
Emitter<EnergyConsumptionByPhasesState> emit,
|
||||
) async {
|
||||
|
@ -7,8 +7,7 @@ sealed class EnergyConsumptionByPhasesEvent extends Equatable {
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class LoadEnergyConsumptionByPhasesEvent
|
||||
extends EnergyConsumptionByPhasesEvent {
|
||||
class LoadEnergyConsumptionByPhasesEvent extends EnergyConsumptionByPhasesEvent {
|
||||
const LoadEnergyConsumptionByPhasesEvent({
|
||||
required this.param,
|
||||
});
|
||||
@ -19,7 +18,6 @@ class LoadEnergyConsumptionByPhasesEvent
|
||||
List<Object> get props => [param];
|
||||
}
|
||||
|
||||
final class ClearEnergyConsumptionByPhasesEvent
|
||||
extends EnergyConsumptionByPhasesEvent {
|
||||
final class ClearEnergyConsumptionByPhasesEvent extends EnergyConsumptionByPhasesEvent {
|
||||
const ClearEnergyConsumptionByPhasesEvent();
|
||||
}
|
||||
|
@ -8,13 +8,12 @@ import 'package:syncrow_web/services/api/api_exception.dart';
|
||||
part 'energy_consumption_per_device_event.dart';
|
||||
part 'energy_consumption_per_device_state.dart';
|
||||
|
||||
class EnergyConsumptionPerDeviceBloc extends Bloc<
|
||||
EnergyConsumptionPerDeviceEvent, EnergyConsumptionPerDeviceState> {
|
||||
class EnergyConsumptionPerDeviceBloc
|
||||
extends Bloc<EnergyConsumptionPerDeviceEvent, EnergyConsumptionPerDeviceState> {
|
||||
EnergyConsumptionPerDeviceBloc(
|
||||
this._energyConsumptionPerDeviceService,
|
||||
) : super(const EnergyConsumptionPerDeviceState()) {
|
||||
on<LoadEnergyConsumptionPerDeviceEvent>(
|
||||
_onLoadEnergyConsumptionPerDeviceEvent);
|
||||
on<LoadEnergyConsumptionPerDeviceEvent>(_onLoadEnergyConsumptionPerDeviceEvent);
|
||||
on<ClearEnergyConsumptionPerDeviceEvent>(
|
||||
_onClearEnergyConsumptionPerDeviceEvent);
|
||||
}
|
||||
@ -27,8 +26,7 @@ class EnergyConsumptionPerDeviceBloc extends Bloc<
|
||||
) async {
|
||||
emit(state.copyWith(status: EnergyConsumptionPerDeviceStatus.loading));
|
||||
try {
|
||||
final chartData =
|
||||
await _energyConsumptionPerDeviceService.load(event.param);
|
||||
final chartData = await _energyConsumptionPerDeviceService.load(event.param);
|
||||
emit(
|
||||
state.copyWith(
|
||||
status: EnergyConsumptionPerDeviceStatus.loaded,
|
||||
@ -52,7 +50,7 @@ class EnergyConsumptionPerDeviceBloc extends Bloc<
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onClearEnergyConsumptionPerDeviceEvent(
|
||||
void _onClearEnergyConsumptionPerDeviceEvent(
|
||||
ClearEnergyConsumptionPerDeviceEvent event,
|
||||
Emitter<EnergyConsumptionPerDeviceState> emit,
|
||||
) async {
|
||||
|
@ -8,8 +8,7 @@ import 'package:syncrow_web/services/api/api_exception.dart';
|
||||
part 'power_clamp_info_event.dart';
|
||||
part 'power_clamp_info_state.dart';
|
||||
|
||||
class PowerClampInfoBloc
|
||||
extends Bloc<PowerClampInfoEvent, PowerClampInfoState> {
|
||||
class PowerClampInfoBloc extends Bloc<PowerClampInfoEvent, PowerClampInfoState> {
|
||||
PowerClampInfoBloc(
|
||||
this._powerClampInfoService,
|
||||
) : super(const PowerClampInfoState()) {
|
||||
@ -26,8 +25,7 @@ class PowerClampInfoBloc
|
||||
) async {
|
||||
emit(state.copyWith(status: PowerClampInfoStatus.loading));
|
||||
try {
|
||||
final powerClampModel =
|
||||
await _powerClampInfoService.getInfo(event.deviceId);
|
||||
final powerClampModel = await _powerClampInfoService.getInfo(event.deviceId);
|
||||
emit(
|
||||
state.copyWith(
|
||||
status: PowerClampInfoStatus.loaded,
|
||||
@ -51,7 +49,7 @@ class PowerClampInfoBloc
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onUpdatePowerClampStatusEvent(
|
||||
void _onUpdatePowerClampStatusEvent(
|
||||
UpdatePowerClampStatusEvent event,
|
||||
Emitter<PowerClampInfoState> emit,
|
||||
) async {
|
||||
|
@ -16,6 +16,7 @@ final class LoadPowerClampInfoEvent extends PowerClampInfoEvent {
|
||||
List<Object> get props => [deviceId];
|
||||
}
|
||||
|
||||
|
||||
final class UpdatePowerClampStatusEvent extends PowerClampInfoEvent {
|
||||
const UpdatePowerClampStatusEvent(this.statusList);
|
||||
|
||||
|
@ -49,7 +49,7 @@ class TotalEnergyConsumptionBloc
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onClearTotalEnergyConsumptionEvent(
|
||||
void _onClearTotalEnergyConsumptionEvent(
|
||||
ClearTotalEnergyConsumptionEvent event,
|
||||
Emitter<TotalEnergyConsumptionState> emit,
|
||||
) async {
|
||||
|
@ -7,8 +7,7 @@ sealed class TotalEnergyConsumptionEvent extends Equatable {
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
final class TotalEnergyConsumptionLoadEvent
|
||||
extends TotalEnergyConsumptionEvent {
|
||||
final class TotalEnergyConsumptionLoadEvent extends TotalEnergyConsumptionEvent {
|
||||
const TotalEnergyConsumptionLoadEvent({required this.param});
|
||||
|
||||
final GetTotalEnergyConsumptionParam param;
|
||||
@ -17,7 +16,6 @@ final class TotalEnergyConsumptionLoadEvent
|
||||
List<Object?> get props => [param];
|
||||
}
|
||||
|
||||
final class ClearTotalEnergyConsumptionEvent
|
||||
extends TotalEnergyConsumptionEvent {
|
||||
final class ClearTotalEnergyConsumptionEvent extends TotalEnergyConsumptionEvent {
|
||||
const ClearTotalEnergyConsumptionEvent();
|
||||
}
|
||||
|
@ -69,8 +69,7 @@ abstract final class EnergyManagementChartsHelper {
|
||||
return labels.where((element) => element.isNotEmpty).join(', ');
|
||||
}
|
||||
|
||||
static List<LineTooltipItem?> getTooltipItems(
|
||||
List<LineBarSpot> touchedSpots) {
|
||||
static List<LineTooltipItem?> getTooltipItems(List<LineBarSpot> touchedSpots) {
|
||||
return touchedSpots.map((spot) {
|
||||
return LineTooltipItem(
|
||||
getToolTipLabel(spot.x, spot.y),
|
||||
@ -86,8 +85,7 @@ abstract final class EnergyManagementChartsHelper {
|
||||
static LineTouchTooltipData lineTouchTooltipData() {
|
||||
return LineTouchTooltipData(
|
||||
getTooltipColor: (touchTooltipItem) => ColorsManager.whiteColors,
|
||||
tooltipBorder:
|
||||
const BorderSide(color: ColorsManager.semiTransparentBlack),
|
||||
tooltipBorder: const BorderSide(color: ColorsManager.semiTransparentBlack),
|
||||
tooltipRoundedRadius: 16,
|
||||
showOnTopOfTheChartBoxArea: false,
|
||||
tooltipPadding: const EdgeInsets.all(8),
|
||||
|
@ -122,8 +122,7 @@ abstract final class FetchEnergyManagementDataHelper {
|
||||
final selectedDevice = getSelectedDevice(context);
|
||||
|
||||
context.read<RealtimeDeviceChangesBloc>().add(
|
||||
RealtimeDeviceChangesStarted(
|
||||
deviceUuid ?? selectedDevice?.uuid ?? ''),
|
||||
RealtimeDeviceChangesStarted(deviceUuid ?? selectedDevice?.uuid ?? ''),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -51,8 +51,7 @@ class AnalyticsEnergyManagementView extends StatelessWidget {
|
||||
spacing: 20,
|
||||
children: [
|
||||
Expanded(child: TotalEnergyConsumptionChartBox()),
|
||||
Expanded(
|
||||
child: EnergyConsumptionPerDeviceChartBox()),
|
||||
Expanded(child: EnergyConsumptionPerDeviceChartBox()),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
@ -52,8 +52,7 @@ class AnalyticsDeviceDropdown extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDevicesDropdown(
|
||||
BuildContext context, AnalyticsDevicesState state) {
|
||||
Widget _buildDevicesDropdown(BuildContext context, AnalyticsDevicesState state) {
|
||||
final spaceUuid = state.selectedDevice?.spaceUuid;
|
||||
return DropdownButton<AnalyticsDevice?>(
|
||||
value: state.selectedDevice,
|
||||
|
@ -18,6 +18,7 @@ class EnergyConsumptionByPhasesChart extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return BarChart(
|
||||
BarChartData(
|
||||
|
||||
gridData: EnergyManagementChartsHelper.gridData().copyWith(
|
||||
checkToShowHorizontalLine: (value) => true,
|
||||
horizontalInterval: 250,
|
||||
@ -99,11 +100,11 @@ class EnergyConsumptionByPhasesChart extends StatelessWidget {
|
||||
}) {
|
||||
final data = energyData;
|
||||
|
||||
final date = DateFormat('dd/MM/yyyy').format(data[group.x].date);
|
||||
final phaseA = data[group.x].energyConsumedA;
|
||||
final phaseB = data[group.x].energyConsumedB;
|
||||
final phaseC = data[group.x].energyConsumedC;
|
||||
final total = data[group.x].energyConsumedKw;
|
||||
final date = DateFormat('dd/MM/yyyy').format(data[group.x.toInt()].date);
|
||||
final phaseA = data[group.x.toInt()].energyConsumedA;
|
||||
final phaseB = data[group.x.toInt()].energyConsumedB;
|
||||
final phaseC = data[group.x.toInt()].energyConsumedC;
|
||||
final total = data[group.x.toInt()].energyConsumedKw;
|
||||
|
||||
return BarTooltipItem(
|
||||
'$date\n',
|
||||
|
@ -22,8 +22,7 @@ class EnergyConsumptionByPhasesChartBox extends StatelessWidget {
|
||||
children: [
|
||||
AnalyticsErrorWidget(state.errorMessage),
|
||||
EnergyConsumptionByPhasesTitle(
|
||||
isLoading:
|
||||
state.status == EnergyConsumptionByPhasesStatus.loading,
|
||||
isLoading: state.status == EnergyConsumptionByPhasesStatus.loading,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Expanded(
|
||||
|
@ -17,6 +17,7 @@ class EnergyConsumptionPerDeviceChart extends StatelessWidget {
|
||||
context,
|
||||
leftTitlesInterval: 250,
|
||||
),
|
||||
|
||||
gridData: EnergyManagementChartsHelper.gridData().copyWith(
|
||||
checkToShowHorizontalLine: (value) => true,
|
||||
horizontalInterval: 250,
|
||||
|
@ -46,8 +46,7 @@ class EnergyConsumptionPerDeviceChartBox extends StatelessWidget {
|
||||
flex: 2,
|
||||
child: EnergyConsumptionPerDeviceDevicesList(
|
||||
chartData: state.chartData,
|
||||
devices:
|
||||
context.watch<AnalyticsDevicesBloc>().state.devices,
|
||||
devices: context.watch<AnalyticsDevicesBloc>().state.devices,
|
||||
),
|
||||
),
|
||||
],
|
||||
@ -56,8 +55,7 @@ class EnergyConsumptionPerDeviceChartBox extends StatelessWidget {
|
||||
const Divider(height: 0),
|
||||
const SizedBox(height: 20),
|
||||
Expanded(
|
||||
child:
|
||||
EnergyConsumptionPerDeviceChart(chartData: state.chartData),
|
||||
child: EnergyConsumptionPerDeviceChart(chartData: state.chartData),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
@ -43,14 +43,11 @@ class PowerClampEnergyDataWidget extends StatelessWidget {
|
||||
title: 'Smart Power Clamp',
|
||||
showSpaceUuidInDevicesDropdown: true,
|
||||
onChanged: (device) {
|
||||
FetchEnergyManagementDataHelper
|
||||
.loadEnergyConsumptionByPhases(
|
||||
FetchEnergyManagementDataHelper.loadEnergyConsumptionByPhases(
|
||||
context,
|
||||
powerClampUuid: device.uuid,
|
||||
selectedDate: context
|
||||
.read<AnalyticsDatePickerBloc>()
|
||||
.state
|
||||
.monthlyDate,
|
||||
selectedDate:
|
||||
context.read<AnalyticsDatePickerBloc>().state.monthlyDate,
|
||||
);
|
||||
},
|
||||
),
|
||||
@ -94,8 +91,7 @@ class PowerClampEnergyDataWidget extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
const Expanded(
|
||||
flex: 3, child: EnergyConsumptionByPhasesChartBox()),
|
||||
const Expanded(flex: 3, child: EnergyConsumptionByPhasesChartBox()),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
@ -140,9 +140,9 @@ class PowerClampPhasesDataWidget extends StatelessWidget {
|
||||
|
||||
String _formatCurrentValue(String? value) {
|
||||
if (value == null) return '--';
|
||||
var str = value;
|
||||
String str = value;
|
||||
if (str.isEmpty || str == '--') return '--';
|
||||
str = str.replaceAll(RegExp('[^0-9]'), '');
|
||||
str = str.replaceAll(RegExp(r'[^0-9]'), '');
|
||||
if (str.isEmpty) return '--';
|
||||
if (str.length == 1) return '${str[0]}.0';
|
||||
return '${str[0]}.${str.substring(1)}';
|
||||
@ -150,9 +150,9 @@ class PowerClampPhasesDataWidget extends StatelessWidget {
|
||||
|
||||
String _formatPowerFactor(String? value) {
|
||||
if (value == null) return '--';
|
||||
var str = value;
|
||||
String str = value;
|
||||
if (str.isEmpty || str == '--') return '--';
|
||||
str = str.replaceAll(RegExp('[^0-9]'), '');
|
||||
str = str.replaceAll(RegExp(r'[^0-9]'), '');
|
||||
if (str.isEmpty) return '--';
|
||||
final intValue = int.tryParse(str);
|
||||
if (intValue == null) return '--';
|
||||
@ -162,9 +162,9 @@ class PowerClampPhasesDataWidget extends StatelessWidget {
|
||||
|
||||
String _formatVoltage(String? value) {
|
||||
if (value == null) return '--';
|
||||
var str = value;
|
||||
String str = value;
|
||||
if (str.isEmpty || str == '--') return '--';
|
||||
str = str.replaceAll(RegExp('[^0-9]'), '');
|
||||
str = str.replaceAll(RegExp(r'[^0-9]'), '');
|
||||
if (str.isEmpty) return '--';
|
||||
if (str.length == 1) return '0.${str[0]}';
|
||||
return '${str.substring(0, str.length - 1)}.${str.substring(str.length - 1)}';
|
||||
|
@ -29,6 +29,7 @@ class TotalEnergyConsumptionChart extends StatelessWidget {
|
||||
),
|
||||
duration: Duration.zero,
|
||||
curve: Curves.easeIn,
|
||||
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -25,8 +25,7 @@ class TotalEnergyConsumptionChartBox extends StatelessWidget {
|
||||
Row(
|
||||
children: [
|
||||
ChartsLoadingWidget(
|
||||
isLoading:
|
||||
state.status == TotalEnergyConsumptionStatus.loading,
|
||||
isLoading: state.status == TotalEnergyConsumptionStatus.loading,
|
||||
),
|
||||
const Expanded(
|
||||
flex: 3,
|
||||
|
@ -23,11 +23,9 @@ class OccupancyBloc extends Bloc<OccupancyEvent, OccupancyState> {
|
||||
emit(state.copyWith(status: OccupancyStatus.loading));
|
||||
try {
|
||||
final chartData = await _occupacyService.load(event.param);
|
||||
emit(
|
||||
state.copyWith(chartData: chartData, status: OccupancyStatus.loaded));
|
||||
emit(state.copyWith(chartData: chartData, status: OccupancyStatus.loaded));
|
||||
} on APIException catch (e) {
|
||||
emit(state.copyWith(
|
||||
status: OccupancyStatus.failure, errorMessage: e.message));
|
||||
emit(state.copyWith(status: OccupancyStatus.failure, errorMessage: e.message));
|
||||
} catch (e) {
|
||||
emit(state.copyWith(status: OccupancyStatus.failure, errorMessage: '$e'));
|
||||
}
|
||||
|
@ -25,18 +25,15 @@ abstract final class FetchOccupancyDataHelper {
|
||||
|
||||
final datePickerState = context.read<AnalyticsDatePickerBloc>().state;
|
||||
|
||||
loadAnalyticsDevices(context,
|
||||
communityUuid: communityId, spaceUuid: spaceId);
|
||||
final selectedDevice =
|
||||
context.read<AnalyticsDevicesBloc>().state.selectedDevice;
|
||||
loadAnalyticsDevices(context, communityUuid: communityId, spaceUuid: spaceId);
|
||||
final selectedDevice = context.read<AnalyticsDevicesBloc>().state.selectedDevice;
|
||||
|
||||
loadOccupancyChartData(
|
||||
context,
|
||||
spaceUuid: spaceId,
|
||||
date: datePickerState.monthlyDate,
|
||||
);
|
||||
loadHeatMapData(context,
|
||||
spaceUuid: spaceId, year: datePickerState.yearlyDate);
|
||||
loadHeatMapData(context, spaceUuid: spaceId, year: datePickerState.yearlyDate);
|
||||
|
||||
if (selectedDevice case final AnalyticsDevice device) {
|
||||
context.read<RealtimeDeviceChangesBloc>()
|
||||
@ -67,8 +64,7 @@ abstract final class FetchOccupancyDataHelper {
|
||||
context.read<OccupancyBloc>().add(
|
||||
LoadOccupancyEvent(
|
||||
GetOccupancyParam(
|
||||
monthDate:
|
||||
'${date.year}-${date.month.toString().padLeft(2, '0')}',
|
||||
monthDate: '${date.year}-${date.month.toString().padLeft(2, '0')}',
|
||||
spaceUuid: spaceUuid,
|
||||
),
|
||||
),
|
||||
|
@ -20,12 +20,9 @@ class AnalyticsOccupancyView extends StatelessWidget {
|
||||
child: Column(
|
||||
spacing: 32,
|
||||
children: [
|
||||
SizedBox(
|
||||
height: height * 0.46, child: const OccupancyEndSideBar()),
|
||||
SizedBox(
|
||||
height: height * 0.5, child: const OccupancyChartBox()),
|
||||
SizedBox(
|
||||
height: height * 0.5, child: const OccupancyHeatMapBox()),
|
||||
SizedBox(height: height * 0.46, child: const OccupancyEndSideBar()),
|
||||
SizedBox(height: height * 0.5, child: const OccupancyChartBox()),
|
||||
SizedBox(height: height * 0.5, child: const OccupancyHeatMapBox()),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
@ -41,8 +41,7 @@ class OccupancyChart extends StatelessWidget {
|
||||
barRods: [
|
||||
BarChartRodData(
|
||||
toY: 100.0,
|
||||
fromY:
|
||||
occupancyValue == 0 ? occupancyValue : occupancyValue + 2.5,
|
||||
fromY: occupancyValue == 0 ? occupancyValue : occupancyValue + 2.5,
|
||||
color: ColorsManager.graysColor,
|
||||
width: _chartWidth,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
@ -89,8 +88,8 @@ class OccupancyChart extends StatelessWidget {
|
||||
}) {
|
||||
final data = chartData;
|
||||
|
||||
final occupancyValue = double.parse(data[group.x].occupancy);
|
||||
final percentage = '${occupancyValue.toStringAsFixed(0)}%';
|
||||
final occupancyValue = double.parse(data[group.x.toInt()].occupancy);
|
||||
final percentage = '${(occupancyValue).toStringAsFixed(0)}%';
|
||||
|
||||
return BarTooltipItem(
|
||||
percentage,
|
||||
@ -117,7 +116,7 @@ class OccupancyChart extends StatelessWidget {
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
fit: BoxFit.scaleDown,
|
||||
child: Text(
|
||||
'${value.toStringAsFixed(0)}%',
|
||||
'${(value).toStringAsFixed(0)}%',
|
||||
style: context.textTheme.bodySmall?.copyWith(
|
||||
fontSize: 12,
|
||||
color: ColorsManager.greyColor,
|
||||
|
@ -44,15 +44,13 @@ class OccupancyChartBox extends StatelessWidget {
|
||||
child: AnalyticsDateFilterButton(
|
||||
onDateSelected: (DateTime value) {
|
||||
context.read<AnalyticsDatePickerBloc>().add(
|
||||
UpdateAnalyticsDatePickerEvent(
|
||||
montlyDate: value),
|
||||
UpdateAnalyticsDatePickerEvent(montlyDate: value),
|
||||
);
|
||||
if (spaceTreeState.selectedSpaces.isNotEmpty) {
|
||||
FetchOccupancyDataHelper.loadOccupancyChartData(
|
||||
context,
|
||||
spaceUuid:
|
||||
spaceTreeState.selectedSpaces.firstOrNull ??
|
||||
'',
|
||||
spaceTreeState.selectedSpaces.firstOrNull ?? '',
|
||||
date: value,
|
||||
);
|
||||
}
|
||||
|
@ -44,15 +44,13 @@ class OccupancyHeatMapBox extends StatelessWidget {
|
||||
child: AnalyticsDateFilterButton(
|
||||
onDateSelected: (DateTime value) {
|
||||
context.read<AnalyticsDatePickerBloc>().add(
|
||||
UpdateAnalyticsDatePickerEvent(
|
||||
yearlyDate: value),
|
||||
UpdateAnalyticsDatePickerEvent(yearlyDate: value),
|
||||
);
|
||||
if (spaceTreeState.selectedSpaces.isNotEmpty) {
|
||||
FetchOccupancyDataHelper.loadHeatMapData(
|
||||
context,
|
||||
spaceUuid:
|
||||
spaceTreeState.selectedSpaces.firstOrNull ??
|
||||
'',
|
||||
spaceTreeState.selectedSpaces.firstOrNull ?? '',
|
||||
year: value,
|
||||
);
|
||||
}
|
||||
|
@ -28,11 +28,11 @@ class OccupancyPainter extends CustomPainter {
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final fillPaint = Paint();
|
||||
final borderPaint = Paint()
|
||||
final Paint fillPaint = Paint();
|
||||
final Paint borderPaint = Paint()
|
||||
..color = ColorsManager.grayBorder.withValues(alpha: 0.4)
|
||||
..style = PaintingStyle.stroke;
|
||||
final hoveredBorderPaint = Paint()
|
||||
final Paint hoveredBorderPaint = Paint()
|
||||
..color = Colors.black
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 1.5;
|
||||
@ -66,24 +66,24 @@ class OccupancyPainter extends CustomPainter {
|
||||
);
|
||||
|
||||
canvas.drawLine(Offset(x, y), Offset(x, y + cellSize), borderPaint);
|
||||
canvas.drawLine(Offset(x + cellSize, y),
|
||||
Offset(x + cellSize, y + cellSize), borderPaint);
|
||||
canvas.drawLine(Offset(x + cellSize, y), Offset(x + cellSize, y + cellSize),
|
||||
borderPaint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _drawDashedLine(Canvas canvas, Offset start, Offset end, Paint paint) {
|
||||
const dashWidth = 2.0;
|
||||
const dashSpace = 4.0;
|
||||
final totalLength = (end - start).distance;
|
||||
final direction = (end - start) / (end - start).distance;
|
||||
const double dashWidth = 2.0;
|
||||
const double dashSpace = 4.0;
|
||||
final double totalLength = (end - start).distance;
|
||||
final Offset direction = (end - start) / (end - start).distance;
|
||||
|
||||
var currentLength = 0.0;
|
||||
double currentLength = 0.0;
|
||||
while (currentLength < totalLength) {
|
||||
final dashStart = start + direction * currentLength;
|
||||
final nextLength = currentLength + dashWidth;
|
||||
final dashEnd = start +
|
||||
direction * (nextLength < totalLength ? nextLength : totalLength);
|
||||
final Offset dashStart = start + direction * currentLength;
|
||||
final double nextLength = currentLength + dashWidth;
|
||||
final Offset dashEnd =
|
||||
start + direction * (nextLength < totalLength ? nextLength : totalLength);
|
||||
canvas.drawLine(dashStart, dashEnd, paint);
|
||||
currentLength = nextLength + dashSpace;
|
||||
}
|
||||
|
@ -5,8 +5,7 @@ import 'package:syncrow_web/pages/analytics/modules/air_quality/widgets/aqi_type
|
||||
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 {
|
||||
class FakeAirQualityDistributionService implements AirQualityDistributionService {
|
||||
final _random = Random();
|
||||
|
||||
@override
|
||||
@ -44,6 +43,7 @@ class FakeAirQualityDistributionService
|
||||
name: 'poor',
|
||||
percentage: nonNullValues[2],
|
||||
type: AqiType.hcho.code,
|
||||
|
||||
),
|
||||
AirQualityPercentageData(
|
||||
name: 'unhealthy',
|
||||
@ -71,7 +71,7 @@ class FakeAirQualityDistributionService
|
||||
List<bool> nullMask,
|
||||
) {
|
||||
double nonNullSum = 0;
|
||||
for (var i = 0; i < originalValues.length; i++) {
|
||||
for (int i = 0; i < originalValues.length; i++) {
|
||||
if (!nullMask[i]) {
|
||||
nonNullSum += originalValues[i];
|
||||
}
|
||||
|
@ -3,8 +3,7 @@ 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/services/api/http_service.dart';
|
||||
|
||||
class RemoteAirQualityDistributionService
|
||||
implements AirQualityDistributionService {
|
||||
class RemoteAirQualityDistributionService implements AirQualityDistributionService {
|
||||
RemoteAirQualityDistributionService(this._httpService);
|
||||
|
||||
final HTTPService _httpService;
|
||||
|
@ -16,8 +16,7 @@ class AnalyticsDevicesServiceDelegate implements AnalyticsDevicesService {
|
||||
GetAnalyticsDevicesParam param,
|
||||
) {
|
||||
return switch (param.requestType) {
|
||||
AnalyticsDeviceRequestType.occupancy =>
|
||||
_occupancyService.getDevices(param),
|
||||
AnalyticsDeviceRequestType.occupancy => _occupancyService.getDevices(param),
|
||||
AnalyticsDeviceRequestType.energyManagement =>
|
||||
_energyManagementService.getDevices(param),
|
||||
};
|
||||
|
@ -14,8 +14,7 @@ final class RemoteEnergyManagementAnalyticsDevicesService
|
||||
static const _defaultErrorMessage = 'Failed to load analytics devices';
|
||||
|
||||
@override
|
||||
Future<List<AnalyticsDevice>> getDevices(
|
||||
GetAnalyticsDevicesParam param) async {
|
||||
Future<List<AnalyticsDevice>> getDevices(GetAnalyticsDevicesParam param) async {
|
||||
try {
|
||||
final response = await _httpService.get(
|
||||
path: '/devices-space-community/recursive-child',
|
||||
@ -38,8 +37,7 @@ final class RemoteEnergyManagementAnalyticsDevicesService
|
||||
final message = e.response?.data as Map<String, dynamic>?;
|
||||
final error = message?['error'] as Map<String, dynamic>?;
|
||||
final errorMessage = error?['error'] as String? ?? '';
|
||||
final formattedErrorMessage =
|
||||
[_defaultErrorMessage, errorMessage].join(': ');
|
||||
final formattedErrorMessage = [_defaultErrorMessage, errorMessage].join(': ');
|
||||
throw APIException(formattedErrorMessage);
|
||||
} catch (e) {
|
||||
throw APIException('$_defaultErrorMessage: $e');
|
||||
|
@ -6,8 +6,7 @@ import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
||||
import 'package:syncrow_web/services/api/api_exception.dart';
|
||||
import 'package:syncrow_web/services/api/http_service.dart';
|
||||
|
||||
class RemoteOccupancyAnalyticsDevicesService
|
||||
implements AnalyticsDevicesService {
|
||||
class RemoteOccupancyAnalyticsDevicesService implements AnalyticsDevicesService {
|
||||
const RemoteOccupancyAnalyticsDevicesService(this._httpService);
|
||||
|
||||
final HTTPService _httpService;
|
||||
@ -15,8 +14,7 @@ class RemoteOccupancyAnalyticsDevicesService
|
||||
static const _defaultErrorMessage = 'Failed to load analytics devices';
|
||||
|
||||
@override
|
||||
Future<List<AnalyticsDevice>> getDevices(
|
||||
GetAnalyticsDevicesParam param) async {
|
||||
Future<List<AnalyticsDevice>> getDevices(GetAnalyticsDevicesParam param) async {
|
||||
try {
|
||||
final requests = await Future.wait<List<AnalyticsDevice>>(
|
||||
param.deviceTypes.map((e) {
|
||||
@ -36,18 +34,15 @@ class RemoteOccupancyAnalyticsDevicesService
|
||||
final message = e.response?.data as Map<String, dynamic>?;
|
||||
final error = message?['error'] as Map<String, dynamic>?;
|
||||
final errorMessage = error?['error'] as String? ?? '';
|
||||
final formattedErrorMessage =
|
||||
[_defaultErrorMessage, errorMessage].join(': ');
|
||||
final formattedErrorMessage = [_defaultErrorMessage, errorMessage].join(': ');
|
||||
throw APIException(formattedErrorMessage);
|
||||
} catch (e) {
|
||||
final formattedErrorMessage =
|
||||
[_defaultErrorMessage, e.toString()].join(': ');
|
||||
final formattedErrorMessage = [_defaultErrorMessage, e.toString()].join(': ');
|
||||
throw APIException(formattedErrorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<AnalyticsDevice>> _makeRequest(
|
||||
GetAnalyticsDevicesParam param) async {
|
||||
Future<List<AnalyticsDevice>> _makeRequest(GetAnalyticsDevicesParam param) async {
|
||||
try {
|
||||
final projectUuid = await ProjectManager.getProjectUUID();
|
||||
|
||||
@ -74,8 +69,7 @@ class RemoteOccupancyAnalyticsDevicesService
|
||||
final message = e.response?.data as Map<String, dynamic>?;
|
||||
final error = message?['error'] as Map<String, dynamic>?;
|
||||
final errorMessage = error?['error'] as String? ?? '';
|
||||
final formattedErrorMessage =
|
||||
[_defaultErrorMessage, errorMessage].join(': ');
|
||||
final formattedErrorMessage = [_defaultErrorMessage, errorMessage].join(': ');
|
||||
throw APIException(formattedErrorMessage);
|
||||
} catch (e) {
|
||||
throw APIException('$_defaultErrorMessage: $e');
|
||||
|
@ -34,7 +34,7 @@ class DeviceLocationDetailsServiceDecorator implements DeviceLocationService {
|
||||
|
||||
return deviceLocationInfo;
|
||||
} catch (e) {
|
||||
throw Exception('Failed to load device location info: $e');
|
||||
throw Exception('Failed to load device location info: ${e.toString()}');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,8 +11,7 @@ final class RemoteEnergyConsumptionByPhasesService
|
||||
|
||||
final HTTPService _httpService;
|
||||
|
||||
static const _defaultErrorMessage =
|
||||
'Failed to load energy consumption per phase';
|
||||
static const _defaultErrorMessage = 'Failed to load energy consumption per phase';
|
||||
|
||||
@override
|
||||
Future<List<PhasesEnergyConsumption>> load(
|
||||
@ -37,8 +36,7 @@ final class RemoteEnergyConsumptionByPhasesService
|
||||
final message = e.response?.data as Map<String, dynamic>?;
|
||||
final error = message?['error'] as Map<String, dynamic>?;
|
||||
final errorMessage = error?['error'] as String? ?? '';
|
||||
final formattedErrorMessage =
|
||||
[_defaultErrorMessage, errorMessage].join(': ');
|
||||
final formattedErrorMessage = [_defaultErrorMessage, errorMessage].join(': ');
|
||||
throw APIException(formattedErrorMessage);
|
||||
} catch (e) {
|
||||
final formattedErrorMessage = [_defaultErrorMessage, '$e'].join(': ');
|
||||
|
@ -13,8 +13,7 @@ class RemoteEnergyConsumptionPerDeviceService
|
||||
|
||||
final HTTPService _httpService;
|
||||
|
||||
static const _defaultErrorMessage =
|
||||
'Failed to load energy consumption per device';
|
||||
static const _defaultErrorMessage = 'Failed to load energy consumption per device';
|
||||
|
||||
@override
|
||||
Future<List<DeviceEnergyDataModel>> load(
|
||||
@ -32,8 +31,7 @@ class RemoteEnergyConsumptionPerDeviceService
|
||||
final message = e.response?.data as Map<String, dynamic>?;
|
||||
final error = message?['error'] as Map<String, dynamic>?;
|
||||
final errorMessage = error?['error'] as String? ?? '';
|
||||
final formattedErrorMessage =
|
||||
[_defaultErrorMessage, errorMessage].join(': ');
|
||||
final formattedErrorMessage = [_defaultErrorMessage, errorMessage].join(': ');
|
||||
throw APIException(formattedErrorMessage);
|
||||
} catch (e) {
|
||||
final formattedErrorMessage = [_defaultErrorMessage, '$e'].join(': ');
|
||||
@ -61,8 +59,7 @@ abstract final class _EnergyConsumptionPerDeviceMapper {
|
||||
final energyJson = data as Map<String, dynamic>;
|
||||
return EnergyDataModel(
|
||||
date: DateTime.parse(energyJson['date'] as String),
|
||||
value:
|
||||
double.parse(energyJson['total_energy_consumed_kw'] as String),
|
||||
value: double.parse(energyJson['total_energy_consumed_kw'] as String),
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
|
@ -33,8 +33,7 @@ final class RemoteOccupancyService implements OccupacyService {
|
||||
final message = e.response?.data as Map<String, dynamic>?;
|
||||
final error = message?['error'] as Map<String, dynamic>?;
|
||||
final errorMessage = error?['error'] as String? ?? '';
|
||||
final formattedErrorMessage =
|
||||
[_defaultErrorMessage, errorMessage].join(': ');
|
||||
final formattedErrorMessage = [_defaultErrorMessage, errorMessage].join(': ');
|
||||
throw APIException(formattedErrorMessage);
|
||||
} catch (e) {
|
||||
final formattedErrorMessage = [_defaultErrorMessage, '$e'].join(': ');
|
||||
|
@ -13,8 +13,7 @@ final class RemoteOccupancyHeatMapService implements OccupancyHeatMapService {
|
||||
static const _defaultErrorMessage = 'Failed to load occupancy heat map';
|
||||
|
||||
@override
|
||||
Future<List<OccupancyHeatMapModel>> load(
|
||||
GetOccupancyHeatMapParam param) async {
|
||||
Future<List<OccupancyHeatMapModel>> load(GetOccupancyHeatMapParam param) async {
|
||||
try {
|
||||
final response = await _httpService.get(
|
||||
path: '/occupancy/heat-map/space/${param.spaceUuid}',
|
||||
@ -25,8 +24,7 @@ final class RemoteOccupancyHeatMapService implements OccupancyHeatMapService {
|
||||
final dailyData = json['data'] as List<dynamic>? ?? <dynamic>[];
|
||||
|
||||
final result = dailyData.map(
|
||||
(json) =>
|
||||
OccupancyHeatMapModel.fromJson(json as Map<String, dynamic>),
|
||||
(json) => OccupancyHeatMapModel.fromJson(json as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
return result.toList();
|
||||
@ -38,8 +36,7 @@ final class RemoteOccupancyHeatMapService implements OccupancyHeatMapService {
|
||||
final message = e.response?.data as Map<String, dynamic>?;
|
||||
final error = message?['error'] as Map<String, dynamic>?;
|
||||
final errorMessage = error?['error'] as String? ?? '';
|
||||
final formattedErrorMessage =
|
||||
[_defaultErrorMessage, errorMessage].join(': ');
|
||||
final formattedErrorMessage = [_defaultErrorMessage, errorMessage].join(': ');
|
||||
throw APIException(formattedErrorMessage);
|
||||
} catch (e) {
|
||||
final formattedErrorMessage = [_defaultErrorMessage, '$e'].join(': ');
|
||||
|
@ -28,8 +28,7 @@ final class RemotePowerClampInfoService implements PowerClampInfoService {
|
||||
final message = e.response?.data as Map<String, dynamic>?;
|
||||
final error = message?['error'] as Map<String, dynamic>?;
|
||||
final errorMessage = error?['error'] as String? ?? '';
|
||||
final formattedErrorMessage =
|
||||
[_defaultErrorMessage, errorMessage].join(': ');
|
||||
final formattedErrorMessage = [_defaultErrorMessage, errorMessage].join(': ');
|
||||
throw APIException(formattedErrorMessage);
|
||||
} catch (e) {
|
||||
final formattedErrorMessage = [_defaultErrorMessage, '$e'].join(': ');
|
||||
|
@ -6,7 +6,7 @@ import 'package:syncrow_web/pages/analytics/services/range_of_aqi/range_of_aqi_s
|
||||
class FakeRangeOfAqiService implements RangeOfAqiService {
|
||||
@override
|
||||
Future<List<RangeOfAqi>> load(GetRangeOfAqiParam param) async {
|
||||
return Future.delayed(const Duration(milliseconds: 800), () {
|
||||
return await Future.delayed(const Duration(milliseconds: 800), () {
|
||||
final random = DateTime.now().millisecondsSinceEpoch;
|
||||
|
||||
return List.generate(30, (index) {
|
||||
@ -21,18 +21,12 @@ class FakeRangeOfAqiService implements RangeOfAqiService {
|
||||
|
||||
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),
|
||||
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,
|
||||
);
|
||||
|
@ -5,8 +5,7 @@ import 'package:syncrow_web/pages/analytics/services/total_energy_consumption/to
|
||||
import 'package:syncrow_web/services/api/api_exception.dart';
|
||||
import 'package:syncrow_web/services/api/http_service.dart';
|
||||
|
||||
class RemoteTotalEnergyConsumptionService
|
||||
implements TotalEnergyConsumptionService {
|
||||
class RemoteTotalEnergyConsumptionService implements TotalEnergyConsumptionService {
|
||||
const RemoteTotalEnergyConsumptionService(this._httpService);
|
||||
|
||||
final HTTPService _httpService;
|
||||
@ -30,8 +29,7 @@ class RemoteTotalEnergyConsumptionService
|
||||
final message = e.response?.data as Map<String, dynamic>?;
|
||||
final error = message?['error'] as Map<String, dynamic>?;
|
||||
final errorMessage = error?['error'] as String? ?? '';
|
||||
final formattedErrorMessage =
|
||||
[_defaultErrorMessage, errorMessage].join(': ');
|
||||
final formattedErrorMessage = [_defaultErrorMessage, errorMessage].join(': ');
|
||||
throw APIException(formattedErrorMessage);
|
||||
} catch (e) {
|
||||
final formattedErrorMessage = [_defaultErrorMessage, '$e'].join(': ');
|
||||
|
@ -75,8 +75,7 @@ class AnalyticsSidebarHeader extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
SelectableText(
|
||||
context.watch<AnalyticsDevicesBloc>().state.selectedDevice?.uuid ??
|
||||
'N/A',
|
||||
context.watch<AnalyticsDevicesBloc>().state.selectedDevice?.uuid ?? 'N/A',
|
||||
style: context.textTheme.bodySmall?.copyWith(
|
||||
color: ColorsManager.blackColor,
|
||||
fontWeight: FontWeight.w400,
|
||||
|
@ -36,8 +36,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
|
||||
////////////////////////////// forget password //////////////////////////////////
|
||||
final TextEditingController forgetEmailController = TextEditingController();
|
||||
final TextEditingController forgetPasswordController =
|
||||
TextEditingController();
|
||||
final TextEditingController forgetPasswordController = TextEditingController();
|
||||
final TextEditingController forgetOtp = TextEditingController();
|
||||
final forgetFormKey = GlobalKey<FormState>();
|
||||
final forgetEmailKey = GlobalKey<FormState>();
|
||||
@ -54,8 +53,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
return;
|
||||
}
|
||||
_remainingTime = 1;
|
||||
add(UpdateTimerEvent(
|
||||
remainingTime: _remainingTime, isButtonEnabled: false));
|
||||
add(UpdateTimerEvent(remainingTime: _remainingTime, isButtonEnabled: false));
|
||||
try {
|
||||
forgetEmailValidate = '';
|
||||
_remainingTime = (await AuthenticationAPI.sendOtp(
|
||||
@ -64,7 +62,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
} on DioException catch (e) {
|
||||
if (e.response!.statusCode == 400) {
|
||||
final errorData = e.response!.data;
|
||||
final String errorMessage = errorData['message'];
|
||||
String errorMessage = errorData['message'];
|
||||
if (errorMessage == 'User not found') {
|
||||
validate = 'Invalid Credential';
|
||||
emit(AuthInitialState());
|
||||
@ -92,8 +90,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
_timer?.cancel();
|
||||
add(const UpdateTimerEvent(remainingTime: 0, isButtonEnabled: true));
|
||||
} else {
|
||||
add(UpdateTimerEvent(
|
||||
remainingTime: _remainingTime, isButtonEnabled: false));
|
||||
add(UpdateTimerEvent(remainingTime: _remainingTime, isButtonEnabled: false));
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -103,11 +100,11 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
emit(const TimerState(isButtonEnabled: true, remainingTime: 0));
|
||||
}
|
||||
|
||||
Future<void> changePassword(
|
||||
Future<void> changePassword(
|
||||
ChangePasswordEvent event, Emitter<AuthState> emit) async {
|
||||
emit(LoadingForgetState());
|
||||
try {
|
||||
final response = await AuthenticationAPI.verifyOtp(
|
||||
var response = await AuthenticationAPI.verifyOtp(
|
||||
email: forgetEmailController.text, otpCode: forgetOtp.text);
|
||||
if (response == true) {
|
||||
await AuthenticationAPI.forgetPassword(
|
||||
@ -125,6 +122,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String? validateCode(String? value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Code is required';
|
||||
@ -133,9 +131,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
}
|
||||
|
||||
void _onUpdateTimer(UpdateTimerEvent event, Emitter<AuthState> emit) {
|
||||
emit(TimerState(
|
||||
isButtonEnabled: event.isButtonEnabled,
|
||||
remainingTime: event.remainingTime));
|
||||
emit(TimerState(isButtonEnabled: event.isButtonEnabled, remainingTime: event.remainingTime));
|
||||
}
|
||||
|
||||
///////////////////////////////////// login /////////////////////////////////////
|
||||
@ -155,7 +151,8 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
static UserModel? user;
|
||||
bool showValidationMessage = false;
|
||||
|
||||
Future<void> _login(LoginButtonPressed event, Emitter<AuthState> emit) async {
|
||||
|
||||
void _login(LoginButtonPressed event, Emitter<AuthState> emit) async {
|
||||
emit(AuthLoading());
|
||||
if (isChecked) {
|
||||
try {
|
||||
@ -182,7 +179,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
}
|
||||
|
||||
if (token.accessTokenIsNotEmpty) {
|
||||
const storage = FlutterSecureStorage();
|
||||
FlutterSecureStorage storage = const FlutterSecureStorage();
|
||||
await storage.write(
|
||||
key: Token.loginAccessTokenKey, value: token.accessToken);
|
||||
const FlutterSecureStorage().write(
|
||||
@ -200,7 +197,8 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
}
|
||||
}
|
||||
|
||||
void checkBoxToggle(
|
||||
|
||||
checkBoxToggle(
|
||||
CheckBoxEvent event,
|
||||
Emitter<AuthState> emit,
|
||||
) {
|
||||
@ -279,12 +277,12 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Please enter your password';
|
||||
}
|
||||
final validationErrors = <String>[];
|
||||
List<String> validationErrors = [];
|
||||
|
||||
if (!RegExp('^(?=.*[a-z])').hasMatch(value)) {
|
||||
if (!RegExp(r'^(?=.*[a-z])').hasMatch(value)) {
|
||||
validationErrors.add(' - one lowercase letter');
|
||||
}
|
||||
if (!RegExp('^(?=.*[A-Z])').hasMatch(value)) {
|
||||
if (!RegExp(r'^(?=.*[A-Z])').hasMatch(value)) {
|
||||
validationErrors.add(' - one uppercase letter');
|
||||
}
|
||||
if (!RegExp(r'^(?=.*\d)').hasMatch(value)) {
|
||||
@ -306,7 +304,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
|
||||
String? fullNameValidator(String? value) {
|
||||
if (value == null) return 'Full name is required';
|
||||
final withoutExtraSpaces = value.replaceAll(RegExp(r'\s+'), ' ').trim();
|
||||
final withoutExtraSpaces = value.replaceAll(RegExp(r"\s+"), ' ').trim();
|
||||
if (withoutExtraSpaces.length < 2 || withoutExtraSpaces.length > 30) {
|
||||
return 'Full name must be between 2 and 30 characters long';
|
||||
}
|
||||
@ -341,14 +339,12 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
static Future<String> getTokenAndValidate() async {
|
||||
try {
|
||||
const storage = FlutterSecureStorage();
|
||||
final firstLaunch = await SharedPreferencesHelper.readBoolFromSP(
|
||||
StringsManager.firstLaunch) ??
|
||||
true;
|
||||
final firstLaunch =
|
||||
await SharedPreferencesHelper.readBoolFromSP(StringsManager.firstLaunch) ?? true;
|
||||
if (firstLaunch) {
|
||||
storage.deleteAll();
|
||||
}
|
||||
await SharedPreferencesHelper.saveBoolToSP(
|
||||
StringsManager.firstLaunch, false);
|
||||
await SharedPreferencesHelper.saveBoolToSP(StringsManager.firstLaunch, false);
|
||||
final value = await storage.read(key: Token.loginAccessTokenKey) ?? '';
|
||||
if (value.isEmpty) {
|
||||
return 'Token not found';
|
||||
@ -370,8 +366,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _fetchRegion(
|
||||
RegionInitialEvent event, Emitter<AuthState> emit) async {
|
||||
void _fetchRegion(RegionInitialEvent event, Emitter<AuthState> emit) async {
|
||||
try {
|
||||
emit(AuthLoading());
|
||||
regionList = await AuthenticationAPI.fetchRegion();
|
||||
@ -394,17 +389,15 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
}
|
||||
|
||||
String formattedTime(int time) {
|
||||
final days = (time / 86400).floor(); // 86400 seconds in a day
|
||||
final hours = ((time % 86400) / 3600).floor();
|
||||
final minutes = (((time % 86400) % 3600) / 60).floor();
|
||||
final seconds = ((time % 86400) % 3600) % 60;
|
||||
final int days = (time / 86400).floor(); // 86400 seconds in a day
|
||||
final int hours = ((time % 86400) / 3600).floor();
|
||||
final int minutes = (((time % 86400) % 3600) / 60).floor();
|
||||
final int seconds = (((time % 86400) % 3600) % 60).floor();
|
||||
|
||||
final formattedTime = [
|
||||
final String formattedTime = [
|
||||
if (days > 0) '${days}d', // Append 'd' for days
|
||||
if (days > 0 || hours > 0)
|
||||
hours
|
||||
.toString()
|
||||
.padLeft(2, '0'), // Show hours if there are days or hours
|
||||
hours.toString().padLeft(2, '0'), // Show hours if there are days or hours
|
||||
minutes.toString().padLeft(2, '0'),
|
||||
seconds.toString().padLeft(2, '0'),
|
||||
].join(':');
|
||||
@ -424,7 +417,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
return checkValidate;
|
||||
}
|
||||
|
||||
void changeValidate(
|
||||
changeValidate(
|
||||
ChangeValidateEvent event,
|
||||
Emitter<AuthState> emit,
|
||||
) {
|
||||
@ -433,7 +426,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
emit(LoginInitial());
|
||||
}
|
||||
|
||||
void changeForgetValidate(
|
||||
changeForgetValidate(
|
||||
ChangeValidateEvent event,
|
||||
Emitter<AuthState> emit,
|
||||
) {
|
||||
|
@ -46,8 +46,7 @@ class StopTimerEvent extends AuthEvent {}
|
||||
class UpdateTimerEvent extends AuthEvent {
|
||||
final int remainingTime;
|
||||
final bool isButtonEnabled;
|
||||
const UpdateTimerEvent(
|
||||
{required this.remainingTime, required this.isButtonEnabled});
|
||||
const UpdateTimerEvent({required this.remainingTime, required this.isButtonEnabled});
|
||||
}
|
||||
|
||||
class ChangePasswordEvent extends AuthEvent {}
|
||||
|
@ -56,8 +56,7 @@ class TimerState extends AuthState {
|
||||
final bool isButtonEnabled;
|
||||
final int remainingTime;
|
||||
|
||||
const TimerState(
|
||||
{required this.isButtonEnabled, required this.remainingTime});
|
||||
const TimerState({required this.isButtonEnabled, required this.remainingTime});
|
||||
|
||||
@override
|
||||
List<Object> get props => [isButtonEnabled, remainingTime];
|
||||
@ -81,7 +80,7 @@ class TimerUpdated extends AuthState {
|
||||
final String formattedTime;
|
||||
final bool isButtonEnabled;
|
||||
|
||||
const TimerUpdated({
|
||||
TimerUpdated({
|
||||
required this.formattedTime,
|
||||
required this.isButtonEnabled,
|
||||
});
|
||||
|
@ -21,7 +21,7 @@ class LoginWithEmailModel {
|
||||
return {
|
||||
'email': email,
|
||||
'password': password,
|
||||
'platform': 'web'
|
||||
"platform": "web"
|
||||
// 'regionUuid': regionUuid,
|
||||
};
|
||||
}
|
||||
|
@ -11,14 +11,6 @@ class Token {
|
||||
final int iat;
|
||||
final int exp;
|
||||
|
||||
Token(
|
||||
this.accessToken,
|
||||
this.refreshToken,
|
||||
this.sessionId,
|
||||
this.iat,
|
||||
this.exp,
|
||||
);
|
||||
|
||||
Token.emptyConstructor()
|
||||
: accessToken = '',
|
||||
refreshToken = '',
|
||||
@ -32,6 +24,14 @@ class Token {
|
||||
|
||||
bool get isNotEmpty => accessToken.isNotEmpty && refreshToken.isNotEmpty;
|
||||
|
||||
Token(
|
||||
this.accessToken,
|
||||
this.refreshToken,
|
||||
this.sessionId,
|
||||
this.iat,
|
||||
this.exp,
|
||||
);
|
||||
|
||||
Token.refreshToken(this.refreshToken)
|
||||
: accessToken = '',
|
||||
sessionId = '',
|
||||
@ -40,7 +40,7 @@ class Token {
|
||||
|
||||
factory Token.fromJson(Map<String, dynamic> json) {
|
||||
//save token to secure storage
|
||||
const storage = FlutterSecureStorage();
|
||||
var storage = const FlutterSecureStorage();
|
||||
storage.write(
|
||||
key: loginAccessTokenKey, value: json[loginAccessTokenKey] ?? '');
|
||||
storage.write(
|
||||
|
@ -55,7 +55,7 @@ class UserModel {
|
||||
|
||||
//from token
|
||||
factory UserModel.fromToken(Token token) {
|
||||
final tempJson = Token.decodeToken(token.accessToken);
|
||||
Map<String, dynamic> tempJson = Token.decodeToken(token.accessToken);
|
||||
|
||||
return UserModel(
|
||||
hasAcceptedWebAgreement: null,
|
||||
@ -69,7 +69,8 @@ class UserModel {
|
||||
phoneNumber: null,
|
||||
isEmailVerified: null,
|
||||
isAgreementAccepted: null,
|
||||
project: null);
|
||||
project: null
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
|
@ -36,18 +36,20 @@ class ForgetPasswordWebPage extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
},
|
||||
builder: _buildForm,
|
||||
builder: (context, state) {
|
||||
return _buildForm(context, state);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildForm(BuildContext context, AuthState state) {
|
||||
late ScrollController scrollController;
|
||||
scrollController = ScrollController();
|
||||
void scrollToCenter() {
|
||||
final middlePosition = scrollController.position.maxScrollExtent / 2;
|
||||
scrollController.animateTo(
|
||||
late ScrollController _scrollController;
|
||||
_scrollController = ScrollController();
|
||||
void _scrollToCenter() {
|
||||
final double middlePosition = _scrollController.position.maxScrollExtent / 2;
|
||||
_scrollController.animateTo(
|
||||
middlePosition,
|
||||
duration: const Duration(seconds: 1),
|
||||
curve: Curves.easeInOut,
|
||||
@ -55,25 +57,24 @@ class ForgetPasswordWebPage extends StatelessWidget {
|
||||
}
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
scrollToCenter();
|
||||
_scrollToCenter();
|
||||
});
|
||||
final forgetBloc = BlocProvider.of<AuthBloc>(context);
|
||||
final size = MediaQuery.of(context).size;
|
||||
Size size = MediaQuery.of(context).size;
|
||||
return FirstLayer(
|
||||
second: Center(
|
||||
child: Stack(
|
||||
children: [
|
||||
if (state is AuthLoading)
|
||||
const Center(child: CircularProgressIndicator()),
|
||||
if (state is AuthLoading) const Center(child: CircularProgressIndicator()),
|
||||
ListView(
|
||||
shrinkWrap: true,
|
||||
controller: scrollController,
|
||||
controller: _scrollController,
|
||||
children: [
|
||||
Container(
|
||||
padding: EdgeInsets.all(size.width * 0.02),
|
||||
margin: EdgeInsets.all(size.width * 0.09),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black.withValues(alpha: 0.3),
|
||||
color: Colors.black.withOpacity(0.3),
|
||||
borderRadius: const BorderRadius.all(Radius.circular(20)),
|
||||
),
|
||||
child: Center(
|
||||
@ -93,22 +94,17 @@ class ForgetPasswordWebPage extends StatelessWidget {
|
||||
flex: 3,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.1),
|
||||
borderRadius:
|
||||
const BorderRadius.all(Radius.circular(30)),
|
||||
border: Border.all(
|
||||
color: ColorsManager.graysColor
|
||||
.withValues(alpha: 0.2)),
|
||||
color: Colors.white.withOpacity(0.1),
|
||||
borderRadius: const BorderRadius.all(Radius.circular(30)),
|
||||
border: Border.all(color: ColorsManager.graysColor.withOpacity(0.2)),
|
||||
),
|
||||
child: Form(
|
||||
key: forgetBloc.forgetFormKey,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: size.width * 0.02,
|
||||
vertical: size.width * 0.003),
|
||||
horizontal: size.width * 0.02, vertical: size.width * 0.003),
|
||||
child: Column(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceEvenly,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
const SizedBox(height: 10),
|
||||
@ -125,9 +121,7 @@ class ForgetPasswordWebPage extends StatelessWidget {
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall!
|
||||
.copyWith(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w400),
|
||||
.copyWith(fontSize: 14, fontWeight: FontWeight.w400),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
// Column(
|
||||
@ -146,90 +140,69 @@ class ForgetPasswordWebPage extends StatelessWidget {
|
||||
Form(
|
||||
key: forgetBloc.forgetEmailKey,
|
||||
child: Column(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Account',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall!
|
||||
.copyWith(
|
||||
fontSize: 14,
|
||||
fontWeight:
|
||||
FontWeight.w400),
|
||||
"Account",
|
||||
style: Theme.of(context).textTheme.bodySmall!.copyWith(
|
||||
fontSize: 14, fontWeight: FontWeight.w400),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
SizedBox(
|
||||
child: TextFormField(
|
||||
controller: forgetBloc
|
||||
.forgetEmailController,
|
||||
validator:
|
||||
forgetBloc.validateEmail,
|
||||
decoration:
|
||||
textBoxDecoration()!.copyWith(
|
||||
controller: forgetBloc.forgetEmailController,
|
||||
validator: forgetBloc.validateEmail,
|
||||
decoration: textBoxDecoration()!.copyWith(
|
||||
hintText: 'Enter your email',
|
||||
hintStyle: Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall!
|
||||
.copyWith(
|
||||
color: ColorsManager
|
||||
.grayColor,
|
||||
fontWeight:
|
||||
FontWeight.w400),
|
||||
color: ColorsManager.grayColor,
|
||||
fontWeight: FontWeight.w400),
|
||||
),
|
||||
style: const TextStyle(
|
||||
color: Colors.black),
|
||||
style: const TextStyle(color: Colors.black),
|
||||
),
|
||||
),
|
||||
],
|
||||
)),
|
||||
const SizedBox(height: 20.0),
|
||||
Column(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'One Time Password',
|
||||
"One Time Password",
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall!
|
||||
.copyWith(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w400),
|
||||
.copyWith(fontSize: 14, fontWeight: FontWeight.w400),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
SizedBox(
|
||||
child: TextFormField(
|
||||
validator: forgetBloc.validateCode,
|
||||
keyboardType:
|
||||
TextInputType.visiblePassword,
|
||||
keyboardType: TextInputType.visiblePassword,
|
||||
controller: forgetBloc.forgetOtp,
|
||||
decoration:
|
||||
textBoxDecoration()!.copyWith(
|
||||
decoration: textBoxDecoration()!.copyWith(
|
||||
hintText: 'Enter Code',
|
||||
hintStyle: Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall!
|
||||
.copyWith(
|
||||
color:
|
||||
ColorsManager.grayColor,
|
||||
fontWeight:
|
||||
FontWeight.w400),
|
||||
color: ColorsManager.grayColor,
|
||||
fontWeight: FontWeight.w400),
|
||||
suffixIcon: SizedBox(
|
||||
width: 100,
|
||||
child: Center(
|
||||
child: InkWell(
|
||||
onTap: state is TimerState &&
|
||||
!state
|
||||
.isButtonEnabled &&
|
||||
state.remainingTime !=
|
||||
1
|
||||
!state.isButtonEnabled &&
|
||||
state.remainingTime != 1
|
||||
? null
|
||||
: () {
|
||||
:
|
||||
() {
|
||||
if (forgetBloc
|
||||
.forgetEmailKey
|
||||
.currentState!
|
||||
@ -238,31 +211,27 @@ class ForgetPasswordWebPage extends StatelessWidget {
|
||||
StartTimerEvent());
|
||||
}
|
||||
},
|
||||
|
||||
child: Text(
|
||||
'Get Code ${state is TimerState && !state.isButtonEnabled && state.remainingTime != 1 ? "(${forgetBloc.formattedTime(state.remainingTime)}) " : ""}',
|
||||
style: TextStyle(
|
||||
color: state
|
||||
is TimerState &&
|
||||
!state
|
||||
.isButtonEnabled
|
||||
color: state is TimerState &&
|
||||
!state.isButtonEnabled
|
||||
? Colors.grey
|
||||
: ColorsManager
|
||||
.btnColor,
|
||||
: ColorsManager.btnColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
style: const TextStyle(
|
||||
color: Colors.black),
|
||||
style: const TextStyle(color: Colors.black),
|
||||
),
|
||||
),
|
||||
if (forgetBloc.forgetValidate !=
|
||||
'') // Check if there is a validation message
|
||||
Padding(
|
||||
padding:
|
||||
const EdgeInsets.only(top: 8.0),
|
||||
padding: const EdgeInsets.only(top: 8.0),
|
||||
child: Text(
|
||||
forgetBloc.forgetValidate,
|
||||
style: const TextStyle(
|
||||
@ -275,44 +244,34 @@ class ForgetPasswordWebPage extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(height: 20.0),
|
||||
Column(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Password',
|
||||
"Password",
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall!
|
||||
.copyWith(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w400),
|
||||
.copyWith(fontSize: 14, fontWeight: FontWeight.w400),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
SizedBox(
|
||||
child: TextFormField(
|
||||
obscureText: forgetBloc.obscureText,
|
||||
keyboardType:
|
||||
TextInputType.visiblePassword,
|
||||
validator:
|
||||
forgetBloc.passwordValidator,
|
||||
controller: forgetBloc
|
||||
.forgetPasswordController,
|
||||
decoration:
|
||||
textBoxDecoration()!.copyWith(
|
||||
keyboardType: TextInputType.visiblePassword,
|
||||
validator: forgetBloc.passwordValidator,
|
||||
controller: forgetBloc.forgetPasswordController,
|
||||
decoration: textBoxDecoration()!.copyWith(
|
||||
suffixIcon: IconButton(
|
||||
onPressed: () {
|
||||
forgetBloc.add(
|
||||
PasswordVisibleEvent(
|
||||
newValue: forgetBloc
|
||||
.obscureText));
|
||||
forgetBloc.add(PasswordVisibleEvent(
|
||||
newValue: forgetBloc.obscureText));
|
||||
},
|
||||
icon: SizedBox(
|
||||
child: SvgPicture.asset(
|
||||
forgetBloc.obscureText
|
||||
? Assets.visiblePassword
|
||||
: Assets
|
||||
.invisiblePassword,
|
||||
: Assets.invisiblePassword,
|
||||
height: 15,
|
||||
width: 15,
|
||||
),
|
||||
@ -323,13 +282,10 @@ class ForgetPasswordWebPage extends StatelessWidget {
|
||||
.textTheme
|
||||
.bodySmall!
|
||||
.copyWith(
|
||||
color:
|
||||
ColorsManager.grayColor,
|
||||
fontWeight:
|
||||
FontWeight.w400),
|
||||
color: ColorsManager.grayColor,
|
||||
fontWeight: FontWeight.w400),
|
||||
),
|
||||
style: const TextStyle(
|
||||
color: Colors.black),
|
||||
style: const TextStyle(color: Colors.black),
|
||||
),
|
||||
),
|
||||
],
|
||||
@ -339,31 +295,23 @@ class ForgetPasswordWebPage extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(height: 20.0),
|
||||
Row(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: size.width * 0.2,
|
||||
child: DefaultButton(
|
||||
backgroundColor:
|
||||
ColorsManager.btnColor,
|
||||
backgroundColor: ColorsManager.btnColor,
|
||||
child: const Text('Submit'),
|
||||
onPressed: () {
|
||||
if (forgetBloc
|
||||
.forgetFormKey.currentState!
|
||||
.validate() ||
|
||||
forgetBloc.forgetEmailKey
|
||||
.currentState!
|
||||
if (forgetBloc.forgetFormKey.currentState!.validate() ||
|
||||
forgetBloc.forgetEmailKey.currentState!
|
||||
.validate()) {
|
||||
if (forgetBloc.forgetEmailKey
|
||||
.currentState!
|
||||
if (forgetBloc.forgetEmailKey.currentState!
|
||||
.validate() &&
|
||||
forgetBloc.forgetFormKey
|
||||
.currentState!
|
||||
forgetBloc.forgetFormKey.currentState!
|
||||
.validate()) {
|
||||
forgetBloc
|
||||
.add(ChangePasswordEvent());
|
||||
forgetBloc.add(ChangePasswordEvent());
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -377,8 +325,7 @@ class ForgetPasswordWebPage extends StatelessWidget {
|
||||
child: Text(
|
||||
forgetBloc.validate,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w700,
|
||||
color: ColorsManager.red),
|
||||
fontWeight: FontWeight.w700, color: ColorsManager.red),
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -390,9 +337,8 @@ class ForgetPasswordWebPage extends StatelessWidget {
|
||||
child: Wrap(
|
||||
children: [
|
||||
const Text(
|
||||
'Do you have an account? ',
|
||||
style:
|
||||
TextStyle(color: Colors.white),
|
||||
"Do you have an account? ",
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
InkWell(
|
||||
onTap: () {
|
||||
@ -400,7 +346,7 @@ class ForgetPasswordWebPage extends StatelessWidget {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text(
|
||||
'Sign in',
|
||||
"Sign in",
|
||||
),
|
||||
),
|
||||
],
|
||||
@ -426,15 +372,14 @@ class ForgetPasswordWebPage extends StatelessWidget {
|
||||
));
|
||||
}
|
||||
|
||||
Widget _buildDropdownField(
|
||||
BuildContext context, AuthBloc loginBloc, Size size) {
|
||||
final textEditingController = TextEditingController();
|
||||
Widget _buildDropdownField(BuildContext context, AuthBloc loginBloc, Size size) {
|
||||
final TextEditingController textEditingController = TextEditingController();
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Country/Region',
|
||||
"Country/Region",
|
||||
style: Theme.of(context).textTheme.bodySmall!.copyWith(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w400,
|
||||
@ -453,13 +398,10 @@ class ForgetPasswordWebPage extends StatelessWidget {
|
||||
builder: (FormFieldState<String> field) {
|
||||
return InputDecorator(
|
||||
decoration: InputDecoration(
|
||||
contentPadding:
|
||||
const EdgeInsets.symmetric(horizontal: 2, vertical: 10),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 2, vertical: 10),
|
||||
errorText: field.errorText,
|
||||
filled:
|
||||
true, // Ensure the dropdown is filled with the background color
|
||||
fillColor: ColorsManager
|
||||
.boxColor, // Match the dropdown container color
|
||||
filled: true, // Ensure the dropdown is filled with the background color
|
||||
fillColor: ColorsManager.boxColor, // Match the dropdown container color
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
borderSide: BorderSide(
|
||||
@ -470,16 +412,14 @@ class ForgetPasswordWebPage extends StatelessWidget {
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
borderSide: BorderSide(
|
||||
color:
|
||||
field.hasError ? Colors.red : ColorsManager.grayColor,
|
||||
color: field.hasError ? Colors.red : ColorsManager.grayColor,
|
||||
width: 1.5,
|
||||
),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
borderSide: BorderSide(
|
||||
color:
|
||||
field.hasError ? Colors.red : ColorsManager.grayColor,
|
||||
color: field.hasError ? Colors.red : ColorsManager.grayColor,
|
||||
width: 1.5,
|
||||
),
|
||||
),
|
||||
@ -506,8 +446,7 @@ class ForgetPasswordWebPage extends StatelessWidget {
|
||||
return DropdownMenuItem<String>(
|
||||
value: region.id,
|
||||
child: Text(
|
||||
style:
|
||||
Theme.of(context).textTheme.bodyMedium!.copyWith(
|
||||
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w400,
|
||||
),
|
||||
@ -523,8 +462,7 @@ class ForgetPasswordWebPage extends StatelessWidget {
|
||||
onChanged: (String? value) {
|
||||
if (value != null) {
|
||||
loginBloc.add(SelectRegionEvent(val: value));
|
||||
field.didChange(
|
||||
value); // Notify the form field of the change
|
||||
field.didChange(value); // Notify the form field of the change
|
||||
}
|
||||
},
|
||||
buttonStyleData: const ButtonStyleData(
|
||||
@ -548,8 +486,7 @@ class ForgetPasswordWebPage extends StatelessWidget {
|
||||
searchInnerWidgetHeight: 50,
|
||||
searchInnerWidget: Container(
|
||||
height: 50,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8, vertical: 4),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
child: TextFormField(
|
||||
style: const TextStyle(color: Colors.black),
|
||||
controller: textEditingController,
|
||||
@ -563,8 +500,7 @@ class ForgetPasswordWebPage extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
searchMatchFn: (item, searchValue) {
|
||||
final regionName =
|
||||
(item.child as Text).data?.toLowerCase() ?? '';
|
||||
final regionName = (item.child as Text).data?.toLowerCase() ?? '';
|
||||
final search = searchValue.toLowerCase().trim();
|
||||
return regionName.contains(search);
|
||||
},
|
||||
|
@ -79,7 +79,7 @@ class LoginMobilePage extends StatelessWidget {
|
||||
child: Container(
|
||||
margin: const EdgeInsets.all(50),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black.withValues(alpha: 0.3),
|
||||
color: Colors.black.withOpacity(0.3),
|
||||
borderRadius: const BorderRadius.all(Radius.circular(20))),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@ -93,15 +93,12 @@ class LoginMobilePage extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
Container(
|
||||
margin: const EdgeInsets.all(30),
|
||||
padding: const EdgeInsets.all(20),
|
||||
margin: EdgeInsets.all(30),
|
||||
padding: EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.1),
|
||||
borderRadius:
|
||||
const BorderRadius.all(Radius.circular(30)),
|
||||
border: Border.all(
|
||||
color: ColorsManager.graysColor
|
||||
.withValues(alpha: 0.2))),
|
||||
color: Colors.white.withOpacity(0.1),
|
||||
borderRadius: const BorderRadius.all(Radius.circular(30)),
|
||||
border: Border.all(color: ColorsManager.graysColor.withOpacity(0.2))),
|
||||
child: Form(
|
||||
key: loginBloc.loginFormKey,
|
||||
child: Column(
|
||||
@ -112,9 +109,7 @@ class LoginMobilePage extends StatelessWidget {
|
||||
const Text(
|
||||
'Login',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold),
|
||||
color: Colors.white, fontSize: 24, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 30),
|
||||
// Column(
|
||||
@ -160,15 +155,15 @@ class LoginMobilePage extends StatelessWidget {
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Email',
|
||||
"Email",
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
SizedBox(
|
||||
child: TextFormField(
|
||||
validator: loginBloc.validateEmail,
|
||||
controller: loginBloc.loginEmailController,
|
||||
decoration: textBoxDecoration()!
|
||||
.copyWith(hintText: 'Enter your email'),
|
||||
decoration:
|
||||
textBoxDecoration()!.copyWith(hintText: 'Enter your email'),
|
||||
style: const TextStyle(color: Colors.black),
|
||||
),
|
||||
),
|
||||
@ -180,7 +175,7 @@ class LoginMobilePage extends StatelessWidget {
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Password',
|
||||
"Password",
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
SizedBox(
|
||||
@ -188,8 +183,7 @@ class LoginMobilePage extends StatelessWidget {
|
||||
validator: loginBloc.validatePassword,
|
||||
obscureText: loginBloc.obscureText,
|
||||
keyboardType: TextInputType.visiblePassword,
|
||||
controller:
|
||||
loginBloc.loginPasswordController,
|
||||
controller: loginBloc.loginPasswordController,
|
||||
decoration: textBoxDecoration()!.copyWith(
|
||||
hintText: 'At least 8 characters',
|
||||
),
|
||||
@ -207,19 +201,16 @@ class LoginMobilePage extends StatelessWidget {
|
||||
children: [
|
||||
InkWell(
|
||||
onTap: () {
|
||||
Navigator.of(context)
|
||||
.push(MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
const ForgetPasswordPage(),
|
||||
Navigator.of(context).push(MaterialPageRoute(
|
||||
builder: (context) => const ForgetPasswordPage(),
|
||||
));
|
||||
},
|
||||
child: Text(
|
||||
'Forgot Password?',
|
||||
"Forgot Password?",
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall!
|
||||
.copyWith(
|
||||
color: ColorsManager.blackColor),
|
||||
.copyWith(color: ColorsManager.blackColor),
|
||||
),
|
||||
),
|
||||
],
|
||||
@ -230,15 +221,13 @@ class LoginMobilePage extends StatelessWidget {
|
||||
Transform.scale(
|
||||
scale: 1.2, // Adjust the scale as needed
|
||||
child: Checkbox(
|
||||
fillColor: WidgetStateProperty.all<Color>(
|
||||
Colors.white),
|
||||
fillColor: MaterialStateProperty.all<Color>(Colors.white),
|
||||
activeColor: Colors.white,
|
||||
value: loginBloc.isChecked,
|
||||
checkColor: Colors.black,
|
||||
shape: const CircleBorder(),
|
||||
onChanged: (bool? newValue) {
|
||||
loginBloc.add(
|
||||
CheckBoxEvent(newValue: newValue));
|
||||
loginBloc.add(CheckBoxEvent(newValue: newValue));
|
||||
},
|
||||
),
|
||||
),
|
||||
@ -247,37 +236,30 @@ class LoginMobilePage extends StatelessWidget {
|
||||
child: RichText(
|
||||
text: TextSpan(
|
||||
text: 'Agree to ',
|
||||
style:
|
||||
const TextStyle(color: Colors.white),
|
||||
style: const TextStyle(color: Colors.white),
|
||||
children: [
|
||||
TextSpan(
|
||||
text: '(Terms of Service)',
|
||||
style: const TextStyle(
|
||||
color: Colors.black),
|
||||
style: const TextStyle(color: Colors.black),
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () {
|
||||
loginBloc.launchURL(
|
||||
'https://example.com/terms');
|
||||
loginBloc.launchURL('https://example.com/terms');
|
||||
},
|
||||
),
|
||||
TextSpan(
|
||||
text: ' (Legal Statement)',
|
||||
style: const TextStyle(
|
||||
color: Colors.black),
|
||||
style: const TextStyle(color: Colors.black),
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () {
|
||||
loginBloc.launchURL(
|
||||
'https://example.com/legal');
|
||||
loginBloc.launchURL('https://example.com/legal');
|
||||
},
|
||||
),
|
||||
TextSpan(
|
||||
text: ' (Privacy Statement)',
|
||||
style: const TextStyle(
|
||||
color: Colors.black),
|
||||
style: const TextStyle(color: Colors.black),
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () {
|
||||
loginBloc.launchURL(
|
||||
'https://example.com/privacy');
|
||||
loginBloc.launchURL('https://example.com/privacy');
|
||||
},
|
||||
),
|
||||
],
|
||||
@ -294,14 +276,11 @@ class LoginMobilePage extends StatelessWidget {
|
||||
: ColorsManager.grayColor,
|
||||
child: const Text('Sign in'),
|
||||
onPressed: () {
|
||||
if (loginBloc.loginFormKey.currentState!
|
||||
.validate()) {
|
||||
if (loginBloc.loginFormKey.currentState!.validate()) {
|
||||
loginBloc.add(
|
||||
LoginButtonPressed(
|
||||
username:
|
||||
loginBloc.loginEmailController.text,
|
||||
password: loginBloc
|
||||
.loginPasswordController.text,
|
||||
username: loginBloc.loginEmailController.text,
|
||||
password: loginBloc.loginPasswordController.text,
|
||||
),
|
||||
);
|
||||
}
|
||||
@ -316,11 +295,10 @@ class LoginMobilePage extends StatelessWidget {
|
||||
Flexible(
|
||||
child: Text(
|
||||
"Don't you have an account? ",
|
||||
style: TextStyle(
|
||||
color: Colors.white, fontSize: 13),
|
||||
style: TextStyle(color: Colors.white, fontSize: 13),
|
||||
)),
|
||||
Text(
|
||||
'Sign up',
|
||||
"Sign up",
|
||||
),
|
||||
],
|
||||
),
|
||||
|
@ -24,8 +24,7 @@ class LoginWebPage extends StatefulWidget {
|
||||
State<LoginWebPage> createState() => _LoginWebPageState();
|
||||
}
|
||||
|
||||
class _LoginWebPageState extends State<LoginWebPage>
|
||||
with HelperResponsiveLayout {
|
||||
class _LoginWebPageState extends State<LoginWebPage> with HelperResponsiveLayout {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@ -43,7 +42,9 @@ class _LoginWebPageState extends State<LoginWebPage>
|
||||
);
|
||||
}
|
||||
},
|
||||
builder: _buildLoginForm,
|
||||
builder: (context, state) {
|
||||
return _buildLoginForm(context, state);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
@ -53,12 +54,12 @@ class _LoginWebPageState extends State<LoginWebPage>
|
||||
final loginBloc = BlocProvider.of<AuthBloc>(context);
|
||||
final isSmallScreen = isSmallScreenSize(context);
|
||||
final isMediumScreen = isMediumScreenSize(context);
|
||||
final size = MediaQuery.of(context).size;
|
||||
Size size = MediaQuery.of(context).size;
|
||||
late ScrollController scrollController;
|
||||
scrollController = ScrollController();
|
||||
|
||||
void scrollToCenter() {
|
||||
final middlePosition = scrollController.position.maxScrollExtent / 2;
|
||||
final double middlePosition = scrollController.position.maxScrollExtent / 2;
|
||||
scrollController.animateTo(
|
||||
middlePosition,
|
||||
duration: const Duration(seconds: 1),
|
||||
@ -83,7 +84,7 @@ class _LoginWebPageState extends State<LoginWebPage>
|
||||
padding: EdgeInsets.all(size.width * 0.02),
|
||||
margin: EdgeInsets.all(size.width * 0.05),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black.withValues(alpha: 0.3),
|
||||
color: Colors.black.withOpacity(0.3),
|
||||
borderRadius: const BorderRadius.all(Radius.circular(20)),
|
||||
),
|
||||
child: Center(
|
||||
@ -120,8 +121,7 @@ class _LoginWebPageState extends State<LoginWebPage>
|
||||
const Spacer(),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: _buildLoginFormFields(
|
||||
context, loginBloc, size),
|
||||
child: _buildLoginFormFields(context, loginBloc, size),
|
||||
),
|
||||
const Spacer(),
|
||||
],
|
||||
@ -132,26 +132,23 @@ class _LoginWebPageState extends State<LoginWebPage>
|
||||
),
|
||||
),
|
||||
),
|
||||
if (state is AuthLoading)
|
||||
const Center(child: CircularProgressIndicator())
|
||||
if (state is AuthLoading) const Center(child: CircularProgressIndicator())
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLoginFormFields(
|
||||
BuildContext context, AuthBloc loginBloc, Size size) {
|
||||
Widget _buildLoginFormFields(BuildContext context, AuthBloc loginBloc, Size size) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.1),
|
||||
color: Colors.white.withOpacity(0.1),
|
||||
borderRadius: const BorderRadius.all(Radius.circular(30)),
|
||||
border:
|
||||
Border.all(color: ColorsManager.graysColor.withValues(alpha: 0.2)),
|
||||
border: Border.all(color: ColorsManager.graysColor.withOpacity(0.2)),
|
||||
),
|
||||
child: Form(
|
||||
key: loginBloc.loginFormKey,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: size.width * 0.02, vertical: size.width * 0.003),
|
||||
padding:
|
||||
EdgeInsets.symmetric(horizontal: size.width * 0.02, vertical: size.width * 0.003),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@ -179,15 +176,14 @@ class _LoginWebPageState extends State<LoginWebPage>
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDropdownField(
|
||||
BuildContext context, AuthBloc loginBloc, Size size) {
|
||||
final textEditingController = TextEditingController();
|
||||
Widget _buildDropdownField(BuildContext context, AuthBloc loginBloc, Size size) {
|
||||
final TextEditingController textEditingController = TextEditingController();
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Country/Region',
|
||||
"Country/Region",
|
||||
style: Theme.of(context).textTheme.bodySmall!.copyWith(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w400,
|
||||
@ -250,8 +246,7 @@ class _LoginWebPageState extends State<LoginWebPage>
|
||||
searchInnerWidgetHeight: 50,
|
||||
searchInnerWidget: Container(
|
||||
height: 50,
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
child: TextFormField(
|
||||
style: const TextStyle(color: Colors.black),
|
||||
controller: textEditingController,
|
||||
@ -266,8 +261,7 @@ class _LoginWebPageState extends State<LoginWebPage>
|
||||
),
|
||||
searchMatchFn: (item, searchValue) {
|
||||
// Use the item's child text (region name) for searching.
|
||||
final regionName =
|
||||
(item.child as Text).data?.toLowerCase() ?? '';
|
||||
final regionName = (item.child as Text).data?.toLowerCase() ?? '';
|
||||
final search = searchValue.toLowerCase().trim();
|
||||
// Debugging print statement to ensure values are captured correctly.
|
||||
// Return true if the region name contains the search term.
|
||||
@ -292,7 +286,7 @@ class _LoginWebPageState extends State<LoginWebPage>
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Email',
|
||||
"Email",
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall!
|
||||
@ -309,9 +303,10 @@ class _LoginWebPageState extends State<LoginWebPage>
|
||||
decoration: textBoxDecoration()!.copyWith(
|
||||
errorStyle: const TextStyle(height: 0),
|
||||
hintText: 'Enter your email address',
|
||||
hintStyle: Theme.of(context).textTheme.bodySmall!.copyWith(
|
||||
color: ColorsManager.grayColor,
|
||||
fontWeight: FontWeight.w400)),
|
||||
hintStyle: Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall!
|
||||
.copyWith(color: ColorsManager.grayColor, fontWeight: FontWeight.w400)),
|
||||
style: const TextStyle(color: Colors.black),
|
||||
),
|
||||
),
|
||||
@ -325,7 +320,7 @@ class _LoginWebPageState extends State<LoginWebPage>
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Password',
|
||||
"Password",
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall!
|
||||
@ -353,18 +348,17 @@ class _LoginWebPageState extends State<LoginWebPage>
|
||||
},
|
||||
decoration: textBoxDecoration()!.copyWith(
|
||||
hintText: 'At least 8 characters',
|
||||
hintStyle: Theme.of(context).textTheme.bodySmall!.copyWith(
|
||||
color: ColorsManager.grayColor, fontWeight: FontWeight.w400),
|
||||
hintStyle: Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall!
|
||||
.copyWith(color: ColorsManager.grayColor, fontWeight: FontWeight.w400),
|
||||
suffixIcon: IconButton(
|
||||
onPressed: () {
|
||||
loginBloc.add(
|
||||
PasswordVisibleEvent(newValue: loginBloc.obscureText));
|
||||
loginBloc.add(PasswordVisibleEvent(newValue: loginBloc.obscureText));
|
||||
},
|
||||
icon: SizedBox(
|
||||
child: SvgPicture.asset(
|
||||
loginBloc.obscureText
|
||||
? Assets.visiblePassword
|
||||
: Assets.invisiblePassword,
|
||||
loginBloc.obscureText ? Assets.visiblePassword : Assets.invisiblePassword,
|
||||
height: 15,
|
||||
width: 15,
|
||||
),
|
||||
@ -391,11 +385,11 @@ class _LoginWebPageState extends State<LoginWebPage>
|
||||
));
|
||||
},
|
||||
child: Text(
|
||||
'Forgot Password?',
|
||||
style: Theme.of(context).textTheme.bodySmall!.copyWith(
|
||||
color: Colors.black,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w400),
|
||||
"Forgot Password?",
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall!
|
||||
.copyWith(color: Colors.black, fontSize: 14, fontWeight: FontWeight.w400),
|
||||
),
|
||||
),
|
||||
],
|
||||
@ -459,8 +453,7 @@ class _LoginWebPageState extends State<LoginWebPage>
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSignInButton(
|
||||
BuildContext context, AuthBloc loginBloc, Size size) {
|
||||
Widget _buildSignInButton(BuildContext context, AuthBloc loginBloc, Size size) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
@ -474,7 +467,7 @@ class _LoginWebPageState extends State<LoginWebPage>
|
||||
fontSize: 14,
|
||||
color: loginBloc.checkValidate
|
||||
? ColorsManager.whiteColors
|
||||
: ColorsManager.whiteColors.withValues(alpha: 0.2),
|
||||
: ColorsManager.whiteColors.withOpacity(0.2),
|
||||
)),
|
||||
onPressed: () {
|
||||
if (loginBloc.loginFormKey.currentState!.validate()) {
|
||||
@ -501,8 +494,7 @@ class _LoginWebPageState extends State<LoginWebPage>
|
||||
SizedBox(
|
||||
child: Text(
|
||||
loginBloc.validate,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w700, color: ColorsManager.red),
|
||||
style: const TextStyle(fontWeight: FontWeight.w700, color: ColorsManager.red),
|
||||
),
|
||||
)
|
||||
],
|
||||
|
@ -108,12 +108,13 @@ class _DynamicTableState extends State<AccessDeviceTable> {
|
||||
child: Row(
|
||||
children: [
|
||||
if (widget.withCheckBox) _buildSelectAllCheckbox(),
|
||||
...widget.headers.map(_buildTableHeaderCell),
|
||||
...widget.headers
|
||||
.map((header) => _buildTableHeaderCell(header)),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (widget.isEmpty)
|
||||
Expanded(
|
||||
widget.isEmpty
|
||||
? Expanded(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
@ -135,7 +136,8 @@ class _DynamicTableState extends State<AccessDeviceTable> {
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall!
|
||||
.copyWith(color: ColorsManager.grayColor),
|
||||
.copyWith(
|
||||
color: ColorsManager.grayColor),
|
||||
)
|
||||
],
|
||||
),
|
||||
@ -144,9 +146,8 @@ class _DynamicTableState extends State<AccessDeviceTable> {
|
||||
],
|
||||
),
|
||||
)
|
||||
else
|
||||
Expanded(
|
||||
child: ColoredBox(
|
||||
: Expanded(
|
||||
child: Container(
|
||||
color: Colors.white,
|
||||
child: ListView.builder(
|
||||
shrinkWrap: true,
|
||||
@ -159,7 +160,8 @@ class _DynamicTableState extends State<AccessDeviceTable> {
|
||||
_buildRowCheckbox(
|
||||
index, widget.size.height * 0.10),
|
||||
...row.map((cell) => _buildTableCell(
|
||||
cell.toString(), widget.size.height * 0.10)),
|
||||
cell.toString(),
|
||||
widget.size.height * 0.10)),
|
||||
],
|
||||
);
|
||||
},
|
||||
@ -243,7 +245,7 @@ class _DynamicTableState extends State<AccessDeviceTable> {
|
||||
}
|
||||
|
||||
Widget _buildTableCell(String content, double size) {
|
||||
final isBatteryLevel = content.endsWith('%');
|
||||
bool isBatteryLevel = content.endsWith('%');
|
||||
double? batteryLevel;
|
||||
|
||||
if (isBatteryLevel) {
|
||||
|
@ -22,19 +22,15 @@ class CancelButton extends StatelessWidget {
|
||||
return ElevatedButton(
|
||||
onPressed: onPressed,
|
||||
style: ButtonStyle(
|
||||
backgroundColor:
|
||||
WidgetStateProperty.all(ColorsManager.boxColor), // White background
|
||||
foregroundColor:
|
||||
WidgetStateProperty.all(Colors.black), // Black text color
|
||||
backgroundColor: WidgetStateProperty.all(ColorsManager.boxColor), // White background
|
||||
foregroundColor: WidgetStateProperty.all(Colors.black), // Black text color
|
||||
shape: WidgetStateProperty.all<RoundedRectangleBorder>(
|
||||
RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(borderRadius ?? 10),
|
||||
side:
|
||||
const BorderSide(color: ColorsManager.boxColor), // Black border
|
||||
side: const BorderSide(color: ColorsManager.boxColor), // Black border
|
||||
),
|
||||
),
|
||||
fixedSize: WidgetStateProperty.all(
|
||||
Size(width ?? 50, height ?? 40)), // Set button height
|
||||
fixedSize: WidgetStateProperty.all(Size(width ?? 50, height ?? 40)), // Set button height
|
||||
),
|
||||
child: Text(label), // Dynamic label
|
||||
);
|
||||
|
@ -64,7 +64,7 @@ class DefaultButton extends StatelessWidget {
|
||||
(Set<WidgetState> states) {
|
||||
return enabled
|
||||
? backgroundColor ?? ColorsManager.primaryColor
|
||||
: Colors.black.withValues(alpha: 0.2);
|
||||
: Colors.black.withOpacity(0.2);
|
||||
}),
|
||||
shape: WidgetStateProperty.all(
|
||||
RoundedRectangleBorder(
|
||||
|
@ -34,7 +34,7 @@ class CurtainToggle extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ClipOval(
|
||||
child: ColoredBox(
|
||||
child: Container(
|
||||
color: ColorsManager.whiteColors,
|
||||
child: SvgPicture.asset(
|
||||
Assets.curtainIcon,
|
||||
@ -52,7 +52,7 @@ class CurtainToggle extends StatelessWidget {
|
||||
width: 35,
|
||||
child: CupertinoSwitch(
|
||||
value: value,
|
||||
activeTrackColor: ColorsManager.dialogBlueTitle,
|
||||
activeColor: ColorsManager.dialogBlueTitle,
|
||||
onChanged: onChanged,
|
||||
),
|
||||
),
|
||||
|
@ -40,20 +40,14 @@ Future<void> showCustomDialog({
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.headlineLarge!
|
||||
.copyWith(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w400,
|
||||
color: Colors.black),
|
||||
.copyWith(fontSize: 20, fontWeight: FontWeight.w400, color: Colors.black),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8.0),
|
||||
child: Text(
|
||||
message,
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodyMedium!
|
||||
.copyWith(color: Colors.black),
|
||||
style: Theme.of(context).textTheme.bodyMedium!.copyWith(color: Colors.black),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
|
@ -20,8 +20,8 @@ class DynamicTable extends StatefulWidget {
|
||||
final void Function(int, bool, dynamic)? onRowSelected;
|
||||
final List<String>? initialSelectedIds;
|
||||
final int uuidIndex;
|
||||
final void Function(dynamic selectedRows)? onSelectionChanged;
|
||||
final void Function(int rowIndex)? onSettingsPressed;
|
||||
final Function(dynamic selectedRows)? onSelectionChanged;
|
||||
final Function(int rowIndex)? onSettingsPressed;
|
||||
const DynamicTable({
|
||||
super.key,
|
||||
required this.headers,
|
||||
@ -79,10 +79,10 @@ class _DynamicTableState extends State<DynamicTable> {
|
||||
// Check if the old and new lists are the same
|
||||
if (oldList.length != newList.length) return false;
|
||||
|
||||
for (var i = 0; i < oldList.length; i++) {
|
||||
for (int i = 0; i < oldList.length; i++) {
|
||||
if (oldList[i].length != newList[i].length) return false;
|
||||
|
||||
for (var j = 0; j < oldList[i].length; j++) {
|
||||
for (int j = 0; j < oldList[i].length; j++) {
|
||||
if (oldList[i][j] != newList[i][j]) return false;
|
||||
}
|
||||
}
|
||||
@ -162,7 +162,7 @@ class _DynamicTableState extends State<DynamicTable> {
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
controller: _horizontalBodyScrollController,
|
||||
child: ColoredBox(
|
||||
child: Container(
|
||||
color: ColorsManager.whiteColors,
|
||||
child: SizedBox(
|
||||
width: widget.size.width,
|
||||
@ -184,7 +184,7 @@ class _DynamicTableState extends State<DynamicTable> {
|
||||
rowIndex: rowIndex,
|
||||
columnIndex: entry.key,
|
||||
);
|
||||
}),
|
||||
}).toList(),
|
||||
],
|
||||
);
|
||||
}),
|
||||
@ -304,13 +304,13 @@ class _DynamicTableState extends State<DynamicTable> {
|
||||
required int rowIndex,
|
||||
required int columnIndex,
|
||||
}) {
|
||||
final isBatteryLevel = content.endsWith('%');
|
||||
bool isBatteryLevel = content.endsWith('%');
|
||||
double? batteryLevel;
|
||||
|
||||
if (isBatteryLevel) {
|
||||
batteryLevel = double.tryParse(content.replaceAll('%', '').trim());
|
||||
}
|
||||
final isSettingsColumn = widget.headers[columnIndex] == 'Settings';
|
||||
bool isSettingsColumn = widget.headers[columnIndex] == 'Settings';
|
||||
|
||||
if (isSettingsColumn) {
|
||||
return buildSettingsIcon(
|
||||
@ -404,7 +404,7 @@ class _DynamicTableState extends State<DynamicTable> {
|
||||
borderRadius: BorderRadius.circular(height / 2),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withValues(alpha: 0.17),
|
||||
color: Colors.black.withOpacity(0.17),
|
||||
blurRadius: 14,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
@ -416,10 +416,11 @@ class _DynamicTableState extends State<DynamicTable> {
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Center(
|
||||
child: SvgPicture.asset(
|
||||
Assets.settings,
|
||||
Assets.settings, // ضع المسار الصحيح هنا
|
||||
width: 40,
|
||||
height: 22,
|
||||
color: ColorsManager.primaryColor,
|
||||
color: ColorsManager
|
||||
.primaryColor, // نفس لون الأيقونة في الصورة
|
||||
),
|
||||
),
|
||||
),
|
||||
|
@ -36,7 +36,7 @@ class FilterWidget extends StatelessWidget {
|
||||
color: ColorsManager.boxColor,
|
||||
border: Border.all(
|
||||
color: isSelected
|
||||
? ColorsManager.blueColor.withValues(alpha: 0.8)
|
||||
? ColorsManager.blueColor.withOpacity(0.8)
|
||||
: Colors.transparent,
|
||||
width: 2.0,
|
||||
),
|
||||
@ -48,7 +48,7 @@ class FilterWidget extends StatelessWidget {
|
||||
tabs[index],
|
||||
style: TextStyle(
|
||||
color: isSelected
|
||||
? ColorsManager.blueColor.withValues(alpha: 0.8)
|
||||
? ColorsManager.blueColor.withOpacity(0.8)
|
||||
: Colors.black,
|
||||
),
|
||||
),
|
||||
|
@ -1,3 +1,5 @@
|
||||
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class HourPickerDialog extends StatefulWidget {
|
||||
@ -16,7 +18,7 @@ class _HourPickerDialogState extends State<HourPickerDialog> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Initialize the selectedHour with the initial time passed to the dialog
|
||||
selectedHour = '${widget.initialTime.hour.toString().padLeft(2, '0')}:00';
|
||||
selectedHour = widget.initialTime.hour.toString().padLeft(2, '0') + ':00';
|
||||
}
|
||||
|
||||
@override
|
||||
@ -26,7 +28,7 @@ class _HourPickerDialogState extends State<HourPickerDialog> {
|
||||
content: DropdownButton<String>(
|
||||
value: selectedHour, // Show the currently selected hour
|
||||
items: List.generate(24, (index) {
|
||||
final hour = index.toString().padLeft(2, '0');
|
||||
String hour = index.toString().padLeft(2, '0');
|
||||
return DropdownMenuItem<String>(
|
||||
value: '$hour:00',
|
||||
child: Text('$hour:00'),
|
||||
@ -35,16 +37,14 @@ class _HourPickerDialogState extends State<HourPickerDialog> {
|
||||
onChanged: (String? newValue) {
|
||||
if (newValue != null) {
|
||||
setState(() {
|
||||
selectedHour =
|
||||
newValue; // Update the selected hour without closing the dialog
|
||||
selectedHour = newValue; // Update the selected hour without closing the dialog
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context)
|
||||
.pop(null), // Close the dialog without selection
|
||||
onPressed: () => Navigator.of(context).pop(null), // Close the dialog without selection
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
TextButton(
|
||||
|
@ -9,8 +9,7 @@ class InfoDialog extends StatelessWidget {
|
||||
final Size? size;
|
||||
final List<Widget>? actions;
|
||||
|
||||
const InfoDialog({
|
||||
super.key,
|
||||
InfoDialog({
|
||||
required this.title,
|
||||
required this.content,
|
||||
this.actions,
|
||||
|
@ -45,8 +45,7 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
|
||||
) async {
|
||||
emit(AcsLoadingState());
|
||||
try {
|
||||
final status =
|
||||
await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
||||
final status = await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
||||
deviceStatus = AcStatusModel.fromJson(event.deviceId, status.status);
|
||||
if (deviceStatus.countdown1 != 0) {
|
||||
final totalMinutes = deviceStatus.countdown1 * 6;
|
||||
@ -72,20 +71,21 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
|
||||
void _listenToChanges(deviceId) {
|
||||
try {
|
||||
final ref = FirebaseDatabase.instance.ref('device-status/$deviceId');
|
||||
ref.onValue.listen((DatabaseEvent event) async {
|
||||
final stream = ref.onValue;
|
||||
|
||||
stream.listen((DatabaseEvent event) async {
|
||||
if (event.snapshot.value == null) return;
|
||||
|
||||
final usersMap = event.snapshot.value! as Map<dynamic, dynamic>;
|
||||
Map<dynamic, dynamic> usersMap =
|
||||
event.snapshot.value as Map<dynamic, dynamic>;
|
||||
|
||||
final statusList = <Status>[];
|
||||
List<Status> statusList = [];
|
||||
|
||||
usersMap['status'].forEach((element) {
|
||||
statusList
|
||||
.add(Status(code: element['code'], value: element['value']));
|
||||
statusList.add(Status(code: element['code'], value: element['value']));
|
||||
});
|
||||
|
||||
deviceStatus =
|
||||
AcStatusModel.fromJson(usersMap['productUuid'], statusList);
|
||||
deviceStatus = AcStatusModel.fromJson(usersMap['productUuid'], statusList);
|
||||
if (!isClosed) {
|
||||
add(AcStatusUpdated(deviceStatus));
|
||||
}
|
||||
@ -129,10 +129,8 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
|
||||
) async {
|
||||
emit(AcsLoadingState());
|
||||
try {
|
||||
final status =
|
||||
await DevicesManagementApi().getBatchStatus(event.devicesIds);
|
||||
deviceStatus =
|
||||
AcStatusModel.fromJson(event.devicesIds.first, status.status);
|
||||
final status = await DevicesManagementApi().getBatchStatus(event.devicesIds);
|
||||
deviceStatus = AcStatusModel.fromJson(event.devicesIds.first, status.status);
|
||||
emit(ACStatusLoaded(status: deviceStatus));
|
||||
} catch (e) {
|
||||
emit(AcsFailedState(error: e.toString()));
|
||||
@ -192,8 +190,8 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
|
||||
void _handleIncreaseTime(IncreaseTimeEvent event, Emitter<AcsState> emit) {
|
||||
if (state is! ACStatusLoaded) return;
|
||||
final currentState = state as ACStatusLoaded;
|
||||
var newHours = scheduledHours;
|
||||
var newMinutes = scheduledMinutes + 30;
|
||||
int newHours = scheduledHours;
|
||||
int newMinutes = scheduledMinutes + 30;
|
||||
newHours += newMinutes ~/ 60;
|
||||
newMinutes = newMinutes % 60;
|
||||
if (newHours > 23) {
|
||||
@ -215,7 +213,7 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
|
||||
) {
|
||||
if (state is! ACStatusLoaded) return;
|
||||
final currentState = state as ACStatusLoaded;
|
||||
var totalMinutes = (scheduledHours * 60) + scheduledMinutes;
|
||||
int totalMinutes = (scheduledHours * 60) + scheduledMinutes;
|
||||
totalMinutes = (totalMinutes - 30).clamp(0, 1440);
|
||||
scheduledHours = totalMinutes ~/ 60;
|
||||
scheduledMinutes = totalMinutes % 60;
|
||||
@ -288,7 +286,7 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
|
||||
|
||||
void _startCountdownTimer(Emitter<AcsState> emit) {
|
||||
_countdownTimer?.cancel();
|
||||
var totalSeconds = (scheduledHours * 3600) + (scheduledMinutes * 60);
|
||||
int totalSeconds = (scheduledHours * 3600) + (scheduledMinutes * 60);
|
||||
|
||||
_countdownTimer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
||||
if (totalSeconds > 0) {
|
||||
@ -338,26 +336,32 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
|
||||
if (value is bool) {
|
||||
deviceStatus = deviceStatus.copyWith(acSwitch: value);
|
||||
}
|
||||
break;
|
||||
case 'temp_set':
|
||||
if (value is int) {
|
||||
deviceStatus = deviceStatus.copyWith(tempSet: value);
|
||||
}
|
||||
break;
|
||||
case 'mode':
|
||||
if (value is String) {
|
||||
deviceStatus = deviceStatus.copyWith(modeString: value);
|
||||
}
|
||||
break;
|
||||
case 'level':
|
||||
if (value is String) {
|
||||
deviceStatus = deviceStatus.copyWith(fanSpeedsString: value);
|
||||
}
|
||||
break;
|
||||
case 'child_lock':
|
||||
if (value is bool) {
|
||||
deviceStatus = deviceStatus.copyWith(childLock: value);
|
||||
}
|
||||
break;
|
||||
case 'countdown_time':
|
||||
if (value is int) {
|
||||
deviceStatus = deviceStatus.copyWith(countdown1: value);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ class AcFetchDeviceStatusEvent extends AcsEvent {
|
||||
|
||||
class AcStatusUpdated extends AcsEvent {
|
||||
final AcStatusModel deviceStatus;
|
||||
const AcStatusUpdated(this.deviceStatus);
|
||||
AcStatusUpdated(this.deviceStatus);
|
||||
}
|
||||
|
||||
class AcFetchBatchStatusEvent extends AcsEvent {
|
||||
@ -77,6 +77,8 @@ class AcFactoryResetEvent extends AcsEvent {
|
||||
List<Object> get props => [deviceId, factoryResetModel];
|
||||
}
|
||||
|
||||
|
||||
|
||||
class OnClose extends AcsEvent {}
|
||||
|
||||
class IncreaseTimeEvent extends AcsEvent {
|
||||
@ -93,7 +95,8 @@ class ToggleScheduleEvent extends AcsEvent {}
|
||||
|
||||
class TimerCompletedEvent extends AcsEvent {}
|
||||
|
||||
class UpdateTimerEvent extends AcsEvent {}
|
||||
class UpdateTimerEvent extends AcsEvent {
|
||||
}
|
||||
|
||||
class ApiCountdownValueEvent extends AcsEvent {
|
||||
final int apiValue;
|
||||
|
@ -18,7 +18,6 @@ class ACStatusLoaded extends AcsState {
|
||||
final DateTime timestamp;
|
||||
final int scheduledHours;
|
||||
final int scheduledMinutes;
|
||||
@override
|
||||
final bool isTimerActive;
|
||||
|
||||
ACStatusLoaded({
|
||||
@ -73,3 +72,5 @@ class TimerRunInProgress extends AcsState {
|
||||
@override
|
||||
List<Object> get props => [remainingTime];
|
||||
}
|
||||
|
||||
|
||||
|
@ -32,9 +32,9 @@ class AcStatusModel {
|
||||
late int currentTemp;
|
||||
late String fanSpeeds;
|
||||
late bool childLock;
|
||||
late var countdown1 = 0;
|
||||
late int _countdown1 = 0;
|
||||
|
||||
for (final status in jsonList) {
|
||||
for (var status in jsonList) {
|
||||
switch (status.code) {
|
||||
case 'switch':
|
||||
acSwitch = status.value ?? false;
|
||||
@ -55,7 +55,7 @@ class AcStatusModel {
|
||||
childLock = status.value ?? false;
|
||||
break;
|
||||
case 'countdown_time':
|
||||
countdown1 = status.value ?? 0;
|
||||
_countdown1 = status.value ?? 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -68,7 +68,7 @@ class AcStatusModel {
|
||||
currentTemp: currentTemp,
|
||||
fanSpeedsString: fanSpeeds,
|
||||
childLock: childLock,
|
||||
countdown1: countdown1,
|
||||
countdown1: _countdown1,
|
||||
);
|
||||
}
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user