6 Commits

Author SHA1 Message Date
Stephen
d3e455c371 [Change Pass] 4. revisi pemberian token ke BE 2024-01-21 13:05:58 +07:00
Stephen
6b28794577 Merge branch 'main' into add_change_password 2024-01-19 15:11:39 +07:00
Stephen
81733ec865 [Change Pass] 3. mengubah styling password input 2024-01-19 15:07:58 +07:00
Stephen
9d9db9eeb4 [Change Pass] 2. merge with main 2024-01-19 14:45:31 +07:00
Stephen
acc42c2d8f Merge branch 'main' into add_change_password 2024-01-19 14:44:33 +07:00
Stephen
f03266674a [Change Pass] 1. add Change Password Fiture 2024-01-19 14:44:20 +07:00
6 changed files with 583 additions and 38 deletions

View File

@@ -1,3 +1,5 @@
import 'package:app_petty_cash/screen/change_pasword/change_password_screen.dart';
import '../screen/change_company/change_company.dart';
import 'package:app_petty_cash/screen/camera/coba_camera.dart';
import 'package:app_petty_cash/screen/camera/example.dart';
@@ -20,6 +22,7 @@ const transaksiRoute = "/transaksiRoute";
const userRoute = "/userRoute";
const reportRoute = "/reportRoute";
const changeCompanyRoute = "/changeCompanyRoute";
const changePasswordRoute = "/changePasswordRoute";
const historyTransaksiRoute = "/historyTransaksiRoute";
const cameraExampleRoute = "/cameraExampleRoute";
const cobaCameraRoute = "/cobaCameraRoute";
@@ -119,6 +122,18 @@ class AppRoute {
);
});
}
// transaksi screen
if (settings.name == changePasswordRoute) {
return MaterialPageRoute(builder: (context) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(
textScaleFactor: 1.0,
padding: EdgeInsets.all(0),
),
child: ChangePasswordScreen(),
);
});
}
// test file picker screen
if (settings.name == testFilePickerRoute) {

View File

@@ -59,35 +59,26 @@ class AuthRepository extends BaseRepository {
}
}
Future<String> change_password({
Future<String> changePassword({
required String userID,
required String token,
required String M_UserID,
required String username,
required String doctor_id,
required String new_password,
required String confirm_password,
required String tokenx,
required String oldPassword,
required String newPassword,
required String confirmPassword,
}) async {
final param = {
"tokenx": tokenx,
"token": token,
"M_UserID": M_UserID,
"username": username,
"doctor_id": doctor_id,
"new_password": new_password,
"confirm_password": confirm_password
"M_UserID": userID,
"old_password": oldPassword,
"new_password": newPassword,
"confirm_password": confirmPassword
// "username": "alhadad",
// "doctor_id": "3101210841",
// "password": "riau123"
};
final service = "${Constant.baseUrlDevone}auth/change_password";
final resp = await post(param: param, service: service);
// final result = AuthModel(
// token: resp["data"]["token"],
// model: AuthDoctorModel.fromJson(resp["data"]["user"]),
// );
// return result;
final resp = await post(param: param, service: service, token: token);
if (resp["status"] == "OK") {
return resp['message'];

View File

@@ -0,0 +1,83 @@
import 'package:app_petty_cash/model/auth_model.dart';
import 'package:app_petty_cash/model/company_model.dart';
import 'package:app_petty_cash/repository/auth_repository.dart';
import 'package:app_petty_cash/repository/company_repository.dart';
import '../../model/list_category_model.dart';
import '../../repository/transaksi_repository.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../provider/dio_provider.dart';
import '../../repository/base_repository.dart';
abstract class ChangePasswordState extends Equatable {
final DateTime date;
const ChangePasswordState(this.date);
@override
List<Object?> get props => [date];
}
class ChangePasswordStateInit extends ChangePasswordState {
ChangePasswordStateInit() : super(DateTime.now());
}
class ChangePasswordStateLoading extends ChangePasswordState {
ChangePasswordStateLoading() : super(DateTime.now());
}
class ChangePasswordStateError extends ChangePasswordState {
final String message;
ChangePasswordStateError({
required this.message,
}) : super(DateTime.now());
}
class ChangePasswordStateDone extends ChangePasswordState {
final String model;
ChangePasswordStateDone({
required this.model,
}) : super(DateTime.now());
}
//notifier
class ChangePasswordNotifier extends StateNotifier<ChangePasswordState> {
final Ref ref;
ChangePasswordNotifier({
required this.ref,
}) : super(ChangePasswordStateInit());
void postChangePassword({
required String userID,
required String userToken,
required String userTokenx,
required String oldPassword,
required String newPassword,
required String confirmPassword,
}) async {
try {
state = ChangePasswordStateLoading();
final dio = ref.read(dioProvider);
final resp = await AuthRepository(dio: dio).changePassword(
userID: userID,
tokenx: userTokenx,
token: userToken,
oldPassword: oldPassword,
newPassword: newPassword,
confirmPassword: confirmPassword);
state = ChangePasswordStateDone(model: resp);
} catch (e) {
if (e is BaseRepositoryException) {
state = ChangePasswordStateError(message: e.message.toString());
} else {
state = ChangePasswordStateError(message: e.toString());
}
}
}
}
//provider
final ChangePasswordProvider =
StateNotifierProvider<ChangePasswordNotifier, ChangePasswordState>(
(ref) => ChangePasswordNotifier(ref: ref),
);

View File

@@ -0,0 +1,426 @@
import 'dart:async';
import 'package:app_petty_cash/app/constant.dart';
import 'package:app_petty_cash/provider/current_menu_provider.dart';
import 'package:app_petty_cash/screen/change_pasword/change_password_provider.dart';
import 'package:app_petty_cash/screen/login/logout_provider.dart';
import 'package:app_petty_cash/widget/custom_drawer.dart';
import 'package:app_petty_cash/widget/sankbar_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../../app/route.dart';
import '../../provider/current_user_provider.dart';
class ChangePasswordScreen extends HookConsumerWidget {
const ChangePasswordScreen({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final selectedUser = ref.read(currentUserProvider);
//menampung user token jika ada
final userToken = ref.read(currentUserProvider)?.token ?? "";
final userID = ref.read(currentUserProvider)?.model.M_UserID ?? "0";
final tokenx = ref.read(currentUserProvider)?.token ?? "";
final isLoading = useState(false);
final obscureText = useState<bool>(true);
final ctrlOldPassword = useTextEditingController(text: "");
final ctrlNewPassword = useTextEditingController(text: "");
final ctrlConfirmPassword = useTextEditingController(text: "");
final loading = useState(false);
// inisialisasi agar bisa cek apakah user sudah login sukses apa belum
useEffect(() {
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
final userID = ref.read(currentUserProvider)?.model.M_UserID ?? "0";
if (userID == "0") {
//not login
Navigator.of(context)
.pushNamedAndRemoveUntil(loginRoute, (route) => true);
// Navigator.popAndPushNamed(context, loginRoute);
return;
}
});
return () {};
}, []);
Logout() async {
final shared = await SharedPreferences.getInstance();
final bearerString = shared.get(Constant.bearerName).toString();
// print(bearerString);
if (bearerString.isNotEmpty) {
shared.remove(bearerString);
shared.clear();
// Navigator.popAndPushNamed(context, loginRoute);
ref.read(currentUserProvider.notifier).state = null;
Navigator.of(context)
.pushNamedAndRemoveUntil(loginRoute, (route) => false);
}
}
// read provider home
ref.listen(
ChangePasswordProvider,
(previous, next) {
if (next is ChangePasswordStateLoading) {
loading.value = true;
} else if (next is ChangePasswordStateError) {
loading.value = false;
SanckbarWidget(context, next.message, snackbarType.error);
} else if (next is ChangePasswordStateDone) {
loading.value = false;
SanckbarWidget(
context,
"Ubah Password Berhasil!\nSilahkan Login dengan password baru",
snackbarType.success,
);
Logout();
}
},
);
return Padding(
padding: EdgeInsets.only(
top: Constant.getActualYPhone(context: context, y: 30)),
child: Scaffold(
appBar: AppBar(
// centerTitle: true,
title: Text(
'Change Password',
style: TextStyle(color: Constant.textWhite),
),
backgroundColor: Constant.pcBtnBackgroundColor,
iconTheme: IconThemeData(
color: Constant.textWhite,
),
),
drawer: CustomDrawer(),
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(20),
child: Container(
width: Constant.getActualXPhone(context: context, x: 390),
height: Constant.getActualYPhone(context: context, y: 844),
child: Column(
children: [
//Old password
Padding(
padding: EdgeInsets.only(
// top: Constant.getActualYPhone(context: context, y: 63),
left: Constant.getActualXPhone(context: context, x: 20),
right: Constant.getActualXPhone(context: context, x: 20),
),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
'Old Password',
style: Constant.body1_400_dibulan(context: context)
.copyWith(
fontWeight: FontWeight.w600,
color: Constant.textBlack),
),
),
),
SizedBox(
height: Constant.getActualYPhone(context: context, y: 4),
),
Padding(
padding: EdgeInsets.only(
top: Constant.getActualYPhone(context: context, y: 5),
left: Constant.getActualXPhone(context: context, x: 20),
right: Constant.getActualXPhone(context: context, x: 20),
),
child: TextField(
obscureText: obscureText.value,
controller: ctrlOldPassword,
decoration: InputDecoration(
suffixIcon: IconButton(
icon: Icon(
obscureText.value
? Icons.visibility
: Icons.visibility_off,
color: Constant.textGreyv2,
),
onPressed: () {
obscureText.value = !obscureText.value;
},
),
hintStyle:
Constant.body2_400(context: context).copyWith(
color: Constant.textGreyv2,
),
labelStyle:
Constant.body2_400(context: context).copyWith(
color: Constant.textGreyv2,
),
border: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.orange,
width: 1,
),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Constant.textGreyv2,
width: 1,
),
),
labelText: "OldPassword",
hintText: 'Old Password',
),
),
),
SizedBox(
height: Constant.getActualYPhone(context: context, y: 40),
),
//New password
Padding(
padding: EdgeInsets.only(
// top: Constant.getActualYPhone(context: context, y: 63),
left: Constant.getActualXPhone(context: context, x: 20),
right: Constant.getActualXPhone(context: context, x: 20),
),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
'New Password',
style: Constant.body1_400_dibulan(context: context)
.copyWith(
fontWeight: FontWeight.w600,
color: Constant.textBlack),
),
),
),
SizedBox(
height: Constant.getActualYPhone(context: context, y: 4),
),
Padding(
padding: EdgeInsets.only(
top: Constant.getActualYPhone(context: context, y: 5),
left: Constant.getActualXPhone(context: context, x: 20),
right: Constant.getActualXPhone(context: context, x: 20),
),
child: TextField(
obscureText: obscureText.value,
controller: ctrlNewPassword,
decoration: InputDecoration(
suffixIcon: IconButton(
icon: Icon(
obscureText.value
? Icons.visibility
: Icons.visibility_off,
color: Constant.textGreyv2,
),
onPressed: () {
obscureText.value = !obscureText.value;
},
),
hintStyle:
Constant.body2_400(context: context).copyWith(
color: Constant.textGreyv2,
),
labelStyle:
Constant.body2_400(context: context).copyWith(
color: Constant.textGreyv2,
),
border: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.orange,
width: 1,
),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Constant.textGreyv2,
width: 1,
),
),
labelText: "New Password",
hintText: 'New Password',
),
),
),
SizedBox(
height: Constant.getActualYPhone(context: context, y: 40),
),
// Confirm password
Padding(
padding: EdgeInsets.only(
// top: Constant.getActualYPhone(context: context, y: 63),
left: Constant.getActualXPhone(context: context, x: 20),
right: Constant.getActualXPhone(context: context, x: 20),
),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
'Confirm Password',
style: Constant.body1_400_dibulan(context: context)
.copyWith(
fontWeight: FontWeight.w600,
color: Constant.textBlack),
),
),
),
SizedBox(
height: Constant.getActualYPhone(context: context, y: 4),
),
Padding(
padding: EdgeInsets.only(
top: Constant.getActualYPhone(context: context, y: 5),
left: Constant.getActualXPhone(context: context, x: 20),
right: Constant.getActualXPhone(context: context, x: 20),
),
child: TextField(
obscureText: obscureText.value,
controller: ctrlConfirmPassword,
decoration: InputDecoration(
suffixIcon: IconButton(
icon: Icon(
obscureText.value
? Icons.visibility
: Icons.visibility_off,
color: Constant.textGreyv2,
),
onPressed: () {
obscureText.value = !obscureText.value;
},
),
hintStyle:
Constant.body2_400(context: context).copyWith(
color: Constant.textGreyv2,
),
labelStyle:
Constant.body2_400(context: context).copyWith(
color: Constant.textGreyv2,
),
border: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.orange,
width: 1,
),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Constant.textGreyv2,
width: 1,
),
),
labelText: "Confirm Password",
hintText: 'Confirm Password',
),
),
),
SizedBox(
height: Constant.getActualYPhone(context: context, y: 50),
),
//Button Update Password
Padding(
padding: EdgeInsets.only(
left: Constant.getActualXPhone(context: context, x: 20),
right: Constant.getActualXPhone(context: context, x: 20),
),
child: SizedBox(
width: Constant.getActualXPhone(context: context, x: 390),
height: Constant.getActualYPhone(context: context, y: 50),
child: ElevatedButton(
onPressed: (loading.value == true)
? null
: () {
if (ctrlNewPassword.text !=
ctrlConfirmPassword.text) {
SanckbarWidget(
context,
'New Password dan dan confirm password tidak sama!',
snackbarType.warning);
return;
}
if (ctrlOldPassword.text ==
ctrlConfirmPassword.text) {
SanckbarWidget(
context,
'Password lama dan baru tidak boleh sama',
snackbarType.warning);
return;
}
if (ctrlOldPassword.text.isEmpty ||
ctrlNewPassword.text.isEmpty ||
ctrlConfirmPassword.text.isEmpty) {
isLoading.value = true;
SanckbarWidget(context, 'Inputan harus diisi',
snackbarType.warning);
} else {
ref
.read(ChangePasswordProvider.notifier)
.postChangePassword(
userTokenx: tokenx,
userToken: userToken,
userID: userID,
oldPassword: ctrlOldPassword.text,
newPassword: ctrlNewPassword.text,
confirmPassword:
ctrlConfirmPassword.text,
);
}
},
style: ButtonStyle(
backgroundColor: MaterialStateColor.resolveWith(
(st) => (loading.value == true)
? Constant.textGrey
: Constant.pcBtnBackgroundColor),
shape:
MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
side: BorderSide(
color: Constant.pcBtnBackgroundColor,
),
),
),
shadowColor:
MaterialStateProperty.all(Color(0xffff48423d)),
elevation: MaterialStateProperty.all(4.0),
),
child: Stack(
children: [
(isLoading.value)
? SizedBox(
width: Constant.getActualXPhone(
context: context, x: 24),
height: Constant.getActualYPhone(
context: context, y: 32),
child: Center(
child: CircularProgressIndicator(
color: Colors.white,
),
),
)
: Align(
alignment: Alignment.center,
child: Text(
'Submit',
style: Constant.titleH3_700(
context: context)
.copyWith(
color: Constant.textLoginColor),
),
),
],
),
),
),
),
],
),
),
),
),
),
);
}
}

