mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 14:47:23 +00:00
104 lines
2.8 KiB
Dart
104 lines
2.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:syncrow_web/utils/color_manager.dart';
|
|
|
|
class DynamicTable extends StatelessWidget {
|
|
final List<String> headers;
|
|
final List<List<dynamic>> data;
|
|
final BoxDecoration? headerDecoration;
|
|
final BoxDecoration? cellDecoration;
|
|
final Size size;
|
|
|
|
const DynamicTable({
|
|
Key? key,
|
|
required this.headers,
|
|
required this.data,
|
|
required this.size,
|
|
this.headerDecoration,
|
|
this.cellDecoration,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
|
|
decoration: cellDecoration,
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(10.0),
|
|
child: ListView(
|
|
scrollDirection: Axis.horizontal,
|
|
children: [
|
|
Container(
|
|
width:size.width,
|
|
child: Column(
|
|
children: [
|
|
Container(
|
|
decoration: headerDecoration ??
|
|
BoxDecoration(color: Colors.grey[200]),
|
|
child: Row(
|
|
children: headers.map((header) =>
|
|
_buildTableHeaderCell(header)).toList(),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: Container(
|
|
color: Colors.white,
|
|
child: ListView(
|
|
shrinkWrap: true,
|
|
children: data.map((row) {
|
|
return Row(
|
|
children: row.map((cell) =>
|
|
_buildTableCell(cell.toString())).toList(),
|
|
);
|
|
}).toList(),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
Widget _buildTableHeaderCell(String title) {
|
|
return Expanded(
|
|
child: Container(
|
|
decoration: const BoxDecoration(
|
|
border: Border.symmetric(
|
|
vertical: BorderSide(color: ColorsManager.boxDivider))),
|
|
alignment: Alignment.centerLeft,
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: Text(title, style: TextStyle(fontWeight: FontWeight.bold)),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildTableCell(String content) {
|
|
return Expanded(
|
|
child: Container(
|
|
height: 80,
|
|
padding: const EdgeInsets.all(20.0),
|
|
decoration: const BoxDecoration(
|
|
border: Border(
|
|
bottom: BorderSide( // <--- right side
|
|
color: ColorsManager.boxDivider,
|
|
width: 1.0,
|
|
),
|
|
)
|
|
),
|
|
alignment: Alignment.centerLeft,
|
|
child: Text(
|
|
content,
|
|
style: TextStyle(color: Colors.black, fontSize: 12),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
|
|
|