diff --git a/lib/main.dart b/lib/main.dart index 56897ec..14ccb55 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,3 +1,4 @@ +import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/material.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:nhance_app_pwa/pages/enrollment/addons.dart'; @@ -19,6 +20,7 @@ import 'package:nhance_app_pwa/pages/postEnrollment/profile.dart'; import 'package:nhance_app_pwa/pages/postEnrollment/termsofuse.dart'; import 'package:nhance_app_pwa/pages/session/SetPinBiometric.dart'; import 'package:nhance_app_pwa/pages/session/authenticationService.dart'; +import 'package:nhance_app_pwa/pages/session/changePin.dart'; import 'package:nhance_app_pwa/pages/session/settingUpPinAndBiometric.dart'; import 'package:nhance_app_pwa/pages/verify.dart'; @@ -26,6 +28,7 @@ import 'models/environment.dart'; Future main() async { WidgetsFlutterBinding.ensureInitialized(); + await Firebase.initializeApp(); await dotenv.load(fileName: Environment.fileName); final AuthService _authService = AuthService(); @@ -51,6 +54,7 @@ Future main() async { 'verify': (context) => MyVerify(), 'pinSettingPage': (context) => pinSettingPage(), 'pinPage': (context) => pinPage(), + 'changePin': (context) => changePin(), 'home': (context) => MyApp(), 'policies': (context) => policies(), 'claims': (context) => claims(), diff --git a/lib/pages/postEnrollment/profile.dart b/lib/pages/postEnrollment/profile.dart index 7d35f44..5470057 100644 --- a/lib/pages/postEnrollment/profile.dart +++ b/lib/pages/postEnrollment/profile.dart @@ -548,11 +548,12 @@ class _profileState extends State { flex: 12, child: Container( width: 150, - height: Responsive.isDesktop(context) ? 150 : 100, + // height: Responsive.isDesktop(context) ? 150 : 100, alignment: Alignment.center, child: ElevatedButton( onPressed: () { - logout(context); + Navigator.pushReplacementNamed( + context, 'changePin'); }, child: Row( mainAxisAlignment: MainAxisAlignment.center, @@ -577,7 +578,7 @@ class _profileState extends State { ], ), ), - // SizedBox(height: 1), + SizedBox(height: 10), Container( child: Row( children: [ @@ -585,7 +586,7 @@ class _profileState extends State { flex: 12, child: Container( width: 150, - height: Responsive.isDesktop(context) ? 150 : 100, + // height: Responsive.isDesktop(context) ? 150 : 100, alignment: Alignment.center, child: ElevatedButton( onPressed: () { diff --git a/lib/pages/session/SetPinBiometric.dart b/lib/pages/session/SetPinBiometric.dart index 51c6db2..131dec5 100644 --- a/lib/pages/session/SetPinBiometric.dart +++ b/lib/pages/session/SetPinBiometric.dart @@ -143,9 +143,9 @@ class _pinPageState extends State { if (value.length != 4) { return 'Pin must be 4 digits'; } - if (value != savedPin) { - return 'Incorrect pin'; - } + // if (value != savedPin) { + // return 'Incorrect pin'; + // } return null; } diff --git a/lib/pages/session/changePin.dart b/lib/pages/session/changePin.dart new file mode 100644 index 0000000..6eea566 --- /dev/null +++ b/lib/pages/session/changePin.dart @@ -0,0 +1,573 @@ +import 'dart:convert'; +import 'dart:io'; +import 'package:google_fonts/google_fonts.dart'; +import 'package:http/http.dart' as http; +import 'package:flutter/material.dart'; +import 'package:pinput/pinput.dart'; +import 'package:shared_preferences/shared_preferences.dart'; +import '../../customAppBar/responsive.dart'; +import '../../customAppBar/toastHelper.dart'; +import '../../models/environment.dart'; +import 'authenticationService.dart'; + +class changePin extends StatefulWidget { + const changePin({Key? key}) : super(key: key); + + @override + State createState() => _changePinState(); +} + +class _changePinState extends State { + bool _enableBiometric = false; + final _oldPinController = TextEditingController(); + final _newPinController = TextEditingController(); + final AuthService _authService = AuthService(); + late final _formKey = GlobalKey(); + late final FocusNode focusNode; + dynamic empMobileNo; + dynamic _token; + dynamic emp_status; + + @override + void initState() { + super.initState(); + } + + @override + void dispose() { + super.dispose(); + } + + Future setChangePin() async { + try { + if (_formKey.currentState!.validate()) { + final SharedPreferences prefs = await SharedPreferences.getInstance(); + empMobileNo = prefs.getString('empMobileNo'); + _token = prefs.getString('token'); + + final response = await http.post( + Uri.parse(Environment.apiUrl + 'updateMpin'), + body: json.encode({ + 'mobile_number': empMobileNo, + 'old_mpin': _oldPinController.text, + 'new_mpin': _newPinController.text + }), + headers: { + HttpHeaders.contentTypeHeader: 'application/json', + 'Authorization': 'Bearer $_token', + }, + ); + + if (response.statusCode == 200) { + Map data = json.decode(response.body); + bool pinVerification = data['data']['mpin_verification']; + String message = data['data']['message']; + if (pinVerification) { + ToastHelper.showSuccessToast(context, message); + Navigator.pushReplacementNamed(context, 'profile'); + } else { + ToastHelper.showErrorToast(context, message); + print('Invalid Pin Number'); + } + } else { + ToastHelper.showErrorToast(context, 'Something went wrong'); + throw Exception('Failed to verify mobile number'); + } + } + } catch (e) { + ToastHelper.showErrorToast(context, 'Something went wrong'); + print('Error: $e'); + } + } + + String? _validatePin(String? value) { + if (value == null || value.isEmpty) { + return 'Please enter a PIN'; + } + if (value.length != 4) { + return 'PIN must be 4 digits'; + } + return null; + } + + String? _validateConfirmPin(String? value) { + if (value == null || value.isEmpty) { + return 'Please enter your PIN'; + } + if (value.length != 4) { + return 'PIN must be 4 digits'; + } + if (value == _oldPinController.text) { + return 'Pin not should be same'; + } + return null; + } + + @override + Widget build(BuildContext context) { + const focusedBorderColor = Color.fromRGBO(23, 171, 144, 1); + const fillColor = Color.fromRGBO(243, 246, 249, 0); + const borderColor = Color.fromRGBO(23, 171, 144, 0.4); + + Size _size = MediaQuery.of(context).size; + EdgeInsets marginInsets = EdgeInsets.zero; + if (Responsive.isDesktop(context)) { + marginInsets = const EdgeInsets.only( + left: 0, + right: 0, + bottom: 0, + top: 0, + ); + } else if (Responsive.isMobile(context)) { + marginInsets = const EdgeInsets.only( + left: 25, // Example value for mobile + right: 25, // Example value for mobile + bottom: 0, // Example value for mobile + top: 0, // Example value for mobile + ); + } else if (Responsive.isTablet(context)) { + marginInsets = const EdgeInsets.only( + left: 25, // Example value for mobile + right: 25, // Example value for mobile + bottom: 0, // Example value for mobile + top: 0, // Example value for mobile + ); + } + // final defaultPinTheme = PinTheme( + // width: 56, + // height: 56, + // textStyle: TextStyle( + // fontSize: 20, + // color: Color.fromRGBO(30, 60, 87, 1), + // fontWeight: FontWeight.w600, + // ), + // decoration: BoxDecoration( + // border: Border.all(color: Color.fromRGBO(234, 239, 243, 1)), + // borderRadius: BorderRadius.circular(20), + // ), + // ); + + final defaultPinTheme = PinTheme( + width: 56, + height: 56, + textStyle: const TextStyle( + fontSize: 20, + color: Color.fromRGBO(30, 60, 87, 1), + ), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(19), + border: Border.all(color: borderColor), + ), + ); + + return Scaffold( + body: Container( + color: Colors.white, // Set the color for the body + child: SizedBox.expand( + child: Stack(children: [ + SingleChildScrollView( + child: Container( + padding: EdgeInsets.all(0), + color: Color(0xFFFFFCE5), + child: Column(children: [ + Container( + decoration: BoxDecoration( + color: Color( + 0xFFFFFCE5), // Set background color for the container + borderRadius: BorderRadius.circular( + 10), // Set border radius for the container + ), + // padding: EdgeInsets.only(top: 0, bottom: 0, left: 10, right: 10), + child: Column( + // crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Expanded( + flex: 12, + child: Align( + alignment: Alignment.topLeft, + child: Padding( + padding: const EdgeInsets.only( + left: 16.0), // Add left margin + child: Image.asset( + 'assets/nhance_app_logo.png', + width: 150, + height: 100, + ), + ), + ), + ), + ], + ), + SizedBox(height: 10), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Expanded( + flex: 12, + child: Align( + alignment: Alignment.center, + child: Padding( + padding: const EdgeInsets.only( + left: 16.0), // Add left margin + child: Image.asset( + 'assets/mpin.png', + width: 150, + height: 150, + ), + ), + ), + ), + ], + ), + SizedBox(height: 10), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Expanded( + flex: 12, + child: Text( + 'Change Pin', + textAlign: TextAlign.center, + style: GoogleFonts.poppins( + fontSize: 16, + color: Color(0xFF404040), + fontWeight: FontWeight.w500, + ), + ), + ), + ], + ), + SizedBox(height: 10), + ], + ), + ), + Container( + decoration: BoxDecoration( + color: Colors + .white, // Set background color for the container + borderRadius: BorderRadius.only( + topLeft: Radius.circular(150.0), + topRight: Radius.circular(0), + ), // Set border radius for the container + ), + padding: EdgeInsets.only( + top: 20, bottom: 10, left: 10, right: 10), + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Container( + margin: marginInsets, + alignment: Alignment.bottomCenter, + child: SingleChildScrollView( + child: Form( + key: _formKey, + child: Column( + children: [ + Row( + children: [ + Expanded( + flex: 12, + child: Column( + children: [ + SizedBox(height: 40), + Container( + margin: EdgeInsets.symmetric( + horizontal: 30), + child: Row( + mainAxisAlignment: + MainAxisAlignment + .start, // Align text to the right + children: [ + Align( + // alignment: Alignment.centerLeft, + child: Text( + 'Enter old pin', + style: GoogleFonts + .poppins( + fontSize: 16, + color: Color( + 0xFF909090), + fontWeight: + FontWeight.w400, + ), + ), + ), + ]), + ), + SizedBox(height: 5), + Container( + margin: EdgeInsets.symmetric( + horizontal: 0), + child: Pinput( + length: 4, + // defaultPinTheme: defaultPinTheme, + // focusedPinTheme: focusedPinTheme, + // submittedPinTheme: submittedPinTheme, + defaultPinTheme: + defaultPinTheme, + separatorBuilder: (index) => + const SizedBox(width: 8), + showCursor: true, + controller: _oldPinController, + validator: _validatePin, + errorPinTheme: defaultPinTheme + .copyBorderWith( + border: Border.all( + color: + Colors.redAccent), + ), + hapticFeedbackType: + HapticFeedbackType + .lightImpact, + onCompleted: (pin) { + debugPrint( + 'onCompleted: $pin'); + }, + onChanged: (value) { + debugPrint( + 'onChanged: $value'); + }, + cursor: Column( + mainAxisAlignment: + MainAxisAlignment.end, + children: [ + Container( + margin: const EdgeInsets + .only(bottom: 9), + width: 22, + height: 1, + color: + focusedBorderColor, + ), + ], + ), + focusedPinTheme: + defaultPinTheme.copyWith( + decoration: defaultPinTheme + .decoration! + .copyWith( + borderRadius: + BorderRadius.circular( + 8), + border: Border.all( + color: + focusedBorderColor), + ), + ), + submittedPinTheme: + defaultPinTheme.copyWith( + decoration: defaultPinTheme + .decoration! + .copyWith( + color: fillColor, + borderRadius: + BorderRadius.circular( + 19), + border: Border.all( + color: + focusedBorderColor), + ), + ), + ), + ), + SizedBox(height: 15), + Container( + margin: EdgeInsets.symmetric( + horizontal: 30), + child: Row( + mainAxisAlignment: + MainAxisAlignment + .start, // Align text to the right + children: [ + Align( + // alignment: Alignment.centerLeft, + child: Text( + 'Enter new pin', + style: GoogleFonts + .poppins( + fontSize: 16, + color: Color( + 0xFF909090), + fontWeight: + FontWeight.w400, + ), + ), + ), + ]), + ), + SizedBox(height: 5), + Container( + margin: Responsive.isDesktop( + context) + ? EdgeInsets.symmetric( + horizontal: 150) + : EdgeInsets.symmetric( + horizontal: 0), + child: Pinput( + length: 4, + // defaultPinTheme: defaultPinTheme, + // focusedPinTheme: focusedPinTheme, + // submittedPinTheme: submittedPinTheme, + + defaultPinTheme: + defaultPinTheme, + separatorBuilder: (index) => + const SizedBox(width: 8), + showCursor: true, + controller: _newPinController, + validator: + _validateConfirmPin, + errorPinTheme: defaultPinTheme + .copyBorderWith( + border: Border.all( + color: + Colors.redAccent), + ), + hapticFeedbackType: + HapticFeedbackType + .lightImpact, + onCompleted: (pin) { + debugPrint( + 'onCompleted: $pin'); + }, + onChanged: (value) { + debugPrint( + 'onChanged: $value'); + }, + cursor: Column( + mainAxisAlignment: + MainAxisAlignment.end, + children: [ + Container( + margin: const EdgeInsets + .only(bottom: 9), + width: 22, + height: 1, + color: + focusedBorderColor, + ), + ], + ), + focusedPinTheme: + defaultPinTheme.copyWith( + decoration: defaultPinTheme + .decoration! + .copyWith( + borderRadius: + BorderRadius.circular( + 8), + border: Border.all( + color: + focusedBorderColor), + ), + ), + submittedPinTheme: + defaultPinTheme.copyWith( + decoration: defaultPinTheme + .decoration! + .copyWith( + color: fillColor, + borderRadius: + BorderRadius.circular( + 19), + border: Border.all( + color: + focusedBorderColor), + ), + ), + ), + ), + SizedBox(height: 15), + Container( + margin: EdgeInsets.symmetric( + horizontal: 30), + child: SizedBox( + width: double.infinity, + height: 45, + child: ElevatedButton( + style: ElevatedButton + .styleFrom( + backgroundColor: + Color(0xFF00989E), + shape: + RoundedRectangleBorder( + borderRadius: + BorderRadius + .circular(10), + ), + ), + onPressed: () async { + setChangePin(); + }, + child: Text( + "Save", + style: + GoogleFonts.poppins( + color: Color( + 0xFFFFFFFF)), + ), + ), + ), + ), + ], + ), + ), + ], + ), + ], + ), + ), + ), + ), + SizedBox(height: 40), + ], + ), + ), + ]), + )), + Align( + alignment: Alignment.bottomCenter, + child: Container( + width: double.infinity, // Make the footer full width + child: RichText( + textAlign: TextAlign.center, + text: TextSpan( + text: 'By continuing, you agree with our ', + style: GoogleFonts.poppins( + color: Colors.black, + fontSize: 9, + ), + children: [ + TextSpan( + text: 'privacy policy ', + style: GoogleFonts.poppins( + color: Color(0xFF00989E), + fontSize: 9, + ), + ), + TextSpan( + text: 'and ', + style: GoogleFonts.poppins( + color: Colors.black, + fontSize: 9, + ), + ), + TextSpan( + text: 'terms of use', + style: GoogleFonts.poppins( + color: Color(0xFF00989E), + fontSize: 9, + ), + ), + ], + ), + ), + ), + ), + ]), + ))); + } +}