api integration
This commit is contained in:
@@ -1,84 +0,0 @@
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'change_password_event.dart';
|
||||
import 'change_password_state.dart';
|
||||
|
||||
class ChangePasswordBloc
|
||||
extends Bloc<ChangePasswordEvent, ChangePasswordState> {
|
||||
final GlobalKey<FormState> formKey = GlobalKey<FormState>();
|
||||
|
||||
final TextEditingController currentPasswordTextField =
|
||||
TextEditingController();
|
||||
final TextEditingController passwordTextField = TextEditingController();
|
||||
final TextEditingController repeatPasswordTextField = TextEditingController();
|
||||
|
||||
GlobalKey<FormState> getFormKey() {
|
||||
return formKey;
|
||||
}
|
||||
|
||||
ChangePasswordBloc() : super(ChangePasswordInitial()) {
|
||||
currentPasswordTextField.addListener(_onFormFieldChanged);
|
||||
passwordTextField.addListener(_onFormFieldChanged);
|
||||
repeatPasswordTextField.addListener(_onFormFieldChanged);
|
||||
on<ChangePasswordFormChanged>(_onLoginFormChanged);
|
||||
on<ChangePasswordSubmitted>((event, emit) async {
|
||||
if (!formKey.currentState!.validate()) {
|
||||
return;
|
||||
}
|
||||
emit(ChangePasswordLoading());
|
||||
try {
|
||||
// Simulate API call
|
||||
await Future.delayed(const Duration(seconds: 2));
|
||||
// Replace the next line with actual API call
|
||||
final isSuccess = await _mockLoginApi(event.password);
|
||||
if (isSuccess) {
|
||||
emit(ChangePasswordSuccess());
|
||||
} else {
|
||||
emit(const ChangePasswordFailure(
|
||||
"Failed. Please check your credentials."));
|
||||
}
|
||||
} catch (e) {
|
||||
emit(ChangePasswordFailure(e.toString()));
|
||||
}
|
||||
});
|
||||
}
|
||||
void _onFormFieldChanged() {
|
||||
add(ChangePasswordFormChanged(
|
||||
currentPasswordTextField.text,
|
||||
passwordTextField.text,
|
||||
repeatPasswordTextField.text,
|
||||
));
|
||||
}
|
||||
|
||||
void _onLoginFormChanged(
|
||||
ChangePasswordFormChanged event, Emitter<ChangePasswordState> emit) {
|
||||
final areFieldsFilled = event.currentPassword.isNotEmpty &&
|
||||
event.password.isNotEmpty &&
|
||||
event.repeatPassword.isNotEmpty;
|
||||
emit(ChangePasswordFieldsState(areFieldsFilled));
|
||||
}
|
||||
|
||||
// Method to reset text fields
|
||||
void resetFields() {
|
||||
currentPasswordTextField.clear();
|
||||
passwordTextField.clear();
|
||||
repeatPasswordTextField.clear();
|
||||
}
|
||||
|
||||
// Mock API function, replace with actual API call
|
||||
Future<bool> _mockLoginApi(
|
||||
String phoneNumber,
|
||||
) async {
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> close() {
|
||||
passwordTextField.dispose();
|
||||
currentPasswordTextField.dispose();
|
||||
repeatPasswordTextField.dispose();
|
||||
|
||||
return super.close();
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
abstract class ChangePasswordEvent extends Equatable {
|
||||
const ChangePasswordEvent();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class ChangePasswordSubmitted extends ChangePasswordEvent {
|
||||
final String currentPassword;
|
||||
final String password;
|
||||
final String repeatPassword;
|
||||
|
||||
const ChangePasswordSubmitted(
|
||||
this.password,
|
||||
this.currentPassword,
|
||||
this.repeatPassword,
|
||||
);
|
||||
|
||||
@override
|
||||
List<Object> get props => [currentPassword, password, repeatPassword];
|
||||
}
|
||||
|
||||
class ChangePasswordFormChanged extends ChangePasswordEvent {
|
||||
final String currentPassword;
|
||||
final String password;
|
||||
final String repeatPassword;
|
||||
|
||||
const ChangePasswordFormChanged(
|
||||
this.currentPassword, this.password, this.repeatPassword);
|
||||
|
||||
@override
|
||||
List<Object> get props => [currentPassword, password, repeatPassword];
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
abstract class ChangePasswordState extends Equatable {
|
||||
const ChangePasswordState();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class ChangePasswordInitial extends ChangePasswordState {}
|
||||
|
||||
class ChangePasswordLoading extends ChangePasswordState {}
|
||||
|
||||
class ChangePasswordSuccess extends ChangePasswordState {}
|
||||
|
||||
class ChangePasswordFailure extends ChangePasswordState {
|
||||
final String error;
|
||||
|
||||
const ChangePasswordFailure(this.error);
|
||||
|
||||
@override
|
||||
List<Object> get props => [error];
|
||||
}
|
||||
|
||||
class ChangePasswordFieldsState extends ChangePasswordState {
|
||||
final bool areFieldsFilled;
|
||||
|
||||
const ChangePasswordFieldsState(this.areFieldsFilled);
|
||||
|
||||
@override
|
||||
List<Object> get props => [areFieldsFilled];
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import 'package:google_fonts/google_fonts.dart';
|
||||
import '../../../../core/styles/app_color.dart';
|
||||
import '../../../../core/styles/app_text.dart';
|
||||
import '../../../../core/utils/language/localizations_delegate.dart';
|
||||
import '../bloc/change_password_bloc.dart';
|
||||
import '../../bloc/change_password_bloc.dart';
|
||||
import 'change_password_layout.dart';
|
||||
|
||||
class ChangePasswordScreen extends StatelessWidget {
|
||||
|
||||
@@ -10,9 +10,9 @@ import '../../../../core/styles/app_color.dart';
|
||||
import '../../../../core/styles/app_text.dart';
|
||||
import '../../../../core/utils/language/localizations_delegate.dart';
|
||||
import '../../../../shared/components/button_widget.dart';
|
||||
import '../bloc/change_password_bloc.dart';
|
||||
import '../bloc/change_password_event.dart';
|
||||
import '../bloc/change_password_state.dart';
|
||||
import '../../bloc/change_password_bloc.dart';
|
||||
import '../../bloc/change_password_event.dart';
|
||||
import '../../bloc/change_password_state.dart';
|
||||
|
||||
class RestorePasswordBottomSection extends StatelessWidget {
|
||||
const RestorePasswordBottomSection({
|
||||
|
||||
@@ -11,7 +11,7 @@ import '../../../../shared/components/bloc/password_field/password_visibility_bl
|
||||
import '../../../../shared/components/button_widget.dart';
|
||||
import '../../../../shared/components/form_label_textfield.dart';
|
||||
import '../../../../shared/components/text_widget.dart';
|
||||
import '../bloc/change_password_bloc.dart';
|
||||
import '../../bloc/change_password_bloc.dart';
|
||||
|
||||
class RestorePasswordForm extends StatelessWidget {
|
||||
const RestorePasswordForm({super.key});
|
||||
|
||||
Reference in New Issue
Block a user