ListView.builder需要显示大小,因此通常我们将一个容器作为ListView.builder的父对象来正确显示列表。
问题是2。
我们设置的高度因设备而异,如果有一个BottomNavigation条形图可以覆盖列表的最后一个元素,我注意到列表的最后一个元素存在问题
这是一张图片:
抱歉,我需要报名,但出于隐私考虑,我需要... 无论如何..正如您所看到的,列表的最后一项被BottomNav Bar覆盖 如何定义和解决此问题? 我可以调整容器的大小并使其更小,但是问题将出在不同的设备上。
答案 0 :(得分:1)
您可以用ListView.builder
而不是Container来包装Expanded
。最好将其放在“列”中,然后用“扩展”小部件将其包装。
答案 1 :(得分:1)
您应该在BuildContext下使用MediaQuery
,然后可以获取高度和宽度,然后进行一些数学运算,而使响应式应用程序成为应用程序的picture
void main() async {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key key}) : super(key: key);
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: TheSize(),
)),
);
}
}
class TheSize extends StatelessWidget {
@override
Widget build(BuildContext context) {
var size = MediaQuery.of(context).size;
var height = size.height;
var width = size.width;
return Container(
height: height / 2,
width: width / 1.5,
color: Colors.blue,
child: Text('the height = $height | the width = $width '),
);
}
}