Vaibhav_Enhancement-#419 #35

Merged
vikas.nale merged 4 commits from Vaibhav_Enhancement-#419 into main 2025-06-02 07:52:53 +00:00
5 changed files with 475 additions and 427 deletions

View File

@ -6,51 +6,65 @@ import 'package:marco/helpers/widgets/my_form_validator.dart';
import 'package:marco/helpers/widgets/my_validators.dart'; import 'package:marco/helpers/widgets/my_validators.dart';
class LoginController extends MyController { class LoginController extends MyController {
MyFormValidator basicValidator = MyFormValidator(); // Form validator
final MyFormValidator basicValidator = MyFormValidator();
bool showPassword = false, isChecked = false; // UI states
RxBool isLoading = false.obs; // Add reactive loading state final RxBool isLoading = false.obs;
final RxBool showPassword = false.obs;
final RxBool isChecked = false.obs;
// Dummy credentials
final String _dummyEmail = "admin@marcoaiot.com"; final String _dummyEmail = "admin@marcoaiot.com";
final String _dummyPassword = "User@123"; final String _dummyPassword = "User@123";
@override @override
void onInit() { void onInit() {
basicValidator.addField('username', required: true, label: "User_Name", validators: [MyEmailValidator()], controller: TextEditingController(text: _dummyEmail));
basicValidator.addField('password', required: true, label: "Password", validators: [MyLengthValidator(min: 6, max: 10)], controller: TextEditingController(text: _dummyPassword));
super.onInit(); super.onInit();
basicValidator.addField(
'username',
required: true,
label: "User_Name",
validators: [MyEmailValidator()],
controller: TextEditingController(text: _dummyEmail),
);
basicValidator.addField(
'password',
required: true,
label: "Password",
validators: [MyLengthValidator(min: 6, max: 10)],
controller: TextEditingController(text: _dummyPassword),
);
} }
void onChangeCheckBox(bool? value) { void onChangeCheckBox(bool? value) {
isChecked = value ?? isChecked; isChecked.value = value ?? isChecked.value;
update();
} }
void onChangeShowPassword() { void onChangeShowPassword() {
showPassword = !showPassword; showPassword.toggle();
update();
} }
Future<void> onLogin() async { Future<void> onLogin() async {
if (basicValidator.validateForm()) { if (!basicValidator.validateForm()) return;
// Set loading to true
isLoading.value = true; isLoading.value = true;
update();
final errors = await AuthService.loginUser(basicValidator.getData());
var errors = await AuthService.loginUser(basicValidator.getData());
if (errors != null) { if (errors != null) {
basicValidator.addErrors(errors); basicValidator.addErrors(errors);
basicValidator.validateForm(); basicValidator.validateForm();
basicValidator.clearErrors(); basicValidator.clearErrors();
} else { } else {
String nextUrl = Uri.parse(ModalRoute.of(Get.context!)?.settings.name ?? "").queryParameters['next'] ?? "/home"; final currentRoute = ModalRoute.of(Get.context!)?.settings.name ?? "";
final nextUrl = Uri.parse(currentRoute).queryParameters['next'] ?? "/home";
Get.toNamed(nextUrl); Get.toNamed(nextUrl);
} }
// Set loading to false after the API call is complete
isLoading.value = false; isLoading.value = false;
update();
}
} }
void goToForgotPassword() { void goToForgotPassword() {

View File

@ -5,7 +5,7 @@ import 'package:intl/intl.dart';
import 'package:marco/helpers/widgets/my_text.dart'; import 'package:marco/helpers/widgets/my_text.dart';
import 'package:marco/helpers/utils/permission_constants.dart'; import 'package:marco/helpers/utils/permission_constants.dart';
class AttendanceFilterBottomSheet extends StatelessWidget { class AttendanceFilterBottomSheet extends StatefulWidget {
final AttendanceController controller; final AttendanceController controller;
final PermissionController permissionController; final PermissionController permissionController;
final String selectedTab; final String selectedTab;
@ -17,56 +17,53 @@ class AttendanceFilterBottomSheet extends StatelessWidget {
required this.selectedTab, required this.selectedTab,
}); });
@override
_AttendanceFilterBottomSheetState createState() =>
_AttendanceFilterBottomSheetState();
}
class _AttendanceFilterBottomSheetState
extends State<AttendanceFilterBottomSheet> {
late String? tempSelectedProjectId;
late String tempSelectedTab;
bool showProjectList = false;
@override
void initState() {
super.initState();
tempSelectedProjectId = widget.controller.selectedProjectId;
tempSelectedTab = widget.selectedTab;
}
String getLabelText() { String getLabelText() {
final startDate = controller.startDateAttendance; final startDate = widget.controller.startDateAttendance;
final endDate = controller.endDateAttendance; final endDate = widget.controller.endDateAttendance;
if (startDate != null && endDate != null) { if (startDate != null && endDate != null) {
final start = DateFormat('dd MM yyyy').format(startDate); final start = DateFormat('dd/MM/yyyy').format(startDate);
final end = DateFormat('dd MM yyyy').format(endDate); final end = DateFormat('dd/MM/yyyy').format(endDate);
return "$start - $end"; return "$start - $end";
} }
return "Date Range"; return "Date Range";
} }
@override List<Widget> buildProjectList() {
Widget build(BuildContext context) { final accessibleProjects = widget.controller.projects
String? tempSelectedProjectId = controller.selectedProjectId;
String tempSelectedTab = selectedTab;
bool showProjectList = false;
final accessibleProjects = controller.projects
.where((project) => .where((project) =>
permissionController.isUserAssignedToProject(project.id.toString())) widget.permissionController.isUserAssignedToProject(
project.id.toString()))
.toList(); .toList();
bool hasRegularizationPermission = if (accessibleProjects.isEmpty) {
permissionController.hasPermission(Permissions.regularizeAttendance); return [
final viewOptions = [
{'label': 'Today\'s Attendance', 'value': 'todaysAttendance'},
{'label': 'Attendance Logs', 'value': 'attendanceLogs'},
{'label': 'Regularization Requests', 'value': 'regularizationRequests'},
];
final filteredViewOptions = viewOptions.where((item) {
if (item['value'] == 'regularizationRequests') {
return hasRegularizationPermission;
}
return true;
}).toList();
return StatefulBuilder(builder: (context, setState) {
List<Widget> filterWidgets;
if (showProjectList) {
filterWidgets = accessibleProjects.isEmpty
? [
const Padding( const Padding(
padding: EdgeInsets.all(12.0), padding: EdgeInsets.all(12.0),
child: Center(child: Text('No Projects Assigned')), child: Center(child: Text('No Projects Assigned')),
), ),
] ];
: accessibleProjects.map((project) { }
final isSelected =
tempSelectedProjectId == project.id.toString(); return accessibleProjects.map((project) {
final isSelected = tempSelectedProjectId == project.id.toString();
return ListTile( return ListTile(
dense: true, dense: true,
contentPadding: const EdgeInsets.symmetric(horizontal: 16), contentPadding: const EdgeInsets.symmetric(horizontal: 16),
@ -80,7 +77,15 @@ class AttendanceFilterBottomSheet extends StatelessWidget {
}, },
); );
}).toList(); }).toList();
} else { }
List<Widget> buildMainFilters() {
final accessibleProjects = widget.controller.projects
.where((project) =>
widget.permissionController.isUserAssignedToProject(
project.id.toString()))
.toList();
final selectedProject = accessibleProjects.isNotEmpty final selectedProject = accessibleProjects.isNotEmpty
? accessibleProjects.firstWhere( ? accessibleProjects.firstWhere(
(p) => p.id.toString() == tempSelectedProjectId, (p) => p.id.toString() == tempSelectedProjectId,
@ -90,7 +95,23 @@ class AttendanceFilterBottomSheet extends StatelessWidget {
final selectedProjectName = selectedProject?.name ?? "Select Project"; final selectedProjectName = selectedProject?.name ?? "Select Project";
filterWidgets = [ final hasRegularizationPermission = widget.permissionController
.hasPermission(Permissions.regularizeAttendance);
final viewOptions = [
{'label': 'Today\'s Attendance', 'value': 'todaysAttendance'},
{'label': 'Attendance Logs', 'value': 'attendanceLogs'},
{'label': 'Regularization Requests', 'value': 'regularizationRequests'},
];
final filteredViewOptions = viewOptions.where((item) {
if (item['value'] == 'regularizationRequests') {
return hasRegularizationPermission;
}
return true;
}).toList();
List<Widget> widgets = [
Padding( Padding(
padding: const EdgeInsets.fromLTRB(16, 12, 16, 4), padding: const EdgeInsets.fromLTRB(16, 12, 16, 4),
child: Align( child: Align(
@ -132,7 +153,7 @@ class AttendanceFilterBottomSheet extends StatelessWidget {
]; ];
if (tempSelectedTab == 'attendanceLogs') { if (tempSelectedTab == 'attendanceLogs') {
filterWidgets.addAll([ widgets.addAll([
const Divider(), const Divider(),
Padding( Padding(
padding: const EdgeInsets.fromLTRB(16, 12, 16, 4), padding: const EdgeInsets.fromLTRB(16, 12, 16, 4),
@ -148,13 +169,13 @@ class AttendanceFilterBottomSheet extends StatelessWidget {
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: InkWell( child: InkWell(
borderRadius: BorderRadius.circular(10), borderRadius: BorderRadius.circular(10),
onTap: () => controller.selectDateRangeForAttendance( onTap: () => widget.controller.selectDateRangeForAttendance(
context, context,
controller, widget.controller,
), ),
child: Ink( child: Ink(
decoration: BoxDecoration( decoration: BoxDecoration(
color: const Color.fromARGB(255, 255, 255, 255), color: Colors.white,
border: Border.all(color: Colors.grey.shade400), border: Border.all(color: Colors.grey.shade400),
borderRadius: BorderRadius.circular(10), borderRadius: BorderRadius.circular(10),
), ),
@ -162,8 +183,7 @@ class AttendanceFilterBottomSheet extends StatelessWidget {
const EdgeInsets.symmetric(horizontal: 16, vertical: 14), const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
child: Row( child: Row(
children: [ children: [
Icon(Icons.date_range, Icon(Icons.date_range, color: Colors.black87),
color: const Color.fromARGB(255, 9, 9, 9)),
const SizedBox(width: 12), const SizedBox(width: 12),
Expanded( Expanded(
child: Text( child: Text(
@ -176,8 +196,7 @@ class AttendanceFilterBottomSheet extends StatelessWidget {
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
), ),
), ),
const Icon(Icons.arrow_drop_down, const Icon(Icons.arrow_drop_down, color: Colors.black87),
color: Color.fromARGB(255, 0, 0, 0)),
], ],
), ),
), ),
@ -185,16 +204,19 @@ class AttendanceFilterBottomSheet extends StatelessWidget {
), ),
]); ]);
} }
return widgets;
} }
@override
Widget build(BuildContext context) {
return Padding( return Padding(
padding: EdgeInsets.only( padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
bottom: MediaQuery.of(context).viewInsets.bottom,
),
child: SingleChildScrollView( child: SingleChildScrollView(
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
// Drag handle
Padding( Padding(
padding: const EdgeInsets.only(top: 12, bottom: 8), padding: const EdgeInsets.only(top: 12, bottom: 8),
child: Center( child: Center(
@ -208,11 +230,10 @@ class AttendanceFilterBottomSheet extends StatelessWidget {
), ),
), ),
), ),
...filterWidgets, if (showProjectList) ...buildProjectList() else ...buildMainFilters(),
const Divider(), const Divider(),
Padding( Padding(
padding: padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
child: SizedBox( child: SizedBox(
width: double.infinity, width: double.infinity,
child: ElevatedButton( child: ElevatedButton(
@ -237,6 +258,5 @@ class AttendanceFilterBottomSheet extends StatelessWidget {
), ),
), ),
); );
});
} }
} }

View File

@ -20,11 +20,11 @@ class LoginScreen extends StatefulWidget {
} }
class _LoginScreenState extends State<LoginScreen> with UIMixin { class _LoginScreenState extends State<LoginScreen> with UIMixin {
late LoginController controller; late final LoginController controller;
@override @override
void initState() { void initState() {
controller = Get.put(LoginController()); controller = Get.put(LoginController(), tag: 'login_controller');
super.initState(); super.initState();
} }
@ -32,13 +32,14 @@ class _LoginScreenState extends State<LoginScreen> with UIMixin {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return AuthLayout( return AuthLayout(
child: GetBuilder<LoginController>( child: GetBuilder<LoginController>(
init: controller,
tag: 'login_controller', tag: 'login_controller',
builder: (controller) { builder: (_) {
return Obx(() { return Obx(() {
return controller.isLoading.value if (controller.isLoading.value) {
? Center(child: CircularProgressIndicator()) // Show loading spinner when isLoading is true return const Center(child: CircularProgressIndicator());
: Form( }
return Form(
key: controller.basicValidator.formKey, key: controller.basicValidator.formKey,
child: SingleChildScrollView( child: SingleChildScrollView(
padding: MySpacing.xy(2, 40), padding: MySpacing.xy(2, 40),
@ -65,104 +66,74 @@ class _LoginScreenState extends State<LoginScreen> with UIMixin {
), ),
MySpacing.height(20), MySpacing.height(20),
/// Welcome Text /// Welcome
Center( Center(child: MyText.bodyLarge("Welcome Back!", fontWeight: 600)),
child: MyText.bodyLarge("Welcome Back!", fontWeight: 600),
),
MySpacing.height(4), MySpacing.height(4),
Center( Center(child: MyText.bodySmall("Please sign in to continue.")),
child: MyText.bodySmall("Please sign in to continue."),
),
MySpacing.height(20), MySpacing.height(20),
/// Email Field /// Email
MyText.bodySmall("Email Address", fontWeight: 600), MyText.bodySmall("Email Address", fontWeight: 600),
MySpacing.height(8), MySpacing.height(8),
Material( _buildInputField(
elevation: 2, controller.basicValidator.getController('username')!,
shadowColor: contentTheme.secondary.withAlpha(30),
borderRadius: BorderRadius.circular(12),
child: TextFormField(
validator:
controller.basicValidator.getValidation('username'), controller.basicValidator.getValidation('username'),
controller:
controller.basicValidator.getController('username'),
keyboardType: TextInputType.emailAddress,
style: MyTextStyle.labelMedium(),
decoration: InputDecoration(
hintText: "Enter your email", hintText: "Enter your email",
hintStyle: MyTextStyle.bodySmall(xMuted: true), icon: LucideIcons.mail,
filled: true, keyboardType: TextInputType.emailAddress,
fillColor: theme.cardColor,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(2),
borderSide: BorderSide.none,
),
prefixIcon: const Icon(LucideIcons.mail, size: 18),
contentPadding: MySpacing.xy(12, 16),
),
),
), ),
MySpacing.height(16), MySpacing.height(16),
/// Password Field Label /// Password
MyText.bodySmall("Password", fontWeight: 600), MyText.bodySmall("Password", fontWeight: 600),
MySpacing.height(8), MySpacing.height(8),
Material( Obx(() {
elevation: 2, return _buildInputField(
shadowColor: contentTheme.secondary.withAlpha(25), controller.basicValidator.getController('password')!,
borderRadius: BorderRadius.circular(12),
child: TextFormField(
validator:
controller.basicValidator.getValidation('password'), controller.basicValidator.getValidation('password'),
controller:
controller.basicValidator.getController('password'),
keyboardType: TextInputType.visiblePassword,
obscureText: !controller.showPassword,
style: MyTextStyle.labelMedium(),
decoration: InputDecoration(
hintText: "Enter your password", hintText: "Enter your password",
hintStyle: MyTextStyle.bodySmall(xMuted: true), icon: LucideIcons.lock,
filled: true, obscureText: !controller.showPassword.value,
fillColor: theme.cardColor, suffix: IconButton(
border: OutlineInputBorder( icon: Icon(
borderRadius: BorderRadius.circular(2), controller.showPassword.value
borderSide: BorderSide.none,
),
prefixIcon: const Icon(LucideIcons.lock, size: 18),
suffixIcon: InkWell(
onTap: controller.onChangeShowPassword,
child: Icon(
controller.showPassword
? LucideIcons.eye ? LucideIcons.eye
: LucideIcons.eye_off, : LucideIcons.eye_off,
size: 18, size: 18,
), ),
onPressed: controller.onChangeShowPassword,
), ),
contentPadding: MySpacing.all(3), );
), }),
),
),
MySpacing.height(16), MySpacing.height(16),
/// Remember Me + Forgot Password /// Remember me + Forgot password
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
InkWell( Obx(() {
onTap: () => controller return InkWell(
.onChangeCheckBox(!controller.isChecked), onTap: () =>
controller.onChangeCheckBox(!controller.isChecked.value),
child: Row( child: Row(
children: [ children: [
Checkbox( Checkbox(
value: controller.isChecked.value,
onChanged: controller.onChangeCheckBox, onChanged: controller.onChangeCheckBox,
value: controller.isChecked,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4), borderRadius: BorderRadius.circular(4),
), ),
fillColor: WidgetStatePropertyAll( fillColor: MaterialStateProperty
contentTheme.secondary), .resolveWith<Color>(
(Set<WidgetState> states) {
if (states
.contains(WidgetState.selected)) {
return Colors.blueAccent;
}
return Colors
.white;
},
),
checkColor: contentTheme.onPrimary, checkColor: contentTheme.onPrimary,
visualDensity: getCompactDensity, visualDensity: getCompactDensity,
materialTapTargetSize: materialTapTargetSize:
@ -172,7 +143,8 @@ class _LoginScreenState extends State<LoginScreen> with UIMixin {
MyText.bodySmall("Remember Me"), MyText.bodySmall("Remember Me"),
], ],
), ),
), );
}),
MyButton.text( MyButton.text(
onPressed: controller.goToForgotPassword, onPressed: controller.goToForgotPassword,
elevation: 0, elevation: 0,
@ -188,7 +160,7 @@ class _LoginScreenState extends State<LoginScreen> with UIMixin {
), ),
MySpacing.height(28), MySpacing.height(28),
/// Login Button /// Login button
Center( Center(
child: MyButton.rounded( child: MyButton.rounded(
onPressed: controller.onLogin, onPressed: controller.onLogin,
@ -205,7 +177,7 @@ class _LoginScreenState extends State<LoginScreen> with UIMixin {
), ),
MySpacing.height(16), MySpacing.height(16),
/// Register Link /// Request demo
Center( Center(
child: MyButton.text( child: MyButton.text(
onPressed: () { onPressed: () {
@ -213,8 +185,7 @@ class _LoginScreenState extends State<LoginScreen> with UIMixin {
}, },
elevation: 0, elevation: 0,
padding: MySpacing.xy(12, 8), padding: MySpacing.xy(12, 8),
splashColor: splashColor: contentTheme.secondary.withAlpha(30),
contentTheme.secondary.withAlpha(30),
child: MyText.bodySmall( child: MyText.bodySmall(
"Request a Demo", "Request a Demo",
color: contentTheme.secondary, color: contentTheme.secondary,
@ -232,4 +203,40 @@ class _LoginScreenState extends State<LoginScreen> with UIMixin {
), ),
); );
} }
Widget _buildInputField(
TextEditingController controller,
FormFieldValidator<String>? validator, {
required String hintText,
required IconData icon,
TextInputType keyboardType = TextInputType.text,
bool obscureText = false,
Widget? suffix,
}) {
return Material(
elevation: 2,
shadowColor: contentTheme.secondary.withAlpha(30),
borderRadius: BorderRadius.circular(12),
child: TextFormField(
controller: controller,
validator: validator,
obscureText: obscureText,
keyboardType: keyboardType,
style: MyTextStyle.labelMedium(),
decoration: InputDecoration(
hintText: hintText,
hintStyle: MyTextStyle.bodySmall(xMuted: true),
filled: true,
fillColor: theme.cardColor,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(2),
borderSide: BorderSide.none,
),
prefixIcon: Icon(icon, size: 18),
suffixIcon: suffix,
contentPadding: MySpacing.xy(12, 16),
),
),
);
}
} }

View File

@ -147,22 +147,29 @@ class _OrganizationFormState extends State<_OrganizationForm> {
'Please select industry', 'Please select industry',
), ),
const SizedBox(height: 10), const SizedBox(height: 10),
Row( GestureDetector(
onTap: () => setState(() => _agreed = !_agreed),
child: Row(
children: [ children: [
Checkbox( Checkbox(
value: _agreed, value: _agreed,
onChanged: (val) => setState(() => _agreed = val ?? false), onChanged: (val) => setState(() => _agreed = val ?? false),
fillColor: MaterialStateProperty.all(Colors.white), fillColor: MaterialStateProperty.resolveWith((states) {
if (states.contains(MaterialState.selected)) {
return Colors.blueAccent;
}
return Colors.white;
}),
checkColor: Colors.white, checkColor: Colors.white,
side: MaterialStateBorderSide.resolveWith( side: const BorderSide(color: Colors.blueAccent, width: 2),
(states) =>
BorderSide(color: Colors.blueAccent, width: 2),
),
), ),
const Expanded( const Expanded(
child: Text('I agree to privacy policy & terms')), child: Text('I agree to privacy policy & terms'),
),
], ],
), ),
),
const SizedBox(height: 10), const SizedBox(height: 10),
ElevatedButton( ElevatedButton(
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(

View File

@ -255,12 +255,12 @@ class Layout extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
MyButton( MyButton(
onPressed: () => {}, onPressed:null,
tapTargetSize: MaterialTapTargetSize.shrinkWrap, tapTargetSize: MaterialTapTargetSize.shrinkWrap,
borderRadiusAll: AppStyle.buttonRadius.medium, borderRadiusAll: AppStyle.buttonRadius.medium,
padding: MySpacing.xy(8, 4), padding: MySpacing.xy(8, 4),
splashColor: contentTheme.onBackground.withAlpha(20), splashColor: contentTheme.onBackground.withAlpha(20),
backgroundColor: Colors.transparent, backgroundColor: const Color.fromARGB(0, 220, 218, 218),
child: Row( child: Row(
children: [ children: [
Icon( Icon(
@ -279,11 +279,11 @@ class Layout extends StatelessWidget {
MySpacing.height(4), MySpacing.height(4),
MyButton( MyButton(
tapTargetSize: MaterialTapTargetSize.shrinkWrap, tapTargetSize: MaterialTapTargetSize.shrinkWrap,
onPressed: () => {}, onPressed:null,
borderRadiusAll: AppStyle.buttonRadius.medium, borderRadiusAll: AppStyle.buttonRadius.medium,
padding: MySpacing.xy(8, 4), padding: MySpacing.xy(8, 4),
splashColor: contentTheme.onBackground.withAlpha(20), splashColor: contentTheme.onBackground.withAlpha(20),
backgroundColor: Colors.transparent, backgroundColor: const Color.fromARGB(0, 220, 218, 218),
child: Row( child: Row(
children: [ children: [
Icon( Icon(