add table view

This commit is contained in:
ashrafzarkanisala
2024-08-24 14:03:13 +03:00
parent e576fb3b47
commit 982954be42
4 changed files with 95 additions and 34 deletions

View File

@ -34,7 +34,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
TextEditingController();
final TextEditingController forgetOtp = TextEditingController();
final forgetFormKey = GlobalKey<FormState>();
late bool checkValidate = false;
late bool checkValidate = false;
Timer? _timer;
int _remainingTime = 0;
@ -58,8 +58,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
add(const UpdateTimerEvent(remainingTime: 0, isButtonEnabled: true));
} else {
add(UpdateTimerEvent(
remainingTime: _remainingTime,
isButtonEnabled: false));
remainingTime: _remainingTime, isButtonEnabled: false));
}
});
}
@ -152,29 +151,35 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
key: UserModel.userUuidKey,
value: Token.decodeToken(token.accessToken)['uuid'].toString());
user = UserModel.fromToken(token);
debugPrint(token.accessToken);
loginEmailController.clear();
loginPasswordController.clear();
emit(LoginSuccess());
} else {
emit(const LoginFailure(error: 'Something went wrong'));
}
} else {
emit(const LoginFailure(error: 'Accept terms and condition'));
}
}
checkBoxToggle(CheckBoxEvent event, Emitter<AuthState> emit,) {
checkBoxToggle(
CheckBoxEvent event,
Emitter<AuthState> emit,
) {
emit(AuthLoading());
isChecked = event.newValue!;
add(CheckEnableEvent());
emit(LoginInitial());
}
checkOtpCode(ChangePasswordEvent event, Emitter<AuthState> emit,) async {
checkOtpCode(
ChangePasswordEvent event,
Emitter<AuthState> emit,
) async {
emit(LoadingForgetState());
await AuthenticationAPI.verifyOtp(email: forgetEmailController.text, otpCode: forgetOtp.text);
await AuthenticationAPI.verifyOtp(
email: forgetEmailController.text, otpCode: forgetOtp.text);
emit(SuccessForgetState());
}
@ -202,19 +207,17 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
} else if (regionUuid == '') {
return 'Please select your region';
}
validate='';
validate = '';
return null;
}
String? loginValidateEmail(String? value) {
if (!RegExp(r'^[^@]+@[^@]+\.[^@]+').hasMatch(value!)) {
if (!RegExp(r'^[^@]+@[^@]+\.[^@]+').hasMatch(value!)) {
return '';
}
return null;
}
bool _validateInputs(Emitter<AuthState> emit) {
emit(LoadingForgetState());
final nameError = validateEmail(forgetEmailController.text);
@ -357,7 +360,9 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
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(':');
@ -365,9 +370,12 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
return formattedTime;
}
bool checkEnable( CheckEnableEvent event, Emitter<AuthState> emit,) {
bool checkEnable(
CheckEnableEvent event,
Emitter<AuthState> emit,
) {
emit(AuthLoading());
checkValidate = isChecked==true &&
checkValidate = isChecked == true &&
loginPasswordController.text.isNotEmpty &&
loginEmailController.text.isNotEmpty &&
regionUuid != '';
@ -375,14 +383,21 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
return checkValidate;
}
changeValidate(ChangeValidateEvent event, Emitter<AuthState> emit,){
changeValidate(
ChangeValidateEvent event,
Emitter<AuthState> emit,
) {
emit(AuthLoading());
validate='';
validate = '';
emit(LoginInitial());
}
changeForgetValidate(ChangeValidateEvent event, Emitter<AuthState> emit,){
changeForgetValidate(
ChangeValidateEvent event,
Emitter<AuthState> emit,
) {
emit(AuthLoading());
forgetValidate='';
forgetValidate = '';
emit(LoginInitial());
}
}

View File

@ -75,8 +75,7 @@ class _DynamicTableState extends State<DynamicTable> {
BoxDecoration(color: Colors.grey[200]),
child: Row(
children: [
if (widget.withCheckBox)
_buildSelectAllCheckbox(),
if (widget.withCheckBox) _buildSelectAllCheckbox(),
...widget.headers
.map((header) => _buildTableHeaderCell(header))
.toList(),
@ -93,10 +92,11 @@ class _DynamicTableState extends State<DynamicTable> {
final row = widget.data[index];
return Row(
children: [
if (widget.withCheckBox)
_buildRowCheckbox(index),
...row.map((cell) =>
_buildTableCell(cell.toString())).toList(),
if (widget.withCheckBox) _buildRowCheckbox(index),
...row
.map((cell) =>
_buildTableCell(cell.toString()))
.toList(),
],
);
},
@ -143,7 +143,10 @@ class _DynamicTableState extends State<DynamicTable> {
alignment: Alignment.centerLeft,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(title, style: const TextStyle(fontWeight: FontWeight.bold)),
child: Text(title,
style: const TextStyle(
fontWeight: FontWeight.w400,
color: ColorsManager.lightGreyColor)),
),
),
);
@ -156,11 +159,11 @@ class _DynamicTableState extends State<DynamicTable> {
padding: const EdgeInsets.all(15.0),
decoration: const BoxDecoration(
border: Border(
bottom: BorderSide(
color: ColorsManager.boxDivider,
width: 1.0,
),
)),
bottom: BorderSide(
color: ColorsManager.boxDivider,
width: 1.0,
),
)),
alignment: Alignment.centerLeft,
child: Text(
content,

View File

@ -1,9 +1,11 @@
import 'package:flutter/material.dart';
import 'package:syncrow_web/core/extension/build_context_x.dart';
import 'package:syncrow_web/pages/common/buttons/search_reset_buttons.dart';
import 'package:syncrow_web/pages/common/custom_table.dart';
import 'package:syncrow_web/pages/common/filter/filter_widget.dart';
import 'package:syncrow_web/pages/common/text_field/custom_text_field.dart';
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
import 'package:syncrow_web/utils/style.dart';
class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
const DeviceManagementBody({super.key});
@ -80,6 +82,46 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
],
),
],
const SizedBox(
height: 12,
),
Expanded(
child: DynamicTable(
cellDecoration: containerDecoration,
selectAll: (p0) {
// visitorBloc.selectedDeviceIds.clear();
// for (var item in state.data) {
// visitorBloc.add(SelectDeviceEvent(item.uuid));
// }
},
onRowCheckboxChanged: (index, isSelected) {
// final deviceId = state.data[index].uuid;
// visitorBloc.add(SelectDeviceEvent(deviceId));
},
withCheckBox: true,
size: context.screenSize,
headers: const [
'Device Name',
'Product Name',
'Device ID',
'Unit Name',
'Room',
'Battery Level',
'Installation Date and Time',
'Status',
'Last Offline Date and Time',
],
data: []
// state.data.map((item) {
// return [
// item.name.toString(),
// item.uuid.toString(),
// item.productType.toString(),
// '',
// item.online.value.toString(),
// ];
// }).toList(),
)),
],
),
);

View File

@ -3,9 +3,10 @@ import 'package:flutter/material.dart';
abstract class ColorsManager {
static const Color textPrimaryColor = Color(0xFF5D5D5D);
static const Color switchOffColor = Color(0x7F8D99AE);
static const Color primaryColor = Color(0xFF0030CB);//023DFE
static const Color primaryColor = Color(0xFF0030CB); //023DFE
static const Color secondaryTextColor = Color(0xFF848484);
static Color primaryColorWithOpacity = const Color(0xFF023DFE).withOpacity(0.6);
static Color primaryColorWithOpacity =
const Color(0xFF023DFE).withOpacity(0.6);
static const Color whiteColors = Colors.white;
static const Color secondaryColor = Color(0xFF023DFE);
static const Color onSecondaryColor = Color(0xFF023DFE);
@ -13,7 +14,7 @@ abstract class ColorsManager {
static const Color primaryTextColor = Colors.black;
static const Color greyColor = Color(0xFFd5d5d5);
static const Color lightGreyColor = Color(0xFF999999);
static const Color backgroundColor = Color(0xFFececec);
static const Color dozeColor = Color(0xFFFEC258);
static const Color relaxColor = Color(0xFFFBD288);