You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
3.6 KiB
Dart
107 lines
3.6 KiB
Dart
|
|
|
|
import 'package:car_customer_app/api/user_api_client.dart';
|
|
import 'package:car_customer_app/classes/utils.dart';
|
|
import 'package:car_customer_app/config/routes.dart';
|
|
import 'package:car_customer_app/extensions/int_extensions.dart';
|
|
import 'package:car_customer_app/extensions/string_extensions.dart';
|
|
import 'package:car_customer_app/models/user/change_password.dart';
|
|
import 'package:car_customer_app/models/user/confirm_password.dart';
|
|
import 'package:car_customer_app/utils/navigator.dart';
|
|
import 'package:car_customer_app/widgets/app_bar.dart';
|
|
import 'package:car_customer_app/widgets/show_fill_button.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'dart:convert';
|
|
import 'package:http/http.dart';
|
|
|
|
class ChangePasswordPage extends StatefulWidget {
|
|
|
|
@override
|
|
State<ChangePasswordPage> createState() => _ChangePasswordPageState();
|
|
}
|
|
|
|
class _ChangePasswordPageState extends State<ChangePasswordPage> {
|
|
String newPassword = "";
|
|
String currentPassword = '';
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: appBar(title: "Change Password"),
|
|
body: SingleChildScrollView(
|
|
child: Container(
|
|
// width: double.infinity,
|
|
// height: double.infinity,
|
|
padding: EdgeInsets.all(40),
|
|
child: Column(
|
|
children: [
|
|
"Enter New Password".toText24(),
|
|
12.height,
|
|
TextFormField(
|
|
decoration: InputDecoration(
|
|
hintText: "Enter Old Password",
|
|
hintStyle: TextStyle(color: Colors.grey),
|
|
border: OutlineInputBorder(
|
|
borderRadius: const BorderRadius.all(
|
|
const Radius.circular(5.0),
|
|
),
|
|
),
|
|
),
|
|
obscureText: true,
|
|
onChanged: (v) => currentPassword = v,
|
|
),
|
|
12.height,
|
|
TextFormField(
|
|
decoration: InputDecoration(
|
|
hintText: "Enter New Password",
|
|
hintStyle: TextStyle(color: Colors.grey),
|
|
border: OutlineInputBorder(
|
|
borderRadius: const BorderRadius.all(
|
|
const Radius.circular(5.0),
|
|
),
|
|
),
|
|
),
|
|
obscureText: true,
|
|
onChanged: (v) => newPassword = v,
|
|
),
|
|
40.height,
|
|
ShowFillButton(
|
|
title: "Confirm",
|
|
width: double.infinity,
|
|
onPressed: () {changePassword(context);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> changePassword(BuildContext context) async {
|
|
if (validateStructure(newPassword ?? "")) {
|
|
Utils.showLoading(context);
|
|
MResponse res = await UserApiClent().ChangePassword(currentPassword, newPassword);
|
|
Utils.hideLoading(context);
|
|
if (res.messageStatus == 1) {
|
|
Utils.showToast("Password is Updated");
|
|
// navigateWithName(context, AppRoutes.loginWithPassword);
|
|
Navigator.of(context)
|
|
.pushNamedAndRemoveUntil(AppRoutes.loginWithPassword, (Route<dynamic> route) => false);
|
|
} else {
|
|
Utils.showToast(res.message ?? "");
|
|
}
|
|
} else {
|
|
Utils.showToast("Password Should contains Character, Number, Capital and small letters");
|
|
}
|
|
}
|
|
|
|
|
|
bool validateStructure(String value){
|
|
String pattern = r'^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[!@#\$&*~]).{6,}$';
|
|
RegExp regExp = new RegExp(pattern);
|
|
return regExp.hasMatch(value);
|
|
}
|
|
}
|