merge_cells 0.0.1
merge_cells: ^0.0.1 copied to clipboard
A highly customizable Flutter table widget supporting cell merging (rowSpan/colSpan), flexible direction, and custom styling.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:merge_cells/merge_cells.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Plugin example app')),
body: Column(
children: [
CustomTable(
horizontalScroll: false, // 开启横向滚动
// columnWidths: {
// 0: 300.0, // 第一列固定200,如果屏幕较小,这可能会导致出现滚动条
// },
direction: Axis.vertical,
border: Border.all(width: 1, color: Colors.grey[300]!),
// 第一行:混合使用 Widget 和 String
titles: [
Text(
'Header A',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
'Header B',
'Header C',
'Header D',
],
titleBackgroundColor: Colors.grey[300],
rows: [
// 第二行:混合使用 Widget 和 String
[
Text('Custom Widget'),
'Simple String',
123, // 数字也会自动转为 Text
"456", // 数字也会自动转为 Text
],
// 第三行:需要合并时使用 CustomTableCell
[
CustomTableCell(
child: Text('Merged Cell'),
colSpan: 2,
rowSpan: 2,
),
'Row 3 Col 3',
'Row 3 Col 4',
],
// 第四行(第一列被合并占用,跳过)
['Row 4 Col 3', 'Row 4 Col 4'],
],
),
],
),
),
);
}
}