Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
fix the location finder
Browse files Browse the repository at this point in the history
  • Loading branch information
Sainaamr committed Feb 2, 2024
1 parent 2d7e0e3 commit 66c7888
Showing 1 changed file with 44 additions and 10 deletions.
54 changes: 44 additions & 10 deletions lib/views/course_view/components/small_stream_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:gocast_mobile/base/networking/api/gocast/api_v2.pb.dart';
import 'package:gocast_mobile/utils/constants.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
//import 'package:http/http.dart' as http;

class SmallStreamCard extends StatelessWidget {
final String title;
Expand Down Expand Up @@ -183,14 +184,25 @@ class SmallStreamCard extends StatelessWidget {
],
);
}

Widget _buildLocation(ThemeData themeData) {
if (roomNumber == null) return const SizedBox();
final isLocationEmpty =
(roomName?.isEmpty ?? true) && (roomNumber?.isEmpty ?? true);

return isLocationEmpty
? _buildInactiveLocation(themeData)
: _buildActiveLocation(themeData);
}

final Uri url = Uri.parse('https://nav.tum.de/room/$roomNumber');
Widget _buildActiveLocation(ThemeData themeData) {
// Determine the URL based on the availability of roomNumber
final Uri url = roomNumber?.isNotEmpty ?? false
? Uri.parse(
'https://nav.tum.de/room/$roomNumber') // Use roomNumber in URL if available
: Uri.parse(
'https://nav.tum.de/search?q=${Uri.encodeComponent(roomName ?? '')}'); // Fall back to search URL using roomName

return Align(
alignment: Alignment.centerRight, // Align to the right
alignment: Alignment.centerRight,
child: Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
Expand All @@ -204,18 +216,19 @@ class SmallStreamCard extends StatelessWidget {
),
child: InkWell(
onTap: () async {
if (await canLaunchUrl(url)) {
await launchUrl(url);
} else {
throw 'Could not launch $url';
try {
if (await canLaunchUrl(url)) {
await launchUrl(url);
}
} catch (e) {
// Handle exceptions or errors here
}
},
child: const Row(
mainAxisSize: MainAxisSize.min,
// Constrain row size to its children
children: [
Icon(Icons.room, size: 24),
SizedBox(width: 8), // Spacing before the arrow icon
SizedBox(width: 8),
Icon(Icons.arrow_forward_ios, size: 16),
],
),
Expand All @@ -224,6 +237,27 @@ class SmallStreamCard extends StatelessWidget {
);
}

Widget _buildInactiveLocation(ThemeData themeData) {
return Align(
alignment: Alignment.centerRight,
child: Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey.withOpacity(0.4)),
borderRadius: BorderRadius.circular(5),
),
child: const Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.room, size: 24, color: Colors.grey),
SizedBox(width: 8),
Icon(Icons.arrow_forward_ios, size: 16, color: Colors.grey),
],
),
),
);
}

Widget _buildCourseTumID() {
return Text(
tumID,
Expand Down

0 comments on commit 66c7888

Please sign in to comment.