我有一個包含 ListView 的 Container,我希望 Container 能像 ListView 一樣大。當我洗掉容器上的高度時,我收到一條錯誤訊息(垂直視口被賦予了無限的高度)。我怎樣才能用顫振實作這一目標?
ListView 可以包含多個卡片項。
order_stack.dart 檔案:
import 'package:flutter/material.dart';
class OrderStack extends StatelessWidget {
const OrderStack({Key? key, required this.id, required this.tableNumber}) : super(key: key);
final int id;
final int tableNumber;
@override
Widget build(BuildContext context) {
return Container(
decoration: const BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(5)),
color: Color.fromRGBO(33, 49, 55, 1),
),
clipBehavior: Clip.antiAlias,
child: Column(
children: [
Container(
height: 80,
width: 400,
color: const Color.fromRGBO(93, 194, 188, 1),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
padding: const EdgeInsets.only(left: 30),
child: Text(
'Table $tableNumber',
style: const TextStyle(
color: Colors.black,
fontSize: 25,
fontWeight: FontWeight.w900,
),
),
),
Container(
padding: const EdgeInsets.only(right: 30),
child: Text(
'#$id',
style: const TextStyle(
color: Colors.black,
fontSize: 25,
fontWeight: FontWeight.bold,
),
),
),
],
),
),
Container(
height: 70,
width: 400,
child: ListView(
physics: const NeverScrollableScrollPhysics(),
children: <Widget>[
Card(
elevation: 0,
margin: EdgeInsets.zero,
child: ListTile(
tileColor: Colors.yellow[200],
leading: const Text(
'3X',
style: TextStyle(
fontSize: 30,
fontWeight: FontWeight.w800
),
),
title: const Text(
'Good Burger',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w800
),
),
subtitle: const Text('Here is a second line'),
trailing: IconButton(
iconSize: 30,
icon: const Icon(Icons.expand_more_outlined),
color: Colors.black,
onPressed: () {},
),
onTap: () => print('Good Burger'),
),
),
],
),
),
],
),
);
}
}
uj5u.com熱心網友回復:
最簡單的方法是ListView()
用 a 包裹你的小部件,Column()
并且在給定用戶螢屏高度的情況下使用媒體查詢來包裝你的小部件,記住你還應該在串列中使用 shrink wrap 為 true 并SingleChildScrollView()
像這樣包裹你的身體:
...
body: SingleChildScrollView(
...
Container(
height: MediaQuery.of(context).size.height,
child: Column(
children: [
///Your listview
ListView(
shrinkWrap: true,
)
]
)
)
...
)
uj5u.com熱心網友回復:
Container
用小部件替換Expanded
。它將擴展ListView
以適應 中的可用空間Column
。
Expanded(
child: ListView(
...
)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/506364.html