Skip to content

Commit

Permalink
Fix board editor color filter
Browse files Browse the repository at this point in the history
  • Loading branch information
veloce committed Dec 20, 2024
1 parent bb6cc12 commit a1bb54b
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 6.2.3

- Fix board editor color filter

## 6.2.2

- Fix default value of brightness
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ packages:
path: ".."
relative: true
source: path
version: "6.2.2"
version: "6.2.3"
clock:
dependency: transitive
description:
Expand Down
26 changes: 10 additions & 16 deletions lib/src/widgets/board_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -232,26 +232,20 @@ class _BoardEditorState extends State<ChessboardEditor> {
),
);

final coloredBoard = BrightnessHueFilter(
hue: widget.settings.hue,
brightness: widget.settings.brightness,
child: board,
);

if (widget.settings.border != null) {
return BorderedChessboard(
size: widget.size,
orientation: widget.orientation,
border: widget.settings.border!,
showCoordinates: widget.settings.enableCoordinates,
child: coloredBoard,
);
}
final borderedChessboard = widget.settings.border != null
? BorderedChessboard(
size: widget.size,
orientation: widget.orientation,
border: widget.settings.border!,
showCoordinates: widget.settings.enableCoordinates,
child: board,
)
: board;

return BrightnessHueFilter(
brightness: widget.settings.brightness,
hue: widget.settings.hue,
child: coloredBoard,
child: borderedChessboard,
);
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: chessground
description: Chess board UI developed for lichess.org. It has no chess logic inside so it can be used for chess variants.
version: 6.2.2
version: 6.2.3
repository: https://github.com/lichess-org/flutter-chessground
funding:
- https://lichess.org/patron
Expand Down
54 changes: 54 additions & 0 deletions test/widgets/board_editor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,60 @@ void main() {
expect(find.byType(PieceWidget), findsNWidgets(12));
});

testWidgets('displays a border', (WidgetTester tester) async {
const board = ChessboardEditor(
size: boardSize,
orientation: Side.white,
pieces: {},
settings: ChessboardSettings(
border: BoardBorder(
width: 16.0,
color: Color(0xFF000000),
),
),
);

await tester.pumpWidget(board);

final size = tester.getSize(
find.byType(SolidColorChessboardBackground),
);
expect(size.width, boardSize - 32.0);
expect(size.height, boardSize - 32.0);
});

testWidgets('change in hue will use a color filter',
(WidgetTester tester) async {
const board = ChessboardEditor(
size: boardSize,
orientation: Side.white,
pieces: {},
settings: ChessboardSettings(
hue: 100.0,
),
);

await tester.pumpWidget(board);

expect(find.byType(ColorFiltered), findsOneWidget);
});

testWidgets('change in brightness will use a color filter',
(WidgetTester tester) async {
const board = ChessboardEditor(
size: boardSize,
orientation: Side.white,
pieces: {},
settings: ChessboardSettings(
brightness: 0.9,
),
);

await tester.pumpWidget(board);

expect(find.byType(ColorFiltered), findsOneWidget);
});

testWidgets(
'touching a square triggers the onEditedSquare callback when the board pointer tool mode is `edit`',
(WidgetTester tester) async {
Expand Down
32 changes: 32 additions & 0 deletions test/widgets/board_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,38 @@ void main() {
expect(size.width, boardSize - 32.0);
expect(size.height, boardSize - 32.0);
});

testWidgets('change in hue will use a color filter',
(WidgetTester tester) async {
const board = Chessboard.fixed(
size: boardSize,
orientation: Side.white,
fen: kInitialFEN,
settings: ChessboardSettings(
hue: 100.0,
),
);

await tester.pumpWidget(board);

expect(find.byType(ColorFiltered), findsOneWidget);
});

testWidgets('change in brightness will use a color filter',
(WidgetTester tester) async {
const board = Chessboard.fixed(
size: boardSize,
orientation: Side.white,
fen: kInitialFEN,
settings: ChessboardSettings(
brightness: 0.9,
),
);

await tester.pumpWidget(board);

expect(find.byType(ColorFiltered), findsOneWidget);
});
});

group('Interactive board', () {
Expand Down

0 comments on commit a1bb54b

Please sign in to comment.