pickBackgroundImage method
Implementation
Future<void> pickBackgroundImage(BuildContext context) async {
try {
_isPickingImage = true;
notifyListeners();
final result = await FilePickerService.pickImageWithDimensions();
if (result != null) {
_backgroundImageUrl = result.dataUrl;
// Update canvas dimensions to match the selected image
_imageWidth = result.width.toString();
_imageHeight = result.height.toString();
notifyListeners();
// If in trace mode, update template with correct dimensions
if (_isTraceMode && _currentTemplate != null) {
updateCurrentTemplateWithImage(
result.dataUrl,
result.width,
result.height,
);
}
}
} catch (e) {
if (context.mounted) {
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text('Error picking image: $e')));
}
} finally {
_isPickingImage = false;
notifyListeners();
}
}