昨天在pub.dev上闲逛,发现一个挺有意思的程序包:photo_manager,决定尝试一下。
废话不多,直接上代码
flutter create flutterdemo01
然后用vscode打开,在终端运行:
flutter pub add photo_manager
安装包。
Widget build(BuildContext context) { PhotoManager.requestPermissionExtend(); return Scaffold( appBar: AppBar( title: Text(widget.title), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Text( ‘You have pushed the button this many times:‘, ), Text( ‘$_counter‘, style: Theme.of(context).textTheme.headline4, ), ], ), ), floatingActionButton: FloatingActionButton( onPressed: _incrementCounter, tooltip: ‘Increment‘, child: Icon(Icons.add), ), // This trailing comma makes auto-formatting nicer for build methods. ); }
编译一下试试,经过漫长等待,终于。。。。。。。。。。。。。。。。。。报错了。
e: G:\flutter\.pub-cache\hosted\pub.dartlang.org\photo_manager-1.2.8\android\src\main\kotlin\top\kikt\imagescanner\thumb\ThumbnailUtil.kt: (78, 21): Class ‘kotlin.Unit‘ was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.
The class is loaded from C:/Users/whl/.gradle/caches/transforms-2/files-2.1/d5103d39f9ee912d632c3d2a4a366c11/jetified-kotlin-stdlib-1.5.21.jar!/kotlin/Unit.class
e: G:\flutter\.pub-cache\hosted\pub.dartlang.org\photo_manager-1.2.8\android\src\main\kotlin\top\kikt\imagescanner\thumb\ThumbnailUtil.kt: (108, 28): Unresolved reference: apply
e: G:\flutter\.pub-cache\hosted\pub.dartlang.org\photo_manager-1.2.8\android\src\main\kotlin\top\kikt\imagescanner\thumb\ThumbnailUtil.kt: (109, 13): Unresolved reference: clearDiskCache
Execution failed for task ‘:photo_manager:compileDebugKotlin‘. > Compilation error. See log for more details * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org BUILD FAILED in 23s Exception: Gradle task assembleDebug failed with exit code 1
好吧,搜一下:photo_manager:compileDebugKotlin,还真有人踩过这个坑,
https://github.com/CaiJingLong/flutter_photo_manager/issues/561
一步步来,还真的解决了,在此记录一下,希望对遇到同样问题的同学有所帮助。