diff --git a/lib/pages/common/custom_table.dart b/lib/pages/common/custom_table.dart index f23daa45..625c59c2 100644 --- a/lib/pages/common/custom_table.dart +++ b/lib/pages/common/custom_table.dart @@ -50,20 +50,11 @@ class _DynamicTableState extends State { bool _selectAll = false; final ScrollController _verticalScrollController = ScrollController(); final ScrollController _horizontalScrollController = ScrollController(); - late ScrollController _horizontalHeaderScrollController; - late ScrollController _horizontalBodyScrollController; + @override void initState() { super.initState(); _initializeSelection(); - _horizontalHeaderScrollController = ScrollController(); - _horizontalBodyScrollController = ScrollController(); - - // Synchronize horizontal scrolling - _horizontalBodyScrollController.addListener(() { - _horizontalHeaderScrollController - .jumpTo(_horizontalBodyScrollController.offset); - }); } @override @@ -113,108 +104,78 @@ class _DynamicTableState extends State { context.read().add(UpdateSelection(_selectedRows)); } - @override - void dispose() { - _horizontalHeaderScrollController.dispose(); - _horizontalBodyScrollController.dispose(); - super.dispose(); - } - @override Widget build(BuildContext context) { return Container( decoration: widget.cellDecoration, - child: Column( - children: [ - Container( - decoration: widget.headerDecoration ?? - const BoxDecoration(color: ColorsManager.boxColor), + child: Scrollbar( + controller: _verticalScrollController, + thumbVisibility: true, + trackVisibility: true, + child: Scrollbar( + //fixed the horizontal scrollbar issue + controller: _horizontalScrollController, + thumbVisibility: true, + trackVisibility: true, + notificationPredicate: (notif) => notif.depth == 1, + child: SingleChildScrollView( + controller: _verticalScrollController, child: SingleChildScrollView( + controller: _horizontalScrollController, scrollDirection: Axis.horizontal, - physics: const NeverScrollableScrollPhysics(), - controller: _horizontalHeaderScrollController, child: SizedBox( width: widget.size.width, - child: Row( + child: Column( children: [ - if (widget.withCheckBox) _buildSelectAllCheckbox(), - ...List.generate(widget.headers.length, (index) { - return _buildTableHeaderCell( - widget.headers[index], index); - }), + Container( + decoration: widget.headerDecoration ?? + const BoxDecoration( + color: ColorsManager.boxColor, + ), + child: Row( + children: [ + if (widget.withCheckBox) _buildSelectAllCheckbox(), + ...List.generate(widget.headers.length, (index) { + return _buildTableHeaderCell( + widget.headers[index], index); + }) + //...widget.headers.map((header) => _buildTableHeaderCell(header)), + ], + ), + ), + SizedBox( + width: widget.size.width, + child: widget.isEmpty + ? _buildEmptyState() + : Column( + children: + List.generate(widget.data.length, (rowIndex) { + final row = widget.data[rowIndex]; + return Row( + children: [ + if (widget.withCheckBox) + _buildRowCheckbox( + rowIndex, widget.size.height * 0.08), + ...row.asMap().entries.map((entry) { + return _buildTableCell( + entry.value.toString(), + widget.size.height * 0.08, + rowIndex: rowIndex, + columnIndex: entry.key, + ); + }).toList(), + ], + ); + }), + ), + ), ], ), ), ), ), - Expanded( - child: Scrollbar( - controller: _verticalScrollController, - thumbVisibility: true, - trackVisibility: true, - child: SingleChildScrollView( - controller: _verticalScrollController, - child: Scrollbar( - controller: _horizontalBodyScrollController, - thumbVisibility: false, - trackVisibility: false, - notificationPredicate: (notif) => notif.depth == 1, - child: SingleChildScrollView( - scrollDirection: Axis.horizontal, - controller: _horizontalBodyScrollController, - child: Container( - color: ColorsManager.whiteColors, - child: SizedBox( - width: widget.size.width, - child: widget.isEmpty - ? _buildEmptyState() - : Column( - children: List.generate(widget.data.length, - (rowIndex) { - final row = widget.data[rowIndex]; - return Row( - children: [ - if (widget.withCheckBox) - _buildRowCheckbox(rowIndex, - widget.size.height * 0.08), - ...row.asMap().entries.map((entry) { - return _buildTableCell( - entry.value.toString(), - widget.size.height * 0.08, - rowIndex: rowIndex, - columnIndex: entry.key, - ); - }).toList(), - ], - ); - }), - ), - ), - ), - ), - ), - ), - ), - ), - ], - ), - ); - } - - Widget _buildSelectAllCheckbox() { - return Container( - width: 50, - decoration: const BoxDecoration( - border: Border.symmetric( - vertical: BorderSide(color: ColorsManager.boxDivider), ), ), - child: Checkbox( - value: _selectAll, - onChanged: widget.withSelectAll && widget.data.isNotEmpty - ? _toggleSelectAll - : null, - ), ); } @@ -244,6 +205,23 @@ class _DynamicTableState extends State { ), ], ); + Widget _buildSelectAllCheckbox() { + return Container( + width: 50, + decoration: const BoxDecoration( + border: Border.symmetric( + vertical: BorderSide(color: ColorsManager.boxDivider), + ), + ), + child: Checkbox( + value: _selectAll, + onChanged: widget.withSelectAll && widget.data.isNotEmpty + ? _toggleSelectAll + : null, + ), + ); + } + Widget _buildRowCheckbox(int index, double size) { return Container( width: 50, @@ -298,12 +276,8 @@ class _DynamicTableState extends State { ); } - Widget _buildTableCell( - String content, - double size, { - required int rowIndex, - required int columnIndex, - }) { + Widget _buildTableCell(String content, double size, + {required int rowIndex, required int columnIndex}) { bool isBatteryLevel = content.endsWith('%'); double? batteryLevel; @@ -311,7 +285,6 @@ class _DynamicTableState extends State { batteryLevel = double.tryParse(content.replaceAll('%', '').trim()); } bool isSettingsColumn = widget.headers[columnIndex] == 'Settings'; - if (isSettingsColumn) { return buildSettingsIcon( width: 120, @@ -416,11 +389,10 @@ class _DynamicTableState extends State { padding: const EdgeInsets.all(8.0), child: Center( child: SvgPicture.asset( - Assets.settings, // ضع المسار الصحيح هنا + Assets.settings, width: 40, height: 22, - color: ColorsManager - .primaryColor, // نفس لون الأيقونة في الصورة + color: ColorsManager.primaryColor, ), ), ),