Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate group_domain_implementation to null safety #740

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import 'dart:async';
import 'dart:developer';

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:group_domain_models/group_domain_accessors.dart';
import 'package:group_domain_models/group_domain_models.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:sharezone_common/helper_functions.dart';
import 'package:sharezone_common/references.dart';
import 'package:user/user.dart';
Expand All @@ -38,10 +38,15 @@ class FirestoreCourseMemberAccessor extends CourseMemberAccessor {
List<MemberData> membersData = [];

void update() {
streamController.add(List.of(membersData)
..addAll(joinedUsersData.where((joinedUser) =>
membersData.where((it) => it.id == joinedUser.id).isEmpty) ??
[]));
streamController.add(
List.of(membersData)
..addAll(
joinedUsersData.where(
(joinedUser) =>
membersData.where((it) => it.id == joinedUser.id).isEmpty,
),
),
);
}

final subscription2 = _firestore
Expand Down Expand Up @@ -73,8 +78,12 @@ class FirestoreCourseMemberAccessor extends CourseMemberAccessor {
final subscription = _memberReference(courseID)
.snapshots()
.map((snapshot) => snapshot.docs
.map((docSnap) =>
MemberData.fromData(docSnap.data(), id: docSnap.id))
.map(
(docSnap) => MemberData.fromData(
docSnap.data() as Map<String, dynamic>,
id: docSnap.id,
),
)
.toList())
.listen((newData) {
membersData = newData;
Expand All @@ -92,11 +101,15 @@ class FirestoreCourseMemberAccessor extends CourseMemberAccessor {
Stream<MemberData> streamSingleMember(String courseID, String memberID) {
// ignore:close_sinks
final StreamController<MemberData> streamController = StreamController();
MemberData joinedUsersData;
MemberData membersData;
MemberData? joinedUsersData;
MemberData? membersData;

void update() {
streamController.add(membersData ?? joinedUsersData);
if (membersData != null) {
streamController.add(membersData!);
} else if (joinedUsersData != null) {
streamController.add(joinedUsersData!);
}
}

final subscription2 = _firestore
Expand All @@ -110,13 +123,13 @@ class FirestoreCourseMemberAccessor extends CourseMemberAccessor {
if (docSnapshot.exists) {
joinedUsersData = MemberData.create(
id: docSnapshot.id,
role: docSnapshot.data()['powerLevel'] == 'owner'
role: docSnapshot.data()!['powerLevel'] == 'owner'
Jonas-Sander marked this conversation as resolved.
Show resolved Hide resolved
? MemberRole.owner
: MemberRole.creator,
user: AppUser.create(id: docSnapshot.id).copyWith(
name: docSnapshot.data()['name'],
name: docSnapshot.data()!['name'],
typeOfUser: enumFromString(
TypeOfUser.values, docSnapshot.data()['typeOfUser'])),
TypeOfUser.values, docSnapshot.data()!['typeOfUser'])),
);
} else {
joinedUsersData = null;
Expand All @@ -129,7 +142,9 @@ class FirestoreCourseMemberAccessor extends CourseMemberAccessor {
final subscription = _memberReference(courseID)
.doc(memberID)
.snapshots()
.map((docSnap) => MemberData.fromData(docSnap.data(), id: docSnap.id))
.map((docSnap) => MemberData.fromData(
docSnap.data() as Map<String, dynamic>,
id: docSnap.id))
.listen((newData) {
membersData = newData;
update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
//
// SPDX-License-Identifier: EUPL-1.2

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:group_domain_models/group_domain_accessors.dart';
import 'package:group_domain_models/group_domain_models.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:sharezone_common/references.dart';

class FirestoreSchoolClassMemberAccessor extends SchoolClassMemberAccessor {
Expand All @@ -27,8 +27,10 @@ class FirestoreSchoolClassMemberAccessor extends SchoolClassMemberAccessor {
return _memberReference(schoolClassID).snapshots().map(
(snapshot) => snapshot.docs
.map(
(docSnap) =>
MemberData.fromData(docSnap.data(), id: docSnap.id),
(docSnap) => MemberData.fromData(
docSnap.data() as Map<String, dynamic>,
id: docSnap.id,
),
)
.toList(),
);
Expand All @@ -37,7 +39,10 @@ class FirestoreSchoolClassMemberAccessor extends SchoolClassMemberAccessor {
@override
Stream<MemberData> streamSingleMember(String schoolClassID, String memberID) {
return _memberReference(schoolClassID).doc(memberID).snapshots().map(
(snapshot) => MemberData.fromData(snapshot.data(), id: snapshot.id),
(snapshot) => MemberData.fromData(
snapshot.data() as Map<String, dynamic>,
id: snapshot.id,
),
);
}
}
2 changes: 1 addition & 1 deletion lib/group_domain_implementation/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ version: 0.0.1
publish_to: none

environment:
sdk: ">=2.10.0 <3.0.0"
sdk: '>=2.12.0 <3.0.0'

dependencies:
group_domain_models:
Expand Down