flutter build apk 时遇到类型错误:Error: The argument type 'String' can't be assigned to the parameter type 'Uint8List'

不知道是我代码问题还是版本问题
[✓] Flutter (Channel unknown, 1.22.6, on Linux, locale en_US.UTF-8)
• Flutter version 1.22.6 at /sdks/flutter
• Framework revision 9b2d32b605 (4 months ago), 2021-01-22 14:36:39 -0800
• Engine revision 2f0af37152
• Dart version 2.10.5


[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at /opt/android-sdk-linux
• Platform android-30, build-tools 30.0.2
• ANDROID_HOME = /opt/android-sdk-linux
• ANDROID_SDK_ROOT = /opt/android-sdk-linux
• Java binary at: /usr/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_265-8u265-b01-0ubuntu2~20.04-b01)
• All Android licenses accepted.

[!] Android Studio (not installed)
• Android Studio not found; download from https://developer.android.com/studio/index.html
(or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).

[!] Connected device
! No devices available

! Doctor found issues in 2 categories.
flutter build apk 时遇到类型错误:Error: The argument type ‘String’ can’t be assigned to the parameter type ‘Uint8List’


更多关于flutter build apk 时遇到类型错误:Error: The argument type 'String' can't be assigned to the parameter type 'Uint8List'的实战教程也可以访问 https://www.itying.com/category-92-b0.html

2 回复

这种报错应该有精确到行才对,楼主已经解决了吧,

更多关于flutter build apk 时遇到类型错误:Error: The argument type 'String' can't be assigned to the parameter type 'Uint8List'的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html


在Flutter开发中,遇到类型错误 Error: The argument type 'String' can't be assigned to the parameter type 'Uint8List' 通常意味着你在某个API调用中错误地将一个字符串(String)作为参数传递给了期望接收一个无符号8位整数列表(Uint8List)的函数或方法。

这个问题常见于处理文件、图像、加密数据等需要字节级操作的场景。例如,当你尝试将一个字符串直接用作图像数据或加密函数的输入时,就可能遇到这种类型不匹配的问题。

要解决这个问题,你需要根据具体情况将字符串转换为Uint8List。如果字符串代表的是Base64编码的数据,你可以使用base64Decode函数来转换:

import 'dart:convert';

// 假设base64String是你要转换的Base64编码字符串
Uint8List uint8List = base64Decode(base64String);

// 现在你可以将uint8List作为参数传递给期望Uint8List的函数

如果字符串代表的是普通的文本数据,并且你需要将其作为字节序列处理(例如,发送网络请求时作为二进制数据),你可能需要先将字符串编码为字节:

Uint8List uint8List = Uint8List.fromList(yourString.codeUnits);

确保你了解API期望的数据类型,并相应地转换你的数据。如果问题依然存在,检查相关API文档或寻求更具体的帮助。

回到顶部