Перенаправить обратно на вход после сброса пароля

Привет, после ввода электронной почты и нажатия кнопки «Отправить» для страницы с забытым паролем он остается на той же странице, я хотел бы перенаправить или отправить его обратно на страницу входа. В этой функции, где я должен добавить маршрут, находится на «локте», «состоянии» или на странице «формы».

это моя форма

      
class ForgotPasswordForm extends StatelessWidget {
  const ForgotPasswordForm({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return BlocListener<ForgotPasswordCubit, ForgotPasswordState>(
      listener: (context, state) {
        if (state.status.isSubmissionFailure) {
          ScaffoldMessenger.of(context)
            ..hideCurrentSnackBar()
            ..showSnackBar(
              SnackBar(
                content: Text(state.errorMessage ?? 'Authentication Failure'),
              ),
            );
        }
      },
      child: SizedBox(
        height: 570,
        width: MediaQuery.of(context).size.width,
        child: Column(
          children: [
            //const SizedBox(height: 16),
            Expanded(
              child: _EmailInput(),
            ),
            const SizedBox(height: 16),
            _ForgotPasswordButton(),
          ],
        ),
      ),
    );
  }
}

class _EmailInput extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return BlocBuilder<ForgotPasswordCubit, ForgotPasswordState>(
      buildWhen: (previous, current) => previous.email != current.email,
      builder: (context, state) {
        return TextField(
          key: const Key('loginForm_emailInput_textField'),
          onChanged: (email) =>
              context.read<ForgotPasswordCubit>().emailChanged(email),
          keyboardType: TextInputType.emailAddress,
          decoration: InputDecoration(
            labelText: 'Email',
            helperText: '',
            errorText: state.email.invalid ? 'invalid email' : null,
            filled: true,
            fillColor: Colors.white,
            hintStyle: const TextStyle(color: Colors.black),
            labelStyle: const TextStyle(color: Colors.black),
            prefixIcon: const Icon(Icons.mail, color: Colors.black),
            border:
                OutlineInputBorder(borderRadius: BorderRadius.circular(15.0)),
            focusedBorder: const OutlineInputBorder(
                borderSide: BorderSide(color: Colors.white, width: 0.0)),
          ),
          style: const TextStyle(
            color: Color.fromARGB(255, 0, 0, 0),
            fontWeight: FontWeight.bold,
          ),
        );
      },
    );
  }
}

class _ForgotPasswordButton extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return BlocBuilder<ForgotPasswordCubit, ForgotPasswordState>(
      buildWhen: (previous, current) => previous.status != current.status,
      builder: (context, state) {
        return state.status.isSubmissionInProgress
            ? const CircularProgressIndicator()
            : Container(
                width: 400,
                //color: Colors.white,
                padding: EdgeInsets.fromLTRB(30, 0, 30, 0),
                child: ElevatedButton(
                  key: const Key('loginForm_continue_raisedButton'),
                  style: ButtonStyle(
                      minimumSize:
                          MaterialStateProperty.all(const Size.fromHeight(50)),
                      backgroundColor: MaterialStateProperty.all(
                        const Color.fromARGB(255, 62, 186, 34),
                      ),
                      shape: MaterialStateProperty.all<RoundedRectangleBorder>(
                          RoundedRectangleBorder(
                        // borderRadius: BorderRadius.zero,
                        borderRadius: BorderRadius.circular(15.0),
                      ))),
                  onPressed: state.status.isValidated
                      ? () => context
                          .read<ForgotPasswordCubit>()
                          .sendForgotPassword()
                      : null,
                  child: const Padding(
                    padding: EdgeInsets.all(10),
                    child: Text('Sends',
                        style: TextStyle(
                          color: Colors.white,
                          fontWeight: FontWeight.bold,
                          fontSize: 17,
                          fontFamily: 'Montserrat',
                        )),
                  ),
                ),
              );
      },
    );
  }
}

Я попытался перейти на локоть и состояние и все еще не знаю, как направить его обратно

Локоть

      class ForgotPasswordCubit extends Cubit<ForgotPasswordState> {
  ForgotPasswordCubit(this._authenticationRepository)
      : super(const ForgotPasswordState());

  final AuthenticationRepository _authenticationRepository;

  void emailChanged(String value) {
    final email = Email.dirty(value);
    emit(state.copyWith(
      email: email,
      status: Formz.validate([email]),
    ));
  }

  Future<void> sendForgotPassword() async {
    if (!state.status.isValidated) return;
    emit(state.copyWith(status: FormzStatus.submissionInProgress));
    try {
      await _authenticationRepository.forgotPasswordEmail(
          email: state.email.value);
      emit(state.copyWith(status: FormzStatus.submissionSuccess));
      MaterialPageRoute<void>(builder: (_) => const LoginPage());
    } on LogInWithEmailAndPasswordFailure catch (e) {
      emit(state.copyWith(
        errorMessage: e.message,
        status: FormzStatus.submissionFailure,
      ));
    } catch (_) {
      emit(state.copyWith(status: FormzStatus.submissionFailure));
    }
  }
}

Состояние

      part of 'forgot_password_cubit.dart';

class ForgotPasswordState extends Equatable {
  const ForgotPasswordState({
    this.email = const Email.pure(),
    this.status = FormzStatus.pure,
    this.errorMessage,
  });

  final Email email;
  final FormzStatus status;
  final String? errorMessage;

  @override
  List<Object> get props => [email, status];

  ForgotPasswordState copyWith({
    Email? email,
    FormzStatus? status,
    String? errorMessage,
  }) {
    return ForgotPasswordState(
      email: email ?? this.email,
      status: status ?? this.status,
      errorMessage: errorMessage ?? this.errorMessage,
    );
  }
}

0 ответов

Другие вопросы по тегам