mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
Merge pull request #77 from SyncrowIOT/web_bugs_fixes
Fix bugs related to the user table, privacy policy, and table filter.
This commit is contained in:
@ -31,7 +31,8 @@ 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>();
|
||||
@ -48,7 +49,8 @@ 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(
|
||||
@ -85,7 +87,8 @@ 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));
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -95,7 +98,8 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
emit(const TimerState(isButtonEnabled: true, remainingTime: 0));
|
||||
}
|
||||
|
||||
Future<void> changePassword(ChangePasswordEvent event, Emitter<AuthState> emit) async {
|
||||
Future<void> changePassword(
|
||||
ChangePasswordEvent event, Emitter<AuthState> emit) async {
|
||||
emit(LoadingForgetState());
|
||||
try {
|
||||
var response = await AuthenticationAPI.verifyOtp(
|
||||
@ -111,7 +115,8 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
final errorData = e.response!.data;
|
||||
String errorMessage = errorData['error']['message'] ?? 'something went wrong';
|
||||
String errorMessage =
|
||||
errorData['error']['message'] ?? 'something went wrong';
|
||||
validate = errorMessage;
|
||||
emit(AuthInitialState());
|
||||
}
|
||||
@ -125,7 +130,9 @@ 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 /////////////////////////////////////
|
||||
@ -161,15 +168,23 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
password: event.password,
|
||||
),
|
||||
);
|
||||
} catch (failure) {
|
||||
} on DioException catch (e) {
|
||||
final errorData = e.response!.data;
|
||||
String errorMessage = errorData['error']['message'];
|
||||
if (errorMessage == "Access denied for web platform") {
|
||||
validate = errorMessage;
|
||||
} else {
|
||||
validate = 'Invalid Credentials!';
|
||||
}
|
||||
emit(LoginInitial());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (token.accessTokenIsNotEmpty) {
|
||||
FlutterSecureStorage storage = const FlutterSecureStorage();
|
||||
await storage.write(key: Token.loginAccessTokenKey, value: token.accessToken);
|
||||
await storage.write(
|
||||
key: Token.loginAccessTokenKey, value: token.accessToken);
|
||||
const FlutterSecureStorage().write(
|
||||
key: UserModel.userUuidKey,
|
||||
value: Token.decodeToken(token.accessToken)['uuid'].toString());
|
||||
@ -327,12 +342,14 @@ 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';
|
||||
@ -385,7 +402,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(':');
|
||||
|
@ -21,7 +21,9 @@ class LoginWithEmailModel {
|
||||
return {
|
||||
'email': email,
|
||||
'password': password,
|
||||
"platform": "web"
|
||||
// 'regionUuid': regionUuid,
|
||||
};
|
||||
}
|
||||
}
|
||||
//tst@tst.com
|
@ -62,6 +62,7 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
||||
emit(LoadingHome());
|
||||
terms = await HomeApi().fetchTerms();
|
||||
add(FetchPolicyEvent());
|
||||
emit(PolicyAgreement());
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
@ -71,6 +72,7 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
||||
try {
|
||||
emit(LoadingHome());
|
||||
policy = await HomeApi().fetchPolicy();
|
||||
emit(PolicyAgreement());
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
|
@ -63,9 +63,11 @@ class _AgreementAndPrivacyDialogState extends State<AgreementAndPrivacyDialog> {
|
||||
}
|
||||
|
||||
String get _dialogTitle =>
|
||||
_currentPage == 2 ? 'User Agreement' : 'Privacy Policy';
|
||||
_currentPage == 1 ? 'User Agreement' : 'Privacy Policy';
|
||||
|
||||
String get _dialogContent => _currentPage == 2 ? widget.terms : widget.policy;
|
||||
String get _dialogContent => _currentPage == 1 ? widget.terms : widget.policy;
|
||||
final String staticText =
|
||||
'<h5 style="color: #FF5722;">If you cancel you will be logged out.</h5>';
|
||||
|
||||
Widget _buildScrollableContent() {
|
||||
return Container(
|
||||
@ -85,7 +87,7 @@ class _AgreementAndPrivacyDialogState extends State<AgreementAndPrivacyDialog> {
|
||||
controller: _scrollController,
|
||||
padding: const EdgeInsets.all(25),
|
||||
child: Html(
|
||||
data: _dialogContent,
|
||||
data: "$_dialogContent $staticText",
|
||||
onLinkTap: (url, attributes, element) async {
|
||||
if (url != null) {
|
||||
final uri = Uri.parse(url);
|
||||
|
@ -24,7 +24,7 @@ class HomeWebPage extends StatelessWidget {
|
||||
listener: (BuildContext context, state) {
|
||||
if (state is HomeInitial) {
|
||||
if (homeBloc.user!.hasAcceptedWebAgreement == false) {
|
||||
Future.delayed(const Duration(seconds: 1), () {
|
||||
Future.delayed(const Duration(seconds: 2), () {
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
|
@ -42,7 +42,9 @@ class RolesUserModel {
|
||||
invitedBy:
|
||||
json['invitedBy'].toString().toLowerCase().replaceAll("_", " "),
|
||||
phoneNumber: json['phoneNumber'],
|
||||
jobTitle: json['jobTitle'] ?? "-",
|
||||
jobTitle: json['jobTitle'] == null || json['jobTitle'] == " "
|
||||
? "_"
|
||||
: json['jobTitle'],
|
||||
createdDate: json['createdDate'],
|
||||
createdTime: json['createdTime'],
|
||||
);
|
||||
|
@ -79,13 +79,14 @@ class UsersBloc extends Bloc<UsersEvent, UsersState> {
|
||||
|
||||
List<TreeNode> updatedCommunities = [];
|
||||
List<TreeNode> spacesNodes = [];
|
||||
|
||||
List<String> communityIds = [];
|
||||
_onLoadCommunityAndSpaces(
|
||||
LoadCommunityAndSpacesEvent event, Emitter<UsersState> emit) async {
|
||||
try {
|
||||
emit(UsersLoadingState());
|
||||
List<CommunityModel> communities =
|
||||
await CommunitySpaceManagementApi().fetchCommunities();
|
||||
communityIds = communities.map((community) => community.uuid).toList();
|
||||
updatedCommunities = await Future.wait(
|
||||
communities.map((community) async {
|
||||
List<SpaceModel> spaces =
|
||||
@ -102,7 +103,6 @@ class UsersBloc extends Bloc<UsersEvent, UsersState> {
|
||||
}).toList(),
|
||||
);
|
||||
emit(const SpacesLoadedState());
|
||||
return updatedCommunities;
|
||||
} catch (e) {
|
||||
emit(ErrorState('Error loading communities and spaces: $e'));
|
||||
}
|
||||
@ -177,7 +177,6 @@ class UsersBloc extends Bloc<UsersEvent, UsersState> {
|
||||
try {
|
||||
emit(UsersLoadingState());
|
||||
roles = await UserPermissionApi().fetchRoles();
|
||||
// add(PermissionEvent(roleUuid: roles.first.uuid));
|
||||
emit(RolePermissionInitial());
|
||||
} catch (e) {
|
||||
emit(ErrorState('Error loading communities and spaces: $e'));
|
||||
@ -208,10 +207,13 @@ class UsersBloc extends Bloc<UsersEvent, UsersState> {
|
||||
return anyMatch;
|
||||
}
|
||||
|
||||
_sendInvitUser(SendInviteUsers event, Emitter<UsersState> emit) async {
|
||||
void _sendInvitUser(SendInviteUsers event, Emitter<UsersState> emit) async {
|
||||
try {
|
||||
emit(UsersLoadingState());
|
||||
List<String> selectedIds = getSelectedIds(updatedCommunities);
|
||||
List<String> selectedIds = getSelectedIds(updatedCommunities)
|
||||
.where((id) => !communityIds.contains(id))
|
||||
.toList();
|
||||
|
||||
bool res = await UserPermissionApi().sendInviteUser(
|
||||
email: emailController.text,
|
||||
firstName: firstNameController.text,
|
||||
@ -221,7 +223,8 @@ class UsersBloc extends Bloc<UsersEvent, UsersState> {
|
||||
roleUuid: roleSelected,
|
||||
spaceUuids: selectedIds,
|
||||
);
|
||||
if (res == true) {
|
||||
|
||||
if (res) {
|
||||
showCustomDialog(
|
||||
barrierDismissible: false,
|
||||
context: event.context,
|
||||
@ -248,10 +251,14 @@ class UsersBloc extends Bloc<UsersEvent, UsersState> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
_editInviteUser(EditInviteUsers event, Emitter<UsersState> emit) async {
|
||||
try {
|
||||
emit(UsersLoadingState());
|
||||
List<String> selectedIds = getSelectedIds(updatedCommunities);
|
||||
List<String> selectedIds = getSelectedIds(updatedCommunities)
|
||||
.where((id) => !communityIds.contains(id))
|
||||
.toList();
|
||||
|
||||
bool res = await UserPermissionApi().editInviteUser(
|
||||
userId: event.userId,
|
||||
firstName: firstNameController.text,
|
||||
|
@ -218,7 +218,7 @@ class BasicsView extends StatelessWidget {
|
||||
if (_blocRole.checkEmailValid != "Valid email") {
|
||||
return _blocRole.checkEmailValid;
|
||||
}
|
||||
return null;
|
||||
// return null;
|
||||
},
|
||||
),
|
||||
),
|
||||
|
@ -81,7 +81,7 @@ Future<void> showPopUpFilterMenu({
|
||||
),
|
||||
const Divider(),
|
||||
const Text(
|
||||
"Filter by Status",
|
||||
"Filter by ",
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
Container(
|
||||
|
@ -40,9 +40,7 @@ class UserTableBloc extends Bloc<UserTableEvent, UserTableState> {
|
||||
roleTypes.clear();
|
||||
jobTitle.clear();
|
||||
createdBy.clear();
|
||||
// deActivate.clear();
|
||||
users = await UserPermissionApi().fetchUsers();
|
||||
|
||||
users.sort((a, b) {
|
||||
final dateA = _parseDateTime(a.createdDate);
|
||||
final dateB = _parseDateTime(b.createdDate);
|
||||
@ -57,15 +55,12 @@ class UserTableBloc extends Bloc<UserTableEvent, UserTableState> {
|
||||
for (var user in users) {
|
||||
createdBy.add(user.invitedBy.toString());
|
||||
}
|
||||
// for (var user in users) {
|
||||
// deActivate.add(user.status.toString());
|
||||
// }
|
||||
initialUsers = List.from(users);
|
||||
roleTypes = roleTypes.toSet().toList();
|
||||
jobTitle = jobTitle.toSet().toList();
|
||||
createdBy = createdBy.toSet().toList();
|
||||
// deActivate = deActivate.toSet().toList();
|
||||
_handlePageChange(ChangePage(1), emit);
|
||||
add(ChangePage(currentPage));
|
||||
emit(UsersLoadedState(users: users));
|
||||
} catch (e) {
|
||||
emit(ErrorState(e.toString()));
|
||||
@ -125,6 +120,10 @@ class UserTableBloc extends Bloc<UserTableEvent, UserTableState> {
|
||||
|
||||
void _toggleSortUsersByNameAsc(
|
||||
SortUsersByNameAsc event, Emitter<UserTableState> emit) {
|
||||
selectedRoles.clear();
|
||||
selectedJobTitles.clear();
|
||||
selectedCreatedBy.clear();
|
||||
selectedStatuses.clear();
|
||||
if (currentSortOrder == "Asc") {
|
||||
emit(UsersLoadingState());
|
||||
currentSortOrder = "";
|
||||
@ -143,13 +142,16 @@ class UserTableBloc extends Bloc<UserTableEvent, UserTableState> {
|
||||
|
||||
void _toggleSortUsersByNameDesc(
|
||||
SortUsersByNameDesc event, Emitter<UserTableState> emit) {
|
||||
selectedRoles.clear();
|
||||
selectedJobTitles.clear();
|
||||
selectedCreatedBy.clear();
|
||||
selectedStatuses.clear();
|
||||
if (currentSortOrder == "Desc") {
|
||||
emit(UsersLoadingState());
|
||||
currentSortOrder = "";
|
||||
users = List.from(initialUsers); // Reset to saved initial state
|
||||
users = List.from(initialUsers);
|
||||
emit(UsersLoadedState(users: users));
|
||||
} else {
|
||||
// Sort descending
|
||||
emit(UsersLoadingState());
|
||||
currentSortOrder = "Desc";
|
||||
users.sort((a, b) => b.firstName!.compareTo(a.firstName!));
|
||||
@ -159,6 +161,10 @@ class UserTableBloc extends Bloc<UserTableEvent, UserTableState> {
|
||||
|
||||
void _toggleSortUsersByDateNewestToOldest(
|
||||
DateNewestToOldestEvent event, Emitter<UserTableState> emit) {
|
||||
selectedRoles.clear();
|
||||
selectedJobTitles.clear();
|
||||
selectedCreatedBy.clear();
|
||||
selectedStatuses.clear();
|
||||
if (currentSortOrderDate == "NewestToOldest") {
|
||||
emit(UsersLoadingState());
|
||||
currentSortOrder = "";
|
||||
@ -179,6 +185,10 @@ class UserTableBloc extends Bloc<UserTableEvent, UserTableState> {
|
||||
|
||||
void _toggleSortUsersByDateOldestToNewest(
|
||||
DateOldestToNewestEvent event, Emitter<UserTableState> emit) {
|
||||
selectedRoles.clear();
|
||||
selectedJobTitles.clear();
|
||||
selectedCreatedBy.clear();
|
||||
selectedStatuses.clear();
|
||||
if (currentSortOrderDate == "OldestToNewest") {
|
||||
emit(UsersLoadingState());
|
||||
currentSortOrder = "";
|
||||
@ -337,7 +347,20 @@ class UserTableBloc extends Bloc<UserTableEvent, UserTableState> {
|
||||
|
||||
final filteredUsers = initialUsers.where((user) {
|
||||
if (selectedStatuses.isEmpty) return true;
|
||||
return selectedStatuses.contains(user.status);
|
||||
|
||||
return selectedStatuses.any((status) {
|
||||
final userStatus = user.status?.toLowerCase() ?? '';
|
||||
switch (status.toLowerCase()) {
|
||||
case 'active':
|
||||
return user.isEnabled == true && userStatus != 'invited';
|
||||
case 'disabled':
|
||||
return user.isEnabled == false;
|
||||
case 'invited':
|
||||
return userStatus == 'invited';
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}).toList();
|
||||
if (event.sortOrder == "Asc") {
|
||||
currentSortOrder = "Asc";
|
||||
@ -351,9 +374,11 @@ class UserTableBloc extends Bloc<UserTableEvent, UserTableState> {
|
||||
} else {
|
||||
currentSortOrder = "";
|
||||
}
|
||||
|
||||
emit(UsersLoadedState(users: filteredUsers));
|
||||
}
|
||||
|
||||
|
||||
void _resetAllFilters(Emitter<UserTableState> emit) {
|
||||
selectedRoles.clear();
|
||||
selectedJobTitles.clear();
|
||||
|
@ -12,7 +12,7 @@ Future<void> showDateFilterMenu({
|
||||
Overlay.of(context).context.findRenderObject() as RenderBox;
|
||||
final RelativeRect position = RelativeRect.fromRect(
|
||||
Rect.fromLTRB(
|
||||
overlay.size.width / 2,
|
||||
overlay.size.width / 3,
|
||||
240,
|
||||
0,
|
||||
overlay.size.height,
|
||||
@ -40,7 +40,6 @@ Future<void> showDateFilterMenu({
|
||||
),
|
||||
title: Text(
|
||||
"Sort from newest to oldest",
|
||||
// style: context.textTheme.bodyMedium,
|
||||
style: TextStyle(
|
||||
color: isSelected == "NewestToOldest"
|
||||
? Colors.black
|
||||
@ -65,9 +64,5 @@ Future<void> showDateFilterMenu({
|
||||
),
|
||||
),
|
||||
],
|
||||
).then((value) {
|
||||
// setState(() {
|
||||
// _isDropdownOpen = false;
|
||||
// });
|
||||
});
|
||||
).then((value) {});
|
||||
}
|
||||
|
@ -40,7 +40,6 @@ Future<void> showDeActivateFilterMenu({
|
||||
),
|
||||
title: Text(
|
||||
"Sort A to Z",
|
||||
// style: context.textTheme.bodyMedium,
|
||||
style: TextStyle(
|
||||
color: isSelected == "NewestToOldest"
|
||||
? Colors.black
|
||||
@ -65,9 +64,5 @@ Future<void> showDeActivateFilterMenu({
|
||||
),
|
||||
),
|
||||
],
|
||||
).then((value) {
|
||||
// setState(() {
|
||||
// _isDropdownOpen = false;
|
||||
// });
|
||||
});
|
||||
).then((value) {});
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ Future<void> showNameMenu({
|
||||
Overlay.of(context).context.findRenderObject() as RenderBox;
|
||||
final RelativeRect position = RelativeRect.fromRect(
|
||||
Rect.fromLTRB(
|
||||
overlay.size.width / 25,
|
||||
overlay.size.width / 35,
|
||||
240,
|
||||
0,
|
||||
overlay.size.height,
|
||||
@ -40,7 +40,6 @@ Future<void> showNameMenu({
|
||||
),
|
||||
title: Text(
|
||||
"Sort A to Z",
|
||||
// style: context.textTheme.bodyMedium,
|
||||
style: TextStyle(
|
||||
color: isSelected == "Asc" ? Colors.black : Colors.blueGrey),
|
||||
),
|
||||
@ -61,9 +60,5 @@ Future<void> showNameMenu({
|
||||
),
|
||||
),
|
||||
],
|
||||
).then((value) {
|
||||
// setState(() {
|
||||
// _isDropdownOpen = false;
|
||||
// });
|
||||
});
|
||||
).then((value) {});
|
||||
}
|
||||
|
@ -1,260 +1,264 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
import 'package:syncrow_web/utils/style.dart';
|
||||
|
||||
class DynamicTableScreen extends StatefulWidget {
|
||||
final List<String> titles;
|
||||
final List<List<Widget>> rows;
|
||||
final void Function(int columnIndex)? onFilter;
|
||||
class _HeaderColumn extends StatelessWidget {
|
||||
final String title;
|
||||
final double width;
|
||||
final bool showFilter;
|
||||
final VoidCallback? onFilter;
|
||||
final Function(double) onResize;
|
||||
|
||||
DynamicTableScreen(
|
||||
{required this.titles, required this.rows, required this.onFilter});
|
||||
|
||||
@override
|
||||
_DynamicTableScreenState createState() => _DynamicTableScreenState();
|
||||
}
|
||||
|
||||
class _DynamicTableScreenState extends State<DynamicTableScreen>
|
||||
with WidgetsBindingObserver {
|
||||
late List<double> columnWidths;
|
||||
late double totalWidth;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
columnWidths = List<double>.filled(widget.titles.length, 150.0);
|
||||
totalWidth = columnWidths.reduce((a, b) => a + b);
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeMetrics() {
|
||||
super.didChangeMetrics();
|
||||
final newScreenWidth = MediaQuery.of(context).size.width;
|
||||
setState(() {
|
||||
columnWidths = List<double>.generate(widget.titles.length, (index) {
|
||||
if (index == 1) {
|
||||
return newScreenWidth *
|
||||
0.12; // 20% of screen width for the second column
|
||||
} else if (index == 9) {
|
||||
return newScreenWidth *
|
||||
0.1; // 25% of screen width for the tenth column
|
||||
}
|
||||
return newScreenWidth *
|
||||
0.09; // Default to 10% of screen width for other columns
|
||||
});
|
||||
});
|
||||
}
|
||||
const _HeaderColumn({
|
||||
required this.title,
|
||||
required this.width,
|
||||
required this.showFilter,
|
||||
required this.onResize,
|
||||
this.onFilter,
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final screenWidth = MediaQuery.of(context).size.width;
|
||||
if (columnWidths.every((width) => width == screenWidth * 7)) {
|
||||
columnWidths = List<double>.generate(widget.titles.length, (index) {
|
||||
if (index == 1) {
|
||||
return screenWidth * 0.11;
|
||||
} else if (index == 9) {
|
||||
return screenWidth * 0.1;
|
||||
}
|
||||
return screenWidth * 0.09;
|
||||
});
|
||||
setState(() {});
|
||||
}
|
||||
return SingleChildScrollView(
|
||||
clipBehavior: Clip.none,
|
||||
scrollDirection: Axis.horizontal,
|
||||
return MouseRegion(
|
||||
cursor: SystemMouseCursors.resizeColumn,
|
||||
child: GestureDetector(
|
||||
onHorizontalDragUpdate: (details) => onResize(details.delta.dx),
|
||||
child: Container(
|
||||
decoration: containerDecoration.copyWith(
|
||||
color: ColorsManager.whiteColors,
|
||||
borderRadius: const BorderRadius.all(Radius.circular(20))),
|
||||
child: FittedBox(
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
width: totalWidth,
|
||||
decoration: containerDecoration.copyWith(
|
||||
color: ColorsManager.circleRolesBackground,
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(15),
|
||||
topRight: Radius.circular(15))),
|
||||
child: Row(
|
||||
children: List.generate(widget.titles.length, (index) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
FittedBox(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.only(left: 5, right: 5),
|
||||
width: columnWidths[index],
|
||||
width: width,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
decoration: const BoxDecoration(
|
||||
border: Border(right: BorderSide(color: ColorsManager.boxDivider)),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(
|
||||
Expanded(
|
||||
child: Text(
|
||||
widget.titles[index],
|
||||
title,
|
||||
maxLines: 2,
|
||||
style: const TextStyle(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w400,
|
||||
fontSize: 13,
|
||||
color: ColorsManager.grayColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (index != 1 &&
|
||||
index != 9 &&
|
||||
index != 8 &&
|
||||
index != 5)
|
||||
FittedBox(
|
||||
child: IconButton(
|
||||
icon: SvgPicture.asset(
|
||||
Assets.filterTableIcon,
|
||||
fit: BoxFit.none,
|
||||
if (showFilter)
|
||||
IconButton(
|
||||
icon: SvgPicture.asset(Assets.filterTableIcon),
|
||||
onPressed: onFilter,
|
||||
padding: EdgeInsets.zero,
|
||||
constraints: const BoxConstraints(),
|
||||
),
|
||||
onPressed: () {
|
||||
if (widget.onFilter != null) {
|
||||
widget.onFilter!(index);
|
||||
}
|
||||
},
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onHorizontalDragUpdate: (details) {
|
||||
setState(() {
|
||||
columnWidths[index] =
|
||||
(columnWidths[index] + details.delta.dx)
|
||||
.clamp(150.0, 300.0);
|
||||
totalWidth = columnWidths.reduce((a, b) => a + b);
|
||||
});
|
||||
},
|
||||
child: MouseRegion(
|
||||
cursor: SystemMouseCursors.resizeColumn,
|
||||
child: Container(
|
||||
color: Colors.green,
|
||||
child: Container(
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _TableRow extends StatelessWidget {
|
||||
final List<Widget> cells;
|
||||
final List<double> columnWidths;
|
||||
final bool isLast;
|
||||
|
||||
const _TableRow({
|
||||
required this.cells,
|
||||
required this.columnWidths,
|
||||
required this.isLast,
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
for (int i = 0; i < cells.length; i++)
|
||||
Container(
|
||||
width: columnWidths[i],
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
// decoration: BoxDecoration(
|
||||
// border: Border(
|
||||
// right: BorderSide(color: ColorsManager.boxDivider),
|
||||
// ),
|
||||
// ),
|
||||
child: cells[i],
|
||||
),
|
||||
],
|
||||
),
|
||||
if (!isLast)
|
||||
Divider(
|
||||
height: 1,
|
||||
thickness: 1,
|
||||
color: ColorsManager.boxDivider,
|
||||
width: 1,
|
||||
height: 50,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}),
|
||||
}
|
||||
}
|
||||
//===========================================================================
|
||||
|
||||
class DynamicTableScreen extends StatefulWidget {
|
||||
final List<String> titles;
|
||||
final List<List<Widget>> rows;
|
||||
final void Function(int columnIndex)? onFilter;
|
||||
|
||||
const DynamicTableScreen({
|
||||
required this.titles,
|
||||
required this.rows,
|
||||
required this.onFilter,
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
_DynamicTableScreenState createState() => _DynamicTableScreenState();
|
||||
}
|
||||
|
||||
class _DynamicTableScreenState extends State<DynamicTableScreen> {
|
||||
late List<double> columnWidths;
|
||||
final double _minColumnWidth = 100.0;
|
||||
final double _maxColumnWidth = 300.0;
|
||||
final double _dividerWidth = 1.0;
|
||||
double _lastAvailableWidth = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
columnWidths = List.filled(widget.titles.length, _minColumnWidth);
|
||||
}
|
||||
|
||||
void _handleColumnResize(int index, double delta) {
|
||||
setState(() {
|
||||
double newWidth = columnWidths[index] + delta;
|
||||
newWidth = newWidth.clamp(_minColumnWidth, _maxColumnWidth);
|
||||
double actualDelta = newWidth - columnWidths[index];
|
||||
if (actualDelta == 0) return;
|
||||
|
||||
int nextIndex = (index + 1) % columnWidths.length;
|
||||
columnWidths[index] = newWidth;
|
||||
columnWidths[nextIndex] = (columnWidths[nextIndex] - actualDelta)
|
||||
.clamp(_minColumnWidth, _maxColumnWidth);
|
||||
});
|
||||
}
|
||||
|
||||
Widget _buildHeader() {
|
||||
return Container(
|
||||
decoration: containerDecoration.copyWith(
|
||||
color: ColorsManager.circleRolesBackground,
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(15),
|
||||
topRight: Radius.circular(15),
|
||||
),
|
||||
),
|
||||
widget.rows.isEmpty
|
||||
? SizedBox(
|
||||
height: MediaQuery.of(context).size.height / 2,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
child: Row(
|
||||
children: [
|
||||
Column(
|
||||
for (int i = 0; i < widget.titles.length; i++)
|
||||
_HeaderColumn(
|
||||
title: widget.titles[i],
|
||||
width: columnWidths[i],
|
||||
showFilter: i != 1 && i != 9 && i != 8 && i != 5,
|
||||
onFilter: () => widget.onFilter?.call(i),
|
||||
onResize: (delta) => _handleColumnResize(i, delta),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody() {
|
||||
if (widget.rows.isEmpty) {
|
||||
return SizedBox(
|
||||
height: 300,
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
SvgPicture.asset(Assets.emptyTable),
|
||||
const SizedBox(
|
||||
height: 15,
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
const Text(
|
||||
'No Users',
|
||||
style: TextStyle(
|
||||
color: ColorsManager.lightGrayColor,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w700),
|
||||
)
|
||||
],
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: Center(
|
||||
child: Container(
|
||||
width: totalWidth,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Container(
|
||||
decoration: containerDecoration.copyWith(
|
||||
color: ColorsManager.whiteColors,
|
||||
borderRadius: const BorderRadius.only(
|
||||
bottomLeft: Radius.circular(15),
|
||||
bottomRight: Radius.circular(15))),
|
||||
child: ListView.builder(
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
shrinkWrap: true,
|
||||
itemCount: widget.rows.length,
|
||||
itemBuilder: (context, rowIndex) {
|
||||
if (columnWidths.every((width) => width == 120.0)) {
|
||||
columnWidths = List<double>.generate(
|
||||
widget.titles.length, (index) {
|
||||
if (index == 1) {
|
||||
return screenWidth * 0.11;
|
||||
} else if (index == 9) {
|
||||
return screenWidth * 0.2;
|
||||
}
|
||||
return screenWidth * 0.11;
|
||||
});
|
||||
setState(() {});
|
||||
}
|
||||
final row = widget.rows[rowIndex];
|
||||
return Column(
|
||||
bottomRight: Radius.circular(15),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 5, top: 10, right: 5, bottom: 10),
|
||||
child: Row(
|
||||
children:
|
||||
List.generate(row.length, (index) {
|
||||
return SizedBox(
|
||||
width: columnWidths[index],
|
||||
child: SizedBox(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 15, right: 10),
|
||||
child: row[index],
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (rowIndex < widget.rows.length - 1)
|
||||
Row(
|
||||
children: List.generate(
|
||||
widget.titles.length, (index) {
|
||||
return SizedBox(
|
||||
width: columnWidths[index],
|
||||
child: const Divider(
|
||||
color: ColorsManager.boxDivider,
|
||||
thickness: 1,
|
||||
height: 1,
|
||||
),
|
||||
);
|
||||
}),
|
||||
for (int rowIndex = 0; rowIndex < widget.rows.length; rowIndex++)
|
||||
_TableRow(
|
||||
cells: widget.rows[rowIndex],
|
||||
columnWidths: columnWidths,
|
||||
isLast: rowIndex == widget.rows.length - 1,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final availableWidth = constraints.maxWidth;
|
||||
final totalDividersWidth = (widget.titles.length - 1) * _dividerWidth;
|
||||
|
||||
if (_lastAvailableWidth != availableWidth) {
|
||||
final equalWidth =
|
||||
(availableWidth - totalDividersWidth) / widget.titles.length;
|
||||
final clampedWidth =
|
||||
equalWidth.clamp(_minColumnWidth, _maxColumnWidth);
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
setState(() {
|
||||
columnWidths = List.filled(widget.titles.length, clampedWidth);
|
||||
_lastAvailableWidth = availableWidth;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
final totalTableWidth =
|
||||
columnWidths.fold(0.0, (sum, w) => sum + w) + totalDividersWidth;
|
||||
return SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Container(
|
||||
width: totalTableWidth,
|
||||
decoration: containerDecoration.copyWith(
|
||||
color: ColorsManager.whiteColors,
|
||||
borderRadius: const BorderRadius.all(Radius.circular(20)),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildHeader(),
|
||||
_buildBody(),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -108,7 +108,6 @@ class UsersPage extends StatelessWidget {
|
||||
final screenSize = MediaQuery.of(context).size;
|
||||
final _blocRole = BlocProvider.of<UserTableBloc>(context);
|
||||
if (state is UsersLoadingState) {
|
||||
_blocRole.add(ChangePage(_blocRole.currentPage));
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else if (state is UsersLoadedState) {
|
||||
return Padding(
|
||||
@ -215,7 +214,7 @@ class UsersPage extends StatelessWidget {
|
||||
|
||||
showPopUpFilterMenu(
|
||||
position: RelativeRect.fromLTRB(
|
||||
overlay.size.width / 4,
|
||||
overlay.size.width / 5.3,
|
||||
240,
|
||||
overlay.size.width / 4,
|
||||
0,
|
||||
@ -225,6 +224,7 @@ class UsersPage extends StatelessWidget {
|
||||
checkboxStates: checkboxStates,
|
||||
isSelected: _blocRole.currentSortOrder,
|
||||
onOkPressed: () {
|
||||
searchController.clear();
|
||||
_blocRole.add(FilterClearEvent());
|
||||
final selectedItems = checkboxStates.entries
|
||||
.where((entry) => entry.value)
|
||||
@ -265,6 +265,7 @@ class UsersPage extends StatelessWidget {
|
||||
checkboxStates: checkboxStates,
|
||||
isSelected: _blocRole.currentSortOrder,
|
||||
onOkPressed: () {
|
||||
searchController.clear();
|
||||
_blocRole.add(FilterClearEvent());
|
||||
final selectedItems = checkboxStates.entries
|
||||
.where((entry) => entry.value)
|
||||
@ -320,6 +321,7 @@ class UsersPage extends StatelessWidget {
|
||||
checkboxStates: checkboxStates,
|
||||
isSelected: _blocRole.currentSortOrder,
|
||||
onOkPressed: () {
|
||||
searchController.clear();
|
||||
_blocRole.add(FilterClearEvent());
|
||||
final selectedItems = checkboxStates.entries
|
||||
.where((entry) => entry.value)
|
||||
@ -343,6 +345,7 @@ class UsersPage extends StatelessWidget {
|
||||
for (var item in _blocRole.status)
|
||||
item: _blocRole.selectedStatuses.contains(item),
|
||||
};
|
||||
|
||||
final RenderBox overlay = Overlay.of(context)
|
||||
.context
|
||||
.findRenderObject() as RenderBox;
|
||||
@ -350,7 +353,7 @@ class UsersPage extends StatelessWidget {
|
||||
position: RelativeRect.fromLTRB(
|
||||
overlay.size.width / 0,
|
||||
240,
|
||||
overlay.size.width / 4,
|
||||
overlay.size.width / 5,
|
||||
0,
|
||||
),
|
||||
list: _blocRole.status,
|
||||
@ -358,8 +361,8 @@ class UsersPage extends StatelessWidget {
|
||||
checkboxStates: checkboxStates,
|
||||
isSelected: _blocRole.currentSortOrder,
|
||||
onOkPressed: () {
|
||||
searchController.clear();
|
||||
_blocRole.add(FilterClearEvent());
|
||||
|
||||
final selectedItems = checkboxStates.entries
|
||||
.where((entry) => entry.value)
|
||||
.map((entry) => entry.key)
|
||||
@ -410,7 +413,7 @@ class UsersPage extends StatelessWidget {
|
||||
return [
|
||||
Text('${user.firstName} ${user.lastName}'),
|
||||
Text(user.email),
|
||||
Text(user.jobTitle ?? '-'),
|
||||
Text(user.jobTitle),
|
||||
Text(user.roleType ?? ''),
|
||||
Text(user.createdDate ?? ''),
|
||||
Text(user.createdTime ?? ''),
|
||||
@ -427,11 +430,6 @@ class UsersPage extends StatelessWidget {
|
||||
userId: user.uuid,
|
||||
onTap: user.status != "invited"
|
||||
? () {
|
||||
// final newStatus = user.status == 'active'
|
||||
// ? 'disabled'
|
||||
// : user.status == 'disabled'
|
||||
// ? 'invited'
|
||||
// : 'active';
|
||||
context.read<UserTableBloc>().add(
|
||||
ChangeUserStatus(
|
||||
userId: user.uuid,
|
||||
@ -443,10 +441,6 @@ class UsersPage extends StatelessWidget {
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
// actionButton(
|
||||
// title: "Activity Log",
|
||||
// onTap: () {},
|
||||
// ),
|
||||
actionButton(
|
||||
title: "Edit",
|
||||
onTap: () {
|
||||
@ -486,11 +480,9 @@ class UsersPage extends StatelessWidget {
|
||||
});
|
||||
},
|
||||
).then((v) {
|
||||
if (v != null) {
|
||||
if (v != null) {
|
||||
_blocRole.add(const GetUsers());
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
|
@ -18,8 +18,7 @@ class UserPermissionApi {
|
||||
showServerMessage: true,
|
||||
expectedResponseModel: (json) {
|
||||
debugPrint('fetchUsers Response: $json');
|
||||
final List<dynamic> data =
|
||||
json['data'] ?? []; // Default to an empty list if no data
|
||||
final List<dynamic> data = json['data'] ?? [];
|
||||
return data.map((item) => RolesUserModel.fromJson(item)).toList();
|
||||
},
|
||||
);
|
||||
@ -119,7 +118,7 @@ class UserPermissionApi {
|
||||
);
|
||||
return response ?? 'Unknown error occurred';
|
||||
} on DioException catch (e) {
|
||||
final errorMessage = e.response?.data['error'];
|
||||
final errorMessage = e.response?.data['error']['message'];
|
||||
return errorMessage;
|
||||
} catch (e) {
|
||||
return e.toString();
|
||||
@ -205,7 +204,6 @@ class UserPermissionApi {
|
||||
.replaceAll("{invitedUserUuid}", userUuid),
|
||||
body: bodya,
|
||||
expectedResponseModel: (json) {
|
||||
print('changeUserStatusById==${json['success']}');
|
||||
return json['success'];
|
||||
},
|
||||
);
|
||||
@ -213,7 +211,6 @@ class UserPermissionApi {
|
||||
return response;
|
||||
} catch (e) {
|
||||
return false;
|
||||
print(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user