From a9454b6e386ab933af4f28a27ba69f8030d1e2fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20K=C3=B6rber?= <56073945+jakobkoerber@users.noreply.github.com> Date: Sat, 16 Dec 2023 14:05:26 +0100 Subject: [PATCH] Make Links in Lecture Details clickable --- lib/base/views/seperated_list.dart | 14 ++++- .../views/detailed_lecture_info_row_view.dart | 12 +++-- .../views/lecture_info_card_view.dart | 5 +- pubspec.lock | 52 ++++++++++++------- pubspec.yaml | 1 + 5 files changed, 61 insertions(+), 23 deletions(-) diff --git a/lib/base/views/seperated_list.dart b/lib/base/views/seperated_list.dart index 9f50e47b..e4a0f6f9 100644 --- a/lib/base/views/seperated_list.dart +++ b/lib/base/views/seperated_list.dart @@ -5,20 +5,28 @@ class SeparatedList extends StatelessWidget { factory SeparatedList.list({ required List data, required Widget Function(T) tile, + CrossAxisAlignment? crossAxisAlignment, bool padded = true, }) { return SeparatedList._( data: data, tile: tile, + crossAxisAlignment: crossAxisAlignment, padded: padded, ); } factory SeparatedList.widgets({ required List widgets, + CrossAxisAlignment? crossAxisAlignment, bool padded = true, }) { - return SeparatedList._(widgets: widgets, padded: padded, list: false); + return SeparatedList._( + widgets: widgets, + crossAxisAlignment: crossAxisAlignment, + padded: padded, + list: false, + ); } const SeparatedList._({ @@ -26,6 +34,7 @@ class SeparatedList extends StatelessWidget { this.data, this.widgets, this.tile, + this.crossAxisAlignment, this.padded = true, this.list = true, }); @@ -33,6 +42,7 @@ class SeparatedList extends StatelessWidget { final List? data; final List? widgets; final Widget Function(T)? tile; + final CrossAxisAlignment? crossAxisAlignment; final bool padded; final bool list; @@ -40,6 +50,7 @@ class SeparatedList extends StatelessWidget { Widget build(BuildContext context) { if (list) { return Column( + crossAxisAlignment: crossAxisAlignment ?? CrossAxisAlignment.center, children: [ for (var dataPoint in data!.indexed) ...[ tile!(dataPoint.$2), @@ -56,6 +67,7 @@ class SeparatedList extends StatelessWidget { ); } else { return Column( + crossAxisAlignment: crossAxisAlignment ?? CrossAxisAlignment.center, children: [ for (var dataPoint in widgets!.indexed) ...[ widgets![dataPoint.$1], diff --git a/lib/lectureComponent/views/detailed_lecture_info_row_view.dart b/lib/lectureComponent/views/detailed_lecture_info_row_view.dart index 2522a571..d2827bb4 100644 --- a/lib/lectureComponent/views/detailed_lecture_info_row_view.dart +++ b/lib/lectureComponent/views/detailed_lecture_info_row_view.dart @@ -1,7 +1,10 @@ import 'package:campus_flutter/base/extensions/context.dart'; +import 'package:campus_flutter/base/helpers/url_launcher.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_linkify/flutter_linkify.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; -class DetailedLectureInfoRowView extends StatelessWidget { +class DetailedLectureInfoRowView extends ConsumerWidget { const DetailedLectureInfoRowView({ super.key, required this.title, @@ -12,7 +15,7 @@ class DetailedLectureInfoRowView extends StatelessWidget { final String information; @override - Widget build(BuildContext context) { + Widget build(BuildContext context, WidgetRef ref) { return Padding( padding: EdgeInsets.all(context.padding), child: Column( @@ -25,7 +28,10 @@ class DetailedLectureInfoRowView extends StatelessWidget { .titleSmall ?.copyWith(fontWeight: FontWeight.bold), ), - Text(information.replaceAll(r'\\n', "\n").replaceAll(r'\t', "\t")), + Linkify( + text: information.replaceAll(r'\\n', "\n").replaceAll(r'\t', "\t"), + onOpen: (link) => UrlLauncher.urlString(link.url, ref), + ), ], ), ); diff --git a/lib/lectureComponent/views/lecture_info_card_view.dart b/lib/lectureComponent/views/lecture_info_card_view.dart index 4f43077f..bc3223ee 100644 --- a/lib/lectureComponent/views/lecture_info_card_view.dart +++ b/lib/lectureComponent/views/lecture_info_card_view.dart @@ -24,7 +24,10 @@ class LectureInfoCardView extends StatelessWidget { style: Theme.of(context).textTheme.titleMedium, ), child: Card( - child: SeparatedList.widgets(widgets: widgets), + child: SeparatedList.widgets( + widgets: widgets, + crossAxisAlignment: CrossAxisAlignment.start, + ), ), ); } diff --git a/pubspec.lock b/pubspec.lock index 207494b3..89304635 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -61,10 +61,10 @@ packages: dependency: transitive description: name: barcode - sha256: "789f898eef0bd88312470bdb2cc996f895ad7dd5f89e9adde84b204546a90b45" + sha256: "2a8b2ee065f419c2aeda141436cc556d91ae772d220fd80679f4d431d6c2ab43" url: "https://pub.dev" source: hosted - version: "2.2.4" + version: "2.2.5" barcode_widget: dependency: "direct main" description: @@ -109,10 +109,10 @@ packages: dependency: transitive description: name: build_resolvers - sha256: "64e12b0521812d1684b1917bc80945625391cb9bdd4312536b1d69dcb6133ed8" + sha256: "339086358431fa15d7eca8b6a36e5d783728cf025e559b834f4609a1fcfb7b0a" url: "https://pub.dev" source: hosted - version: "2.4.1" + version: "2.4.2" build_runner: dependency: "direct dev" description: @@ -141,10 +141,10 @@ packages: dependency: transitive description: name: built_value - sha256: "69acb7007eb2a31dc901512bfe0f7b767168be34cb734835d54c070bfa74c1b2" + sha256: c9aabae0718ec394e5bc3c7272e6bb0dc0b32201a08fe185ec1d8401d3e39309 url: "https://pub.dev" source: hosted - version: "8.8.0" + version: "8.8.1" cached_network_image: dependency: "direct main" description: @@ -197,10 +197,10 @@ packages: dependency: transitive description: name: code_builder - sha256: b2151ce26a06171005b379ecff6e08d34c470180ffe16b8e14b6d52be292b55f + sha256: feee43a5c05e7b3199bb375a86430b8ada1b04104f2923d0e03cc01ca87b6d84 url: "https://pub.dev" source: hosted - version: "4.8.0" + version: "4.9.0" collection: dependency: "direct main" description: @@ -221,10 +221,10 @@ packages: dependency: transitive description: name: coverage - sha256: ac86d3abab0f165e4b8f561280ff4e066bceaac83c424dd19f1ae2c2fcd12ca9 + sha256: "8acabb8306b57a409bf4c83522065672ee13179297a6bb0cb9ead73948df7c76" url: "https://pub.dev" source: hosted - version: "1.7.1" + version: "1.7.2" crypto: dependency: transitive description: @@ -374,6 +374,14 @@ packages: url: "https://pub.dev" source: hosted version: "3.3.1" + flutter_linkify: + dependency: "direct main" + description: + name: flutter_linkify + sha256: "74669e06a8f358fee4512b4320c0b80e51cffc496607931de68d28f099254073" + url: "https://pub.dev" + source: hosted + version: "6.0.0" flutter_lints: dependency: "direct dev" description: @@ -735,6 +743,14 @@ packages: url: "https://pub.dev" source: hosted version: "6.7.1" + linkify: + dependency: transitive + description: + name: linkify + sha256: "4139ea77f4651ab9c315b577da2dd108d9aa0bd84b5d03d33323f1970c645832" + url: "https://pub.dev" + source: hosted + version: "5.0.0" lints: dependency: "direct dev" description: @@ -1112,10 +1128,10 @@ packages: dependency: transitive description: name: source_gen - sha256: fc0da689e5302edb6177fdd964efcb7f58912f43c28c2047a808f5bfff643d16 + sha256: "14658ba5f669685cd3d63701d01b31ea748310f7ab854e471962670abcf57832" url: "https://pub.dev" source: hosted - version: "1.4.0" + version: "1.5.0" source_helper: dependency: transitive description: @@ -1360,10 +1376,10 @@ packages: dependency: transitive description: name: url_launcher_linux - sha256: "9f2d390e096fdbe1e6e6256f97851e51afc2d9c423d3432f1d6a02a8a9a8b9fd" + sha256: ab360eb661f8879369acac07b6bb3ff09d9471155357da8443fd5d3cf7363811 url: "https://pub.dev" source: hosted - version: "3.1.0" + version: "3.1.1" url_launcher_macos: dependency: transitive description: @@ -1392,18 +1408,18 @@ packages: dependency: transitive description: name: url_launcher_windows - sha256: "7754a1ad30ee896b265f8d14078b0513a4dba28d358eabb9d5f339886f4a1adc" + sha256: ecf9725510600aa2bb6d7ddabe16357691b6d2805f66216a97d1b881e21beff7 url: "https://pub.dev" source: hosted - version: "3.1.0" + version: "3.1.1" uuid: dependency: "direct main" description: name: uuid - sha256: df5a4d8f22ee4ccd77f8839ac7cb274ebc11ef9adcce8b92be14b797fe889921 + sha256: "22c94e5ad1e75f9934b766b53c742572ee2677c56bc871d850a57dad0f82127f" url: "https://pub.dev" source: hosted - version: "4.2.1" + version: "4.2.2" vector_graphics: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index a09baa5c..155d5b47 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -53,6 +53,7 @@ dependencies: collection: ^1.18.0 firebase_crashlytics: ^3.4.6 firebase_core: ^2.24.0 + flutter_linkify: ^6.0.0 dependency_overrides: xml2json: