fixed issues
parent
7921ffe26d
commit
47f10738d7
@ -0,0 +1,34 @@
|
||||
|
||||
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
ChangePassword confirmPasswordFromJson(String str) => ChangePassword.fromJson(json.decode(str));
|
||||
|
||||
String changePasswordToJson(ChangePassword data) => json.encode(data.toJson());
|
||||
|
||||
class ChangePassword {
|
||||
int? messageStatus;
|
||||
Null? totalItemsCount;
|
||||
bool? data;
|
||||
String? message;
|
||||
|
||||
ChangePassword(
|
||||
{this.messageStatus, this.totalItemsCount, this.data, this.message});
|
||||
|
||||
ChangePassword.fromJson(Map<String, dynamic> json) {
|
||||
messageStatus = json['messageStatus'];
|
||||
totalItemsCount = json['totalItemsCount'];
|
||||
data = json['data'];
|
||||
message = json['message'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['messageStatus'] = this.messageStatus;
|
||||
data['totalItemsCount'] = this.totalItemsCount;
|
||||
data['data'] = this.data;
|
||||
data['message'] = this.message;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,111 @@
|
||||
import 'package:car_provider_app/api/client/user_api_client.dart';
|
||||
|
||||
import 'package:car_provider_app/classes/utils.dart';
|
||||
import 'package:car_provider_app/config/routes.dart';
|
||||
import 'package:car_provider_app/models/user/change_password.dart';
|
||||
import 'package:car_provider_app/models/user/confirm_password.dart';
|
||||
import 'package:car_provider_app/utils/navigator.dart';
|
||||
import 'package:car_provider_app/utils/utils.dart';
|
||||
import 'package:car_provider_app/widgets/app_bar.dart';
|
||||
import 'package:car_provider_app/widgets/dialog/dialogs.dart';
|
||||
import 'package:car_provider_app/widgets/dialog/message_dialog.dart';
|
||||
import 'package:car_provider_app/widgets/show_fill_button.dart';
|
||||
import 'package:car_provider_app/extensions/string_extensions.dart';
|
||||
import 'package:car_provider_app/extensions/int_extensions.dart';
|
||||
import 'package:car_provider_app/widgets/txt_field.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart';
|
||||
|
||||
class ChangePasswordPage extends StatefulWidget {
|
||||
String userToken;
|
||||
|
||||
ChangePasswordPage(this.userToken, {Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<ChangePasswordPage> createState() => _ChangePasswordPageState();
|
||||
}
|
||||
|
||||
class _ChangePasswordPageState extends State<ChangePasswordPage> {
|
||||
String newPassword = "";
|
||||
String currentPasswor = '';
|
||||
|
||||
@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: [
|
||||
"Inter New Phone Number".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) => currentPasswor = v,
|
||||
),
|
||||
12.height,
|
||||
TextFormField(
|
||||
decoration: InputDecoration(
|
||||
hintText: "Inter 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);
|
||||
Response res = await UserApiClent().ChangePassword(currentPasswor, newPassword);
|
||||
Utils.hideLoading(context);
|
||||
ChangePassword data = ChangePassword.fromJson(jsonDecode(res.body));
|
||||
if (data.messageStatus == 1) {
|
||||
Utils.showToast("Password is Updated");
|
||||
navigateWithName(context, AppRoutes.loginWithPassword);
|
||||
} else {
|
||||
Utils.showToast(data.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);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue