Skip to content

Commit

Permalink
Fix Calendar Decoding, Optimize Error Handling, Fix Movie Cards (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobkoerber committed Nov 1, 2023
1 parent 0c8a609 commit e577e6d
Show file tree
Hide file tree
Showing 37 changed files with 146 additions and 45 deletions.
7 changes: 7 additions & 0 deletions lib/base/enums/error_handling_view_type.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
enum ErrorHandlingViewType {
fullScreen,
fullScreenNoImage,
textOnly,
descriptionOnly,
redDescriptionOnly
}
1 change: 1 addition & 0 deletions lib/base/localization/l10n/app_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@
"requestCancelled":"Anfrage abgebrochen",
"pleaseReport":"Bitte melden Sie dies als Fehler \nper E-Mail oder auf GitHub",
"connectionTimeout":"Zeitüberschreitung",
"decodingError":"Dekodierungsfehler",
"unknownError":"Unbekannter Fehler",
"monday":"Montag",
"tuesday":"Dienstag",
Expand Down
1 change: 1 addition & 0 deletions lib/base/localization/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@
"requestCancelled":"Request Cancelled",
"pleaseReport":"Please report this is as a bug \nvia Email or on GitHub",
"connectionTimeout":"Connection Timeout",
"decodingError":"Decoding Error",
"unknownError":"Unknown Error",
"monday":"Monday",
"tuesday":"Tuesday",
Expand Down
8 changes: 6 additions & 2 deletions lib/base/networking/protocols/main_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,19 @@ class MainApi {
.data;
} on U catch (e) {
/// rethrow error if specified error U
e.toString();
log(e.toString());
rethrow;
} catch (_) {
/// catch possible decoding error and return actual expected object
try {
return ApiResponse<T>.fromJson(jsonDecode(response.data.toString()),
response.headers, createObject);
} catch (e) {
log(e.toString());
if (e is Error) {
log(e.stackTrace.toString());
} else {
log(e.toString());
}
rethrow;
}
}
Expand Down
88 changes: 72 additions & 16 deletions lib/base/views/error_handling_view.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:campus_flutter/base/enums/error_handling_view_type.dart';
import 'package:campus_flutter/base/extensions/custom_exception.dart';
import 'package:campus_flutter/base/networking/apis/tumOnlineApi/tum_online_api_exception.dart';
import 'package:campus_flutter/searchComponent/model/search_exception.dart';
Expand Down Expand Up @@ -71,6 +72,9 @@ class ErrorHandlingView extends StatelessWidget {
} else if (error is CustomException) {
final exception = error as CustomException;
return _exceptionMessage(context, exception.message, null);
} else if (error is TypeError) {
return _exceptionMessage(context, context.localizations.decodingError,
context.localizations.pleaseReport);
} else {
return _exceptionMessage(context, context.localizations.unknownError,
context.localizations.pleaseReport);
Expand All @@ -95,11 +99,15 @@ class ErrorHandlingView extends StatelessWidget {
Expanded(
flex: 0,
child: Column(children: [
Text(errorMessage,
style: Theme.of(context).textTheme.titleLarge?.copyWith(
color: titleColor ?? Theme.of(context).primaryColor),
maxLines: 1,
overflow: TextOverflow.ellipsis),
_errorMessageText(
errorMessage,
context,
style: Theme.of(context).textTheme.titleLarge?.copyWith(
color: titleColor ?? Theme.of(context).primaryColor,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
if (fixMessage != null)
Text(fixMessage,
style: Theme.of(context)
Expand All @@ -121,8 +129,9 @@ class ErrorHandlingView extends StatelessWidget {
case ErrorHandlingViewType.textOnly:
return Center(
child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
Text(
_errorMessageText(
errorMessage,
context,
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
color: titleColor ?? Theme.of(context).primaryColor),
textAlign: TextAlign.center,
Expand All @@ -135,19 +144,66 @@ class ErrorHandlingView extends StatelessWidget {
);
case ErrorHandlingViewType.descriptionOnly:
return Center(
child: Text(errorMessage, style: TextStyle(color: bodyColor)));
child: _errorMessageText(
errorMessage,
context,
style: TextStyle(color: bodyColor),
),
);
case ErrorHandlingViewType.redDescriptionOnly:
return Center(
child:
Text(errorMessage, style: const TextStyle(color: Colors.red)));
child: _errorMessageText(
errorMessage,
context,
style: const TextStyle(color: Colors.red),
),
);
}
}
}

enum ErrorHandlingViewType {
fullScreen,
fullScreenNoImage,
textOnly,
descriptionOnly,
redDescriptionOnly
Widget _errorMessageText(String errorMessage, BuildContext context,
{TextStyle? style,
TextAlign? textAlign,
int? maxLines,
TextOverflow? overflow}) {
return GestureDetector(
onDoubleTap: () => showStackTrace(context),
child: Text(
errorMessage,
style: style,
textAlign: textAlign,
maxLines: maxLines,
overflow: overflow,
),
);
}

showStackTrace(BuildContext context) {
if (error is Error) {
showDialog(
context: context,
builder: (context) {
final split = (error as Error).stackTrace.toString().split("\n");
return AlertDialog(
title: Text(
"Error Description",
style: Theme.of(context).textTheme.titleMedium,
textAlign: TextAlign.center,
),
content: Text(
split.isNotEmpty
? split.first
: (error as Error).stackTrace.toString(),
textAlign: TextAlign.center,
),
actions: [
ElevatedButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text("Okay"))
],
actionsAlignment: MainAxisAlignment.center,
);
});
}
}
}
17 changes: 8 additions & 9 deletions lib/calendarComponent/model/calendar_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,21 @@ class CalendarEvent extends Searchable {
@JsonKey(name: "nr")
final String id;
final String status;
final String url;
final String? url;
final String title;
@JsonKey(name: "description")
final String descriptionText;
final String? description;
@JsonKey(name: "dtstart")
final DateTime startDate;
@JsonKey(name: "dtend")
final DateTime endDate;
final String location;
final String? location;

Duration get duration {
return endDate.difference(startDate);
}

String? get lvNr {
return url.split("LvNr=").last;
return url?.split("LvNr=").last;
}

String get timePeriod {
Expand Down Expand Up @@ -79,18 +78,18 @@ class CalendarEvent extends Searchable {
@JsonKey(includeFromJson: false, includeToJson: false)
List<ComparisonToken> get comparisonTokens => [
ComparisonToken(value: title),
ComparisonToken(value: location),
if (location != null) ComparisonToken(value: location!),
];

CalendarEvent(
{required this.id,
required this.status,
required this.url,
this.url,
required this.title,
required this.descriptionText,
this.description,
required this.startDate,
required this.endDate,
required this.location});
this.location});

factory CalendarEvent.fromJson(Map<String, dynamic> json) =>
_$CalendarEventFromJson(json);
Expand Down
8 changes: 4 additions & 4 deletions lib/calendarComponent/model/calendar_event.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion lib/calendarComponent/views/appointment_view.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:campus_flutter/calendarComponent/model/calendar_event.dart';
import 'package:campus_flutter/theme.dart';
import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_calendar/calendar.dart';

Expand Down Expand Up @@ -30,7 +31,9 @@ class AppointmentView extends StatelessWidget {
.compareTo(const Duration(hours: 0, minutes: 45)) >
0)
_eventLocation(
calendarEvent.location, calendarEvent.isCanceled, context),
calendarEvent.location ?? context.localizations.unknown,
calendarEvent.isCanceled,
context),
if (calendarEvent.endDate
.difference(calendarEvent.startDate)
.compareTo(const Duration(hours: 1, minutes: 30)) >=
Expand Down
9 changes: 2 additions & 7 deletions lib/calendarComponent/views/calendars_view.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:campus_flutter/base/enums/error_handling_view_type.dart';
import 'package:campus_flutter/base/helpers/delayed_loading_indicator.dart';
import 'package:campus_flutter/base/helpers/last_updated_text.dart';
import 'package:campus_flutter/base/views/error_handling_view.dart';
Expand Down Expand Up @@ -28,16 +29,10 @@ class _CalendarsViewState extends ConsumerState<CalendarsView>
@override
void initState() {
ref.read(calendarViewModel).fetch(false);
_selectedCalendarTab = 1;
super.initState();
}

@override
void didChangeDependencies() {
_selectedCalendarTab =
MediaQuery.orientationOf(context) == Orientation.landscape ? 1 : 0;
super.didChangeDependencies();
}

@override
Widget build(BuildContext context) {
super.build(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ class CalendarHomeWidgetEventView extends ConsumerWidget {
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.labelSmall),
Text(calendarEvent.location,
Text(
calendarEvent.location ??
context.localizations.unknown,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.labelSmall)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:campus_flutter/base/enums/error_handling_view_type.dart';
import 'package:campus_flutter/base/helpers/card_with_padding.dart';
import 'package:campus_flutter/base/helpers/delayed_loading_indicator.dart';
import 'package:campus_flutter/base/views/error_handling_view.dart';
Expand Down
1 change: 1 addition & 0 deletions lib/departuresComponent/views/departures_details_view.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:campus_flutter/base/enums/error_handling_view_type.dart';
import 'package:campus_flutter/base/helpers/card_with_padding.dart';
import 'package:campus_flutter/base/helpers/delayed_loading_indicator.dart';
import 'package:campus_flutter/base/helpers/directions_launcher.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:campus_flutter/base/enums/error_handling_view_type.dart';
import 'package:campus_flutter/base/helpers/card_with_padding.dart';
import 'package:campus_flutter/base/helpers/delayed_loading_indicator.dart';
import 'package:campus_flutter/base/views/error_handling_view.dart';
Expand Down
1 change: 1 addition & 0 deletions lib/gradeComponent/views/grades_view.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:campus_flutter/base/enums/error_handling_view_type.dart';
import 'package:campus_flutter/base/helpers/delayed_loading_indicator.dart';
import 'package:campus_flutter/base/helpers/last_updated_text.dart';
import 'package:campus_flutter/base/helpers/padded_divider.dart';
Expand Down
1 change: 1 addition & 0 deletions lib/homeComponent/widgetComponent/views/widget_screen.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:campus_flutter/base/enums/error_handling_view_type.dart';
import 'package:campus_flutter/base/enums/home_widget.dart';
import 'package:campus_flutter/base/helpers/delayed_loading_indicator.dart';
import 'package:campus_flutter/base/views/error_handling_view.dart';
Expand Down
1 change: 1 addition & 0 deletions lib/lectureComponent/views/lecture_details_view.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:campus_flutter/base/enums/error_handling_view_type.dart';
import 'package:campus_flutter/base/helpers/delayed_loading_indicator.dart';
import 'package:campus_flutter/base/helpers/last_updated_text.dart';
import 'package:campus_flutter/base/views/error_handling_view.dart';
Expand Down
3 changes: 2 additions & 1 deletion lib/lectureComponent/views/lecture_meeting_info_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class LectureMeetingInfoView extends ConsumerWidget {
information: ref.read(viewModel).event!.timeDatePeriod(context),
iconData: Icons.hourglass_top),
BasicLectureInfoRowView(
information: ref.read(viewModel).event!.location,
information: ref.read(viewModel).event!.location ??
context.localizations.unknown,
iconData: Icons.location_on,
trailingWidget: IconButton(
onPressed: () => Navigator.push(
Expand Down
1 change: 1 addition & 0 deletions lib/lectureComponent/views/lectures_view.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:campus_flutter/base/enums/error_handling_view_type.dart';
import 'package:campus_flutter/base/helpers/last_updated_text.dart';
import 'package:campus_flutter/base/helpers/padded_divider.dart';
import 'package:campus_flutter/base/helpers/delayed_loading_indicator.dart';
Expand Down
1 change: 1 addition & 0 deletions lib/loginComponent/views/confirm_view.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:campus_flutter/base/enums/error_handling_view_type.dart';
import 'dart:io';

import 'package:campus_flutter/base/helpers/icon_text.dart';
Expand Down
1 change: 1 addition & 0 deletions lib/loginComponent/views/login_view.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:campus_flutter/base/enums/error_handling_view_type.dart';
import 'package:campus_flutter/base/views/error_handling_view.dart';
import 'package:campus_flutter/providers_get_it.dart';
import 'package:flutter/foundation.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/movieComponent/views/homeWidget/movie_card_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MovieCardView extends ConsumerWidget {
top: Radius.circular(10)),
child: CachedNetworkImage(
imageUrl: movie.coverUrl.toString(),
fit: BoxFit.fitWidth,
fit: BoxFit.fill,
fadeOutDuration: Duration.zero,
fadeInDuration: Duration.zero,
placeholder: (context, string) => Image.asset(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:campus_flutter/base/enums/error_handling_view_type.dart';
import 'package:campus_flutter/base/helpers/delayed_loading_indicator.dart';
import 'package:campus_flutter/base/helpers/horizontal_slider.dart';
import 'package:campus_flutter/base/networking/apis/tumdev/campus_backend.pbgrpc.dart';
Expand Down
1 change: 1 addition & 0 deletions lib/navigaTumComponent/views/navigatum_room_view.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:campus_flutter/base/enums/error_handling_view_type.dart';
import 'package:campus_flutter/base/helpers/delayed_loading_indicator.dart';
import 'package:campus_flutter/base/views/error_handling_view.dart';
import 'package:campus_flutter/navigaTumComponent/model/navigatum_navigation_details.dart';
Expand Down
1 change: 1 addition & 0 deletions lib/newsComponent/views/homeWidget/news_widget_view.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:campus_flutter/base/enums/error_handling_view_type.dart';
import 'package:campus_flutter/base/helpers/delayed_loading_indicator.dart';
import 'package:campus_flutter/base/helpers/horizontal_slider.dart';
import 'package:campus_flutter/base/views/error_handling_view.dart';
Expand Down
1 change: 1 addition & 0 deletions lib/personDetailedComponent/views/person_details_view.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:campus_flutter/base/enums/error_handling_view_type.dart';
import 'package:campus_flutter/base/extensions/base_64_decode_image_data.dart';
import 'package:campus_flutter/base/helpers/delayed_loading_indicator.dart';
import 'package:campus_flutter/base/helpers/url_launcher.dart';
Expand Down
2 changes: 0 additions & 2 deletions lib/placesComponent/services/mealplan_service.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:developer';

import 'package:campus_flutter/base/extensions/date_time_week_number.dart';
import 'package:campus_flutter/base/networking/apis/eatApi/eat_api.dart';
import 'package:campus_flutter/base/networking/apis/eatApi/eat_api_service.dart';
Expand Down
1 change: 1 addition & 0 deletions lib/placesComponent/views/cafeterias/cafeteria_view.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:campus_flutter/base/enums/error_handling_view_type.dart';
import 'package:campus_flutter/base/helpers/delayed_loading_indicator.dart';
import 'package:campus_flutter/base/helpers/info_row.dart';
import 'package:campus_flutter/base/helpers/padded_divider.dart';
Expand Down
1 change: 1 addition & 0 deletions lib/placesComponent/views/cafeterias/cafeterias_view.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:campus_flutter/base/enums/error_handling_view_type.dart';
import 'package:campus_flutter/base/helpers/delayed_loading_indicator.dart';
import 'package:campus_flutter/base/helpers/padded_divider.dart';
import 'package:campus_flutter/base/views/error_handling_view.dart';
Expand Down
Loading

0 comments on commit e577e6d

Please sign in to comment.