1、android 启动 白屏/黑屏 问题解决
在android 工程目录下,找到res的values目录下的styles.xml文件,theme设置中添加
<item name="android:windowBackground">@drawable/launch_background</item>,
该图片即为默认图
2、android 状态栏 高度设置
2.1 沉浸式全透明时,可以手动添加状态高度
MediaQueryData.fromWindow(window).padding.top
2.2 其次,另外有safeArea控件,自动留出状态栏高度padding
3、图片问题
桌面启动图标,分别在android、ios对应 图标目录放入对应图标尺寸
正常图片,可以根目录创建images目录,并在其中创建2x、3x命名的目录,放入对应尺寸的图片。并在pubspec.yaml文件的asset节点,配置上对应图片名称。
例 assets:
- images/icon_back.png
- images/icon_avator.png
4、复用问题
flutter UI显示是 element树,element根据widget配置创建。更新时,widget有缓存,使用缓存配置;无缓存,则重新创建widget;element如果可复用,则根据widget配置复用更新(牵涉到key);不可复用,移除
旧element,根据widget配置创建新的element加入节点树。
key 是widget的标识,判定element是否可复用。
关键函数
static bool canUpdate(Widget oldWidget, Widget newWidget) {
return oldWidget.runtimeType == newWidget.runtimeType
&& oldWidget.key == newWidget.key;
}
5、关于 yield 可参考 https://www.ibm.com/developerworks/cn/opensource/os-cn-python-yield/
6、net
dart:io 基础网络请求
dio 进一步封装的网络框架
=> https://github.com/flutterchina/dio
7、Expanded控件
父控件必须是Flex类型, Flex、Row、Column,否则报错。充满主轴可用空间。Match_Parent
Stack -> Align、positioned,实现类似android RelativeLayout效果。
当需要实现 距离屏幕底部特定尺寸的布局时,可用到。
8、响应式
stream、sink、rxdart
9、async、await future 异步
async函数标识异步,返回值为future
10、json 序列化、反序列化
使用json_serializable进行序列化
pubspec.yaml
dependencies:
# Your other regular dependencies here
json_annotation: ^2.0.0
dev_dependencies:
# Your other dev_dependencies here
build_runner: ^1.0.0
json_serializable: ^2.0.0
==> https://flutterchina.club/json/
11、工厂构造函数
12、输入框 TextField
获取输入框文本 TextEditingController.text
输入完成切换焦点
FocusNode secondTextFieldNode = FocusNode();
onEditingComplete: () => { FocusScope.of(context).requestFocus(secondTextFieldNode)}
hint提示样式
decoration: InputDecoration(hintText: "请输入手机号码或邮箱",
border: InputBorder.none,
hintStyle: TextStyle(
color: Color(0xffc7c7cd),
fontSize: 15)),
复制代码
转载于:https://juejin.im/post/5c7e3a71f265da2dbb1251cc