Skip to content

Commit

Permalink
Merge pull request #4 from Emon526/dev
Browse files Browse the repository at this point in the history
fix: OnBoarding Provider Added
fix: Auth Provider Added
  • Loading branch information
Emon526 committed Mar 2, 2024
2 parents adcb532 + 16f348c commit 073a936
Show file tree
Hide file tree
Showing 9 changed files with 549 additions and 516 deletions.
7 changes: 5 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:provider/provider.dart';
import 'consts/consts.dart';
import 'consts/style.dart';
import 'provider/addpasswordprovider.dart';
import 'provider/authprovider.dart';
import 'provider/generatedpassswordprovideer.dart';
import 'provider/onboardprovider.dart';
import 'provider/themeprovider.dart';
Expand All @@ -30,6 +31,9 @@ class MyApp extends StatelessWidget {
ChangeNotifierProvider(create: (_) {
return OnBoardingProvider();
}),
ChangeNotifierProvider(
create: (context) => AuthProvider(),
),
ChangeNotifierProvider(
create: (context) => DatabaseService(),
),
Expand All @@ -41,13 +45,12 @@ class MyApp extends StatelessWidget {
),
],
builder: (context, child) {
removesplash();
return Consumer<ThemeProvider>(builder: (
context,
value,
child,
) {
removesplash();

return MaterialApp(
debugShowCheckedModeBanner: false,
title: Consts.APP_NAME,
Expand Down
31 changes: 31 additions & 0 deletions lib/provider/authprovider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';

class AuthProvider with ChangeNotifier {
AuthProvider() {
getMasterPassword();
}
bool _isObsecured = true;
bool get isObsecured => _isObsecured;
set isObsecured(bool value) {
_isObsecured = value;
notifyListeners();
}

late String _masterpassword;
String get masterpassword => _masterpassword;
set masterpassword(String value) {
_masterpassword = value;
notifyListeners();
}

void savePassword({required String password}) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setString('password', password);
}

Future<void> getMasterPassword() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
masterpassword = prefs.getString('password') ?? '';
}
}
6 changes: 6 additions & 0 deletions lib/provider/onboardprovider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ class OnBoardingProvider with ChangeNotifier {
OnBoardingProvider() {
getOnboardInfo();
}
int _currentIndex = 0;
int get currentIndex => _currentIndex;
set currentIndex(value) {
_currentIndex = value;
notifyListeners();
}

bool _isBoardingCompleate = false;
bool get isBoardingCompleate => _isBoardingCompleate;
Expand Down
149 changes: 149 additions & 0 deletions lib/screens/auth/chagepassword.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import 'package:flutter/material.dart';
import 'package:form_field_validator/form_field_validator.dart';
import 'package:provider/provider.dart';

import '../../consts/consts.dart';
import '../../provider/authprovider.dart';
import '../../widgets/custombutton.dart';

class ChangePasswordPage extends StatefulWidget {
const ChangePasswordPage({super.key});

@override
State<ChangePasswordPage> createState() => _ChangePasswordPageState();
}

class _ChangePasswordPageState extends State<ChangePasswordPage> {
final focus = FocusNode();
final passwordController = TextEditingController();
final confirmpasswordController = TextEditingController();

final GlobalKey<FormState> _changePasswordFormKey = GlobalKey<FormState>();

final passwordValidator = MultiValidator([
RequiredValidator(errorText: 'Password is required'),
MinLengthValidator(8, errorText: 'Password must be at least 8 digits long'),
PatternValidator(r'(?=.*?[#?!@$%^&*-])',
errorText: 'Passwords must have at least one special character'),
]);
final passwordMatchValidator =
MatchValidator(errorText: 'Passwords do not match');

@override
void dispose() {
passwordController.dispose();
confirmpasswordController.dispose();
focus.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;
return Consumer<AuthProvider>(
builder: (BuildContext context, provider, Widget? child) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: const Text(
'Change Password',
),
),
body: SingleChildScrollView(
child: SafeArea(
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: size.width * 0.07,
),
child: Form(
key: _changePasswordFormKey,
child: Column(
children: [
SizedBox(
height: size.height * 0.04,
),
TextFormField(
onFieldSubmitted: (value) {
FocusScope.of(context).requestFocus(focus);
},
obscureText: provider.isObsecured,
controller: passwordController,
keyboardType: TextInputType.visiblePassword,
textInputAction: TextInputAction.next,
validator: passwordValidator.call,
decoration: InputDecoration(
filled: true,
labelText: 'Password',
border: OutlineInputBorder(
borderRadius:
BorderRadius.circular(Consts.BORDER_RADIUS)),
suffix: InkWell(
child: Icon(
provider.isObsecured
? Icons.visibility
: Icons.visibility_off,
),
onTap: () {
provider.isObsecured = !provider.isObsecured;
},
),
),
),
SizedBox(
height: size.height * 0.03,
),
TextFormField(
focusNode: focus,
obscureText: provider.isObsecured,
controller: confirmpasswordController,
keyboardType: TextInputType.visiblePassword,
textInputAction: TextInputAction.done,
validator: (val) => passwordMatchValidator.validateMatch(
val!, passwordController.text.trim()),
decoration: InputDecoration(
labelText: 'Confirm Password',
filled: true,
border: OutlineInputBorder(
borderRadius:
BorderRadius.circular(Consts.BORDER_RADIUS)),
suffix: InkWell(
child: Icon(
provider.isObsecured
? Icons.visibility
: Icons.visibility_off,
),
onTap: () {
provider.isObsecured = !provider.isObsecured;
},
),
),
),
SizedBox(
height: size.height * 0.04,
),
CustomButton(
ontap: () {
validate();
},
buttontext: 'Change Password',
),
],
),
),
),
),
),
);
});
}

void validate() async {
final FormState form = _changePasswordFormKey.currentState!;
if (form.validate()) {
context
.read<AuthProvider>()
.savePassword(password: confirmpasswordController.text.trim());
Navigator.pop(context);
}
}
}
Loading

0 comments on commit 073a936

Please sign in to comment.