-
-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c2c931f
commit e948d04
Showing
7 changed files
with
271 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
import 'dart:math'; | ||
|
||
import 'package:dartchess/dartchess.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:lichess_mobile/src/model/broadcast/broadcast.dart'; | ||
import 'package:lichess_mobile/src/model/broadcast/broadcast_providers.dart'; | ||
import 'package:lichess_mobile/src/model/common/id.dart'; | ||
import 'package:lichess_mobile/src/view/broadcast/broadcast_player_widget.dart'; | ||
import 'package:lichess_mobile/src/widgets/platform_scaffold.dart'; | ||
import 'package:lichess_mobile/src/widgets/progression_widget.dart'; | ||
|
||
class BroadcastPlayerScreen extends StatelessWidget { | ||
final BroadcastTournamentId tournamentId; | ||
final FideId fideId; | ||
const BroadcastPlayerScreen( | ||
this.tournamentId, | ||
this.fideId, | ||
); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return PlatformScaffold( | ||
appBar: const PlatformAppBar( | ||
title: Text('Player details'), | ||
), | ||
body: _Body(tournamentId, fideId), | ||
); | ||
} | ||
} | ||
|
||
const _kTableRowPadding = EdgeInsets.symmetric( | ||
vertical: 12.0, | ||
); | ||
|
||
class _Body extends ConsumerWidget { | ||
final BroadcastTournamentId tournamentId; | ||
final FideId fideId; | ||
|
||
const _Body(this.tournamentId, this.fideId); | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
final playersResults = | ||
ref.watch(broadcastPlayerResultProvider(tournamentId, fideId)); | ||
|
||
switch (playersResults) { | ||
case AsyncData(value: final playerResults): | ||
final indexWidth = | ||
max(8.0 + playerResults.length.toString().length * 10.0, 28.0); | ||
|
||
return ListView.builder( | ||
itemCount: playerResults.length, | ||
itemBuilder: (context, index) { | ||
final playerResult = playerResults[index]; | ||
return ColoredBox( | ||
color: index.isEven | ||
? Theme.of(context).colorScheme.surfaceContainerLow | ||
: Theme.of(context).colorScheme.surfaceContainerHigh, | ||
child: Padding( | ||
padding: _kTableRowPadding, | ||
child: Row( | ||
children: [ | ||
SizedBox( | ||
width: indexWidth, | ||
child: Center(child: Text((index + 1).toString())), | ||
), | ||
Expanded( | ||
flex: 5, | ||
child: BroadcastPlayerWidget( | ||
federation: playerResult.opponent.federation, | ||
title: playerResult.opponent.title, | ||
name: playerResult.opponent.name, | ||
), | ||
), | ||
Expanded( | ||
flex: 3, | ||
child: (playerResult.opponent.rating != null) | ||
? Center( | ||
child: | ||
Text(playerResult.opponent.rating.toString()), | ||
) | ||
: const SizedBox.shrink(), | ||
), | ||
SizedBox( | ||
width: 30, | ||
child: Center( | ||
child: Container( | ||
width: 15, | ||
height: 15, | ||
decoration: BoxDecoration( | ||
border: (Theme.of(context).brightness == | ||
Brightness.light && | ||
playerResult.color == Side.white || | ||
Theme.of(context).brightness == | ||
Brightness.dark && | ||
playerResult.color == Side.black) | ||
? Border.all( | ||
width: 2.0, | ||
color: | ||
Theme.of(context).colorScheme.outline, | ||
) | ||
: null, | ||
shape: BoxShape.circle, | ||
color: switch (playerResult.color) { | ||
Side.white => Colors.white.withValues(alpha: 0.9), | ||
Side.black => Colors.black.withValues(alpha: 0.9), | ||
}, | ||
), | ||
), | ||
), | ||
), | ||
SizedBox( | ||
width: 30, | ||
child: Center( | ||
child: Text( | ||
switch (playerResult.points) { | ||
BroadcastPoints.one => '1', | ||
BroadcastPoints.half => '½', | ||
BroadcastPoints.zero => '0', | ||
_ => '*' | ||
}, | ||
), | ||
), | ||
), | ||
SizedBox( | ||
width: 38, | ||
child: (playerResult.ratingDiff != null) | ||
? ProgressionWidget( | ||
playerResult.ratingDiff!, | ||
fontSize: 15, | ||
) | ||
: null, | ||
), | ||
], | ||
), | ||
), | ||
); | ||
}, | ||
); | ||
case AsyncError(:final error): | ||
return Text('Cannot load player data: $error'); | ||
case _: | ||
return const CircularProgressIndicator.adaptive(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.