no message

This commit is contained in:
2025-11-10 17:12:53 +08:00
parent 1d4556fc49
commit 6281dd56a0
14 changed files with 1060 additions and 506 deletions

View File

@@ -1,4 +1,7 @@
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:image_editor_plus/image_editor_plus.dart';
void main() {
runApp(const MyApp());
@@ -36,6 +39,27 @@ class MyApp extends StatelessWidget {
}
}
/// Dio 最简版:网络图片转 Uint8List
Future<Uint8List?> networkImageToUint8ListWithDio(String imageUrl) async {
final dio = Dio(); // 初始化 Dio 实例
try {
// 发起 GET 请求,响应类型设为字节数组(关键)
final response = await dio.get<List<int>>(
imageUrl,
options: Options(responseType: ResponseType.bytes),
);
// 响应成功且数据非空时,直接转为 Uint8List
return response.statusCode == 200 && response.data != null
? Uint8List.fromList(response.data!)
: null;
} catch (e) {
print('图片转换失败:$e'); // 捕获网络错误、URL 非法等异常
return null;
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
@@ -55,19 +79,53 @@ class MyHomePage extends StatefulWidget {
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
final int _counter = 0;
void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
Future<void> _incrementCounter()async {
String imageUrl = 'https://static.cop.jingheyijia.com/wxapp-map2/upload/moment/20251029/app-bpItvFOQufCL.jpg';
Uint8List? imageBytes = await networkImageToUint8ListWithDio(imageUrl);
ImageEditor.setI18n({
'crop': '裁剪',
'rotate left': '左旋转',
'rotate right': '右旋转',
'flip': '水平翻转',
'brush': '涂抹',
'link':'链接',
'save': '保存',
'text': '文本',
'blur': '模糊',
'filter': '滤镜',
'size': '大小',
'color': '颜色',
'background color': '背景颜色',
'background opacity': '背景透明度',
'reset': '重置',
'freeform': '自由裁剪',
'remove': '移除',
'emoji': '表情',
'slider color': '滑块颜色',
'color opacity': '透明度',
'blur radius': '模糊半径',
});
if(mounted){
final editedImage = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ImageEditor(
image: imageBytes,
blurOption: null,
filtersOption: null,
brushOption: null,
textOption: null,
emojiOption: null,
),
),
);
print(editedImage);
}
}
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
@@ -122,4 +180,4 @@ class _MyHomePageState extends State<MyHomePage> {
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
}