Переглянути джерело

Fix BadElement: use firstOrNull instead of first

Neeraj Gupta 2 роки тому
батько
коміт
9f84a49952

+ 1 - 0
lib/ui/sharing/album_participants_page.dart

@@ -0,0 +1 @@
+

+ 9 - 7
lib/ui/sharing/manage_links_widget.dart

@@ -2,6 +2,7 @@
 
 
 import 'dart:convert';
 import 'dart:convert';
 
 
+import 'package:collection/collection.dart';
 import 'package:flutter/cupertino.dart';
 import 'package:flutter/cupertino.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
 import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
@@ -59,7 +60,7 @@ class _ManageSharedLinkWidgetState extends State<ManageSharedLinkWidget> {
   @override
   @override
   Widget build(BuildContext context) {
   Widget build(BuildContext context) {
     final enteColorScheme = getEnteColorScheme(context);
     final enteColorScheme = getEnteColorScheme(context);
-    final PublicURL url = widget.collection?.publicURLs?.first;
+    final PublicURL url = widget.collection?.publicURLs?.firstOrNull;
     return Scaffold(
     return Scaffold(
       backgroundColor: Theme.of(context).backgroundColor,
       backgroundColor: Theme.of(context).backgroundColor,
       appBar: AppBar(
       appBar: AppBar(
@@ -128,9 +129,9 @@ class _ManageSharedLinkWidgetState extends State<ManageSharedLinkWidget> {
                     menuItemColor: getEnteColorScheme(context).fillFaint,
                     menuItemColor: getEnteColorScheme(context).fillFaint,
                     pressedColor: getEnteColorScheme(context).fillFaint,
                     pressedColor: getEnteColorScheme(context).fillFaint,
                     trailingSwitch: Switch.adaptive(
                     trailingSwitch: Switch.adaptive(
-                      value:
-                          widget.collection.publicURLs?.first?.enableDownload ??
-                              true,
+                      value: widget.collection.publicURLs?.firstOrNull
+                              ?.enableDownload ??
+                          true,
                       onChanged: (value) async {
                       onChanged: (value) async {
                         if (!value) {
                         if (!value) {
                           final choice = await showChoiceDialog(
                           final choice = await showChoiceDialog(
@@ -177,8 +178,8 @@ class _ManageSharedLinkWidgetState extends State<ManageSharedLinkWidget> {
                     menuItemColor: getEnteColorScheme(context).fillFaint,
                     menuItemColor: getEnteColorScheme(context).fillFaint,
                     pressedColor: getEnteColorScheme(context).fillFaint,
                     pressedColor: getEnteColorScheme(context).fillFaint,
                     trailingSwitch: Switch.adaptive(
                     trailingSwitch: Switch.adaptive(
-                      value: widget
-                              .collection.publicURLs?.first?.passwordEnabled ??
+                      value: widget.collection.publicURLs?.firstOrNull
+                              ?.passwordEnabled ??
                           false,
                           false,
                       onChanged: (enablePassword) async {
                       onChanged: (enablePassword) async {
                         if (enablePassword) {
                         if (enablePassword) {
@@ -471,7 +472,8 @@ class _ManageSharedLinkWidgetState extends State<ManageSharedLinkWidget> {
   }
   }
 
 
   Text _getLinkExpiryTimeWidget() {
   Text _getLinkExpiryTimeWidget() {
-    final int validTill = widget.collection.publicURLs?.first?.validTill ?? 0;
+    final int validTill =
+        widget.collection.publicURLs?.firstOrNull?.validTill ?? 0;
     if (validTill == 0) {
     if (validTill == 0) {
       return const Text(
       return const Text(
         'Never',
         'Never',

+ 3 - 2
lib/ui/sharing/share_collection_page.dart

@@ -2,6 +2,7 @@
 
 
 import 'dart:async';
 import 'dart:async';
 
 
+import 'package:collection/collection.dart';
 import 'package:fast_base58/fast_base58.dart';
 import 'package:fast_base58/fast_base58.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter/services.dart';
 import 'package:flutter/services.dart';
@@ -44,7 +45,7 @@ class _ShareCollectionPageState extends State<ShareCollectionPage> {
 
 
   @override
   @override
   Widget build(BuildContext context) {
   Widget build(BuildContext context) {
-    _sharees = widget.collection.sharees;
+    _sharees = widget.collection.sharees ?? [];
     final children = <Widget>[];
     final children = <Widget>[];
     children.add(
     children.add(
       MenuSectionTitle(
       MenuSectionTitle(
@@ -83,7 +84,7 @@ class _ShareCollectionPageState extends State<ShareCollectionPage> {
 
 
     final bool hasUrl = widget.collection.publicURLs?.isNotEmpty ?? false;
     final bool hasUrl = widget.collection.publicURLs?.isNotEmpty ?? false;
     final bool hasExpired =
     final bool hasExpired =
-        widget.collection.publicURLs?.first?.isExpired ?? false;
+        widget.collection?.publicURLs?.firstOrNull?.isExpired ?? false;
     children.addAll([
     children.addAll([
       const SizedBox(
       const SizedBox(
         height: 24,
         height: 24,

+ 0 - 8
lib/ui/viewer/gallery/gallery_app_bar_widget.dart

@@ -337,14 +337,6 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
           ShareCollectionPage(collection),
           ShareCollectionPage(collection),
         ),
         ),
       );
       );
-      /*return showDialog<void>(
-        context: context,
-        builder: (BuildContext context) {
-          return SharingDialog(
-            collection,
-          );
-        },
-      );*/
     } catch (e, s) {
     } catch (e, s) {
       _logger.severe(e, s);
       _logger.severe(e, s);
       await dialog.hide();
       await dialog.hide();