tane/apps/app_seeds/lib/ui/avatar_edit.dart
vjrj c4421f768a feat(profile): Material default avatar + square photo crop
Drop the DiceBear generated avatar (and dicebear_core/dicebear_styles/
flutter_svg): the default is again a Material coloured-initial disc from
the pubkey. Picking a photo now goes through a square crop step
(crop_your_image — pure Flutter, all platforms incl. desktop, Apache-2.0,
only pulls the image package we already had) before the 24 KB thumbnail.
2026-07-12 23:39:56 +02:00

67 lines
2.5 KiB
Dart

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<String?> showAvatarPicker(
BuildContext context, {
required String current,
}) {
return showModalBottomSheet<String>(
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),
),
),
],
],
),
),
);
},
);
}