Skip to content

Commit

Permalink
Make Student Card Picture on Home hideable
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobkoerber committed Dec 10, 2024
1 parent 6353668 commit 860f9f4
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 24 deletions.
3 changes: 2 additions & 1 deletion assets/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,5 +233,6 @@
"suggested": "Interessante {}",
"more": "Mehr",
"visibility": "Sichtbarkeit",
"utilizationAt": "Auslastung bei {}%"
"utilizationAt": "Auslastung bei {}%",
"showStudentCardPicture": "Student Card Bild zeigen"
}
3 changes: 2 additions & 1 deletion assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,5 +233,6 @@
"suggested": "Suggested {}",
"more": "More",
"visibility": "Visibility",
"utilizationAt": "Utilization at {}%"
"utilizationAt": "Utilization at {}%",
"showStudentCardPicture": "Show Student Card Picture"
}
1 change: 1 addition & 0 deletions lib/base/enums/user_preference.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ enum UserPreference {
theme(int),
calendarColors(String),
browser(bool),
studentCardPicture(bool),
failedGrades(bool),
weekends(bool),
hiddenCalendarEntries(bool),
Expand Down
46 changes: 27 additions & 19 deletions lib/homeComponent/view/contactCard/contact_card_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:campus_flutter/navigation_service.dart';
import 'package:campus_flutter/personComponent/model/personDetails/person_details.dart';
import 'package:campus_flutter/personComponent/model/profile/profile.dart';
import 'package:campus_flutter/personComponent/viewModel/person_details_viewmodel.dart';
import 'package:campus_flutter/studentCardComponent/model/student_card.dart';
import 'package:campus_flutter/settingsComponent/views/settings_view.dart';
import 'package:campus_flutter/studentCardComponent/viewModel/student_card_viewmodel.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -60,7 +60,7 @@ class _ContactCardViewState extends ConsumerState<ContactCardView> {
padding: const EdgeInsets.all(10.0),
child: Row(
children: [
profilePicture(),
profilePicture(data),
const Padding(padding: EdgeInsets.only(left: 15)),
Expanded(
child: Column(
Expand Down Expand Up @@ -95,27 +95,35 @@ class _ContactCardViewState extends ConsumerState<ContactCardView> {
);
}

Widget profilePicture() {
return StreamBuilder(
stream: ref.watch(studentCardViewModel).studentCard,
builder: (context, snapshot) {
if (snapshot.hasData || snapshot.hasError) {
return CircleAvatar(
backgroundImage: imageData(snapshot),
backgroundColor: Theme.of(context).cardTheme.color,
radius: contactImageSize / 2,
);
} else {
return SizedBox(height: contactImageSize, width: contactImageSize);
}
},
Widget profilePicture(PersonDetails? data) {
if (ref.read(showStudentCardPicture)) {
return StreamBuilder(
stream: ref.watch(studentCardViewModel).studentCard,
builder: (context, snapshot) {
if (snapshot.hasData || snapshot.hasError) {
return image(snapshot.data?.first.image);
} else {
return SizedBox(height: contactImageSize, width: contactImageSize);
}
},
);
} else {
return image(data?.imageData);
}
}

Widget image(String? imageData) {
return CircleAvatar(
backgroundImage: provideImage(imageData),
backgroundColor: Theme.of(context).cardTheme.color,
radius: contactImageSize / 2,
);
}

ImageProvider<Object> imageData(AsyncSnapshot<List<StudentCard>?> snapshot) {
if (snapshot.hasData && snapshot.data!.isNotEmpty) {
ImageProvider<Object> provideImage(String? imageData) {
if (imageData != null) {
return Image.memory(
base64DecodeImageData(snapshot.data!.first.image),
base64DecodeImageData(imageData),
).image;
} else {
return const AssetImage(
Expand Down
5 changes: 2 additions & 3 deletions lib/personComponent/model/personDetails/person_details.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import 'package:campus_flutter/base/enums/gender.dart';
import 'package:campus_flutter/personComponent/model/personDetails/contact_info.dart';
import 'package:campus_flutter/personComponent/model/personDetails/organisation.dart';
import 'package:campus_flutter/personComponent/model/personDetails/phone_extension.dart';
import 'package:campus_flutter/personComponent/model/personDetails/room.dart';
import 'package:json_annotation/json_annotation.dart';

import '../../../base/enums/gender.dart';
import 'organisation.dart';

part 'person_details.g.dart';

@JsonSerializable()
Expand Down
2 changes: 2 additions & 0 deletions lib/settingsComponent/viewModels/settings_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class SettingsViewModel {
value = value.index;
case UserPreference.browser:
ref.read(useWebView.notifier).state = value as bool;
case UserPreference.studentCardPicture:
ref.read(showStudentCardPicture.notifier).state = value as bool;
case UserPreference.failedGrades:
ref.read(hideFailedGrades.notifier).state = value as bool;
case UserPreference.weekends:
Expand Down
22 changes: 22 additions & 0 deletions lib/settingsComponent/views/appearance_settings_view.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:campus_flutter/base/enums/appearance.dart';
import 'package:campus_flutter/base/enums/user_preference.dart';
import 'package:campus_flutter/base/util/seperated_list.dart';
import 'package:campus_flutter/personComponent/viewModel/profile_viewmodel.dart';
import 'package:campus_flutter/studiesComponent/viewModel/grade_viewmodel.dart';
import 'package:campus_flutter/homeComponent/view/widget/widget_frame_view.dart';
import 'package:campus_flutter/main.dart';
Expand All @@ -22,6 +23,7 @@ class AppearanceSettingsView extends ConsumerWidget {
widgets: [
_appearanceSelection(context, ref),
_useWebView(context, ref),
_showStudentCardPicture(context, ref),
_hideFailedGrades(context, ref),
],
),
Expand Down Expand Up @@ -71,6 +73,26 @@ class AppearanceSettingsView extends ConsumerWidget {
);
}

Widget _showStudentCardPicture(BuildContext context, WidgetRef ref) {
return ListTile(
dense: true,
title: Text(
context.tr("showStudentCardPicture"),
style: Theme.of(context).textTheme.bodyMedium,
),
trailing: Switch(
value: ref.watch(showStudentCardPicture),
onChanged: (value) {
ref.read(settingsViewModel).savePreference(
UserPreference.studentCardPicture,
value,
);
ref.read(profileViewModel).fetch(false);
},
),
);
}

Widget _hideFailedGrades(BuildContext context, WidgetRef ref) {
return ListTile(
dense: true,
Expand Down
1 change: 1 addition & 0 deletions lib/settingsComponent/views/settings_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:go_router/go_router.dart';
import 'package:package_info_plus/package_info_plus.dart';

final useWebView = StateProvider<bool>((ref) => true);
final showStudentCardPicture = StateProvider<bool>((ref) => true);
final hideFailedGrades = StateProvider<bool>((ref) => false);
final showWeekends = StateProvider<bool>((ref) => false);
final showHiddenCalendarEntries = StateProvider<bool>((ref) => false);
Expand Down

0 comments on commit 860f9f4

Please sign in to comment.