Potential fix for null pointer err

This commit is contained in:
Neeraj Gupta 2023-01-25 16:32:08 +05:30
parent 6095d9b5e4
commit ba7475db01
No known key found for this signature in database
GPG key ID: 3C5A1684DC1729E1
3 changed files with 36 additions and 29 deletions

View file

@ -49,6 +49,13 @@ class Collection {
return mMdVersion > 0 && magicMetadata.visibility == visibilityArchive;
}
// hasLink returns true if there's any link attached to the collection
// including expired links
bool get hasLink => publicURLs != null && publicURLs!.isNotEmpty;
// hasSharees returns true if the collection is shared with other ente users
bool get hasSharees => sharees != null && sharees!.isNotEmpty;
bool isHidden() {
if (isDefaultHidden()) {
return true;

View file

@ -72,9 +72,7 @@ class _SharedCollectionGalleryState extends State<SharedCollectionGallery>
final c = CollectionsService.instance
.getCollectionByID(file.collectionID!)!;
if (c.owner!.id == Configuration.instance.getUserID()) {
if (c.sharees!.isNotEmpty ||
c.publicURLs!.isNotEmpty ||
c.isSharedFilesCollection()) {
if (c.hasSharees || c.hasLink || c.isSharedFilesCollection()) {
outgoing.add(
CollectionWithThumbnail(
c,
@ -268,27 +266,29 @@ class OutgoingCollectionItem extends StatelessWidget {
@override
Widget build(BuildContext context) {
final sharees = <String?>[];
for (int index = 0; index < c.collection.sharees!.length; index++) {
final sharee = c.collection.sharees![index]!;
final name =
(sharee.name?.isNotEmpty ?? false) ? sharee.name : sharee.email;
if (index < 2) {
sharees.add(name);
} else {
final remaining = c.collection.sharees!.length - index;
if (remaining == 1) {
// If it's the last sharee
sharees.add(name);
final shareesName = <String>[];
if (c.collection.hasSharees) {
for (int index = 0; index < c.collection.sharees!.length; index++) {
final sharee = c.collection.sharees![index]!;
final String name =
(sharee.name?.isNotEmpty ?? false) ? sharee.name! : sharee.email;
if (index < 2) {
shareesName.add(name);
} else {
sharees.add(
"and " +
remaining.toString() +
" other" +
(remaining > 1 ? "s" : ""),
);
final remaining = c.collection.sharees!.length - index;
if (remaining == 1) {
// If it's the last sharee
shareesName.add(name);
} else {
shareesName.add(
"and " +
remaining.toString() +
" other" +
(remaining > 1 ? "s" : ""),
);
}
break;
}
break;
}
}
return GestureDetector(
@ -325,22 +325,22 @@ class OutgoingCollectionItem extends StatelessWidget {
),
),
const Padding(padding: EdgeInsets.all(2)),
c.collection.publicURLs!.isEmpty
? Container()
: (c.collection.publicURLs!.first!.isExpired
c.collection.hasLink
? (c.collection.publicURLs!.first!.isExpired
? const Icon(
Icons.link,
color: warning500,
)
: const Icon(Icons.link)),
: const Icon(Icons.link))
: Container(),
],
),
sharees.isEmpty
shareesName.isEmpty
? Container()
: Padding(
padding: const EdgeInsets.fromLTRB(0, 4, 0, 0),
child: Text(
"Shared with " + sharees.join(", "),
"Shared with " + shareesName.join(", "),
style: TextStyle(
fontSize: 14,
color: Theme.of(context).primaryColorLight,

View file

@ -46,7 +46,7 @@ class _ShareCollectionPageState extends State<ShareCollectionPage> {
@override
Widget build(BuildContext context) {
_sharees = widget.collection.sharees ?? [];
final bool hasUrl = widget.collection.publicURLs?.isNotEmpty ?? false;
final bool hasUrl = widget.collection.hasLink;
final children = <Widget>[];
children.add(
MenuSectionTitle(