Created
August 20, 2020 12:10
-
-
Save guilhermecarvalhocarneiro/ad1a89be508a8b3197108aa0c44725a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:bloc/bloc.dart'; | |
import 'package:cubit_example/apps/usuario/model.dart'; | |
import 'package:equatable/equatable.dart'; | |
import '../service.dart'; | |
part 'usuario_state.dart'; | |
class UsuarioCubit extends Cubit<UsuarioState> { | |
UsuarioService _service; | |
List<String> cidades = []; | |
UsuarioCubit() : super(UsuarioInitial()) { | |
_service = UsuarioService(); | |
} | |
Future<void> fetch(UsuarioModel usuario) async { | |
try { | |
emit(UsuarioProcessState()); | |
emit(UsuarioSuccessState()); | |
} catch (e) { | |
emit(UsuarioErrorState(e.toString())); | |
} | |
} | |
Future<void> fetchEscola() async { | |
try { | |
emit(UsuarioProcessState()); | |
cidades = await _service.fetchAllCidadeEscola(); | |
emit( | |
UsuarioSuccessState(successMessage: "Dados carregados com sucesso.")); | |
} catch (e) { | |
emit(UsuarioErrorState(e.toString())); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment