1:如何在Flutter中自动调整Table的大小并适合Card?
桌子的行不适合卡 as shown in image.
我已经尝试过将FittedBox与Boxfit.scaleDown配合使用,但它会呈现空白卡。
2:如何在Flutter中的表中创建4 * 8等值框?
class MagicCard extends StatelessWidget {
@override
Widget build(BuildContext context) {
final double screenHeight = MediaQuery.of(context).size.height;
double cardHeight = screenHeight * 0.60;
double cardWidth = screenHeight * 0.30;
return Container(
width: cardWidth,
height: cardHeight,
child: Card(
color: Colors.amber,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Table(
children: _buildCardTable(),
),
),
),
);
}
List<TableRow> _buildCardTable() {
List<int> list = cards[5].getNumbers;
List<TableRow> tableRows = <TableRow>[];
partition(list, 4).forEach((numList) {
TableRow tableRow = _buildRow(List<int>.from(numList));
tableRows.add(tableRow);
});
return tableRows;
}
TableRow _buildRow(List<int> numbers) {
return TableRow(
children: numbers.map<Widget>((num) => DigitButton(num)).toList());
}
}
/// Number
class DigitButton extends StatelessWidget {
DigitButton(this.num);
final int num;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: RawMaterialButton(
shape: CircleBorder(),
elevation: 6,
padding: const EdgeInsets.all(8.0),
fillColor: Colors.white,
child: Text(num.toString(),),
),
);
}
}