simplified code across the app and consolidated duplicated helpers
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
|
||||
import '../routing/app_routes.dart';
|
||||
import 'details_bottom_sheet.dart';
|
||||
@@ -36,31 +35,11 @@ Future<AvatarSheetResult?> showAvatarActionsSheet(
|
||||
await showDetailsBottomSheet(
|
||||
context,
|
||||
children: (sheetContext) => [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.photo_library_outlined),
|
||||
title: const Text('Aus Galerie wählen'),
|
||||
onTap: () async {
|
||||
final bytes = await _pickAndCrop(
|
||||
sheetContext,
|
||||
() => FilePick.singleGalleryPick(sheetContext, forCrop: true),
|
||||
);
|
||||
if (bytes == null || !sheetContext.mounted) return;
|
||||
result = AvatarUploadResult(bytes);
|
||||
Navigator.of(sheetContext).pop();
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.photo_camera_outlined),
|
||||
title: const Text('Foto aufnehmen'),
|
||||
onTap: () async {
|
||||
final bytes = await _pickAndCrop(
|
||||
sheetContext,
|
||||
() => FilePick.cameraPick(sheetContext, forCrop: true),
|
||||
);
|
||||
if (bytes == null || !sheetContext.mounted) return;
|
||||
result = AvatarUploadResult(bytes);
|
||||
Navigator.of(sheetContext).pop();
|
||||
},
|
||||
...imageSourceTiles(
|
||||
sheetContext,
|
||||
transform: (bytes) =>
|
||||
AppRoutes.openAvatarCrop(sheetContext, imageBytes: bytes),
|
||||
onPicked: (bytes) => result = AvatarUploadResult(bytes),
|
||||
),
|
||||
if (allowRemove) ...[
|
||||
const Divider(),
|
||||
@@ -83,14 +62,3 @@ Future<AvatarSheetResult?> showAvatarActionsSheet(
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<Uint8List?> _pickAndCrop(
|
||||
BuildContext context,
|
||||
Future<XFile?> Function() pick,
|
||||
) async {
|
||||
final picked = await pick();
|
||||
if (picked == null) return null;
|
||||
final bytes = await picked.readAsBytes();
|
||||
if (!context.mounted) return null;
|
||||
return AppRoutes.openAvatarCrop(context, imageBytes: bytes);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user