我有一个SingleChildScrollView,里面有一个Container。我想要实现的是Container's高度应该是完整的视口高度。
我的代码:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'MyApp',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
fontFamily: 'OpenSans',
),
home: SingleChildScrollView(
child: Container(
color: Colors.white,
height: double.infinity,
),
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
如果我运行我的代码,我有一个例外:
I/flutter ( 6293): ??? EXCEPTION CAUGHT BY RENDERING LIBRARY ??????????????????????????????????????????????????????????
I/flutter ( 6293): The following assertion was thrown during performLayout():
I/flutter ( 6293): BoxConstraints forces an infinite height.
I/flutter ( 6293): These invalid constraints were provided to RenderDecoratedBox's layout() function by the following
I/flutter ( 6293): function, which probably computed the invalid constraints in question:
I/flutter ( 6293): RenderConstrainedBox.performLayout (package:flutter/src/rendering/proxy_box.dart:258:13)
I/flutter ( 6293): The offending constraints were:
I/flutter ( 6293): BoxConstraints(w=411.4, h=Infinity)
Run Code Online (Sandbox Code Playgroud)
Gün*_*uer 11
也许
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
final mq = MediaQueryData.fromWindow(window);
return MaterialApp(
title: 'MyApp',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
fontFamily: 'OpenSans',
),
home: SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints.tightFor(
height: mq.size.height,
),
child: Container(
height: double.infinity,
decoration: BoxDecoration(
color: Colors.red,
border: Border.all(color: Colors.blue, width: 8)),
),
),
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
Rid*_*zag 11
我有同样的问题,但答案对我不起作用,所以我不得不将 SingleChildScrollView() 包装在容器中并给它高度:double.infinity
Container(
height: double.infinity,
color: Colors.green,
child: SingleChildScrollView()
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7157 次 |
| 最近记录: |