You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
GestureDetector(onPanUpdate: (details) {
if (details.delta.dx >0) {
// swiping in right direction
}
});
以编程的方式打开 drawer
GlobalKey<ScaffoldState> _drawerKey =GlobalKey();
@overrideWidgetbuild(BuildContext context) {
returnScaffold(
key: _drawerKey,
drawer:Drawer(),
//
onPanUpdate: () {
if (!_drawerKey.currentState.isDrawerOpen) {
// open drawer if this value is true
_drawerKey.currentState.openDrawer();
}
},
);
}
The reason an Alert needs the BuildContext in order to display is that the alert is a generalized dialog box that is essentially another Route that is displayed in the Navigation Stack.
You can potentially get around this by having a direct reference to the Navigator itself. However, a
The text was updated successfully, but these errors were encountered:
According to the Dart style guide, you should avoid explicitly assigning objects to null
(see http://mng.bz/om52).
comment
// Inline comments/*Blocks of comments. It's not convention to use block comments in Dart. *//// Documentation////// This is what you should use to document your classes.
Null-aware operator
dart中没有基本类型, 所有类型的默认值都是null
this.userAge = user?.age; // 如果user为null, 则userAge也赋值为nullthis.userAge = user.age ??18// 如果user.age为null, 则userAge赋值为18int x =5
x ??=3; // 如果x的值为null, 则给他赋值为3, 如果不为null, 则保持原值不变
Column
高度是 max available height
ListView
ListView 是 Column 的 scrollable 版本, 他的高度是 infinite
不能把 ListView 直接放进 Column
必须给 ListView 限制高度, 比如包裹一层 height=300 的 container
注册需要传参的函数
保留两位小数
double.toStringAsFixed(2)
actionSheet
FittedBox(child: Text('long text'))
缩小文字以避免折行
FractionallySizedBox(heightFactor: 0.7)
大小为父容器的 70%
Expanded / Flexible
作为 Column、Row 的子元素
Flexible(fit: FlexFit.loose) 默认值
Flexible(fit: FlexFit.tight) tight 表示此元素不能占用或挤压兄弟元素的空间
Expanded(flex:1) = Flexible(fit: FlexFit.tight, flex: 1)
Expanded: 按照 flex 的值(默认=1) 占用尽可能多的剩余空间
Responsive
screen 的高度: MediaQuery.of(context).size.height
statusBar 的高度 MediaQuery.of(context).padding.top
appBar 的高度:appBar.preferredSize.height (或 kToolbarHeight)
parent 的高度:LayoutBuilder(build:(ctx, constraints)=>Widget(height: constraint.maxHeight))
键盘弹出时不要向上推屏幕
移除 TextField 默认的 padding
椭圆形 button
去掉 tabview 的侧滑切屏功能
向 ListView.builder 里添加固定项
https://stackoverflow.com/a/59517826/2497876
在出现键盘的页面慎用 MediaQuery
在 build 方法中
final mq = MediaQuery.of(context);
此时键盘的 show/hide 都会导致 build 方法被重复调用!
见:flutter/flutter#37878
解决办法: 在首屏的 build 方法中将 screen size 提前保存下来。 可以借助 flutter_screenutil 插件
flutter_screenutil 插件
Stack 中也可以使用 Align 对齐, 不用 Positioned
监听 swipe right 事件
以编程的方式打开 drawer
不传context 怎么打开dialog
https://stackoverflow.com/questions/56280736/alertdialog-without-context-in-flutter
https://www.reddit.com/r/Flutter/comments/fiky2t/show_alert_without_context/
The text was updated successfully, but these errors were encountered: