feat(app): 集成图片上传到编辑器 — 拍照/相册 + 压缩 + 拖拽定位
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
// - 单击选中/取消选中
|
||||
// - 选中时显示边框和删除按钮
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../data/models/journal_element.dart';
|
||||
@@ -176,21 +178,18 @@ class _DraggableElementState extends State<DraggableElement> {
|
||||
);
|
||||
|
||||
case ElementType.image:
|
||||
return Container(
|
||||
color: Colors.grey.shade200,
|
||||
alignment: Alignment.center,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.image_rounded, size: 32, color: Colors.grey.shade400),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'照片',
|
||||
style: TextStyle(fontSize: 12, color: Colors.grey.shade500),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
final filePath = element.content['filePath'] as String?;
|
||||
if (filePath != null && filePath.isNotEmpty) {
|
||||
return ClipRRect(
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
child: Image.file(
|
||||
File(filePath),
|
||||
fit: BoxFit.contain,
|
||||
errorBuilder: (_, __, ___) => _buildImagePlaceholder(),
|
||||
),
|
||||
);
|
||||
}
|
||||
return _buildImagePlaceholder();
|
||||
|
||||
case ElementType.tape:
|
||||
final tapeColor = _parseColor(element.content['tapeColor'] as String?);
|
||||
@@ -230,4 +229,24 @@ class _DraggableElementState extends State<DraggableElement> {
|
||||
if (value == null) return const Color(0xFF2D2420);
|
||||
return Color(0xFF000000 + value);
|
||||
}
|
||||
|
||||
/// 图片加载失败时的占位符
|
||||
Widget _buildImagePlaceholder() {
|
||||
return Container(
|
||||
width: 160,
|
||||
height: 120,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade200,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: const Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.broken_image_outlined, color: Colors.grey),
|
||||
SizedBox(height: 4),
|
||||
Text('图片加载失败', style: TextStyle(color: Colors.grey, fontSize: 11)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user