Skip to content

Commit

Permalink
frontend: moodle course open
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesbrandenburger committed Apr 15, 2024
1 parent ebcc953 commit 935325c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
35 changes: 26 additions & 9 deletions frontend/lib/components/choose/choose_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:frontend/models/course.dart';
import 'package:frontend/theme/assets.dart';
import 'package:frontend/enums/form_type.dart';
import 'package:rive/rive.dart';
import 'package:url_launcher/url_launcher.dart';

class ChooseForm extends StatefulWidget {
final Course course;
Expand Down Expand Up @@ -71,6 +72,18 @@ class _ChooseFormState extends State<ChooseForm> {
);
}

void _openMoodle() async {
final moodleCourseId = widget.course.moodleCourseId;
final moodleUrl =
"https://moodle.htwg-konstanz.de/moodle/course/view.php?id=$moodleCourseId";
final moodleUri = Uri.parse(moodleUrl);
if (await canLaunchUrl(moodleUri)) {
await launchUrl(moodleUri);
} else {
throw 'Could not launch $moodleUrl';
}
}

@override
Widget build(BuildContext context) {
final colors = Theme.of(context).colorScheme;
Expand Down Expand Up @@ -117,15 +130,19 @@ class _ChooseFormState extends State<ChooseForm> {
padding: const EdgeInsets.only(right: 20),
child: Align(
alignment: Alignment.centerRight,
child: ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0),
),
),
child: Image.asset(moodleLogo, width: 80),
),
child: widget.course.moodleCourseId != ''
? ElevatedButton(
onPressed: () {
_openMoodle();
},
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0),
),
),
child: Image.asset(moodleLogo, width: 80),
)
: null,
),
),
body: Column(
Expand Down
5 changes: 4 additions & 1 deletion frontend/lib/models/course.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Course {
final List<FeedbackForm> feedbackForms;
final List<QuizForm> quizForms;
final bool isOwner;
final String moodleCourseId;

Course({
required this.id,
Expand All @@ -17,6 +18,7 @@ class Course {
required this.feedbackForms,
required this.quizForms,
required this.isOwner,
required this.moodleCourseId,
});

factory Course.fromJson(Map<String, dynamic> json) {
Expand All @@ -25,7 +27,7 @@ class Course {
List<String> owners = json['owners'].cast<String>();
isOwner = owners.contains(getSession()!.userId);
}

return Course(
id: json['id'],
name: json['name'],
Expand All @@ -37,6 +39,7 @@ class Course {
.map((e) => QuizForm.fromJson(e, isOwner: isOwner))
.toList(),
isOwner: isOwner,
moodleCourseId: json['moodleCourseId'] ?? '',
);
}
}
1 change: 1 addition & 0 deletions frontend/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ dependencies:
jwt_decoder: ^2.0.1
intl: ^0.19.0
rive: ^0.13.1
url_launcher: ^6.2.6
# mobile_scanner: ^3.5.7

dev_dependencies:
Expand Down

0 comments on commit 935325c

Please sign in to comment.