From 5518e3d46d7d0086ad1cd9d9079516ce5746e18c Mon Sep 17 00:00:00 2001 From: Calcitem Date: Tue, 21 May 2024 00:47:52 +0800 Subject: [PATCH] movelist: Highlight the active selection --- .../widgets/dialogs/move_list_dialog.dart | 53 +++++++++++++------ .../lib/shared/themes/app_theme.dart | 2 + 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/src/ui/flutter_app/lib/game_page/widgets/dialogs/move_list_dialog.dart b/src/ui/flutter_app/lib/game_page/widgets/dialogs/move_list_dialog.dart index edbf74bfc..9a16e0893 100644 --- a/src/ui/flutter_app/lib/game_page/widgets/dialogs/move_list_dialog.dart +++ b/src/ui/flutter_app/lib/game_page/widgets/dialogs/move_list_dialog.dart @@ -40,6 +40,9 @@ class _MoveListDialog extends StatelessWidget { rootScaffoldMessengerKey.currentState!.clearSnackBars(); } + // ValueNotifier to track the selected index + final ValueNotifier selectedIndex = ValueNotifier(null); + return GamePageActionSheet( child: AlertDialog( backgroundColor: UIColors.semiTransparentBlack, @@ -70,8 +73,13 @@ class _MoveListDialog extends StatelessWidget { ), ...List.generate( movesCount, - (int index) => - _buildMoveListItem(context, mergedMoves, fen, index), + (int index) => _buildMoveListItem( + context, + mergedMoves, + fen, + index, + selectedIndex, + ), ), ], ), @@ -145,8 +153,8 @@ class _MoveListDialog extends StatelessWidget { return mergedMoves; } - Widget _buildMoveListItem( - BuildContext context, List mergedMoves, String? fen, int index) { + Widget _buildMoveListItem(BuildContext context, List mergedMoves, + String? fen, int index, ValueNotifier selectedIndex) { final int moveIndex = index * 2; final List spans = []; @@ -168,16 +176,32 @@ class _MoveListDialog extends StatelessWidget { final String moveText = mergedMoves[moveIndex + i]; spans.add( WidgetSpan( - child: InkWell( - onTap: () => _importGame(context, mergedMoves, fen, moveIndex + i), - child: Padding( - padding: const EdgeInsets.only(right: 24.0), - child: Text( - moveText, - style: _getTitleTextStyle(context), - textDirection: TextDirection.ltr, - ), - ), + child: ValueListenableBuilder( + valueListenable: selectedIndex, + builder: (BuildContext context, int? value, Widget? child) { + final bool isSelected = value == moveIndex + i; + return InkWell( + onTap: () { + selectedIndex.value = moveIndex + i; + _importGame(context, mergedMoves, fen, moveIndex + i); + }, + child: Container( + padding: const EdgeInsets.only(right: 24.0), + color: isSelected + ? AppTheme.gamePageActionSheetTextBackgroundColor + : null, + child: Text( + moveText, + style: _getTitleTextStyle(context).copyWith( + color: isSelected + ? AppTheme.gamePageActionSheetTextColor + : AppTheme.gamePageActionSheetTextColor, + ), + textDirection: TextDirection.ltr, + ), + ), + ); + }, ), ), ); @@ -202,7 +226,6 @@ class _MoveListDialog extends StatelessWidget { Future _importGame(BuildContext context, List mergedMoves, String? fen, int clickedIndex) async { String ml = mergedMoves.sublist(0, clickedIndex + 1).join(' '); - // If fen is not null, prepend it to ml with a space if (fen != null) { ml = '$fen $ml'; } diff --git a/src/ui/flutter_app/lib/shared/themes/app_theme.dart b/src/ui/flutter_app/lib/shared/themes/app_theme.dart index fa37f846a..38d7ac496 100644 --- a/src/ui/flutter_app/lib/shared/themes/app_theme.dart +++ b/src/ui/flutter_app/lib/shared/themes/app_theme.dart @@ -333,6 +333,8 @@ class AppTheme { static const Color infoDialogBackgroundColor = Colors.transparent; static const Color modalBottomSheetBackgroundColor = Colors.transparent; static const Color gamePageActionSheetTextColor = Colors.yellow; + static Color gamePageActionSheetTextBackgroundColor = + Colors.deepPurple.withOpacity(0.8); /// Settings page static const Color listItemDividerColor = UIColors.rosewood20;