Moh*_*hah 1 windows dart flutter flutter-layout
我在设计 flutter 程序时遇到了麻烦。
当我运行程序并调整程序大小时,一切都崩溃并且不正常。
你可以在下图中看到。

如果您想监听调整大小事件,则必须将根小部件包装在其中:
@override
Widget build(BuildContext context) {
return NotificationListener<SizeChangedLayoutNotification>(
onNotification: (notification) {
//here you can't use setState, so you can't have a bool on which differentiate the layout,
//but you should be able to call build(context) to force a rebuild
},
child: SizeChangedLayoutNotifier(
child: MediaQuery.of(context).size.width> 400? //set your width threshold here
//widget layout for small window
:
//widget layout for big window
Run Code Online (Sandbox Code Playgroud)
至于你最后的评论,小部件不适合宽度的事实不是颤动的错。您正在使用固定大小的小部件或其他默认情况下不会扩展以适应可用空间的小部件。Scaffold应该这样做,例如:我在我的应用程序中以 aScaffold作为根测试了上述代码,并且小部件会拉伸以适应窗口的宽度。
| 归档时间: |
|
| 查看次数: |
6322 次 |
| 最近记录: |