Commit 755d922c authored by Leon Tappe's avatar Leon Tappe 🔥
Browse files

upgrade to bloc 3.0 package

parent 7b92119b
......@@ -23,9 +23,9 @@ class AdminsBloc extends Bloc<AdminsEvent, AdminsState> {
AdminsState get initialState => AdminsState.init();
@override
void dispose() {
_log.info('disposing of $this');
super.dispose();
Future<void> close() {
_log.info('closing $this');
return super.close();
}
@override
......@@ -45,17 +45,17 @@ class AdminsBloc extends Bloc<AdminsEvent, AdminsState> {
}
}
void onCreateAdmin(String firstName, String lastName, String password, {String login}) =>
add(AddAdmin(firstName, lastName, login, password));
void onStart(String token) => add(InitAdmins(token));
@override
void onTransition(Transition<AdminsEvent, AdminsState> transition) {
_log.fine('Transition from ${transition.currentState} to ${transition.nextState}');
super.onTransition(transition);
}
void onStart(String token) => dispatch(InitAdmins(token));
void onCreateAdmin(String firstName, String lastName, String password, {String login}) =>
dispatch(AddAdmin(firstName, lastName, login, password));
Future<Admin> _postAdmin(String firstName, String lastName, String password,
{String login}) async {
_log.fine('_postAdmin: run for $lastName, $firstName ($login)');
......
......@@ -22,14 +22,14 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
AuthState get initialState => AuthState.unauthorized();
@override
void dispose() {
log.fine('disposing of $this');
super.dispose();
Future<void> close() {
log.fine('closing $this');
return super.close();
}
void login(String username, String password) => dispatch(Login(username, password));
void login(String username, String password) => add(Login(username, password));
void logout() => dispatch(Logout());
void logout() => add(Logout());
@override
Stream<AuthState> mapEventToState(AuthEvent event) async* {
......@@ -61,7 +61,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
super.onTransition(transition);
}
void tokenLogin(String token) => dispatch(TokenLogin(token));
void tokenLogin(String token) => add(TokenLogin(token));
Future<void> _postLogin(String user, String password) async {
log.finer('_postLogin: $user, $password');
......
......@@ -24,9 +24,9 @@ class DispatcherBloc extends Bloc<DispatcherEvent, DispatcherState> {
DispatcherState get initialState => DispatcherState.init();
@override
void dispose() {
_l.fine('disposing of $this');
super.dispose();
Future<void> close() {
_l.fine('closing $this');
return super.close();
}
@override
......@@ -55,9 +55,9 @@ class DispatcherBloc extends Bloc<DispatcherEvent, DispatcherState> {
}
}
void onStart(String token) => dispatch(InitDispatcher(token));
void onStart(String token) => add(InitDispatcher(token));
void onRefresh() => dispatch(GetTasks());
void onRefresh() => add(GetTasks());
Future<List<DispatcherTask>> _getQueue() async {
_l.finer('_getQueue');
......
......@@ -30,9 +30,9 @@ class JournalBloc extends Bloc<JournalEvent, JournalState> {
JournalState get initialState => JournalState.init();
@override
void dispose() {
log.fine('disposing of $this');
super.dispose();
Future<void> close() {
log.fine('closing $this');
return super.close();
}
@override
......@@ -86,13 +86,13 @@ class JournalBloc extends Bloc<JournalEvent, JournalState> {
}
}
void onRefresh() => dispatch(RefreshJournal());
void onRefresh() => add(RefreshJournal());
void onStart(String token) => dispatch(InitJournal(token));
void onStart(String token) => add(InitJournal(token));
void onAddTransaction(int userId, int adminId, int value, String description,
{bool withoutReceipt = false}) =>
dispatch(AddTransaction(userId, adminId, value, description, withoutReceipt));
add(AddTransaction(userId, adminId, value, description, withoutReceipt));
@override
void onTransition(Transition<JournalEvent, JournalState> transition) {
......@@ -100,9 +100,9 @@ class JournalBloc extends Bloc<JournalEvent, JournalState> {
super.onTransition(transition);
}
void onFilterJournal(Transaction filter) => dispatch(FilterJournal(filter));
void onFilterJournal(Transaction filter) => add(FilterJournal(filter));
void onFuzzyFilterJournal(String filter) => dispatch(FuzzyFilterJournal(filter));
void onFuzzyFilterJournal(String filter) => add(FuzzyFilterJournal(filter));
bool _filterJournal(Transaction filter) {
_journalFiltered = [];
......
......@@ -27,9 +27,9 @@ class JournalTokenBloc extends Bloc<JournalTokenEvent, JournalTokenState> {
JournalTokenState get initialState => JournalTokenState.init();
@override
void dispose() {
log.fine('disposing of $this');
super.dispose();
Future<void> close() {
log.fine('closing $this');
return super.close();
}
@override
......@@ -60,11 +60,11 @@ class JournalTokenBloc extends Bloc<JournalTokenEvent, JournalTokenState> {
}
}
void onRefresh() => dispatch(RefreshJournalToken());
void onRefresh() => add(RefreshJournalToken());
void onStart(String token) => dispatch(InitJournalToken(token));
void onStart(String token) => add(InitJournalToken(token));
void onCreateToken(int value) => dispatch(CreateJournalToken(value));
void onCreateToken(int value) => add(CreateJournalToken(value));
@override
void onTransition(Transition<JournalTokenEvent, JournalTokenState> transition) {
......
......@@ -25,9 +25,9 @@ class PrintQueueBloc extends Bloc<PrintQueueEvent, PrintQueueState> {
PrintQueueState get initialState => PrintQueueState.init();
@override
void dispose() {
log.fine('disposing of $this with device id $_printer');
super.dispose();
Future<void> close() {
log.fine('closing $this with device id $_printer');
return super.close();
}
@override
......@@ -58,16 +58,16 @@ class PrintQueueBloc extends Bloc<PrintQueueEvent, PrintQueueState> {
}
}
void onCancelJobs() => dispatch(CancelJob(_printer));
void onCancelJobs() => add(CancelJob(_printer));
void onRefresh() => dispatch(GetQueue(_printer));
void onRefresh() => add(GetQueue(_printer));
void onSetPrinter(int deviceId) {
_printer = deviceId;
log.fine('printer set to $_printer');
}
void onStart(String token) => dispatch(InitPrintQueue(token));
void onStart(String token) => add(InitPrintQueue(token));
@override
void onTransition(Transition<PrintQueueEvent, PrintQueueState> transition) {
......
......@@ -32,9 +32,9 @@ class PrintersBloc extends Bloc<PrintersEvent, PrintersState> {
PrintersState get initialState => PrintersState.init();
@override
void dispose() {
log.fine('disposing of $this');
super.dispose();
Future<void> close() {
log.fine('closing $this');
return super.close();
}
@override
......@@ -111,26 +111,26 @@ class PrintersBloc extends Bloc<PrintersEvent, PrintersState> {
bool hasA3,
bool coinOperated,
}) {
dispatch(AddPrinter(
add(AddPrinter(
deviceId,
PrinterDetails(hostname, ip, community, mac, location, description, deviceId, hasA3,
coinOperated, null)));
}
void onDeletePrinter(int deviceId) => dispatch(DeletePrinter(deviceId));
void onDeletePrinter(int deviceId) => add(DeletePrinter(deviceId));
void onFilterPrinters(PrinterDetails filter) => dispatch(FilterPrinters(filter));
void onFilterPrinters(PrinterDetails filter) => add(FilterPrinters(filter));
void onFuzzyFilterPrinters(String filter) => dispatch(FuzzyFilterPrinters(filter));
void onFuzzyFilterPrinters(String filter) => add(FuzzyFilterPrinters(filter));
void onRefresh() => dispatch(RefreshPrinters());
void onRefresh() => add(RefreshPrinters());
void onRefreshPrinterById(int id) => dispatch(GetPrinterDetails(id));
void onRefreshPrinterById(int id) => add(GetPrinterDetails(id));
void onSortPrinters(SortParam param, SortDirection direction) =>
dispatch(SortPrinters(param, direction));
add(SortPrinters(param, direction));
void onStart(String token) => dispatch(InitPrinters(token));
void onStart(String token) => add(InitPrinters(token));
@override
void onTransition(Transition<PrintersEvent, PrintersState> transition) {
......@@ -154,7 +154,7 @@ class PrintersBloc extends Bloc<PrintersEvent, PrintersState> {
bool watchTray3,
int watchInterval,
}) {
dispatch(UpdatePrinter(
add(UpdatePrinter(
deviceId,
PrinterDetails(
hostname,
......
......@@ -28,9 +28,9 @@ class UsersBloc extends Bloc<UsersEvent, UsersState> {
UsersState get initialState => UsersState.init();
@override
void dispose() {
log.fine('disposing of $this');
super.dispose();
Future<void> close() {
log.fine('closing $this');
return super.close();
}
@override
......@@ -119,25 +119,25 @@ class UsersBloc extends Bloc<UsersEvent, UsersState> {
}
void onCreateUser(String name, String password, {int card, int pin}) =>
dispatch(CreateUser(name, password, card: card, pin: pin));
add(CreateUser(name, password, card: card, pin: pin));
void onFilterByUser(String username) => dispatch(FilterUsers(username));
void onFilterByUser(String username) => add(FilterUsers(username));
void onGetCredit(int userId) => dispatch(GetCredit(userId));
void onGetCredit(int userId) => add(GetCredit(userId));
void onGetJournal(int userId) => dispatch(GetJournal(userId));
void onGetJournal(int userId) => add(GetJournal(userId));
void onRefresh() => dispatch(RefreshUsers());
void onRefresh() => add(RefreshUsers());
void onResetPassword(int id) => dispatch(ResetPassword(id));
void onResetPassword(int id) => add(ResetPassword(id));
void onSetEmail(int id, String email) => dispatch(SetEmail(id, email));
void onSetEmail(int id, String email) => add(SetEmail(id, email));
void onSetPassword(int id, String password) => dispatch(SetPassword(id, password));
void onSetPassword(int id, String password) => add(SetPassword(id, password));
void onSetUsername(int id, String name) => dispatch(SetName(id, name));
void onSetUsername(int id, String name) => add(SetName(id, name));
void onStart(String token) => dispatch(InitUsers(token));
void onStart(String token) => add(InitUsers(token));
@override
void onTransition(Transition<UsersEvent, UsersState> transition) {
......@@ -145,7 +145,7 @@ class UsersBloc extends Bloc<UsersEvent, UsersState> {
super.onTransition(transition);
}
void onUpdateLocked(int userId, bool locked) => dispatch(UpdateLocked(userId, locked));
void onUpdateLocked(int userId, bool locked) => add(UpdateLocked(userId, locked));
Future<void> _getCredit(int userId) async {
log.finer('_getCredit: $userId');
......
......@@ -10,7 +10,7 @@ environment:
dependencies:
logging: ^0.11.4
bloc: ^0.14.4
bloc: ^3.0.0
http: ^0.12.0+4
meta: ^1.1.8
......
......@@ -19,12 +19,12 @@ void main() {
setUpAll(() async {
bloc = JournalBloc(Client());
bloc.onStart(await getToken(user, pw));
await bloc.state.takeWhile((state) => state.isResult != true).toList();
await bloc.takeWhile((state) => state.isResult != true).toList();
});
test('get journal', () {
StreamSubscription listener;
listener = bloc.state.skip(1).listen(expectAsync1(
listener = bloc.skip(1).listen(expectAsync1(
(JournalState state) {
if (state.isException) {
fail('exception in bloc');
......@@ -37,4 +37,8 @@ void main() {
));
bloc.onRefresh();
});
tearDownAll(() async {
await bloc.close();
});
}
......@@ -19,13 +19,13 @@ void main() {
setUpAll(() async {
bloc = PrintersBloc(Client());
bloc.onStart(await getToken(user, pw));
await bloc.state.takeWhile((state) => state.isResult != true).toList();
await bloc.takeWhile((state) => state.isResult != true).toList();
});
group('filter tests', () {
test('filter printers by hostname', () {
StreamSubscription listener;
listener = bloc.state.skip(1).listen(expectAsync1(
listener = bloc.skip(1).listen(expectAsync1(
(PrintersState state) {
if (state.isException) {
fail('exception in bloc');
......@@ -41,7 +41,7 @@ void main() {
test('filter printers by ip', () {
StreamSubscription listener;
listener = bloc.state.skip(1).listen(expectAsync1(
listener = bloc.skip(1).listen(expectAsync1(
(PrintersState state) {
if (state.isException) {
fail('exception in bloc');
......@@ -59,7 +59,7 @@ void main() {
group('sort tests', () {
test('sort printers by location ascending', () {
StreamSubscription listener;
listener = bloc.state.skip(1).listen(expectAsync1(
listener = bloc.skip(1).listen(expectAsync1(
(PrintersState state) {
if (state.isException) {
fail('exception in bloc');
......@@ -75,7 +75,7 @@ void main() {
test('sort printers by hostname descending', () {
StreamSubscription listener;
listener = bloc.state.skip(1).listen(expectAsync1(
listener = bloc.skip(1).listen(expectAsync1(
(PrintersState state) {
if (state.isException) {
fail('exception in bloc');
......@@ -91,7 +91,7 @@ void main() {
test('sort printers by coinOperated ascending', () {
StreamSubscription listener;
listener = bloc.state.skip(1).listen(expectAsync1(
listener = bloc.skip(1).listen(expectAsync1(
(PrintersState state) {
if (state.isException) {
fail('exception in bloc');
......@@ -107,7 +107,7 @@ void main() {
test('sort printers by hostname descending after filtering by location', () {
StreamSubscription listener;
listener = bloc.state.skip(1).listen(expectAsync1((PrintersState state) {
listener = bloc.skip(1).listen(expectAsync1((PrintersState state) {
if (state.isException) {
fail('exception in bloc');
} else if (state.isResult) {
......@@ -121,7 +121,7 @@ void main() {
});
});
tearDownAll(() {
bloc.dispose();
tearDownAll(() async {
await bloc.close();
});
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment