<
Flutter学习笔记 遇到的问题
>
上一篇

Adb 截图命令
下一篇

Android 适配 深色模式 夜间模式 暗黑模式 黑夜模式 暗夜模式

Flutter学习笔记

遇到的问题


环境识别AS路径有误 (已解决)

flutter config –android-studio-dir=C:\ProgramGreen\Android\android-studio_4.1.2

中文适配问题 (已解决)

App 设置了全局 Locale 的话, 需要对 Widgets/Material/Cupertino 配置 localizationsDelegates, (若使用到对应的Widget) 如果没有配置会在使用到时出现异常


导包别名 (已解决)

当遇到类名相同时, import 时使用 as 设置别名

import 'package:date_format/date_format.dart' as format; // Local类可能与Flutter原生冲突
format.formatDate()

TabBarView 和 PageView 滑动问题 (待解决)

当 PageView 里面嵌套 TabBarView, 停留在 TabBarView 所在 PageView 对应 index 页面时 默认 TabBarView 会消费触摸滑动事件, 即使滑动到最后一个也不会释放给外层


BottomNavigationBar + PageView 时, PageView 没有响应 没有双向绑定 (已解决)

在 BottomNavigationBar 只需要在构造传入参数 currentIndex 即可, 但 PageView 需要在代码设置 index animateToPage 或 jumpToPage


Container color和decoration同时设置会冲突 (已解决)


Row 里的 Text 长文本 超出范围报错 (已解决)

解决: 添加一层 Flexible/Expanded 即可自动换行, 如果Text外还有Column, 加在Column外层


Json 序列化方案 之 json_serializable (已解决)

google示例 链接

1.添加依赖

//pubspec.yaml
dependencies:
  json_annotation: ^3.1.1

dev_dependencies:
  build_runner: ^1.11.1
  json_serializable: ^3.5.1

2.利用插件生成 entity 代码

3.使用命令生成帮助类, 执行后可能要等几秒

flutter packages pub run build_runner build --delete-conflicting-outputs

注意1: build_runner 不能放在依赖的 module, 否则 build_runner 命令无效

注意2: json_serializable 不能放在依赖的 module, 否则不会生成 xx.g.dart 文件


请求时 get参数 value空不拼接等号 签名逻辑对不上


convert库 解析 String 时 遇到换行符出错

1.传参为String时, 转译字符不能正常解析,
可传参为Map解析,dio返回response的dynamic是map不是string

2.convert库json不能解析Map类型, 需要手动处理


jcenter maven 报错

(2022-04 更新)

仓库要关闭了,Android 项目 build.gradle 中替换掉 jcenter() 就好了

替换国内镜像,或者别的仓库


清除缓存后执行 flutter create . 重新创建flutter时 可能会更新库的版本,从而会导致兼容问题报错

Top
Foot