View File

@@ -272,6 +272,28 @@ class CustomDrawer extends HookConsumerWidget {
ref.read(currentPageProvider.state).update((state) => 4);
Navigator.pushNamed(context, changeCompanyRoute);
},
),
ListTile(
leading: Icon(
Icons.lock_reset,
color: (currentMenu == 5)
? Constant.pcBtnBackgroundColor
: Constant.textGreyv2,
),
title: Text(
'Change Password',
style: TextStyle(
color: (currentMenu == 5)
? Constant.pcBtnBackgroundColor
: Constant.textGreyv2,
),
),
onTap: () {
// Handle navigation to Transaksi screen
Navigator.pop(context);
ref.read(currentPageProvider.state).update((state) => 5);
Navigator.pushNamed(context, changePasswordRoute);
},
),
ListTile(
leading: Icon(

View File

@@ -85,10 +85,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
url: "https://pub.dev"
source: hosted
version: "1.17.1"
version: "1.18.0"
convert:
dependency: transitive
description:
@@ -444,26 +444,26 @@ packages:
dependency: transitive
description:
name: matcher
sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb"
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
url: "https://pub.dev"
source: hosted
version: "0.12.15"
version: "0.12.16"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
url: "https://pub.dev"
source: hosted
version: "0.2.0"
version: "0.5.0"
meta:
dependency: transitive
description:
name: meta
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.10.0"
mime:
dependency: "direct main"
description:
@@ -697,18 +697,18 @@ packages:
dependency: transitive
description:
name: source_span
sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.10.0"
stack_trace:
dependency: transitive
description:
name: stack_trace
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
url: "https://pub.dev"
source: hosted
version: "1.11.0"
version: "1.11.1"
state_notifier:
dependency: transitive
description:
@@ -721,10 +721,10 @@ packages:
dependency: transitive
description:
name: stream_channel
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
url: "https://pub.dev"
source: hosted
version: "2.1.1"
version: "2.1.2"
string_scanner:
dependency: transitive
description:
@@ -745,10 +745,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
url: "https://pub.dev"
source: hosted
version: "0.5.1"
version: "0.6.1"
top_snackbar_flutter:
dependency: "direct main"
description:
@@ -901,6 +901,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.17"
web:
dependency: transitive
description:
name: web
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
url: "https://pub.dev"
source: hosted
version: "0.3.0"
whatsapp_share:
dependency: "direct main"
description:
@@ -942,5 +950,5 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=3.0.6 <4.0.0"
dart: ">=3.2.0-194.0.dev <4.0.0"
flutter: ">=3.10.0"