ente/mobile/lib/ui/collections/new_album_icon.dart

65 lines
2.1 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
2023-07-03 07:00:05 +00:00
import "package:logging/logging.dart";
2023-04-05 09:50:48 +00:00
import "package:photos/generated/l10n.dart";
2023-08-25 04:39:30 +00:00
import 'package:photos/models/collection/collection.dart';
import 'package:photos/models/collection/collection_items.dart';
2023-07-03 07:00:05 +00:00
import "package:photos/services/collections_service.dart";
import "package:photos/ui/components/buttons/icon_button_widget.dart";
2023-07-03 07:00:05 +00:00
import "package:photos/ui/viewer/gallery/collection_page.dart";
import "package:photos/utils/dialog_util.dart";
import "package:photos/utils/navigation_util.dart";
2023-08-25 04:31:03 +00:00
class NewAlbumIcon extends StatelessWidget {
final IconData icon;
final Color? color;
final IconButtonType iconButtonType;
const NewAlbumIcon({
required this.icon,
required this.iconButtonType,
this.color,
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return IconButtonWidget(
icon: icon,
iconButtonType: iconButtonType,
onTap: () async {
2023-07-03 07:00:05 +00:00
final result = await showTextInputDialog(
context,
2023-07-03 07:00:05 +00:00
title: S.of(context).newAlbum,
submitButtonLabel: S.of(context).create,
hintText: S.of(context).enterAlbumName,
alwaysShowSuccessState: false,
initialValue: "",
textCapitalization: TextCapitalization.words,
onSubmit: (String text) async {
// indicates user cancelled the rename request
if (text.trim() == "") {
return;
}
try {
final Collection c =
await CollectionsService.instance.createAlbum(text);
2023-12-21 07:34:06 +00:00
// ignore: unawaited_futures
2023-07-03 07:00:05 +00:00
routeToPage(
2023-07-03 08:24:49 +00:00
context,
CollectionPage(CollectionWithThumbnail(c, null)),
);
2023-07-03 07:00:05 +00:00
} catch (e, s) {
Logger("CreateNewAlbumIcon")
.severe("Failed to rename album", e, s);
rethrow;
}
},
);
2023-07-03 07:00:05 +00:00
if (result is Exception) {
2023-12-02 11:42:52 +00:00
await showGenericErrorDialog(context: context, error: result);
2023-07-03 07:00:05 +00:00
}
},
);
}
}