本人小白,正在学习flutter,之前看见一个大佬发的joker fun(段子乐)Flutter仿写段子乐app来咯~Flutter仿写段子乐app,项目整体基于GetX实现路由跳转、依赖注入、状态管理 - 掘金的项目,下载下来后一直没时间看,最近打开编译发现一堆问题,最后总结两个路线,第一条是尽可能最小改动运行起来,不保证第三库最新,第二条是保证所有库最新以及运行起来,所以在解决方案上有2条路 本地环境:
- android studio:最新LadyBug 2024.2.1 patch3
- flutter 3.27.1
- dart 3.6.0
- kotlin 1.9.23
打开项目,打开控制台,运行flutter pub get 运行flutter run -v ,这里报了很多错,一个个看
- DecoderCallback类找不到,这是因为在flutter 3.16移除了这个类,详情看3.16.0 release notes | Flutter,然后我发现并没有主动获取photo_manager这个库,它是从何而来呢?在官方plugin商店搜索集成这个库的库: 然后我发现了
wechat_assets_picker
,这个库也集成了,那解决方式就像之前说的有两条: - 【最小改动】就是添加photo_manager并且版本为
3.0.0
,不要升级太高,可能会出另外的问题(当然你可以试试),版本问题也可以看看官方:flutter_photo_manager/MIGRATION_GUIDE.md at main · fluttercandies/flutter_photo_manager · GitHub 再次运行flutter pub get
和run -v
gradle版本问题,compileSdkVersion 33改为34,gradle改为8.3-all,build gradle为8.1.1,kotlin为1.8.22。 第三方库的改动:
注释签名
统一设置namespace: 代码修改: 到这应该就没问题了,接下来在这基础上把所有第三库更新到最新,如果你没有特别需要,就不用往下看了
注:最新库有新的问题,后面说
【更新到最新】 基本上每个都有更新,这里重点说下pull_refresh,有个flutter3版本,所以需要更新: json_serizble这个库最新和retrofit冲突,所以注释掉: 全体更新pull_refresh build_runner: 完整如下:
less
name: joke_fun_flutter
description: A new Flutter project.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1
environment:
sdk: '>=3.0.1 <4.0.0'
dependencies:
flutter:
sdk: flutter
photo_manager: ^3.6.3
cupertino_icons: ^1.0.8
# lottie动画 https://pub-web.flutter-io.cn/packages/lottie/install
lottie: ^3.3.0
# getX:https://pub-web.flutter-io.cn/packages/get/install
get: ^4.6.6
# 屏幕适配:https://pub-web.flutter-io.cn/packages/flutter_screenutil/install
flutter_screenutil: ^5.9.3
# 日志:https://pub-web.flutter-io.cn/packages/logger/install
logger: ^2.5.0
# 下拉刷新 https://pub-web.flutter-io.cn/packages/pull_to_refresh/install
pull_to_refresh_flutter3: ^2.0.2
# 图片加载 https://pub-web.flutter-io.cn/packages/cached_network_image/install
cached_network_image: ^3.4.1
# retrofit https://pub-web.flutter-io.cn/packages/retrofit/install flutter pub run build_runner build
retrofit: ^4.4.1
# dio https://pub-web.flutter-io.cn/packages/dio/install
dio: ^5.7.0
# json_serializable https://pub-web.flutter-io.cn/packages/json_serializable/install
# json_serializable: ^6.9.2
# json_annotation https://pub-web.flutter-io.cn/packages/json_annotation/install
json_annotation: ^4.9.0
# 网络请求日志 https://pub-web.flutter-io.cn/packages/pretty_dio_logger/install
pretty_dio_logger: ^1.4.0
# encrypt https://pub-web.flutter-io.cn/packages/encrypt/install
encrypt: ^5.0.3
# Widget可见行监听 https://pub-web.flutter-io.cn/packages/visibility_detector/install
visibility_detector: ^0.4.0+2
# shared_preferences https://pub-web.flutter-io.cn/packages/shared_preferences/install
shared_preferences: ^2.3.4
# toast https://pub-web.flutter-io.cn/packages/fluttertoast
fluttertoast: ^8.2.10
# extended_nested_scroll_view https://pub-web.flutter-io.cn/packages/extended_nested_scroll_view/install
extended_nested_scroll_view: ^6.2.1
# 动态权限 https://pub-web.flutter-io.cn/packages/permission_handler/install
permission_handler: ^11.3.1
# 图片裁剪 https://pub-web.flutter-io.cn/packages/custom_image_crop/install
custom_image_crop: ^0.0.13
# qiniu_flutter_sdk: ^0.5.0
# path_provider https://pub-web.flutter-io.cn/packages/path_provider/install
path_provider: ^2.1.5
# 事件总线 https://pub-web.flutter-io.cn/packages/event_bus/install
event_bus: ^2.0.1
# 图片预览 https://pub-web.flutter-io.cn/packages/photo_view/install
photo_view: ^0.15.0
# image_gallery_saver https://pub-web.flutter-io.cn/packages/image_gallery_saver/install
image_gallery_saver:
git:
url: https://github.com/knottx/image_gallery_saver.git
ref: knottx-latest
# 微信图片选择器 https://pub-web.flutter-io.cn/packages/wechat_assets_picker/install
wechat_assets_picker: ^9.4.2
# image_picker https://pub-web.flutter-io.cn/packages/image_picker/install
image_picker: ^1.1.2
# 视频播放器 https://pub-web.flutter-io.cn/packages/chewie/install
chewie: ^1.8.5
video_player: ^2.9.2
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^5.0.0
# retrofit
retrofit_generator: '>=5.0.0 <6.0.0'
build_runner: '>=2.3.0 <4.0.0'
# build_runner: ^2.4.6
flutter:
uses-material-design: true
assets:
- assets/lottie/
- assets/image/
到这里就没什么问题了 enjoy!
最新库问题:
- chewie这个库导致的,全屏播放状态下点击静音按钮和全屏按钮和暂停/恢复播放没有反应,在之前1.7.0版本是可以的,操作步骤:打开首页,推荐栏目下,找到一个视频item,点击全屏播放,再操作相关操作没有任何反馈,但是拉动进度条是正常的
其他问题有待发现
总结: 只有自己走一遍,才能对于各种错误如何处理熟记于心,本文只推荐给想要快速运行起来不关注细节的小伙伴,如果想要积累经验,还是建议自己走一遍,很多错误google很多次,看了很多第三库issue,才知道怎么改