wt1.1a flutter_bloc

This commit is contained in:
Bossanyi Tibor
2020-08-17 12:38:47 +02:00
parent 8363d7772f
commit ac1c6be8f3
90 changed files with 4281 additions and 2854 deletions
+35
View File
@@ -0,0 +1,35 @@
import 'dart:async';
import 'package:aitrainer_app/util/session.dart';
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:meta/meta.dart';
part 'session_event.dart';
part 'session_state.dart';
class SessionBloc extends Bloc<SessionEvent, SessionState> {
final Session session;
SessionBloc({this.session}) : super(SessionInitial());
@override
Stream<SessionState> mapEventToState(
SessionEvent event,
) async* {
try {
if (event is SessionStart) {
yield SessionLoading();
await session.fetchSessionAndNavigate();
yield SessionReady();
}
} on Exception catch(ex) {
yield SessionFailure(message: ex.toString());
}
}
@override
Future<void> close() async {
await this.close(); super.close();
}
}
+16
View File
@@ -0,0 +1,16 @@
part of 'session_bloc.dart';
@immutable
abstract class SessionEvent extends Equatable {
const SessionEvent();
@override
List<Object> get props => [];
}
class SessionStart extends SessionEvent {
const SessionStart();
@override
List<Object> get props => [];
}
+32
View File
@@ -0,0 +1,32 @@
part of 'session_bloc.dart';
@immutable
abstract class SessionState extends Equatable {
const SessionState();
@override
List<Object> get props => [];
}
class SessionInitial extends SessionState {
const SessionInitial();
}
class SessionLoading extends SessionState {
const SessionLoading();
}
class SessionReady extends SessionState {
const SessionReady();
}
class SessionFailure extends SessionState {
final String message;
const SessionFailure({this.message});
@override
List<Object> get props => [message];
}