单例
class Singleton {
Singleton._();
static final instance = Singleton._();
}
AppBar 修改高度
设置AppBar的height
使用PreferredSize:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Example',
home: Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(50.0), // here the desired height
child: AppBar(
// ...
)
),
body: // ...
)
);
}
}
刷新报错
setState() or markNeedsBuild() called during build
WidgetsBinding.instance.addPostFrameCallback((_){
_model.setOpacity(opacity);
});
setState() called after dispose()
if (!mounted) return;
setState(() {
// do somthing
});
相机预览 高度填充
FittedBox(
fit: BoxFit.fitHeight,
child: SizedBox(
width: _controller.value.aspectRatio,
height: 1,
child: CameraPreview(_controller),
),
)
Android 下去除滚动波纹动画
NotificationListener<OverscrollIndicatorNotification>(
onNotification: (notification) {
notification.disallowGlow();
return false;
},
child: xxxxx
}
bool _handleGlowNotification(OverscrollIndicatorNotification notification) {
if (notification.depth != 0 || !notification.leading) return false;
notification.disallowGlow();
return false;
}
Row/Column 宽度/高度 Wrap_content
return Column(
mainAxisSize: MainAxisSize.min,
children: widgets,
);
https://stackoverflow.com/questions/42257668/the-equivalent-of-wrap-content-and-match-parent-in-flutter
键盘弹出导致 overflow 处理方法
1. scaffold: resizeToAvoidBottomPadding: false,
2. SingleChildScrollView 包裹 Column
添加图片资源
添加 images 下的所有图片
assets:
- assets/images/
Splash 页面跳转问题
使用
Navigator.pushNamedAndRemoveUntil(context, ’/home‘ , (_) => false);
表示跳转到新页面,并且清理之前 router 中的所有历史页面。
计时器
3s 后执行某段代码:
Timer(Duration(seconds: 3), () {
print("Yeah, this line is printed after 3 seconds");
});
重复执行循环执行:
Timer.periodic(Duration(seconds: 5), (timer) {
print(DateTime.now());
});