Flutter组件常见问题
常见问题整合
去除按钮点击态(IconButton)
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
文字和数字无法对齐问题
在TextStyle 中添加相同的 height即可
注意:height表示行高,显示多行文字时1.0需根据需要调整
TextStyle(
height: 1.0,
fontSize: ScreenUtil().setSp(30),
color: ColorConstant.thirdTextColor)
字体缩放
添加缩放属性 textScaleFactor: 1.0,
TextFiled长按显示英文(国际化)
MaterialApp(
title: '',
builder: FlutterBoost.init(
postPush: _onRoutePushed,
builder: (context, child) {
return MediaQuery(
child: child,
data: MediaQuery.of(context).copyWith(
textScaleFactor: 1.0,
),
);
},
),
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [
const Locale('zh', 'CN'), //设置语言为中文
],
home: Container());
TextField 多行文本下的居中对齐
同时设置
maxLines: 2,
minLines: 1,
禁止键盘被撑起
return Scaffold(
//可以通过设置 这个属性 防止键盘 覆盖内容 或者 键盘 撑起内容
resizeToAvoidBottomInset: false,
);
侧滑返回键监听WillPopScope
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () {
_showConfirmDialog();
return Future.value(false);
},
child: xxxx,
);
}
针对IOS系统键盘输入拼音时回调处理
○ 问题现象:IOS系统键盘搜索输入拼音时,会实时回调搜索
○ 处理方式:在onChange中禁止iOS键盘输入拼音未完成时的回调,判断是否compose完成
注意:经测试添加判断后Android使用搜狗键盘输入compose效果相反,故区分平台
if (Platform.isIOS && _editingController.value.isComposingRangeValid) {
return;
}
//TODO 搜索操作
TextField的autoFocus属性唤起键盘失败
问题描述:页面进入时自动获取输入框焦点,页面发生闪动异常
解决方案:在flutterboost3.0提供的onPageShow里手动获取较短
@override
void onPageShow() {
super.onPageShow();
if (!_focusNode.hasFocus) {
FocusScope.of(context).requestFocus(_focusNode);
}
}
JSON Model化
使用yaml依赖 :build_runner: xxx ;json_serializable: xxx
执行自动生成.g文件
flutter packages pub run build_runner build --delete-conflicting-outputs
Waiting for another flutter command to release the startup lock…
杀死所有dart相关的进程,在命令行中键入如下内容: killall -9
dart或者在sdk删除lockfile文件(…/hummerFlutter/bin/cache)
打产物指定平台
只支持64位:flutter build aar --target-platform android-arm64
支持32位:flutter build aar --target-platform=android-arm
同时支持64位和32位:flutter build aar