140 lines
3.9 KiB
Dart
140 lines
3.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:image_picker/image_picker.dart';
|
|
import 'package:lucide_icons/lucide_icons.dart';
|
|
import '../../../../core/l10n/l10n.dart';
|
|
|
|
class HomeSheet extends StatelessWidget {
|
|
final Function(List<XFile>) onImagesSelected;
|
|
|
|
const HomeSheet({super.key, required this.onImagesSelected});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final colorScheme = Theme.of(context).colorScheme;
|
|
|
|
return GestureDetector(
|
|
onTap: () => Navigator.of(context).pop(),
|
|
child: Container(
|
|
color: colorScheme.scrim.withValues(alpha: 0.3),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: [
|
|
GestureDetector(
|
|
onTap: () {},
|
|
child: Container(
|
|
width: double.infinity,
|
|
padding: const EdgeInsets.all(16),
|
|
decoration: BoxDecoration(
|
|
color: colorScheme.surface,
|
|
borderRadius: const BorderRadius.vertical(
|
|
top: Radius.circular(28),
|
|
),
|
|
),
|
|
child: Column(
|
|
children: [
|
|
Container(
|
|
width: 36,
|
|
height: 4,
|
|
decoration: BoxDecoration(
|
|
color: colorScheme.outlineVariant,
|
|
borderRadius: BorderRadius.circular(2),
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
_buildSheetContent(context),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildSheetContent(BuildContext context) {
|
|
return SizedBox(
|
|
height: 280,
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
_buildOptionCard(
|
|
context: context,
|
|
icon: LucideIcons.camera,
|
|
label: context.l10n.homeSheetTakePhoto,
|
|
onTap: () => _handleCameraTap(context),
|
|
),
|
|
const SizedBox(width: 24),
|
|
_buildOptionCard(
|
|
context: context,
|
|
icon: LucideIcons.image,
|
|
label: context.l10n.homeSheetPhotoLibrary,
|
|
onTap: () => _handlePhotoTap(context),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildOptionCard({
|
|
required BuildContext context,
|
|
required IconData icon,
|
|
required String label,
|
|
required VoidCallback onTap,
|
|
}) {
|
|
final colorScheme = Theme.of(context).colorScheme;
|
|
|
|
return GestureDetector(
|
|
onTap: onTap,
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Container(
|
|
width: 72,
|
|
height: 72,
|
|
decoration: BoxDecoration(
|
|
color: colorScheme.primaryContainer,
|
|
borderRadius: BorderRadius.circular(16),
|
|
),
|
|
child: Icon(icon, size: 32, color: colorScheme.primary),
|
|
),
|
|
const SizedBox(height: 12),
|
|
Text(
|
|
label,
|
|
style: TextStyle(
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w500,
|
|
color: colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> _handleCameraTap(BuildContext context) async {
|
|
final picker = ImagePicker();
|
|
final image = await picker.pickImage(
|
|
source: ImageSource.camera,
|
|
imageQuality: 80,
|
|
);
|
|
if (image != null) {
|
|
onImagesSelected([image]);
|
|
}
|
|
if (context.mounted) {
|
|
Navigator.of(context).pop();
|
|
}
|
|
}
|
|
|
|
Future<void> _handlePhotoTap(BuildContext context) async {
|
|
final picker = ImagePicker();
|
|
final images = await picker.pickMultiImage(imageQuality: 80, limit: 3);
|
|
if (images.isNotEmpty) {
|
|
onImagesSelected(images);
|
|
}
|
|
if (context.mounted) {
|
|
Navigator.of(context).pop();
|
|
}
|
|
}
|
|
}
|