|
@@ -1,11 +1,19 @@
|
|
|
+import 'dart:convert';
|
|
|
+import 'dart:io';
|
|
|
+
|
|
|
+import 'package:file_picker/file_picker.dart';
|
|
|
+import 'package:fis_common/index.dart';
|
|
|
import 'package:get/get.dart';
|
|
|
import 'package:vitalapp/architecture/defines.dart';
|
|
|
+import 'package:vitalapp/architecture/storage/storage.dart';
|
|
|
import 'package:vitalapp/architecture/utils/prompt_box.dart';
|
|
|
import 'package:vitalapp/managers/interfaces/account.dart';
|
|
|
import 'package:vitalapp/managers/interfaces/doctor.dart';
|
|
|
import 'package:vitalapp/pages/home/personal_center/state.dart';
|
|
|
+import 'package:vitalapp/rpc.dart';
|
|
|
import 'package:vitalapp/store/store.dart';
|
|
|
import 'package:fis_common/helpers/encrypt.dart';
|
|
|
+import 'package:universal_html/html.dart' as html;
|
|
|
|
|
|
class PersonalCenterController extends FControllerBase {
|
|
|
final state = PersonalCenterState();
|
|
@@ -90,4 +98,41 @@ class PersonalCenterController extends FControllerBase {
|
|
|
PromptBox.toast("更新成功!");
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ Future<void> chooseImage() async {
|
|
|
+ final files = await FilePicker.platform.pickFiles(type: FileType.image);
|
|
|
+ if (files != null && files.files.first.path.isNotNullOrEmpty) {
|
|
|
+ // 这里获取到的是一个File对象,你可以根据需要进行处理
|
|
|
+ // 例如,将文件路径传递给Image组件进行显示
|
|
|
+ String imagePath = files.files.first.path!;
|
|
|
+ // 接下来,你可以将imagePath传递给Image组件
|
|
|
+ // if (kIsWeb) {
|
|
|
+ var imageBase64 = await imageToBase64(imagePath);
|
|
|
+ final file = convertBase64ToFile(imageBase64);
|
|
|
+ var url = await rpc.storage.webUpload(file!);
|
|
|
+ // }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Future<String> imageToBase64(String imagePath) async {
|
|
|
+ final file = File(imagePath);
|
|
|
+ List<int> imageBytes = await file.readAsBytes();
|
|
|
+ String base64String = base64Encode(imageBytes);
|
|
|
+ return base64String;
|
|
|
+ }
|
|
|
+
|
|
|
+ html.File? convertBase64ToFile(String base64Image) {
|
|
|
+ try {
|
|
|
+ final bytes = base64Decode(base64Image);
|
|
|
+ const mimeType = 'image/jpeg'; // 替换为您的图片类型
|
|
|
+
|
|
|
+ final blob = html.Blob([bytes], mimeType);
|
|
|
+ final file = html.File([blob], 'image.jpg'); // 替换为您的文件名
|
|
|
+
|
|
|
+ return file;
|
|
|
+ } catch (e) {
|
|
|
+ print('Error converting base64 to File: $e');
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|