Base URL change - 2026-04-21
This commit is contained in:
1 parent
7d25e77138
commit
a27aaf5cdf
13 files changed
+465
-15
No files matched your search
@@ -0,0 +1,378 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:taxglide/consts/app_asstes.dart';
|
||||
import 'package:taxglide/consts/app_colors.dart';
|
||||
import 'package:taxglide/consts/comman_button.dart';
|
||||
import 'package:taxglide/consts/comman_container_auth.dart';
|
||||
import 'package:taxglide/consts/responsive_helper.dart';
|
||||
import 'package:taxglide/consts/validation_popup.dart';
|
||||
import 'package:taxglide/controller/api_contoller.dart';
|
||||
import 'package:taxglide/view/Main_controller/main_controller.dart';
|
||||
import 'package:taxglide/consts/app_style.dart';
|
||||
|
||||
class ChangePinScreen extends ConsumerStatefulWidget {
|
||||
const ChangePinScreen({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<ChangePinScreen> createState() => _ChangePinScreenState();
|
||||
}
|
||||
|
||||
class _ChangePinScreenState extends ConsumerState<ChangePinScreen> {
|
||||
final ValidationPopup _validationPopup = ValidationPopup();
|
||||
final int pinLength = 4;
|
||||
final List<TextEditingController> _controllers = [];
|
||||
final List<FocusNode> _focusNodes = [];
|
||||
String pinValue = '';
|
||||
|
||||
final List<TextEditingController> _confirmControllers = [];
|
||||
final List<FocusNode> _confirmFocusNodes = [];
|
||||
String confirmPinValue = '';
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_initControllers();
|
||||
}
|
||||
|
||||
void _initControllers() {
|
||||
for (var c in _controllers) c.dispose();
|
||||
for (var f in _focusNodes) f.dispose();
|
||||
for (var c in _confirmControllers) c.dispose();
|
||||
for (var f in _confirmFocusNodes) f.dispose();
|
||||
|
||||
_controllers.clear();
|
||||
_focusNodes.clear();
|
||||
_confirmControllers.clear();
|
||||
_confirmFocusNodes.clear();
|
||||
|
||||
pinValue = '';
|
||||
confirmPinValue = '';
|
||||
|
||||
for (int i = 0; i < pinLength; i++) {
|
||||
_controllers.add(TextEditingController());
|
||||
_focusNodes.add(FocusNode());
|
||||
_confirmControllers.add(TextEditingController());
|
||||
_confirmFocusNodes.add(FocusNode());
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
for (var c in _controllers) c.dispose();
|
||||
for (var f in _focusNodes) f.dispose();
|
||||
for (var c in _confirmControllers) c.dispose();
|
||||
for (var f in _confirmFocusNodes) f.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _handleAction() async {
|
||||
if (pinValue.length != pinLength) {
|
||||
_validationPopup.showErrorMessage(context, "Please enter all 4 digits");
|
||||
return;
|
||||
}
|
||||
|
||||
if (confirmPinValue.length != pinLength) {
|
||||
_validationPopup.showErrorMessage(context, "Please confirm your PIN");
|
||||
return;
|
||||
}
|
||||
|
||||
if (pinValue != confirmPinValue) {
|
||||
_validationPopup.showErrorMessage(context, "PINs do not match");
|
||||
return;
|
||||
}
|
||||
|
||||
// Call API to set/change PIN
|
||||
await ref.read(changePinProvider.notifier).changePin(pinValue);
|
||||
final state = ref.read(changePinProvider);
|
||||
|
||||
state.when(
|
||||
data: (result) {
|
||||
if (result['success'] == true) {
|
||||
_validationPopup.showSuccessMessage(
|
||||
context,
|
||||
"MPIN Set Successfully!",
|
||||
);
|
||||
Future.delayed(const Duration(seconds: 1), () {
|
||||
Navigator.of(context).pop();
|
||||
});
|
||||
} else {
|
||||
_validationPopup.showErrorMessage(
|
||||
context,
|
||||
result['error'] ?? "Failed to set MPIN. Please try again.",
|
||||
);
|
||||
}
|
||||
},
|
||||
loading: () {},
|
||||
error: (error, stack) {
|
||||
_validationPopup.showErrorMessage(
|
||||
context,
|
||||
"Failed to set MPIN. Please try again.",
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _onPinChange(int index, String value) {
|
||||
if (value.isNotEmpty && index < pinLength - 1) {
|
||||
_focusNodes[index + 1].requestFocus();
|
||||
}
|
||||
if (value.isEmpty && index > 0) {
|
||||
_focusNodes[index - 1].requestFocus();
|
||||
}
|
||||
setState(() {
|
||||
pinValue = _controllers.map((c) => c.text).join();
|
||||
});
|
||||
}
|
||||
|
||||
void _onConfirmPinChange(int index, String value) {
|
||||
if (value.isNotEmpty && index < pinLength - 1) {
|
||||
_confirmFocusNodes[index + 1].requestFocus();
|
||||
}
|
||||
if (value.isEmpty && index > 0) {
|
||||
_confirmFocusNodes[index - 1].requestFocus();
|
||||
}
|
||||
setState(() {
|
||||
confirmPinValue = _confirmControllers.map((c) => c.text).join();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final pinState = ref.watch(changePinProvider);
|
||||
final isLoading = pinState is AsyncLoading;
|
||||
|
||||
final r = ResponsiveUtils(context);
|
||||
|
||||
final logoWidth = r.getValue<double>(mobile: 120, tablet: 141, desktop: 160);
|
||||
final logoHeight = r.getValue<double>(mobile: 85, tablet: 100, desktop: 115);
|
||||
final titleFontSize = r.fontSize(mobile: 26, tablet: 32, desktop: 36);
|
||||
final subtitleFontSize = r.fontSize(mobile: 13, tablet: 14, desktop: 15);
|
||||
|
||||
final boxWidth = r.getValue<double>(mobile: 57, tablet: 60, desktop: 68);
|
||||
final boxHeight = r.getValue<double>(mobile: 57, tablet: 56, desktop: 64);
|
||||
final pinFontSize = r.fontSize(mobile: 22, tablet: 28, desktop: 32);
|
||||
final boxMargin = r.getValue<double>(mobile: 5, tablet: 6, desktop: 8);
|
||||
final boxRadius = r.getValue<double>(mobile: 5, tablet: 6, desktop: 8);
|
||||
|
||||
final spacingSM = r.spacing(mobile: 20, tablet: 20, desktop: 24);
|
||||
final spacingLG = r.spacing(mobile: 50, tablet: 50, desktop: 50);
|
||||
|
||||
return Scaffold(
|
||||
body: Stack(
|
||||
children: [
|
||||
Container(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
Color(0xFFFFF8F0),
|
||||
Color(0xFFEBC894),
|
||||
Color(0xFFE8DAF2),
|
||||
Color(0xFFB49EF4),
|
||||
],
|
||||
stops: [0.0, 0.3, 0.6, 1.0],
|
||||
),
|
||||
),
|
||||
),
|
||||
SingleChildScrollView(
|
||||
child: SizedBox(
|
||||
height: r.screenHeight,
|
||||
child: Center(
|
||||
child: CommonContainerAuth(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Image.asset(
|
||||
AppAssets.taxgildelogoauth,
|
||||
width: logoWidth,
|
||||
height: logoHeight,
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
SizedBox(height: spacingSM),
|
||||
Text(
|
||||
"Change Your PIN",
|
||||
textAlign: TextAlign.center,
|
||||
style: AppTextStyles.semiBold.copyWith(
|
||||
fontSize: titleFontSize,
|
||||
color: AppColors.authheading,
|
||||
),
|
||||
),
|
||||
SizedBox(height: spacingSM),
|
||||
Text(
|
||||
"Set a 4-digit security PIN for your account",
|
||||
textAlign: TextAlign.center,
|
||||
style: AppTextStyles.semiBold.copyWith(
|
||||
fontSize: subtitleFontSize,
|
||||
color: AppColors.authleading,
|
||||
),
|
||||
),
|
||||
SizedBox(height: spacingLG),
|
||||
Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: boxMargin * 2),
|
||||
child: Text(
|
||||
"Enter PIN *",
|
||||
style: AppTextStyles.medium.copyWith(
|
||||
fontSize: subtitleFontSize,
|
||||
color: AppColors.authheading,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: List.generate(pinLength, (index) {
|
||||
bool isFilled = _controllers[index].text.isNotEmpty;
|
||||
return Container(
|
||||
margin: EdgeInsets.symmetric(horizontal: boxMargin),
|
||||
width: boxWidth,
|
||||
height: boxHeight,
|
||||
decoration: BoxDecoration(
|
||||
color: isFilled ? AppColors.commanbutton : Colors.white,
|
||||
borderRadius: BorderRadius.circular(boxRadius),
|
||||
border: Border.all(color: const Color(0xFFDFDFDF)),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: const Color(0xFFBDBDBD).withOpacity(0.25),
|
||||
blurRadius: 7,
|
||||
offset: const Offset(0, 1),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Center(
|
||||
child: KeyboardListener(
|
||||
focusNode: FocusNode(),
|
||||
onKeyEvent: (event) {
|
||||
if (event is KeyDownEvent &&
|
||||
event.logicalKey ==
|
||||
LogicalKeyboardKey.backspace) {
|
||||
if (_controllers[index].text.isEmpty &&
|
||||
index > 0) {
|
||||
_focusNodes[index - 1].requestFocus();
|
||||
}
|
||||
}
|
||||
},
|
||||
child: TextField(
|
||||
controller: _controllers[index],
|
||||
focusNode: _focusNodes[index],
|
||||
textAlign: TextAlign.center,
|
||||
keyboardType: TextInputType.number,
|
||||
maxLength: 1,
|
||||
obscureText: true,
|
||||
enabled: !isLoading,
|
||||
style: TextStyle(
|
||||
fontFamily: "Gilroy",
|
||||
fontWeight: FontWeight.w400,
|
||||
fontSize: pinFontSize,
|
||||
color: isFilled ? Colors.white : Colors.black,
|
||||
),
|
||||
decoration: const InputDecoration(
|
||||
counterText: '',
|
||||
border: InputBorder.none,
|
||||
),
|
||||
onChanged: (value) =>
|
||||
_onPinChange(index, value),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
SizedBox(height: spacingSM),
|
||||
Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: boxMargin * 2),
|
||||
child: Text(
|
||||
"Confirm PIN *",
|
||||
style: AppTextStyles.medium.copyWith(
|
||||
fontSize: subtitleFontSize,
|
||||
color: AppColors.authheading,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: List.generate(pinLength, (index) {
|
||||
bool isFilled = _confirmControllers[index].text.isNotEmpty;
|
||||
return Container(
|
||||
margin: EdgeInsets.symmetric(horizontal: boxMargin),
|
||||
width: boxWidth,
|
||||
height: boxHeight,
|
||||
decoration: BoxDecoration(
|
||||
color: isFilled ? AppColors.commanbutton : Colors.white,
|
||||
borderRadius: BorderRadius.circular(boxRadius),
|
||||
border: Border.all(color: const Color(0xFFDFDFDF)),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: const Color(0xFFBDBDBD).withOpacity(0.25),
|
||||
blurRadius: 7,
|
||||
offset: const Offset(0, 1),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Center(
|
||||
child: KeyboardListener(
|
||||
focusNode: FocusNode(),
|
||||
onKeyEvent: (event) {
|
||||
if (event is KeyDownEvent &&
|
||||
event.logicalKey ==
|
||||
LogicalKeyboardKey.backspace) {
|
||||
if (_confirmControllers[index].text.isEmpty &&
|
||||
index > 0) {
|
||||
_confirmFocusNodes[index - 1].requestFocus();
|
||||
}
|
||||
}
|
||||
},
|
||||
child: TextField(
|
||||
controller: _confirmControllers[index],
|
||||
focusNode: _confirmFocusNodes[index],
|
||||
textAlign: TextAlign.center,
|
||||
keyboardType: TextInputType.number,
|
||||
maxLength: 1,
|
||||
obscureText: true,
|
||||
enabled: !isLoading,
|
||||
style: TextStyle(
|
||||
fontFamily: "Gilroy",
|
||||
fontWeight: FontWeight.w400,
|
||||
fontSize: pinFontSize,
|
||||
color: isFilled ? Colors.white : Colors.black,
|
||||
),
|
||||
decoration: const InputDecoration(
|
||||
counterText: '',
|
||||
border: InputBorder.none,
|
||||
),
|
||||
onChanged: (value) =>
|
||||
_onConfirmPinChange(index, value),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
SizedBox(height: spacingLG),
|
||||
isLoading
|
||||
? const CircularProgressIndicator()
|
||||
: CommanButton(
|
||||
text: "Set PIN",
|
||||
onPressed: _handleAction,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -144,6 +144,18 @@ class _EmployeeProfileScreenState extends ConsumerState<EmployeeProfileScreen> {
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildMenuItem(
|
||||
id: 'change_pin',
|
||||
icon: Icons.lock_outline,
|
||||
title: 'Change PIN',
|
||||
onTap: () {
|
||||
setState(() {
|
||||
selectedItem = 'change_pin';
|
||||
});
|
||||
Get.toNamed(ConstRouters.changePin);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
_buildMenuItem(
|
||||
id: 'terms',
|
||||
|
||||
@@ -152,6 +152,18 @@ class _ProfileScreenState extends ConsumerState<ProfileScreen> {
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildMenuItem(
|
||||
id: 'change_pin',
|
||||
icon: Icons.lock_outline,
|
||||
title: 'Change PIN',
|
||||
onTap: () {
|
||||
setState(() {
|
||||
selectedItem = 'change_pin';
|
||||
});
|
||||
Get.toNamed(ConstRouters.changePin);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
if (userRole != "employee")
|
||||
_buildMenuItem(
|
||||
id: 'Staff',
|
||||
|
||||
Reference in new issue
Block a user