Files
Client/lib/widget/avatar_actions_sheet.dart
T

65 lines
2.0 KiB
Dart

import 'dart:typed_data';
import 'package:flutter/material.dart';
import '../routing/app_routes.dart';
import 'details_bottom_sheet.dart';
import 'file_pick.dart';
/// Result of the user's choice inside [showAvatarActionsSheet]. The sheet
/// only collects intent + the (cropped) image bytes — the actual upload /
/// delete and any loading state are the caller's responsibility, so failures
/// surface in the screen that owns the avatar, not in a transient sheet.
sealed class AvatarSheetResult {
const AvatarSheetResult();
}
class AvatarUploadResult extends AvatarSheetResult {
final Uint8List bytes;
const AvatarUploadResult(this.bytes);
}
class AvatarRemoveResult extends AvatarSheetResult {
const AvatarRemoveResult();
}
/// Bottom sheet with "from gallery", "take photo" and optional "remove"
/// actions. The picker + 1:1 cropper run with the sheet still mounted, so a
/// cancelled pick simply returns the user to the sheet. The sheet only pops
/// once a concrete result exists (or never, if everything was cancelled).
Future<AvatarSheetResult?> showAvatarActionsSheet(
BuildContext context, {
required bool allowRemove,
}) async {
AvatarSheetResult? result;
await showDetailsBottomSheet(
context,
children: (sheetContext) => [
...imageSourceTiles(
sheetContext,
transform: (bytes) =>
AppRoutes.openAvatarCrop(sheetContext, imageBytes: bytes),
onPicked: (bytes) => result = AvatarUploadResult(bytes),
),
if (allowRemove) ...[
const Divider(),
ListTile(
leading: Icon(
Icons.delete_outline,
color: Theme.of(sheetContext).colorScheme.error,
),
title: Text(
'Profilbild entfernen',
style: TextStyle(color: Theme.of(sheetContext).colorScheme.error),
),
onTap: () {
result = const AvatarRemoveResult();
Navigator.of(sheetContext).pop();
},
),
],
],
);
return result;
}