ente/lib/ui/collections/create_new_album_widget.dart

56 lines
1.9 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-07-03 07:00:05 +00:00
import "package:photos/models/collection.dart";
import "package:photos/models/collection_items.dart";
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";
class CreateNewAlbumIcon extends StatelessWidget {
const CreateNewAlbumIcon({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return IconButtonWidget(
icon: Icons.add_rounded,
iconButtonType: IconButtonType.secondary,
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);
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) {
showGenericErrorDialog(context: context);
}
},
);
}
}