Skip to content
Snippets Groups Projects
Commit 01bf3aa2 authored by Andri Joos's avatar Andri Joos :blush:
Browse files

calendar error handling

parent 32a6dce9
No related branches found
No related tags found
1 merge request!10Resolve "Add icon"
Pipeline #5916 passed with stage
in 7 minutes and 37 seconds
......@@ -80,6 +80,7 @@ class App extends StatelessWidget {
ChangeNotifierProvider(create: (context) => CalendarViewModel(
calendarEventService: Provider.of(context, listen: false),
authenticationService: Provider.of(context, listen: false),
loggingService: Provider.of(context, listen: false),
)),
],
child: MaterialApp(
......
import 'package:car_app/exception/server.dart';
import 'package:car_app/model/calendar_event.dart';
import 'package:car_app/model/user.dart';
import 'package:car_app/service/interface/authentication.dart';
import 'package:car_app/service/interface/calendar_event.dart';
import 'package:car_app/service/interface/logging.dart';
import 'package:flutter/foundation.dart';
class CalendarViewModel extends ChangeNotifier {
final CalendarEventService calendarEventService;
final AuthenticationService authenticationService;
final LoggingService loggingService;
final List<CalendarEvent> events = [];
User? currentUser;
CalendarViewModel({required this.calendarEventService, required this.authenticationService}) {
CalendarViewModel({required this.calendarEventService, required this.authenticationService, required this.loggingService}) {
authenticationService.isLoggedIn().then((isLoggedIn) async {
if(isLoggedIn) {
currentUser = await authenticationService.user;
}
});
})
.catchError(
test: (e) => e is ServerException,
(e, s) => loggingService.error(e.toString(), exception: e, trace: s),
);
}
void addNewlyAddedCalendarEvent(CalendarEvent event) {
......@@ -38,7 +45,10 @@ class CalendarViewModel extends ChangeNotifier {
_addEvent(event);
});
}
});
})
.catchError(test: (e) => e is ServerException,
(e, s) => loggingService.error(e.toString(), exception: e, trace: s),
);
}
String avatarTextFromName(String name) {
......@@ -104,7 +114,11 @@ class CalendarViewModel extends ChangeNotifier {
calendarEventService.delete(event).then((event) {
_removeEvent(event);
undoToast(event);
});
})
.catchError(
test: (e) => e is ServerException,
(e, s) => loggingService.error(e.toString(), exception: e, trace: s),
);
}
}
......@@ -118,7 +132,14 @@ class CalendarViewModel extends ChangeNotifier {
calendarEventService.add(event).then((eventFromServer) {
_removeEvent(event);
_addEvent(eventFromServer);
});
})
.catchError(
test: (e) => e is ServerException,
(e, s) {
loggingService.error(e.toString(), exception: e, trace: s);
_removeEvent(event);
},
);
}
bool isEventFromCurrentUser(CalendarEvent event) {
......
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