“multi_image_picker”颤动的问题
Posted
技术标签:
【中文标题】“multi_image_picker”颤动的问题【英文标题】:Problem with "multi_image_picker" flutter 【发布时间】:2020-07-25 07:52:43 【问题描述】:我为 multi_image_picker 制作了示例代码
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:multi_image_picker/multi_image_picker.dart';
void main() => runApp(new MyApp());
class MyApp extends StatefulWidget
@override
_MyAppState createState() => new _MyAppState();
class _MyAppState extends State<MyApp>
List<Asset> images = List<Asset>();
String _error = 'No Error Dectected';
@override
void initState()
super.initState();
Widget buildGridView()
return GridView.count(
crossAxisCount: 3,
children: List.generate(images.length, (index)
Asset asset = images[index];
return AssetThumb(
asset: asset,
width: 300,
height: 300,
);
),
);
Future<void> loadAssets() async
List<Asset> resultList = List<Asset>();
String error = 'No Error Dectected';
try
resultList = await MultiImagePicker.pickImages(
maxImages: 300,
enableCamera: true,
selectedAssets: images,
cupertinoOptions: CupertinoOptions(takePhotoIcon: "chat"),
materialOptions: MaterialOptions(
actionBarColor: "#abcdef",
actionBarTitle: "Example App",
allViewTitle: "All Photos",
useDetailsView: false,
selectCircleStrokeColor: "#000000",
),
);
on Exception catch (e)
error = e.toString();
if (!mounted) return;
setState(()
images = resultList;
_error = error;
);
@override
Widget build(BuildContext context)
return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: const Text('Plugin example app'),
),
body: Column(
children: <Widget>[
Center(child: Text('Error: $_error')),
RaisedButton(
child: Text("Pick images"),
onPressed: loadAssets,
),
Expanded(
child: buildGridView(),
)
],
),
),
);
在真实设备上启动应用程序后 我有这个日志输出
V/BoostFramework(27660): BoostFramework() : mPerf = com.qualcomm.qti.Performance@323e3f1
如果我触摸中心按钮,我有这个输出
I/Timeline(27660): Timeline: Activity_launch_request time:878329589 intent:Intent cmp=com.kiryacompany.test003/com.sangcomz.fishbun.ui.album.AlbumActivity
W/art (27660): Before android 4.1, method android.graphics.PorterDuffColorFilter androidx.vectordrawable.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
I/art (27660): Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$2>: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/view/View$OnUnhandledKeyEventListener;
I/art (27660): at void androidx.core.view.ViewCompat.setOnApplyWindowInsetsListener(android.view.View, androidx.core.view.OnApplyWindowInsetsListener) (ViewCompat.java:2421)
I/art (27660): at android.view.ViewGroup androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor() (AppCompatDelegateImpl.java:637)
I/art (27660): at void androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor() (AppCompatDelegateImpl.java:518)
I/art (27660): at void androidx.appcompat.app.AppCompatDelegateImpl.setContentView(int) (AppCompatDelegateImpl.java:466)
I/art (27660): at void androidx.appcompat.app.AppCompatActivity.setContentView(int) (AppCompatActivity.java:140)
I/art (27660): at void com.sangcomz.fishbun.ui.album.AlbumActivity.onCreate(android.os.Bundle) (AlbumActivity.java:75)
I/art (27660): at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:6875)
I/art (27660): at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1119)
I/art (27660): at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2677)
I/art (27660): at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2785)
I/art (27660): at void android.app.ActivityThread.-wrap12(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1)
I/art (27660): at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1524)
I/art (27660): at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:102)
I/art (27660): at void android.os.Looper.loop() (Looper.java:163)
I/art (27660): at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6239)
I/art (27660): at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-2)
I/art (27660): at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:904)
I/art (27660): at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:794)
I/art (27660): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.View$OnUnhandledKeyEventListener" on path: DexPathList[[zip file "/data/app/com.kiryacompany.test003-1/base.apk"],nativeLibraryDirectories=[/data/app/com.kiryacompany.test003-1/lib/arm64, /data/app/com.kiryacompany.test003-1/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]
I/art (27660): at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:56)
I/art (27660): at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:380)
I/art (27660): at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
I/art (27660): at void androidx.core.view.ViewCompat.setOnApplyWindowInsetsListener(android.view.View, androidx.core.view.OnApplyWindowInsetsListener) (ViewCompat.java:2421)
I/art (27660): at android.view.ViewGroup androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor() (AppCompatDelegateImpl.java:637)
I/art (27660): at void androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor() (AppCompatDelegateImpl.java:518)
I/art (27660): at void androidx.appcompat.app.AppCompatDelegateImpl.setContentView(int) (AppCompatDelegateImpl.java:466)
I/art (27660): at void androidx.appcompat.app.AppCompatActivity.setContentView(int) (AppCompatActivity.java:140)
I/art (27660): at void com.sangcomz.fishbun.ui.album.AlbumActivity.onCreate(android.os.Bundle) (AlbumActivity.java:75)
I/art (27660): at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:6875)
I/art (27660): at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1119)
I/art (27660): at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2677)
I/art (27660): at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2785)
I/art (27660): at void android.app.ActivityThread.-wrap12(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1)
I/art (27660): at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1524)
I/art (27660): at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:102)
I/art (27660): at void android.os.Looper.loop() (Looper.java:163)
I/art (27660): at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6239)
I/art (27660): at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-2)
I/art (27660): at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:904)
I/art (27660): at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:794)
I/art (27660):
V/BoostFramework(27660): BoostFramework() : mPerf = com.qualcomm.qti.Performance@324ab61
V/BoostFramework(27660): BoostFramework() : mPerf = com.qualcomm.qti.Performance@dab686
I/Timeline(27660): Timeline: Activity_launch_request time:878329874 intent:Intent act=android.content.pm.action.REQUEST_PERMISSIONS pkg=com.google.android.packageinstaller (has extras)
E/RecyclerView(27660): No adapter attached; skipping layout
我该如何解决?
颤振医生
[√] Flutter(Channel beta,v1.17.0,在 Microsoft Windows [版本 10.0.18363.752],区域设置 ru-RU) • Flutter 1.17.0 版,位于 C:\src\flutter • 框架修订 d3ed9ec945(6 天前),2020-04-06 14:07:34 -0700 • 引擎修订版 c9506cb8e9 • Dart 版本 2.8.0(构建 2.8.0-dev.18.0 eea9717938)
[√] Android 工具链 - 为 Android 设备开发(Android SDK 版本 29.0.3) • Android SDK 位于 C:\Users\kiril\AppData\Local\Android\sdk • 平台 android-29,构建工具 29.0.3 • Java 二进制文件位于:C:\Program Files\Android\Android Studio\jre\bin\java • Java 版 OpenJDK 运行时环境(内部版本 1.8.0_212-release-1586-b04) • 接受所有 Android 许可证。
[√]Android Studio(3.6版)
• C:\Program Files\Android\Android Studio 中的 Android Studio
• Flutter 插件版本 44.0.2
• Dart 插件版本 192.7761
• Java 版本 OpenJDK 运行时环境(内部版本 1.8.0_212-release-1586-b04)
[√] VS Code(版本 1.43.1) • C:\Users\kiril\AppData\Local\Programs\Microsoft VS 代码中的 VS 代码 • Flutter 扩展版本 3.8.1
[√] 已连接设备(1 个可用) • Redmi 5 • 1d9634957ce5 • android-arm64 • Android 7.1.2 (API 25)
• 未发现任何问题!
【问题讨论】:
【参考方案1】:您能否检查一下您是否在AndroidManifest.xml
中添加了所需的权限?
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
【讨论】:
【参考方案2】:<application
android:requestLegacyExternalStorage="true">
</application>
如果相机没有打开 将此添加到 下的清单中
【讨论】:
以上是关于“multi_image_picker”颤动的问题的主要内容,如果未能解决你的问题,请参考以下文章
如何在 Flutter 中使用 Dio 和 multi_image_picker 插件上传多张图片
使用 multi_image_picker http 上传图片