Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.6 kB
1
Indexable
Never
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:gravid_mobile_app/data/remote/api_base_helper.dart';
import 'package:gravid_mobile_app/data/remote/apis.dart';
import 'package:gravid_mobile_app/data/repos/register/register_sreen_repository.dart';
import 'package:equatable/equatable.dart';
part 'register_screen_state.dart';

class RegisterScreenCubit extends Cubit<RegisterScreenState> {
  final RegisterScreenRepository _registerScreenRepository;
  RegisterScreenCubit(this._registerScreenRepository)
      : super(const Initialized());

  Future<void> changeState() async {
    emit(Initialized());
  }

  Future<void> postRequest(
      String apiSelector, Map<String, dynamic> formData) async {
    try {
      emit(const Loading());

      _registerScreenRepository.postRequest(apiSelector, formData).then(
          (String event) {
        emit(
          LoadingSuccessful(posts: event),
        );
      }, onError: (error) {
        emit(LoadingFailed(error.toString()));
      });
    } catch (e) {
      emit(LoadingFailed(e.toString()));
    }
  }

  // Future<String> sendRequest(
  //     String apiSelector, Map<String, dynamic> formData) async {
  //   try {
  //     print('at fetch');
  //     final result = await apiBaseHelper!.post(
  //       url: Apis.registerApi,
  //       body: formData,
  //       headerObject: {},
  //     );
  //     final posts = result.data["message"];
  //     return posts;
  //   } catch (e) {
  //     return Future.error(e);
  //   }
  // }
}