1. MediaQuery.of(context).size.width, //宽度设置为和屏幕等宽
2. 点击输入框以外区域,关闭键盘:
GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: (){
// 点击空白页面关闭键盘
FocusScope.of(context).requestFocus(blankNode);
},
child: 内容区域,
)
3. 禁止右滑返回上一页:
WillPopScope(
onWillPop: () async => false,
child: 内容区域,
)
4. 获取时间戳:
DateTime now = new DateTime.now();print(now.millisecondsSinceEpoch); // 单位毫秒,13位时间戳
DateTime now = new DateTime.now();print(now.microsecondsSinceEpoch); // 单位微秒,16位时间戳
5.格式化时间:
方法一:
DateTime date = new DateTime.now();
String time = "${date.year.toString()}-${date.month.toString().padLeft(2,'0')}-${date.day.toString().padLeft(2,'0')} ${date.hour.toString().padLeft(2, '0')}:${date.minute.toString().padLeft(2, '0')}:${date.second.toString().padLeft(2, '0')}";
print(time);
方法二:
DateTime date = new DateTime.now();
var a=date.millisecondsSinceEpoch; //时间戳
print(DateTime.fromMillisecondsSinceEpoch(a));
6.字符串和unicode转换:
Unicode转字符串:String.fromCharCode()
字符串转Unicode:str.codeUnits或者str.codeUnitAt(单个字符下标)