185 lines
9.5 KiB
Dart
185 lines
9.5 KiB
Dart
import 'package:cheminova/provider/change_password_provider.dart';
|
|
import 'package:cheminova/provider/login_provider.dart';
|
|
import 'package:cheminova/screens/password_change_screen.dart';
|
|
import 'package:cheminova/widgets/common_app_bar.dart';
|
|
import 'package:cheminova/widgets/common_background.dart';
|
|
import 'package:cheminova/widgets/common_elevated_button.dart';
|
|
import 'package:cheminova/widgets/common_text_form_field.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../widgets/common_drawer.dart';
|
|
import 'home_screen.dart';
|
|
|
|
class ChangePasswordPage extends StatefulWidget {
|
|
const ChangePasswordPage({super.key});
|
|
|
|
@override
|
|
State<ChangePasswordPage> createState() => _ChangePasswordPageState();
|
|
}
|
|
|
|
class _ChangePasswordPageState extends State<ChangePasswordPage> {
|
|
late ChangePasswordProvider changePasswordProvider;
|
|
final _formKey = GlobalKey<FormState>();
|
|
|
|
@override
|
|
void initState() {
|
|
changePasswordProvider = ChangePasswordProvider();
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ChangeNotifierProvider<ChangePasswordProvider>(
|
|
create: (_) => changePasswordProvider,
|
|
builder: (context, child) {
|
|
return Stack(
|
|
children: [
|
|
CommonBackground(
|
|
isFullWidth: true,
|
|
child: Scaffold(
|
|
drawer: const CommonDrawer(),
|
|
backgroundColor: Colors.transparent,
|
|
appBar: CommonAppBar(
|
|
title: const Text(''),
|
|
backgroundColor: Colors.transparent,
|
|
elevation: 0,
|
|
actions: [
|
|
IconButton(
|
|
onPressed: () {
|
|
Navigator.pop(context);
|
|
},
|
|
icon: Image.asset('assets/Back_attendance.png'),
|
|
padding: const EdgeInsets.only(right: 20),
|
|
),
|
|
],
|
|
),
|
|
body: SingleChildScrollView(
|
|
child: Column(
|
|
children: [
|
|
// const SizedBox(height: 50),
|
|
// const SizedBox(height: 60),
|
|
Container(
|
|
padding: const EdgeInsets.all(20.0)
|
|
.copyWith(top: 15, bottom: 30),
|
|
margin: const EdgeInsets.symmetric(horizontal: 30.0),
|
|
decoration: BoxDecoration(
|
|
border: Border.all(color: Colors.white),
|
|
color: const Color(0xffB4D1E5).withOpacity(0.9),
|
|
borderRadius: BorderRadius.circular(26.0)),
|
|
child: Form(
|
|
key: _formKey,
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: <Widget>[
|
|
const SizedBox(height: 20),
|
|
const Text('Change Password',
|
|
style: TextStyle(
|
|
fontSize: 30,
|
|
color: Colors.black,
|
|
fontWeight: FontWeight.w500,
|
|
fontFamily: 'Roboto')),
|
|
const SizedBox(height: 20),
|
|
Consumer<ChangePasswordProvider>(
|
|
builder: (context, value, child) =>
|
|
CommonTextFormField(
|
|
controller: value.oldPasswordController,
|
|
validator: (val) {
|
|
if (val == null || val.isEmpty) {
|
|
return 'Please enter your password';
|
|
}
|
|
return null;
|
|
},
|
|
title: 'Old Password'),
|
|
),
|
|
const SizedBox(height: 20),
|
|
Consumer<ChangePasswordProvider>(
|
|
builder: (context, value, child) =>
|
|
CommonTextFormField(
|
|
controller: value.newPasswordController,
|
|
validator: (val) {
|
|
if (val == null || val.isEmpty) {
|
|
return 'Please enter your password';
|
|
}
|
|
return null;
|
|
},
|
|
title: 'New Password'),
|
|
),
|
|
const SizedBox(height: 20),
|
|
Consumer<ChangePasswordProvider>(
|
|
builder: (context, value, child) =>
|
|
CommonTextFormField(
|
|
controller:
|
|
value.confirmPasswordController,
|
|
validator: (val) {
|
|
if (val == null || val.isEmpty) {
|
|
return 'Please enter your password';
|
|
} else if (val !=
|
|
value
|
|
.newPasswordController.text) {
|
|
return 'Password does not match';
|
|
}
|
|
return null;
|
|
},
|
|
title: 'Confirm Password'),
|
|
),
|
|
const SizedBox(height: 15),
|
|
Align(
|
|
alignment: Alignment.center,
|
|
child: Consumer<ChangePasswordProvider>(
|
|
builder: (context, value, child) =>
|
|
CommonElevatedButton(
|
|
backgroundColor: const Color(0xff004791),
|
|
borderRadius: 30,
|
|
width: double.infinity,
|
|
height: kToolbarHeight - 10,
|
|
text: 'SIGN IN',
|
|
isLoading: false,
|
|
onPressed: value.isLoading
|
|
? null
|
|
: () async {
|
|
if (_formKey.currentState!
|
|
.validate()) {
|
|
value
|
|
.changePassword()
|
|
.then((result) {
|
|
var (status, message) =
|
|
result;
|
|
ScaffoldMessenger.of(context)
|
|
.showSnackBar(SnackBar(
|
|
content:
|
|
Text(message)));
|
|
if (status) {
|
|
Navigator.pushReplacement(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) =>
|
|
const HomePage()));
|
|
}
|
|
});
|
|
}
|
|
},
|
|
),
|
|
))
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
)),
|
|
),
|
|
Consumer<ChangePasswordProvider>(
|
|
builder: (context, value, child) => value.isLoading?
|
|
Container(
|
|
color: Colors.black.withOpacity(0.5),
|
|
child: const Center(child: CircularProgressIndicator())):Container(),
|
|
)
|
|
],
|
|
);
|
|
});
|
|
}
|
|
}
|