Flutter 中的 DataTable 小部件:全面指南
    		       		warning:
    		            这篇文章距离上次修改已过437天,其中的内容可能已经有所变动。
    		        
        		                
                在Flutter中,DataTable是一个小部件,用于显示排序和分页的表格数据。以下是如何使用DataTable小部件的示例代码:
import 'package:flutter/material.dart';
 
void main() => runApp(MyApp());
 
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('DataTable Example'),
        ),
        body: DataTable(
          columns: <DataColumn>[
            DataColumn(
              label: Text(
                'Column 1',
                style: TextStyle(fontStyle: FontStyle.italic),
              ),
            ),
            DataColumn(
              label: Text(
                'Column 2',
                style: TextStyle(fontStyle: FontStyle.italic),
              ),
            ),
          ],
          rows: const <DataRow>[
            DataRow(
              cells: <DataCell>[
                DataCell(Text('Row 1, Cell 1')),
                DataCell(Text('Row 1, Cell 2')),
              ],
            ),
            DataRow(
              cells: <DataCell>[
                DataCell(Text('Row 2, Cell 1')),
                DataCell(Text('Row 2, Cell 2')),
              ],
            ),
          ],
        ),
      ),
    );
  }
}这段代码创建了一个简单的DataTable,其中包含两列和两行数据。每个DataRow中的DataCell对应表格中的一个单元格。这个例子展示了如何使用DataTable来组织和显示表格数据。
评论已关闭