import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter/cupertino.dart';
import '../model/new_model.dart';
import '../request/new_request.dart';


part 'new_event.dart';
part 'new_state.dart';

class NewBloc extends Bloc<NewEvent, NewState> {
  NewBloc() : super(const NewInitial()) {
    on<RequestNew>((event, emit) async {
      await _requestNew(event, emit);
    });
  }

  Future<void> _requestNew(RequestNew event, Emitter<NewState> emit) async {
    RemoteNew remoteNew = RemoteNew();
    try {
      NewModel? newModel = await remoteNew.getNewModel();
      emit(NewSuccess(newModel!));
    } catch (e) {
      emit(const NewFailed('request false2!'));
    }
  }

  @override
  Future<void> close() {
    return super.close();
  }

}

