Skip to content

Commit

Permalink
Merge branch 'develop' into ui/exam_card
Browse files Browse the repository at this point in the history
  • Loading branch information
thePeras authored Nov 2, 2024
2 parents b0f5f01 + 7e98d31 commit 7e0a60d
Show file tree
Hide file tree
Showing 16 changed files with 708 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
build/
*.bin
.flutter-plugins*
packages/uni_ui/pubspec.lock

# IDE files
.DS_Store
Expand Down
2 changes: 1 addition & 1 deletion packages/uni_app/app_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.10.0-beta.25+328
1.10.0-beta.33+336
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class LibraryOccupationFetcher {
}),
);

libraryOccupation.sortFloors();
return libraryOccupation;
}

Expand Down
4 changes: 4 additions & 0 deletions packages/uni_app/lib/model/entities/library_occupation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class LibraryOccupation {
return floors[number - 1];
}

void sortFloors() {
floors.sort((a, b) => a.number.compareTo(b.number));
}

Map<String, dynamic> toJson() => _$LibraryOccupationToJson(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ abstract class StateProviderNotifier<T> extends ChangeNotifier {
if (!context.mounted || _state != null) {
return;
}
await _loadFromStorage(context).then((value) {
await _loadFromStorage(context).then((value) async {
if (context.mounted) {
_loadFromRemoteFromContext(context);
await _loadFromRemoteFromContext(context);
}
});
},
Expand Down
5 changes: 3 additions & 2 deletions packages/uni_app/lib/view/home/widgets/exit_app_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:uni/generated/l10n.dart';

/// Manages the app section displayed when the user presses the back button
Expand Down Expand Up @@ -34,9 +35,9 @@ class BackButtonExitWrapper extends StatelessWidget {
child: Text(S.of(context).no),
),
ElevatedButton(
onPressed: () {
onPressed: () async {
userActionCompleter.complete(true);
Navigator.of(context).pop(false);
await SystemNavigator.pop();
},
child: Text(S.of(context).yes),
),
Expand Down
19 changes: 7 additions & 12 deletions packages/uni_app/lib/view/home/widgets/schedule_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class ScheduleCard extends GenericCard {
),
),
contentLoadingWidget: const ScheduleCardShimmer().build(context),
mapper: (lectures) => lectures
.where((lecture) => lecture.endTime.isAfter(DateTime.now()))
.toList(),
);
}

Expand All @@ -71,16 +74,8 @@ class ScheduleCard extends GenericCard {
for (final dayLectures
in lecturesByDay.sublist(0, min(2, lecturesByDay.length))) {
final day = dayLectures.key;
final lectures = dayLectures.value
.where(
(element) =>
// Hide finished lectures from today
element.startTime.weekday != DateTime.now().weekday ||
element.endTime.isAfter(DateTime.now()),
)
.toList();

if (lectures.isEmpty) {

if (dayLectures.value.isEmpty) {
continue;
}

Expand All @@ -91,11 +86,11 @@ class ScheduleCard extends GenericCard {
),
);

for (final lecture in lectures) {
for (final lecture in dayLectures.value) {
rows.add(createRowFromLecture(context, lecture));
}

if (lectures.length >= 2) {
if (dayLectures.value.length >= 2) {
break;
}
}
Expand Down
13 changes: 10 additions & 3 deletions packages/uni_app/lib/view/lazy_consumer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ class LazyConsumer<T1 extends StateProviderNotifier<T2>, T2>
required this.hasContent,
required this.onNullContent,
this.contentLoadingWidget,
this.mapper,
super.key,
});

final Widget Function(BuildContext, T2) builder;
final bool Function(T2) hasContent;
final Widget onNullContent;
final Widget? contentLoadingWidget;
final T2 Function(T2)? mapper;

static T2 _defaultMapper<T2>(T2 value) => value;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -89,8 +93,11 @@ class LazyConsumer<T1 extends StateProviderNotifier<T2>, T2>
}

Widget requestDependantWidget(BuildContext context, T1 provider) {
final showContent =
provider.state != null && hasContent(provider.state as T2);
final mappedState = provider.state != null
? (mapper ?? _defaultMapper)(provider.state as T2)
: null;

final showContent = provider.state != null && hasContent(mappedState as T2);

if (provider.requestStatus == RequestStatus.busy && !showContent) {
return loadingWidget(context);
Expand All @@ -99,7 +106,7 @@ class LazyConsumer<T1 extends StateProviderNotifier<T2>, T2>
}

return showContent
? builder(context, provider.state as T2)
? builder(context, mappedState)
: Center(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 10),
Expand Down
2 changes: 1 addition & 1 deletion packages/uni_app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ publish_to: "none" # We do not publish to pub.dev
# To change it manually, override the value in app_version.txt.
# The app version code is automatically also bumped by CI.
# Do not change it manually.
version: 1.10.0-beta.25+328
version: 1.10.0-beta.33+336

environment:
sdk: ">=3.4.0 <4.0.0"
Expand Down
Loading

0 comments on commit 7e0a60d

Please sign in to comment.