From e0ca6c217de6d7424e0bcba3d6830e74383b95e9 Mon Sep 17 00:00:00 2001 From: cp-mayank-v Date: Fri, 7 Jun 2024 12:28:32 +0530 Subject: [PATCH] Add Five Seven Run Sheet --- khelo/assets/locales/app_en.arb | 2 + .../components/add_extra_sheet.dart | 68 ++++++++++++++++--- khelo/lib/ui/flow/team/team_list_screen.dart | 2 +- 3 files changed, 63 insertions(+), 9 deletions(-) diff --git a/khelo/assets/locales/app_en.arb b/khelo/assets/locales/app_en.arb index 614098ec..c6b6149e 100644 --- a/khelo/assets/locales/app_en.arb +++ b/khelo/assets/locales/app_en.arb @@ -517,6 +517,8 @@ "score_board_six_text": "6", "score_board_six_title": "Six", "score_board_five_or_seven_text": "5, 7", + "score_board_five_text": "5", + "score_board_seven_text": "7", "score_board_out_text": "OUT", "score_board_wicket_text": "WICKET", "score_board_leg_bye_text": "LB", diff --git a/khelo/lib/ui/flow/score_board/components/add_extra_sheet.dart b/khelo/lib/ui/flow/score_board/components/add_extra_sheet.dart index bcf44672..033345ff 100644 --- a/khelo/lib/ui/flow/score_board/components/add_extra_sheet.dart +++ b/khelo/lib/ui/flow/score_board/components/add_extra_sheet.dart @@ -4,6 +4,7 @@ import 'package:flutter/services.dart'; import 'package:go_router/go_router.dart'; import 'package:khelo/domain/extensions/context_extensions.dart'; import 'package:khelo/ui/flow/score_board/components/bottom_sheet_wrapper.dart'; +import 'package:style/animations/on_tap_scale.dart'; import 'package:style/button/primary_button.dart'; import 'package:style/extensions/context_extensions.dart'; import 'package:style/text/app_text_field.dart'; @@ -56,7 +57,6 @@ class AddExtraSheet extends StatefulWidget { class _AddExtraSheetState extends State { bool notFromBat = false; bool isBoundary = false; - bool isButtonEnable = false; TextEditingController runController = TextEditingController(); @@ -67,7 +67,7 @@ class _AddExtraSheetState extends State { action: [ PrimaryButton( context.l10n.common_next_title, - enabled: isButtonEnable, + enabled: runController.text.isNotEmpty, onPressed: () { context.pop(( int.parse(runController.text), @@ -92,11 +92,66 @@ class _AddExtraSheetState extends State { .copyWith(color: context.colorScheme.textPrimary), ), const SizedBox(height: 16), - _addRunsView(context), + if (widget.isFiveSeven) ...[ + Wrap( + spacing: 16, + children: [ + _runButton( + text: context.l10n.score_board_five_text, + onTap: () { + setState(() { + runController.text = context.l10n.score_board_five_text; + }); + }, + selected: runController.text.contains( + context.l10n.score_board_five_text, + ), + ), + _runButton( + text: context.l10n.score_board_seven_text, + onTap: () { + setState(() { + runController.text = context.l10n.score_board_seven_text; + }); + }, + selected: runController.text.contains( + context.l10n.score_board_seven_text, + ), + ), + ], + ), + ] else ...[ + _addRunsView(context), + ], ], ); } + Widget _runButton({ + required text, + required Function() onTap, + required bool selected, + }) { + return OnTapScale( + onTap: onTap, + child: Container( + padding: const EdgeInsets.symmetric(horizontal: 32, vertical: 24), + decoration: BoxDecoration( + color: context.colorScheme.containerLow, + borderRadius: BorderRadius.circular(12), + border: selected + ? Border.all(color: context.colorScheme.primary) + : null), + child: Text( + text, + style: AppTextStyle.subtitle1.copyWith( + color: context.colorScheme.textPrimary, + ), + ), + ), + ); + } + Widget _addRunsView(BuildContext context) { return Container( padding: const EdgeInsets.all(16), @@ -136,8 +191,7 @@ class _AddExtraSheetState extends State { ], style: AppTextStyle.subtitle2 .copyWith(color: context.colorScheme.textPrimary), - onChanged: (value) => - setState(() => isButtonEnable = value.isNotEmpty), + onChanged: (_) => setState(() {}), ), ), ), @@ -208,9 +262,7 @@ class _AddExtraSheetState extends State { } String _getExtraTitle(BuildContext context, ExtrasType? type) { - if (widget.isFiveSeven) { - return context.l10n.score_board_five_or_seven_text; - } else if (type == ExtrasType.noBall) { + if (type == ExtrasType.noBall) { return "${context.l10n.score_board_no_ball_short_text} +"; } else if (type == ExtrasType.bye) { return context.l10n.score_board_bye_text; diff --git a/khelo/lib/ui/flow/team/team_list_screen.dart b/khelo/lib/ui/flow/team/team_list_screen.dart index 0000f39a..fabe463e 100644 --- a/khelo/lib/ui/flow/team/team_list_screen.dart +++ b/khelo/lib/ui/flow/team/team_list_screen.dart @@ -103,7 +103,7 @@ class _TeamListScreenState extends ConsumerState return ListView.separated( itemCount: state.filteredTeams.length, - padding: const EdgeInsets.all(16) + context.mediaQueryPadding, + padding: const EdgeInsets.symmetric(horizontal: 16) + context.mediaQueryPadding, separatorBuilder: (context, index) => Divider(color: context.colorScheme.outline), itemBuilder: (context, index) {