From e4482b0aece155fd19eb3766b5cfb7d0143b4513 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20K=C3=B6rber?= <56073945+jakobkoerber@users.noreply.github.com> Date: Fri, 13 Oct 2023 15:43:13 +0200 Subject: [PATCH] Bugfixes introduced up to 0.2.2 (Part 2) (#125) --- lib/base/helpers/fullscreen_image_view.dart | 1 - lib/base/helpers/hyperlink_text.dart | 50 +++++++++++-------- lib/base/helpers/url_launcher.dart | 37 ++++++++------ .../contactComponent/views/link_view.dart | 3 +- .../views/basic_lecture_info_view.dart | 1 - .../views/detailed_lecture_info_view.dart | 17 +++---- .../views/lecture_details_view.dart | 10 +++- .../views/lecture_links_view.dart | 25 +++++----- .../viewModels/study_rooms_viewmodel.dart | 1 - .../views/cafeterias/cafeterias_view.dart | 6 +-- .../views/settings_view.dart | 41 ++++++--------- 11 files changed, 98 insertions(+), 94 deletions(-) diff --git a/lib/base/helpers/fullscreen_image_view.dart b/lib/base/helpers/fullscreen_image_view.dart index 97d23a49..ded0df0d 100644 --- a/lib/base/helpers/fullscreen_image_view.dart +++ b/lib/base/helpers/fullscreen_image_view.dart @@ -6,7 +6,6 @@ import 'package:campus_flutter/navigaTumComponent/model/navigatum_roomfinder_map import 'package:campus_flutter/theme.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/rendering.dart'; class ImageFullScreenScaffold extends StatelessWidget { factory ImageFullScreenScaffold.network( diff --git a/lib/base/helpers/hyperlink_text.dart b/lib/base/helpers/hyperlink_text.dart index 26b25a0b..05d1789b 100644 --- a/lib/base/helpers/hyperlink_text.dart +++ b/lib/base/helpers/hyperlink_text.dart @@ -3,18 +3,24 @@ import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -class HyperLinkText extends ConsumerStatefulWidget { - const HyperLinkText({super.key, this.link, this.uri, required this.label}); +class HyperLinkListTile extends ConsumerStatefulWidget { + const HyperLinkListTile( + {super.key, + this.link, + this.uri, + required this.label, + this.dense = false}); final String? link; final Uri? uri; final String label; + final bool dense; @override ConsumerState createState() => _HyperlinkTextState(); } -class _HyperlinkTextState extends ConsumerState { +class _HyperlinkTextState extends ConsumerState { late TapGestureRecognizer tapGestureRecognizer; @override @@ -31,23 +37,25 @@ class _HyperlinkTextState extends ConsumerState { @override Widget build(BuildContext context) { - return Row( - children: [ - RichText( - text: TextSpan( - text: widget.label, - style: Theme.of(context).textTheme.bodyMedium, - recognizer: tapGestureRecognizer - ..onTap = () { - if (widget.link != null) { - UrlLauncher.urlString(widget.link!, ref); - } else if (widget.uri != null) { - UrlLauncher.url(widget.uri!, ref); - } - })), - const Padding(padding: EdgeInsets.symmetric(horizontal: 2.0)), - const Icon(Icons.open_in_new, size: 15 /*, color: Colors.blue*/) - ], - ); + return ListTile( + dense: widget.dense, + title: Row( + children: [ + RichText( + text: TextSpan( + text: widget.label, + style: Theme.of(context).textTheme.bodyMedium, + )), + const Padding(padding: EdgeInsets.symmetric(horizontal: 2.0)), + const Icon(Icons.open_in_new, size: 15 /*, color: Colors.blue*/) + ], + ), + onTap: () { + if (widget.link != null) { + UrlLauncher.urlString(widget.link!, ref); + } else if (widget.uri != null) { + UrlLauncher.url(widget.uri!, ref); + } + }); } } diff --git a/lib/base/helpers/url_launcher.dart b/lib/base/helpers/url_launcher.dart index 21dbfcac..0985badd 100644 --- a/lib/base/helpers/url_launcher.dart +++ b/lib/base/helpers/url_launcher.dart @@ -1,31 +1,40 @@ import 'dart:io'; import 'package:campus_flutter/providers_get_it.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher_string.dart'; class UrlLauncher { static urlString(String urlString, WidgetRef ref) async { - if (await canLaunchUrlString(urlString)) { - if (ref.read(useWebView) && Platform.isIOS) { - launchUrlString(urlString, mode: LaunchMode.inAppWebView).onError( - (error, stackTrace) => launchUrlString(urlString, - mode: LaunchMode.externalApplication)); - } else { - launchUrlString(urlString, mode: LaunchMode.externalApplication); + if (kIsWeb) { + launchUrlString(urlString, mode: LaunchMode.platformDefault); + } else { + if (await canLaunchUrlString(urlString)) { + if (ref.read(useWebView) && Platform.isIOS) { + launchUrlString(urlString, mode: LaunchMode.inAppWebView).onError( + (error, stackTrace) => launchUrlString(urlString, + mode: LaunchMode.externalApplication)); + } else { + launchUrlString(urlString, mode: LaunchMode.externalApplication); + } } } } static url(Uri url, WidgetRef ref) async { - if (await canLaunchUrl(url)) { - if (ref.read(useWebView) && Platform.isIOS) { - launchUrl(url, mode: LaunchMode.inAppWebView).onError( - (error, stackTrace) => - launchUrl(url, mode: LaunchMode.externalApplication)); - } else { - launchUrl(url, mode: LaunchMode.externalApplication); + if (kIsWeb) { + launchUrl(url, mode: LaunchMode.platformDefault); + } else { + if (await canLaunchUrl(url)) { + if (ref.read(useWebView) && Platform.isIOS) { + launchUrl(url, mode: LaunchMode.inAppWebView).onError( + (error, stackTrace) => + launchUrl(url, mode: LaunchMode.externalApplication)); + } else { + launchUrl(url, mode: LaunchMode.externalApplication); + } } } } diff --git a/lib/homeComponent/contactComponent/views/link_view.dart b/lib/homeComponent/contactComponent/views/link_view.dart index d9815308..38ec5c96 100644 --- a/lib/homeComponent/contactComponent/views/link_view.dart +++ b/lib/homeComponent/contactComponent/views/link_view.dart @@ -1,6 +1,7 @@ import 'package:campus_flutter/providers_get_it.dart'; import 'package:campus_flutter/base/helpers/url_launcher.dart'; import 'package:campus_flutter/theme.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:webview_flutter/webview_flutter.dart'; @@ -43,7 +44,7 @@ class LinkView extends ConsumerWidget { } void _launchUrl(String url, BuildContext context, WidgetRef ref) { - if (MediaQuery.orientationOf(context) == Orientation.portrait) { + if (MediaQuery.orientationOf(context) == Orientation.portrait || kIsWeb) { UrlLauncher.urlString(url, ref); } else { final controller = WebViewController() diff --git a/lib/lectureComponent/views/basic_lecture_info_view.dart b/lib/lectureComponent/views/basic_lecture_info_view.dart index b8d3bf90..f9876ed8 100644 --- a/lib/lectureComponent/views/basic_lecture_info_view.dart +++ b/lib/lectureComponent/views/basic_lecture_info_view.dart @@ -25,7 +25,6 @@ class BasicLectureInfoView extends ConsumerWidget { BasicLectureInfoRowView( information: lectureDetails.organisation, iconData: Icons.import_contacts), - // TODO: person finder if (lectureDetails.speaker != null) BasicLectureInfoRowView( information: lectureDetails.speaker!, diff --git a/lib/lectureComponent/views/detailed_lecture_info_view.dart b/lib/lectureComponent/views/detailed_lecture_info_view.dart index e44b1c27..f3cb6930 100644 --- a/lib/lectureComponent/views/detailed_lecture_info_view.dart +++ b/lib/lectureComponent/views/detailed_lecture_info_view.dart @@ -15,23 +15,18 @@ class DetailedLectureInfoView extends StatelessWidget { icon: Icons.info_outline_rounded, title: context.localizations.detailedLectureInformation, widgets: [ - if (lectureDetails.courseContents != null) ...[ + if (lectureDetails.courseContents != null) DetailedLectureInfoRowView( title: context.localizations.courseContents, - information: lectureDetails.courseContents!) - ], - if (lectureDetails.courseObjective != null) ...[ - const Divider(), + information: lectureDetails.courseContents!), + if (lectureDetails.courseObjective != null) DetailedLectureInfoRowView( title: context.localizations.courseObjective, - information: lectureDetails.courseObjective!) - ], - if (lectureDetails.note != null) ...[ - const Divider(), + information: lectureDetails.courseObjective!), + if (lectureDetails.note != null) DetailedLectureInfoRowView( title: context.localizations.note, - information: lectureDetails.note!) - ], + information: lectureDetails.note!), ], ); } diff --git a/lib/lectureComponent/views/lecture_details_view.dart b/lib/lectureComponent/views/lecture_details_view.dart index 669c1aeb..07023c1b 100644 --- a/lib/lectureComponent/views/lecture_details_view.dart +++ b/lib/lectureComponent/views/lecture_details_view.dart @@ -89,8 +89,14 @@ class _LectureDetailsViewState extends ConsumerState { if (ref.read(viewModel).event != null) LectureMeetingInfoView(viewModel: viewModel), BasicLectureInfoView(lectureDetails: lectureDetails), - DetailedLectureInfoView(lectureDetails: lectureDetails), - LectureLinksView(lectureDetails: lectureDetails) + if (lectureDetails.courseContents != null || + lectureDetails.courseObjective != null || + lectureDetails.note != null) + DetailedLectureInfoView(lectureDetails: lectureDetails), + if (lectureDetails.curriculumURL != null || + lectureDetails.scheduledDatesURL != null || + lectureDetails.examDateURL != null) + LectureLinksView(lectureDetails: lectureDetails) ]; } } diff --git a/lib/lectureComponent/views/lecture_links_view.dart b/lib/lectureComponent/views/lecture_links_view.dart index aa97d495..b4d6683f 100644 --- a/lib/lectureComponent/views/lecture_links_view.dart +++ b/lib/lectureComponent/views/lecture_links_view.dart @@ -16,22 +16,21 @@ class LectureLinksView extends StatelessWidget { title: context.localizations.lectureLinks, widgets: [ if (lectureDetails.curriculumURL != null) - _entry(lectureDetails.curriculumURL, - context.localizations.lectureCurriculum), + HyperLinkListTile( + dense: true, + link: lectureDetails.curriculumURL, + label: context.localizations.lectureCurriculum), if (lectureDetails.scheduledDatesURL != null) - _entry(lectureDetails.scheduledDatesURL, - context.localizations.scheduledLectureDates), + HyperLinkListTile( + dense: true, + link: lectureDetails.scheduledDatesURL, + label: context.localizations.scheduledLectureDates), if (lectureDetails.examDateURL != null) - _entry(lectureDetails.examDateURL, - context.localizations.lectureExamDate), + HyperLinkListTile( + dense: true, + link: lectureDetails.examDateURL, + label: context.localizations.lectureExamDate), ], ); } - - Widget _entry(String? url, String label) { - return ListTile( - dense: true, - title: HyperLinkText(link: url ?? "", label: label), - ); - } } diff --git a/lib/placesComponent/viewModels/study_rooms_viewmodel.dart b/lib/placesComponent/viewModels/study_rooms_viewmodel.dart index 55d0b880..570fcea0 100644 --- a/lib/placesComponent/viewModels/study_rooms_viewmodel.dart +++ b/lib/placesComponent/viewModels/study_rooms_viewmodel.dart @@ -138,7 +138,6 @@ class StudyRoomsViewModel { .map((e) => Marker( markerId: MarkerId(const Uuid().v4()), position: LatLng(e.coordinate!.latitude, e.coordinate!.longitude), - icon: BitmapDescriptor.defaultMarkerWithHue(208), infoWindow: InfoWindow( title: e.name ?? "Unknown", onTap: () { diff --git a/lib/placesComponent/views/cafeterias/cafeterias_view.dart b/lib/placesComponent/views/cafeterias/cafeterias_view.dart index d4b77083..c462935a 100644 --- a/lib/placesComponent/views/cafeterias/cafeterias_view.dart +++ b/lib/placesComponent/views/cafeterias/cafeterias_view.dart @@ -60,7 +60,7 @@ class _CafeteriasState extends ConsumerState { top: context.halfPadding, bottom: context.padding), markers: - ref.read(studyRoomsViewModel).mapMakers(context)), + ref.read(cafeteriasViewModel).mapMakers(context)), ), Expanded( child: SingleChildScrollView( @@ -73,7 +73,7 @@ class _CafeteriasState extends ConsumerState { child: Column( children: [ MapWidget.horizontalPadding( - markers: ref.read(studyRoomsViewModel).mapMakers(context), + markers: ref.read(cafeteriasViewModel).mapMakers(context), ), const PaddedDivider(), _cafeteriaList(cafeterias, true) @@ -85,7 +85,7 @@ class _CafeteriasState extends ConsumerState { return ErrorHandlingView( error: snapshot.error!, errorHandlingViewType: ErrorHandlingViewType.fullScreen, - retry: ref.read(studyRoomsViewModel).fetch, + retry: ref.read(cafeteriasViewModel).fetch, ); } else { return DelayedLoadingIndicator( diff --git a/lib/settingsComponent/views/settings_view.dart b/lib/settingsComponent/views/settings_view.dart index f23a87c3..0def9851 100644 --- a/lib/settingsComponent/views/settings_view.dart +++ b/lib/settingsComponent/views/settings_view.dart @@ -4,7 +4,6 @@ import 'package:campus_flutter/base/enums/appearance.dart'; import 'package:campus_flutter/base/extensions/locale+fullname.dart'; import 'package:campus_flutter/base/helpers/hyperlink_text.dart'; import 'package:campus_flutter/base/helpers/icon_text.dart'; -import 'package:campus_flutter/base/helpers/padded_divider.dart'; import 'package:campus_flutter/base/views/seperated_list.dart'; import 'package:campus_flutter/homeComponent/widgetComponent/views/widget_frame_view.dart'; import 'package:campus_flutter/loginComponent/viewModels/login_viewmodel.dart'; @@ -166,33 +165,23 @@ class SettingsView extends ConsumerWidget { return WidgetFrameView( title: context.localizations.contactUs, child: Card( - child: Column( - children: [ + child: SeparatedList.widgets( + widgets: [ if (!kIsWeb) - ListTile( + HyperLinkListTile( + dense: true, + link: _betaTester(), + label: context.localizations.becomeABetaTester), + HyperLinkListTile( dense: true, - title: HyperLinkText( - link: _betaTester(), - label: context.localizations.becomeABetaTester), - ), - const PaddedDivider(height: 0), - ListTile( - dense: true, - title: HyperLinkText( - link: "https://github.com/TUM-Dev", - label: context.localizations.usOnGitHub), - ), - const PaddedDivider(height: 0), - const ListTile( - dense: true, - title: HyperLinkText( - link: "https://app.tum.de", label: "TUM Dev Website"), - ), - const PaddedDivider(height: 0), - ListTile( - dense: true, - title: HyperLinkText(uri: _feedbackEmail(), label: "Feedback"), - ), + link: "https://github.com/TUM-Dev", + label: context.localizations.usOnGitHub), + const HyperLinkListTile( + dense: true, + link: "https://app.tum.de", + label: "TUM Dev Website"), + HyperLinkListTile( + dense: true, uri: _feedbackEmail(), label: "Feedback"), ], ))); }