import 'package:flutter/material.dart'; import '../i18n/strings.g.dart'; import '../services/offer_thumbnail.dart' show offerThumbnailDataUri; import 'photo_crop.dart'; import 'photo_pick.dart'; import 'theme.dart'; /// Lets the user choose a profile avatar: take/pick a photo, square-crop it, and /// keep it as a tiny inline thumbnail — or remove it. With no photo, the /// coloured-initial disc is used. /// /// Returns the new avatar value (a `data:` photo thumbnail), an empty string to /// clear it (falls back to the coloured-initial disc), or null when cancelled. Future showAvatarPicker( BuildContext context, { required String current, }) { return showModalBottomSheet( context: context, isScrollControlled: true, builder: (sheetContext) { final t = sheetContext.t; return SafeArea( child: Padding( padding: const EdgeInsets.fromLTRB(16, 12, 16, 16), child: Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(t.avatar.title, style: Theme.of(sheetContext).textTheme.titleMedium), const SizedBox(height: 8), ListTile( key: const Key('avatar.fromPhoto'), contentPadding: EdgeInsets.zero, leading: const Icon(Icons.add_a_photo_outlined, color: seedGreen), title: Text(t.avatar.fromPhoto), onTap: () async { final bytes = await pickPhoto(sheetContext); if (bytes == null || !sheetContext.mounted) return; final cropped = await cropToSquare(sheetContext, bytes); if (cropped == null || !sheetContext.mounted) return; final uri = offerThumbnailDataUri(cropped, maxBytes: 24000); Navigator.of(sheetContext).pop(uri ?? ''); }, ), if (current.isNotEmpty) ...[ const SizedBox(height: 8), Align( alignment: AlignmentDirectional.centerStart, child: TextButton.icon( key: const Key('avatar.remove'), onPressed: () => Navigator.of(sheetContext).pop(''), icon: const Icon(Icons.delete_outline, size: 18), label: Text(t.avatar.remove), ), ), ], ], ), ), ); }, ); }