我在Flutter应用程序中使用DataTable。这是我的代码的简单示例:
DataTable(
columns: [
DataColumn(label: Text('Column1')),
DataColumn(label: Text('Column2')),
DataColumn(label: Text('Column3')),
],
rows: [
DataRow(cells: [
DataCell(Text('1')),
DataCell(Text('2')),
DataCell(Text('6')),
]),
DataRow(cells: [
DataCell(Text('12')),
DataCell(Text('John')),
DataCell(Text('9')),
]),
],
)
我需要:
-column1为可用宽度的20%
-column1为可用宽度的40%
-column1为可用宽度的40%
我该怎么做呢?DataTable有可能实现吗?
发布于 2020-12-16 07:32:25
您可以尝试如下所示:
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(home: MyApp()));
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
final double width = MediaQuery.of(context).size.width;
return Scaffold(
appBar: AppBar(
title: const Text("Flutter Demo"),
),
body: Container(
width: width,
child: DataTable(
columnSpacing: 0,
horizontalMargin: 0,
columns: [
DataColumn(
label: Container(
width: width * .2,
child: Text('Column1'),
),
),
DataColumn(
label: Container(
width: width * .4,
child: Text('Column2'),
),
),
DataColumn(
label: Container(
width: width * .4,
child: Text('Column3'),
),
),
],
rows: [
DataRow(cells: [
DataCell(Text('1')),
DataCell(Text('2')),
DataCell(Text('6')),
]),
DataRow(cells: [
DataCell(Text('12')),
DataCell(Text('John')),
DataCell(Text('9')),
]),
],
),
),
);
}
}
https://stackoverflow.com/questions/65312609
复制相似问题