Flutter常见问题汇总
欢迎加群交流(qq:839981465)
目录
- Mac os 10.15 运行‘idevice_id’无法验证开发者
- json数据转换
- TextField键盘显示隐藏
- 横竖屏设置
- TextField光标文字焦点不对齐问题
- ios打包白屏
- 图片充满父视图
- 运行报错:Unhandled Exception: ServicesBinding.defaultBinaryMessenger was accessed before the binding was initialized.
- showModalBottomSheet顶部圆角
- 限制TextField输入长度(使用maxLength会有counter控件)
- 背景图会被键盘顶起
- ios Cocoapods报错: NoMethodError - undefined method `size' for nil:NilClass
- setState更新数据,PageView、ListView等子控件没更新
解决方案
-
Mac os 10.15 运行‘idevice_id’无法验证开发者
-
sudo xattr -d com.apple.quarantine [your_path]/flutter/bin/cache/artifacts/libimobiledevice/idevice_id
sudo xattr -d com.apple.quarantine [your_path]/flutter/bin/cache/artifacts/libimobiledevice/ideviceinfo
sudo xattr -d com.apple.quarantine [your_path]/flutter/bin/cache/artifacts/libimobiledevice/idevicesyslog
sudo xattr -d com.apple.quarantine [your_path]/flutter/bin/cache/artifacts/usbmuxd/iproxy
替换为自己的路径
- json数据转换
json_to_dart
- json数据转换
// 使用范例:
var list = json.decode(widget.itemBean.formDefaultValue);
var items = (list as List).cast().map((value) {
return Bean.formJson(value);
}).toList();
- TextField键盘显示隐藏
// 显示键盘
focusNode.requestFocus();
// 隐藏键盘
focusNode.unfocus();
- 横竖屏设置
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown
]);
runApp(MyApp());
- TextField光标文字焦点不对齐问题
TextField(
style: TextStyle(textBaseline: TextBaseline.alphabetic),
)
- ios打包白屏
1. 在项目下终端运行:
flutter build ios --release
2. 在Xcode中打开项目, Product -> Archive 即可
- 图片充满父视图
ConstrainedBox(
child: Image.asset(
AssetImages.start2,
fit: BoxFit.cover,
),
constraints: new BoxConstraints.expand(),
)
- 运行报错:Unhandled Exception: ServicesBinding.defaultBinaryMessenger was accessed before the binding was initialized.
void main() {
// 加上这句即可
WidgetsFlutterBinding.ensureInitialized();
//
runApp(MyApp());
}
- showModalBottomSheet顶部圆角
showModalBottomSheet(
context: context,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
builder: (context) {
return Container();
},
)
- 限制TextField输入长度(使用maxLength会有counter控件)
inputFormatters: <TextInputFormatter>[
LengthLimitingTextInputFormatter(6)
],
- 背景图会被键盘顶起
Scaffold中设置:
resizeToAvoidBottomInset: false,
- ios Cocoapods报错: NoMethodError - undefined method `size' for nil:NilClass
flutter clean
rm -Rf ios/Pods
rm -Rf ios/.symlinks
rm -Rf ios/Flutter/Flutter.framework
rm -Rf ios/Flutter/Flutter.podspec
rm -Rf ios/Podfile.lock /// 加上这个
- setState更新数据,PageView、ListView等子控件没更新
详见:https://www.jianshu.com/p/977e1448f95d