import 'package:bloc/bloc.dart';
import 'package:flutter/material.dart';

import 'invest_payment_event.dart';
import 'invest_payment_state.dart';

class InvestPaymentBloc extends Bloc<InvestPaymentEvent, InvestPaymentState> {
  final GlobalKey<FormState> formKey = GlobalKey<FormState>();
  TextEditingController amountController = TextEditingController();

  GlobalKey<FormState> getFormKey() {
    return formKey;
  }

  InvestPaymentBloc() : super(const InvestPaymentState(isFormValid: false)) {
    on<FormTextChanged>((event, emit) {
      emit(state.copyWith(isFormValid: event.text.isNotEmpty));
    });
  }

  @override
  Future<void> close() {
    amountController.dispose();

    return super.close();
  }
}
