Add error states to deal with no-network situations

This commit is contained in:
Vishnu Mohandas 2020-10-31 02:21:17 +05:30
parent 03e7b385e2
commit 5d65eb2e05
2 changed files with 27 additions and 44 deletions

View file

@ -14,7 +14,7 @@ import 'package:photos/ui/email_entry_page.dart';
import 'package:photos/ui/passphrase_entry_page.dart';
import 'package:photos/ui/passphrase_reentry_page.dart';
import 'package:photos/ui/settings_page.dart';
import 'package:photos/ui/share_folder_widget.dart';
import 'package:photos/ui/share_collection_widget.dart';
import 'package:photos/utils/dialog_util.dart';
import 'package:photos/utils/file_util.dart';
import 'package:photos/utils/share_util.dart';
@ -158,21 +158,38 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
if (collection == null) {
final dialog = createProgressDialog(context, "Please wait...");
await dialog.show();
collection =
await CollectionsService.instance.getOrCreateForPath(widget.path);
await dialog.hide();
try {
collection = await CollectionsService.instance
.getOrCreateForPath(widget.path);
await dialog.hide();
} catch (e, s) {
_logger.severe(e, s);
await dialog.hide();
showGenericErrorDialog(context);
}
}
} else {
throw Exception(
"Cannot create a collection of type" + widget.type.toString());
}
}
return showDialog<void>(
context: context,
builder: (BuildContext context) {
return ShareFolderWidget(collection);
},
);
final dialog = createProgressDialog(context, "Please wait...");
await dialog.show();
try {
final sharees =
await CollectionsService.instance.getSharees(widget.collection.id);
await dialog.hide();
return showDialog<void>(
context: context,
builder: (BuildContext context) {
return SharingDialog(collection, sharees);
},
);
} catch (e, s) {
_logger.severe(e, s);
await dialog.hide();
showGenericErrorDialog(context);
}
}
Future<void> _createAlbum() async {

View file

@ -1,7 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_sodium/flutter_sodium.dart';
import 'package:flutter_typeahead/flutter_typeahead.dart';
import 'package:photos/core/configuration.dart';
import 'package:photos/db/public_keys_db.dart';
@ -12,44 +11,11 @@ import 'package:photos/services/sync_service.dart';
import 'package:photos/services/user_service.dart';
import 'package:photos/ui/common_elements.dart';
import 'package:photos/ui/loading_widget.dart';
import 'package:photos/utils/crypto_util.dart';
import 'package:photos/utils/dialog_util.dart';
import 'package:photos/utils/email_util.dart';
import 'package:photos/utils/share_util.dart';
import 'package:photos/utils/toast_util.dart';
class ShareFolderWidget extends StatefulWidget {
final Collection collection;
const ShareFolderWidget(
this.collection, {
Key key,
}) : super(key: key);
@override
_ShareFolderWidgetState createState() => _ShareFolderWidgetState();
}
class _ShareFolderWidgetState extends State<ShareFolderWidget> {
@override
Widget build(BuildContext context) {
return FutureBuilder<List<String>>(
future: widget.collection == null
? Future.value(List<String>())
: CollectionsService.instance.getSharees(widget.collection.id),
builder: (context, snapshot) {
if (snapshot.hasData) {
return SharingDialog(widget.collection, snapshot.data);
} else if (snapshot.hasError) {
return Text(snapshot.error.toString());
} else {
return loadWidget;
}
},
);
}
}
class SharingDialog extends StatefulWidget {
final Collection collection;
final List<String> sharees;