Skip to content

Commit

Permalink
Remove package:optional.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas-Sander committed Sep 4, 2023
1 parent e1139fb commit 3d46757
Show file tree
Hide file tree
Showing 35 changed files with 105 additions and 182 deletions.
14 changes: 7 additions & 7 deletions app/lib/onboarding/group_onboarding/pages/create_courses.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import 'package:bloc_provider/bloc_provider.dart';
import 'package:flutter/material.dart';
import 'package:optional/optional.dart';

import 'package:sharezone/groups/src/pages/course/create/course_create_page.dart';
import 'package:sharezone/groups/src/pages/course/create/course_template_page.dart';
import 'package:sharezone/groups/src/pages/school_class/create_course/school_class_course_template_page.dart';
Expand All @@ -27,16 +27,16 @@ class GroupOnboardingCreateCourse extends StatelessWidget {
}) : super(key: key);

static const tag = 'onboarding-course-page';
final Optional<String> schoolClassId;
final String? schoolClassId;

@override
Widget build(BuildContext context) {
return GroupOnboardingPageTemplate(
title: getTitle(context),
children: [
if (schoolClassId.isPresent)
if (schoolClassId != null)
SchoolClassCourseCreateTemplateBody(
schoolClassID: schoolClassId.value,
schoolClassID: schoolClassId!,
bottom: _CreateCustomCourse(schoolClassId: schoolClassId),
)
else
Expand Down Expand Up @@ -73,7 +73,7 @@ class _CreateCustomCourse extends StatelessWidget {
required this.schoolClassId,
}) : super(key: key);

final Optional<String> schoolClassId;
final String? schoolClassId;

@override
Widget build(BuildContext context) {
Expand All @@ -99,8 +99,8 @@ class _CreateCustomCourse extends StatelessWidget {
],
),
onPressed: () {
if (schoolClassId.isPresent) {
openSchoolClassCourseCreatePage(context, schoolClassId.value);
if (schoolClassId != null) {
openSchoolClassCourseCreatePage(context, schoolClassId!);
} else {
openCourseCreatePage(context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import 'package:bloc_provider/bloc_provider.dart';
import 'package:bloc_provider/multi_bloc_provider.dart';
import 'package:crash_analytics/crash_analytics.dart';
import 'package:flutter/material.dart';
import 'package:optional/optional.dart';
import 'package:sharezone/auth/login_button.dart';
import 'package:sharezone/blocs/application_bloc.dart';
import 'package:sharezone/groups/src/pages/school_class/my_school_class_bloc.dart';
Expand Down Expand Up @@ -164,9 +163,7 @@ class __TextFieldSubmitButtonState extends State<_TextFieldSubmitButton> {
Navigator.push(
context,
FadeRoute(
child: GroupOnboardingCreateCourse(
schoolClassId: Optional.ofNullable(schoolClassID),
),
child: GroupOnboardingCreateCourse(schoolClassId: schoolClassID),
tag: GroupOnboardingCreateCourse.tag,
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import 'package:bloc_provider/bloc_provider.dart';
import 'package:flutter/material.dart';
import 'package:optional/optional.dart';
import 'package:sharezone/onboarding/group_onboarding/logic/group_onboarding_bloc.dart';
import 'package:sharezone/onboarding/group_onboarding/pages/create_schoolclass.dart';
import 'package:sharezone/onboarding/group_onboarding/pages/group_onboarding_page_template.dart';
Expand Down Expand Up @@ -68,8 +67,7 @@ class _CourseTeacherButton extends StatelessWidget {
Navigator.push(
context,
FadeRoute(
child: GroupOnboardingCreateCourse(
schoolClassId: Optional.ofNullable(null)),
child: GroupOnboardingCreateCourse(schoolClassId: null),
tag: GroupOnboardingCreateCourse.tag,
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:bloc_provider/bloc_provider.dart';
import 'package:design/design.dart';
import 'package:flutter/material.dart';
import 'package:group_domain_models/group_domain_models.dart';
import 'package:optional/optional.dart';

import 'package:sharezone/groups/src/widgets/group_qr_code.dart';
import 'package:sharezone/groups/src/widgets/group_share.dart';
import 'package:sharezone/groups/src/widgets/sharecode_text.dart';
Expand All @@ -28,7 +28,7 @@ class GroupOnboardingShareSharecode extends StatelessWidget {
}) : super(key: key);

static const tag = 'onboarding-share-sharecode-page';
final Optional<String> schoolClassId;
final String? schoolClassId;

@override
Widget build(BuildContext context) {
Expand All @@ -43,8 +43,8 @@ class GroupOnboardingShareSharecode extends StatelessWidget {
const SizedBox(height: 6),
_JoinHint(),
const SizedBox(height: 18),
if (schoolClassId.isPresent)
_SchoolClassSharecodeBox(schoolClassId: schoolClassId.value)
if (schoolClassId != null)
_SchoolClassSharecodeBox(schoolClassId: schoolClassId!)
else
_CoursesSharecodeBox(),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ class _FileCard extends StatelessWidget {
key: ValueKey(view.id),
padding: const EdgeInsets.only(bottom: 10),
child: CustomCard(
onTap: view.downloadUrl.isPresent
onTap: view.downloadUrl != null
? () => openCreateSubmissionFile(context, view)
: null,
child: Column(
Expand Down Expand Up @@ -336,7 +336,7 @@ class _FileCard extends StatelessWidget {
LinearProgressIndicator(
backgroundColor: Colors.grey[400],
valueColor: const AlwaysStoppedAnimation(Colors.lightBlue),
value: view.uploadProgress.orElse(0),
value: view.uploadProgress ?? 0,
),
if (view.status == FileViewStatus.failed)
LinearProgressIndicator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import 'package:sharezone/filesharing/widgets/download_unknown_file_type_dialog_
import 'package:sharezone_utils/platform.dart';

void openCreateSubmissionFile(BuildContext context, FileView view) {
if (view.downloadUrl.isPresent) {
if (view.downloadUrl != null) {
openFirestoreFilePage(
context: context,
fileFormat: view.fileFormat,
Expand All @@ -25,14 +25,14 @@ void openCreateSubmissionFile(BuildContext context, FileView view) {
icon: const Icon(Icons.file_download),
onPressed: () => _downloadFile(
context: context,
downloadUrl: view.downloadUrl.value,
downloadUrl: view.downloadUrl!,
fileId: view.id,
fileName: view.name,
format: view.fileFormat,
),
)
],
downloadURL: view.downloadUrl.value,
downloadURL: view.downloadUrl,
id: view.id,
name: view.name,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class _SelectionSheet extends StatelessWidget {

@override
Widget build(BuildContext context) {
final isASchoolClassSelected = view.selectedSchoolClass.isPresent;
final isASchoolClassSelected = view.selectedSchoolClass != null;
return SafeArea(
child: SingleChildScrollView(
child: Column(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import 'package:collection/collection.dart';
import 'package:common_domain_models/common_domain_models.dart';
import 'package:optional/optional_internal.dart';

class SchoolClassFilterView {
final List<SchoolClassView> schoolClassList;
Expand All @@ -31,7 +30,7 @@ class SchoolClassFilterView {
/// Gibt den Namen der ausgewählten Schulklasse zurück.
/// Falls keine Schulklasse ausgewählt ist, wird null zurückgegeben.
String? get currentSchoolClassName =>
hasSchoolClassSelected ? selectedSchoolClass.value.name : null;
hasSchoolClassSelected ? selectedSchoolClass!.name : null;

bool get hasMoreThanOneSchoolClass => schoolClassList.length > 1;

Expand All @@ -41,12 +40,11 @@ class SchoolClassFilterView {

bool get shouldShowAllGroups => !hasSchoolClassSelected;

Optional<SchoolClassView> get selectedSchoolClass {
if (!hasSchoolClassSelected) return Optional.empty();
SchoolClassView? get selectedSchoolClass {
if (!hasSchoolClassSelected) return null;

return schoolClassList
.singleWhere((schoolClass) => schoolClass.isSelected == true)
.toOptional;
.singleWhere((schoolClass) => schoolClass.isSelected == true);
}

@override
Expand Down
8 changes: 0 additions & 8 deletions app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1387,14 +1387,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.4.1"
optional:
dependency: "direct main"
description:
name: optional
sha256: f80327d7a3335a0be68418072668043c7ab291df575c21aa42e0c5633641da39
url: "https://pub.dev"
source: hosted
version: "6.1.0+1"
overlay_support:
dependency: "direct main"
description:
Expand Down
1 change: 0 additions & 1 deletion app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ dependencies:
path: ../lib/notifications
numberpicker: ^2.1.1
open_file_plus: ^3.4.1
optional: ^6.1.0+1
overlay_support: ^2.1.0
package_info_plus: ^4.1.0
permission_handler: ^10.2.0
Expand Down
9 changes: 4 additions & 5 deletions app/test/timetable/mock/mock_school_class_gateway.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:app_functions/app_functions.dart';
import 'package:common_domain_models/common_domain_models.dart';
import 'package:group_domain_models/group_domain_accessors.dart';
import 'package:group_domain_models/group_domain_models.dart';
import 'package:optional/optional_internal.dart';

import 'package:rxdart/rxdart.dart';
import 'package:sharezone/groups/src/pages/school_class/my_school_class_bloc.dart';
import 'package:sharezone/util/api/school_class_gateway.dart';
Expand Down Expand Up @@ -105,7 +105,7 @@ class MockSchoolClassGateway implements SchoolClassGateway {
@override
Stream<List<String>> streamCoursesID(String schoolClassID) {
return Stream.value(_courses.valueOrNull!
.where((course) => course.schoolClassId.value.id == schoolClassID)
.where((course) => course.schoolClassId!.id == schoolClassID)
.map((course) => course.courseId.id)
.toList());
}
Expand Down Expand Up @@ -138,8 +138,7 @@ class MockSchoolClassGateway implements SchoolClassGateway {

class MockCourse {
final GroupId courseId;
final Optional<GroupId> schoolClassId;
final GroupId? schoolClassId;

MockCourse({GroupId? schoolClassId, required this.courseId})
: schoolClassId = Optional.ofNullable(schoolClassId);
MockCourse({this.schoolClassId, required this.courseId});
}
6 changes: 3 additions & 3 deletions app/test/timetable/school_class_filter_view_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import 'package:common_domain_models/common_domain_models.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:optional/optional.dart';

import 'package:random_string/random_string.dart';
import 'package:sharezone/timetable/timetable_page/school_class_filter/school_class_filter_view.dart';

Expand Down Expand Up @@ -100,7 +100,7 @@ void main() {
test(
'selectedSchoolClass returns empty Optional if no school class is selected',
() {
expect(viewWithNoSelection.selectedSchoolClass, Optional.empty());
expect(viewWithNoSelection.selectedSchoolClass, isNull);
});

test(
Expand All @@ -114,7 +114,7 @@ void main() {
createSchoolClassView('group2'),
]);

expect(view.selectedSchoolClass, Optional.of(selectedSchoolClassView));
expect(view.selectedSchoolClass, selectedSchoolClassView);
});

test('throw argument error if more than one school class is selected', () {
Expand Down
4 changes: 1 addition & 3 deletions app/test/timetable/timetable_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,7 @@ void main() {
await tester.tap(find.text(klasse10a.name));
await tester.pumpAndSettle();

expect(
bloc.schoolClassFilterView.valueOrNull!.selectedSchoolClass.value
.id,
expect(bloc.schoolClassFilterView.valueOrNull!.selectedSchoolClass!.id,
klasse10a.groupId);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ extension on AbgegebeneAbgabe {
username: author.name.ausgeschrieben,
submittedFiles: abgegebeneDateien.map((datei) => datei.toView()).toList(),
lastActionDateTime: letzteAktion,
wasEditedAfterwards: zuletztBearbeitet.isPresent,
wasEditedAfterwards: zuletztBearbeitet != null,
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import 'package:built_collection/built_collection.dart';
import 'package:collection/collection.dart' show IterableExtension;
import 'package:common_domain_models/common_domain_models.dart';
import 'package:files_basics/local_file.dart';
import 'package:optional/optional.dart';

import 'package:rxdart/rxdart.dart' as rx;
import 'package:rxdart/subjects.dart';
import 'contains_where_extension.dart';
Expand Down Expand Up @@ -124,7 +124,7 @@ class HomeworkUserCreateSubmissionsBloc extends BlocBase {
/// Es gibt schon erfolgreich hochgeladene Dateien, vielleicht wurde
/// die Abgabe auch schon abgegeben.
} else {
final hochgeladeneDateien = abgabenSnapshot.abgabe.value.abgabedateien;
final hochgeladeneDateien = abgabenSnapshot.abgabe?.abgabedateien ?? [];
final nurLokaleDateien = hochladeneDateien.where((datei) =>
!hochgeladeneDateien.containsWhere((hd) => hd.id == datei.id));

Expand Down Expand Up @@ -168,12 +168,10 @@ class HomeworkUserCreateSubmissionsBloc extends BlocBase {
hochgeladeneDateien.isNotEmpty && keineDateiAmHochladen;

return SubmissionPageView(
submittable: istAbgebbar,
deadlineState: state,
files: views,
submitted:
abgabenSnapshot.abgabe.map((val) => val.abgegeben).orElse(false),
);
submittable: istAbgebbar,
deadlineState: state,
files: views,
submitted: abgabenSnapshot.abgabe?.abgegeben ?? false);
}
});

Expand All @@ -195,7 +193,7 @@ class HomeworkUserCreateSubmissionsBloc extends BlocBase {
(localFiles) async {
final res = _localFileKonvertierer.konvertiereLocalFiles(localFiles);

final aktuelleAbgabe = _aktuelleAbgabe.valueOrNull?.abgabe.orElseNull;
final aktuelleAbgabe = _aktuelleAbgabe.valueOrNull?.abgabe;
final hochgeladeneNamen =
aktuelleAbgabe?.abgabedateien.map((e) => e.name).toSet() ?? {};

Expand Down Expand Up @@ -253,7 +251,7 @@ class HomeworkUserCreateSubmissionsBloc extends BlocBase {
}
final abgabeSnapshot = _aktuelleAbgabe.value;
if (abgabeSnapshot.existiertAbgabe) {
final abgabe = abgabeSnapshot.abgabe.value;
final abgabe = abgabeSnapshot.abgabe!;
final hatDateiMitId = abgabe.abgabedateien
.where((element) => element.id == AbgabedateiId(fileId))
.isNotEmpty;
Expand All @@ -280,7 +278,7 @@ class HomeworkUserCreateSubmissionsBloc extends BlocBase {
Future<void> renameFile(String fileId, String newBasename) async {
final abgabeSnapshot = _aktuelleAbgabe.value;
if (abgabeSnapshot.existiertAbgabe) {
final abgabe = abgabeSnapshot.abgabe.value;
final abgabe = abgabeSnapshot.abgabe!;
final datei = abgabe.abgabedateien
.firstWhereOrNull((element) => element.id == AbgabedateiId(fileId));
if (datei != null) {
Expand Down Expand Up @@ -357,7 +355,7 @@ extension on BuiltList<HochladeneLokaleAbgabedatei> {
}

class Fortschritt {
final Optional<double> inProzent;
final double? inProzent;
final FileViewStatus status;

const Fortschritt({
Expand All @@ -367,7 +365,7 @@ class Fortschritt {

factory Fortschritt.nichtGestartet() {
return const Fortschritt(
inProzent: Optional.empty(),
inProzent: null,
status: FileViewStatus.unitiated,
);
}
Expand Down Expand Up @@ -418,7 +416,7 @@ class HochladeneLokaleAbgabedatei extends LokaleAbgabedatei {
name: datei.name,
dateigroesse: datei.dateigroesse,
erstellungsdatum: datei.erstellungsdatum,
pfad: datei.pfad.orElseNull,
pfad: datei.pfad,
localFile: datei.localFile,
);

Expand Down
Loading

0 comments on commit 3d46757

Please sign in to comment.