Added sticky header to table

This commit is contained in:
2025-08-02 18:57:18 +02:00
parent 03462808c2
commit e265a671ff
2 changed files with 172 additions and 106 deletions

View File

@@ -29,15 +29,15 @@ class _PointsViewState extends State<PointsView> {
(constraints.maxWidth - roundColWidth - (tablePadding)) / (constraints.maxWidth - roundColWidth - (tablePadding)) /
playerCount; playerCount;
return SingleChildScrollView( return Column(
scrollDirection: Axis.vertical, children: [
child: ConstrainedBox( ConstrainedBox(
constraints: BoxConstraints(maxWidth: constraints.maxWidth), constraints: BoxConstraints(maxWidth: constraints.maxWidth),
child: Padding( child: Padding(
padding: const EdgeInsets.symmetric(horizontal: tablePadding), padding: const EdgeInsets.symmetric(horizontal: tablePadding),
child: DataTable( child: DataTable(
dataRowMaxHeight: 75, dataRowMaxHeight: 0,
dataRowMinHeight: 75, dataRowMinHeight: 0,
columnSpacing: 0, columnSpacing: 0,
horizontalMargin: 0, horizontalMargin: 0,
columns: [ columns: [
@@ -73,6 +73,58 @@ class _PointsViewState extends State<PointsView> {
), ),
), ),
], ],
rows: const [],
),
),
),
Expanded(
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: ConstrainedBox(
constraints:
BoxConstraints(maxWidth: constraints.maxWidth),
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: tablePadding),
child: DataTable(
dataRowMaxHeight: 75,
dataRowMinHeight: 75,
columnSpacing: 0,
horizontalMargin: 0,
headingRowHeight: 0,
columns: [
const DataColumn(
label: SizedBox(
width: roundColWidth,
child: Text(
'#',
style: TextStyle(fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
),
),
numeric: true,
),
...widget.gameSession.players.map(
(player) => DataColumn(
label: SizedBox(
width: playerColWidth,
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 8),
child: Text(
player,
style: const TextStyle(
fontWeight: FontWeight.bold),
overflow: TextOverflow.ellipsis,
softWrap: true,
maxLines: 2,
textAlign: TextAlign.center,
),
),
),
),
),
],
rows: [ rows: [
...List<DataRow>.generate( ...List<DataRow>.generate(
widget.gameSession.roundList.length, widget.gameSession.roundList.length,
@@ -91,7 +143,8 @@ class _PointsViewState extends State<PointsView> {
...List.generate( ...List.generate(
widget.gameSession.players.length, widget.gameSession.players.length,
(playerIndex) { (playerIndex) {
final int score = round.scores[playerIndex]; final int score =
round.scores[playerIndex];
final int update = final int update =
round.scoreUpdates[playerIndex]; round.scoreUpdates[playerIndex];
final bool saidCabo = final bool saidCabo =
@@ -106,9 +159,11 @@ class _PointsViewState extends State<PointsView> {
0.2), // Adjust width based on amount of players 0.2), // Adjust width based on amount of players
decoration: BoxDecoration( decoration: BoxDecoration(
color: saidCabo color: saidCabo
? CustomTheme.buttonBackgroundColor ? CustomTheme
.buttonBackgroundColor
: CupertinoColors.transparent, : CupertinoColors.transparent,
borderRadius: BorderRadius.circular(5), borderRadius:
BorderRadius.circular(5),
), ),
child: Column( child: Column(
mainAxisAlignment: mainAxisAlignment:
@@ -118,20 +173,27 @@ class _PointsViewState extends State<PointsView> {
height: 5, height: 5,
), ),
Container( Container(
padding: const EdgeInsets.symmetric( padding: const EdgeInsets
horizontal: 6, vertical: 2), .symmetric(
horizontal: 6,
vertical: 2),
decoration: BoxDecoration( decoration: BoxDecoration(
color: update <= 0 color: update <= 0
? CustomTheme.pointLossColor ? CustomTheme
: CustomTheme.pointGainColor, .pointLossColor
: CustomTheme
.pointGainColor,
borderRadius: borderRadius:
BorderRadius.circular(6), BorderRadius.circular(
6),
), ),
child: Text( child: Text(
'${update >= 0 ? '+' : ''}$update', '${update >= 0 ? '+' : ''}$update',
style: const TextStyle( style: const TextStyle(
color: CupertinoColors.white, color:
fontWeight: FontWeight.bold, CupertinoColors.white,
fontWeight:
FontWeight.bold,
), ),
), ),
), ),
@@ -162,7 +224,8 @@ class _PointsViewState extends State<PointsView> {
child: Text( child: Text(
'Σ', 'Σ',
style: TextStyle( style: TextStyle(
fontSize: 25, fontWeight: FontWeight.bold), fontSize: 25,
fontWeight: FontWeight.bold),
), ),
)), )),
...widget.gameSession.playerScores.map( ...widget.gameSession.playerScores.map(
@@ -182,7 +245,10 @@ class _PointsViewState extends State<PointsView> {
], ],
), ),
), ),
)); )),
),
],
);
}))); })));
} }
} }

View File

@@ -2,7 +2,7 @@ name: cabo_counter
description: "Mobile app for the card game Cabo" description: "Mobile app for the card game Cabo"
publish_to: 'none' publish_to: 'none'
version: 0.5.5+636 version: 0.5.5+639
environment: environment:
sdk: ^3.5.4 sdk: ^3.5.4