From b09fa2a8ed3cfa8da961b8f7f2b9283039dd0400 Mon Sep 17 00:00:00 2001 From: cp-mayank-v Date: Tue, 4 Jun 2024 15:58:47 +0530 Subject: [PATCH] Refactor observers --- .../matches/add_match/add_match_screen.dart | 80 +- .../match_official_selection_view.dart | 2 +- .../components/over_detail_view.dart | 2 +- .../add_match_officials_screen.dart | 1 - .../search_user/search_user_screen.dart | 6 +- .../power_play/power_play_screen.dart | 1 - .../select_squad/select_squad_screen.dart | 23 +- khelo/lib/ui/flow/profile/profile_screen.dart | 34 +- .../add_toss_detail_screen.dart | 40 +- .../components/select_player_sheet.dart | 9 +- .../flow/score_board/score_board_screen.dart | 958 +++++++++--------- .../edit_profile/edit_profile_screen.dart | 44 +- .../phone_verification_screen.dart | 40 +- .../sign_in_with_phone_screen.dart | 82 +- .../flow/team/add_team/add_team_screen.dart | 65 +- khelo/lib/ui/flow/team/team_list_screen.dart | 26 +- 16 files changed, 705 insertions(+), 708 deletions(-) diff --git a/khelo/lib/ui/flow/matches/add_match/add_match_screen.dart b/khelo/lib/ui/flow/matches/add_match/add_match_screen.dart index f772ef3a..3d38a401 100644 --- a/khelo/lib/ui/flow/matches/add_match/add_match_screen.dart +++ b/khelo/lib/ui/flow/matches/add_match/add_match_screen.dart @@ -44,46 +44,6 @@ class AddMatchScreen extends ConsumerStatefulWidget { class _AddMatchScreenState extends ConsumerState { late AddMatchViewNotifier notifier; - void _observeActionError(BuildContext context, WidgetRef ref) { - ref.listen(addMatchViewStateProvider.select((value) => value.actionError), - (previous, next) { - if (next != null) { - showErrorSnackBar(context: context, error: next); - } - }); - } - - void _observePushTossDetailScreen( - BuildContext context, - WidgetRef ref, - String? matchId, - ) { - ref.listen( - addMatchViewStateProvider.select((value) => value.pushTossDetailScreen), - (previous, next) { - if (next == true) { - AppRoute.addTossDetail( - matchId: ref.read(addMatchViewStateProvider.notifier).matchId ?? - "INVALID ID") - .pushReplacement(context); - } else if (next == false) { - AppRoute.scoreBoard( - matchId: ref.read(addMatchViewStateProvider.notifier).matchId ?? - "INVALID ID") - .pushReplacement(context); - } - }); - } - - void _observePop(BuildContext context, WidgetRef ref) { - ref.listen(addMatchViewStateProvider.select((value) => value.pop), - (previous, next) { - if (next != null && next) { - context.pop(); - } - }); - } - @override void initState() { super.initState(); @@ -472,4 +432,44 @@ class _AddMatchScreenState extends ConsumerState { }, ); } + + void _observeActionError(BuildContext context, WidgetRef ref) { + ref.listen(addMatchViewStateProvider.select((value) => value.actionError), + (previous, next) { + if (next != null) { + showErrorSnackBar(context: context, error: next); + } + }); + } + + void _observePushTossDetailScreen( + BuildContext context, + WidgetRef ref, + String? matchId, + ) { + ref.listen( + addMatchViewStateProvider.select((value) => value.pushTossDetailScreen), + (previous, next) { + if (next == true) { + AppRoute.addTossDetail( + matchId: ref.read(addMatchViewStateProvider.notifier).matchId ?? + "INVALID ID") + .pushReplacement(context); + } else if (next == false) { + AppRoute.scoreBoard( + matchId: ref.read(addMatchViewStateProvider.notifier).matchId ?? + "INVALID ID") + .pushReplacement(context); + } + }); + } + + void _observePop(BuildContext context, WidgetRef ref) { + ref.listen(addMatchViewStateProvider.select((value) => value.pop), + (previous, next) { + if (next != null && next) { + context.pop(); + } + }); + } } diff --git a/khelo/lib/ui/flow/matches/add_match/components/match_official_selection_view.dart b/khelo/lib/ui/flow/matches/add_match/components/match_official_selection_view.dart index a2048a95..c8793ebf 100644 --- a/khelo/lib/ui/flow/matches/add_match/components/match_official_selection_view.dart +++ b/khelo/lib/ui/flow/matches/add_match/components/match_official_selection_view.dart @@ -51,4 +51,4 @@ class MatchOfficialSelectionView extends StatelessWidget { ], ); } -} \ No newline at end of file +} diff --git a/khelo/lib/ui/flow/matches/add_match/components/over_detail_view.dart b/khelo/lib/ui/flow/matches/add_match/components/over_detail_view.dart index 8d1670bb..4e5f5384 100644 --- a/khelo/lib/ui/flow/matches/add_match/components/over_detail_view.dart +++ b/khelo/lib/ui/flow/matches/add_match/components/over_detail_view.dart @@ -209,4 +209,4 @@ class OverDetailView extends StatelessWidget { ), ); } -} \ No newline at end of file +} diff --git a/khelo/lib/ui/flow/matches/add_match/match_officials/add_match_officials_screen.dart b/khelo/lib/ui/flow/matches/add_match/match_officials/add_match_officials_screen.dart index 8dd50403..2d4d61b2 100644 --- a/khelo/lib/ui/flow/matches/add_match/match_officials/add_match_officials_screen.dart +++ b/khelo/lib/ui/flow/matches/add_match/match_officials/add_match_officials_screen.dart @@ -39,7 +39,6 @@ class _AddMatchOfficialsScreenState @override Widget build(BuildContext context) { - notifier = ref.watch(addMatchOfficialsStateProvider.notifier); final state = ref.watch(addMatchOfficialsStateProvider); return AppPage( diff --git a/khelo/lib/ui/flow/matches/add_match/match_officials/search_user/search_user_screen.dart b/khelo/lib/ui/flow/matches/add_match/match_officials/search_user/search_user_screen.dart index eecd10ce..6b0f2396 100644 --- a/khelo/lib/ui/flow/matches/add_match/match_officials/search_user/search_user_screen.dart +++ b/khelo/lib/ui/flow/matches/add_match/match_officials/search_user/search_user_screen.dart @@ -65,8 +65,8 @@ class SearchUserBottomSheet extends ConsumerWidget { return state.searchedUsers.isEmpty ? Padding( - padding: const EdgeInsets.symmetric(horizontal: 16.0), - child: Center( + padding: const EdgeInsets.symmetric(horizontal: 16.0), + child: Center( child: Text( context.l10n.search_user_empty_text, textAlign: TextAlign.center, @@ -75,7 +75,7 @@ class SearchUserBottomSheet extends ConsumerWidget { ), ), ), - ) + ) : ListView.separated( separatorBuilder: (context, index) { return Divider( diff --git a/khelo/lib/ui/flow/matches/add_match/power_play/power_play_screen.dart b/khelo/lib/ui/flow/matches/add_match/power_play/power_play_screen.dart index 9403b48a..9fab7b65 100644 --- a/khelo/lib/ui/flow/matches/add_match/power_play/power_play_screen.dart +++ b/khelo/lib/ui/flow/matches/add_match/power_play/power_play_screen.dart @@ -52,7 +52,6 @@ class _PowerPlayScreenState extends ConsumerState { int maxOversInRow = _calculateMaxOversInRow(context); double approxCellWidth = _calculateCellWidth(context, maxOversInRow); - notifier = ref.watch(powerPlayStateProvider.notifier); final state = ref.watch(powerPlayStateProvider); return AppPage( diff --git a/khelo/lib/ui/flow/matches/add_match/select_squad/select_squad_screen.dart b/khelo/lib/ui/flow/matches/add_match/select_squad/select_squad_screen.dart index dfac3d6b..33d37a7d 100644 --- a/khelo/lib/ui/flow/matches/add_match/select_squad/select_squad_screen.dart +++ b/khelo/lib/ui/flow/matches/add_match/select_squad/select_squad_screen.dart @@ -49,7 +49,6 @@ class _SelectSquadScreenState extends ConsumerState { @override Widget build(BuildContext context) { - notifier = ref.watch(selectSquadStateProvider.notifier); final state = ref.watch(selectSquadStateProvider); return AppPage( @@ -76,18 +75,16 @@ class _SelectSquadScreenState extends ConsumerState { BlendMode.srcIn), )), ], - body: Builder( - builder: (context) { - return ListView( - padding: context.mediaQueryPadding + - const EdgeInsets.symmetric(horizontal: 16), - children: [ - _playingSquadList(context, notifier, state), - _teamMemberList(context, notifier, state) - ], - ); - } - ), + body: Builder(builder: (context) { + return ListView( + padding: context.mediaQueryPadding + + const EdgeInsets.symmetric(horizontal: 16), + children: [ + _playingSquadList(context, notifier, state), + _teamMemberList(context, notifier, state) + ], + ); + }), ); } diff --git a/khelo/lib/ui/flow/profile/profile_screen.dart b/khelo/lib/ui/flow/profile/profile_screen.dart index f3ac247d..22b9d052 100644 --- a/khelo/lib/ui/flow/profile/profile_screen.dart +++ b/khelo/lib/ui/flow/profile/profile_screen.dart @@ -17,23 +17,6 @@ import 'package:style/text/app_text_style.dart'; class ProfileScreen extends ConsumerWidget { const ProfileScreen({super.key}); - void _observeActionError(BuildContext context, WidgetRef ref) { - ref.listen(profileStateProvider.select((value) => value.actionError), - (previous, next) { - if (next != null) { - showErrorSnackBar(context: context, error: next); - } - }); - } - - void _observeUserSession(BuildContext context, WidgetRef ref) { - ref.listen(hasUserSession, (previous, next) { - if (!next) { - AppRoute.intro.go(context); - } - }); - } - @override Widget build(BuildContext context, WidgetRef ref) { final notifier = ref.watch(profileStateProvider.notifier); @@ -164,4 +147,21 @@ class ProfileScreen extends ConsumerWidget { return const SizedBox(); } } + + void _observeActionError(BuildContext context, WidgetRef ref) { + ref.listen(profileStateProvider.select((value) => value.actionError), + (previous, next) { + if (next != null) { + showErrorSnackBar(context: context, error: next); + } + }); + } + + void _observeUserSession(BuildContext context, WidgetRef ref) { + ref.listen(hasUserSession, (previous, next) { + if (!next) { + AppRoute.intro.go(context); + } + }); + } } diff --git a/khelo/lib/ui/flow/score_board/add_toss_detail/add_toss_detail_screen.dart b/khelo/lib/ui/flow/score_board/add_toss_detail/add_toss_detail_screen.dart index 6ca1f75d..ef163834 100644 --- a/khelo/lib/ui/flow/score_board/add_toss_detail/add_toss_detail_screen.dart +++ b/khelo/lib/ui/flow/score_board/add_toss_detail/add_toss_detail_screen.dart @@ -40,26 +40,6 @@ class _AddTossDetailScreenState extends ConsumerState { runPostFrame(() => notifier.setData(widget.matchId)); } - void _observeActionError(BuildContext context, WidgetRef ref) { - ref.listen(addTossDetailStateProvider.select((value) => value.actionError), - (previous, next) { - if (next != null) { - showErrorSnackBar(context: context, error: next); - } - }); - } - - void _observePushScoreBoard() { - ref.listen( - addTossDetailStateProvider.select((value) => value.pushScoreBoard), - (previous, next) { - if (next != null && next) { - AppRoute.scoreBoard(matchId: notifier.matchId!) - .pushReplacement(context); - } - }); - } - @override Widget build(BuildContext context) { final state = ref.watch(addTossDetailStateProvider); @@ -267,4 +247,24 @@ class _AddTossDetailScreenState extends ConsumerState { return Assets.images.bowler; } } + + void _observeActionError(BuildContext context, WidgetRef ref) { + ref.listen(addTossDetailStateProvider.select((value) => value.actionError), + (previous, next) { + if (next != null) { + showErrorSnackBar(context: context, error: next); + } + }); + } + + void _observePushScoreBoard() { + ref.listen( + addTossDetailStateProvider.select((value) => value.pushScoreBoard), + (previous, next) { + if (next != null && next) { + AppRoute.scoreBoard(matchId: notifier.matchId!) + .pushReplacement(context); + } + }); + } } diff --git a/khelo/lib/ui/flow/score_board/components/select_player_sheet.dart b/khelo/lib/ui/flow/score_board/components/select_player_sheet.dart index 77851162..1f3e21fe 100644 --- a/khelo/lib/ui/flow/score_board/components/select_player_sheet.dart +++ b/khelo/lib/ui/flow/score_board/components/select_player_sheet.dart @@ -74,10 +74,11 @@ class _SelectPlayerSheetState extends ConsumerState { final state = ref.watch(scoreBoardStateProvider); final notifier = ref.watch(scoreBoardStateProvider.notifier); - final showCheckBox = widget.playerSelectionType != - PlayerSelectionType.bowler - ? widget.batsManList.any((element) => element.status == PlayerStatus.injured) - : false; + final showCheckBox = + widget.playerSelectionType != PlayerSelectionType.bowler + ? widget.batsManList + .any((element) => element.status == PlayerStatus.injured) + : false; final injuredPlayerRemained = widget.playerSelectionType != PlayerSelectionType.bowler diff --git a/khelo/lib/ui/flow/score_board/score_board_screen.dart b/khelo/lib/ui/flow/score_board/score_board_screen.dart index b6695afa..cb10f685 100644 --- a/khelo/lib/ui/flow/score_board/score_board_screen.dart +++ b/khelo/lib/ui/flow/score_board/score_board_screen.dart @@ -40,598 +40,598 @@ class ScoreBoardScreen extends ConsumerStatefulWidget { class _ScoreBoardScreenState extends ConsumerState { late ScoreBoardViewNotifier notifier; - void _observeActionError(BuildContext context, WidgetRef ref) { - ref.listen(scoreBoardStateProvider.select((value) => value.actionError), - (previous, next) { - if (next != null) { - showErrorSnackBar(context: context, error: next); - } - }); + @override + void initState() { + super.initState(); + notifier = ref.read(scoreBoardStateProvider.notifier); + runPostFrame(() => notifier.setData(widget.matchId)); } - void _observeShowSelectBatsManSheet( + @override + Widget build(BuildContext context) { + final state = ref.watch(scoreBoardStateProvider); + + _observeActionError(context, ref); + _observeShowSelectBatsManSheet( + context, ref, state.continueWithInjuredPlayers); + _observeShowSelectBowlerSheet( + context, ref, state.continueWithInjuredPlayers); + _observeShowSelectBowlerAndBatsManSheet( + context, ref, state.continueWithInjuredPlayers); + _observeShowSelectPlayerSheet( + context, ref, state.continueWithInjuredPlayers); + _observeShowSelectWicketTypeSheet(context, ref); + _observeShowStrikerSelectionSheet(context, ref); + _observeShowUndoBallConfirmationDialog(context, ref); + _observeShowOverCompleteSheet(context, ref); + _observeShowInningCompleteSheet(context, ref); + _observeShowMatchCompleteSheet(context, ref); + _observeShowBoundaryConfirmationDialogForSix(context, ref); + _observeShowBoundaryConfirmationDialogForFour(context, ref); + _observeShowAddExtraSheetForNoBall(context, ref); + _observeShowAddExtraSheetForLegBye(context, ref); + _observeShowAddExtraSheetForBye(context, ref); + _observeShowAddExtraSheetForFiveSeven(context, ref); + _observePop(context, ref); + _observeShowPauseScoringSheet(context, ref); + _observeShowAddPenaltyRunSheet(context, ref); + _observeEndMatchSheet(context, ref); + _observeInvalidUndoToast(context, ref); + + return PopScope( + canPop: false, + child: AppPage( + title: context.l10n.score_board_screen_title, + actions: [_moreOptionButton(context, state)], + automaticallyImplyLeading: false, + resizeToAvoidBottomInset: false, + body: Builder(builder: (context) { + return _body(context, state); + }), + ), + ); + } + + Widget _moreOptionButton( BuildContext context, - WidgetRef ref, - bool continueWithInjuredPlayers, + ScoreBoardViewState state, ) { - ref.listen( - scoreBoardStateProvider.select((value) => value.showSelectBatsManSheet), - (previous, next) { - if (next != null) { - _showSelectPlayerSheet( - context, - continueWithInjuredPlayers, - PlayerSelectionType.batsMan, - ); - } - }); + return IconButton( + onPressed: () async { + showActionBottomSheet( + context: context, + items: MatchOption.values + .map( + (option) => BottomSheetAction( + title: option.getTitle(context), + onTap: () { + if (option != MatchOption.continueWithInjuredPlayer) { + context.pop(); + notifier.onMatchOptionSelect(option, true); + } + }, + child: option == MatchOption.continueWithInjuredPlayer + ? _toggleButton(context, state) + : null, + ), + ) + .toList()); + }, + icon: const Icon(Icons.more_horiz)); } - void _observeShowSelectBowlerSheet( + Widget _toggleButton( BuildContext context, - WidgetRef ref, - bool continueWithInjuredPlayers, + ScoreBoardViewState state, ) { - ref.listen( - scoreBoardStateProvider.select((value) => value.showSelectBowlerSheet), - (previous, next) { - if (next != null) { - _showSelectPlayerSheet( - context, - continueWithInjuredPlayers, - PlayerSelectionType.bowler, + bool isContinue = state.continueWithInjuredPlayers; + + return StatefulBuilder( + builder: (context, setStateSwitch) { + return Theme( + data: context.brightness == Brightness.dark + ? materialThemeDataDark + : materialThemeDataLight, + child: SizedBox( + height: 22, + child: Switch( + inactiveTrackColor: context.colorScheme.containerHigh, + trackOutlineColor: WidgetStateColor.transparent, + thumbColor: WidgetStatePropertyAll(context.colorScheme.onPrimary), + value: isContinue, + onChanged: (value) { + setStateSwitch(() { + isContinue = value; + notifier.onContinueWithInjuredPlayersChange(value); + }); + }, + ), + ), ); - } - }); + }, + ); } - void _observeShowSelectBowlerAndBatsManSheet( + Widget _body( BuildContext context, - WidgetRef ref, - bool continueWithInjuredPlayers, + ScoreBoardViewState state, ) { - ref.listen( - scoreBoardStateProvider - .select((value) => value.showSelectBowlerAndBatsManSheet), - (previous, next) { - if (next != null) { - _showSelectPlayerSheet( - context, - continueWithInjuredPlayers, - PlayerSelectionType.batsManAndBowler, - ); - } - }); + if (state.loading) { + return const Center(child: AppProgressIndicator()); + } + if (state.error != null) { + return ErrorScreen( + error: state.error, + onRetryTap: notifier.onResume, + ); + } + + return Column( + children: [ + ScoreDisplayView( + currentOverBall: notifier.getCurrentOverBall(), + overCountString: notifier.getOverCount(), + battingTeamName: notifier.getTeamName(), + bowlingTeamName: notifier.getTeamName(isBattingTeam: false), + ), + ScoreBoardButtons(onTap: notifier.onScoreButtonTap), + ], + ); } - void _observeShowSelectPlayerSheet( + Future _showSelectPlayerSheet( BuildContext context, - WidgetRef ref, bool continueWithInjuredPlayers, - ) { - ref.listen( - scoreBoardStateProvider.select((value) => value.showSelectPlayerSheet), - (previous, next) { - if (next != null) { - _showSelectPlayerSheet( - context, - continueWithInjuredPlayers, - PlayerSelectionType.all, - ); + PlayerSelectionType type, + ) async { + final result = await SelectPlayerSheet.show< + ({ + List<({List players, String teamId})>? selectedPlayer, + bool contWithInjPlayer, + })>( + context, + type: type, + continueWithInjPlayer: continueWithInjuredPlayers, + batsManList: notifier.getFilteredPlayerList(PlayerSelectionType.batsMan), + bowlerList: notifier.getFilteredPlayerList(PlayerSelectionType.bowler), + ); + if (result != null && context.mounted) { + if (result.selectedPlayer != null) { + notifier.setPlayers( + currentPlayers: result.selectedPlayer!, + contWithInjPlayer: result.contWithInjPlayer); + } else { + notifier.onReviewMatchResult(result.contWithInjPlayer); } - }); + } } - void _observeShowSelectWicketTypeSheet(BuildContext context, WidgetRef ref) { - ref.listen( - scoreBoardStateProvider.select( - (value) => value.showSelectWicketTypeSheet), (previous, next) { - if (next != null) { - _showSelectWicketTypeSheet(context); - } - }); + Future _showSelectWicketTypeSheet(BuildContext context) async { + final type = await SelectWicketTypeSheet.show(context); + if (type != null && context.mounted) { + _onWicketTypeSelect(context, type); + } } - void _observeShowStrikerSelectionSheet(BuildContext context, WidgetRef ref) { - ref.listen( - scoreBoardStateProvider.select( - (value) => value.showStrikerSelectionSheet), (previous, next) { - if (next != null) { - _showStrikerSelectionSheet(context); - } - }); - } + Future _onWicketTypeSelect( + BuildContext context, WicketType type) async { + final outBatsMan = await StrikerSelectionSheet.show( + context, + isForStrikerSelection: false, + ); - void _observeShowUndoBallConfirmationDialog( - BuildContext context, WidgetRef ref) { - ref.listen( - scoreBoardStateProvider.select( - (value) => value.showUndoBallConfirmationDialog), (previous, next) { - if (next != null) { - showConfirmationDialog(context, - title: context.l10n.score_board_undo_last_ball_title, - message: context.l10n.score_board_undo_last_ball_description_text, - confirmBtnText: context.l10n.score_board_undo_title, - onConfirm: notifier.undoLastBall); - } - }); - } + String? wicketTakerId; + if ((type == WicketType.caught || + type == WicketType.bowled || + type == WicketType.stumped || + type == WicketType.runOut || + type == WicketType.caughtBehind) && + context.mounted) { + wicketTakerId = await SelectWicketTakerSheet.show(context, + fielderList: notifier.getFielderList()); + } - void _observeShowOverCompleteSheet(BuildContext context, WidgetRef ref) { - ref.listen( - scoreBoardStateProvider.select((value) => value.showOverCompleteSheet), - (previous, next) { - if (next != null) { - _showOverCompleteSheet(context); - } - }); - } + int? extra; + if (type == WicketType.runOut && context.mounted) { + final runBeforeWicket = await AddExtraSheet.show<(int, bool, bool)>( + context, + isOnWicket: true); + extra = runBeforeWicket?.$1; + } - void _observeShowInningCompleteSheet( - BuildContext context, - WidgetRef ref, - ) { - ref.listen( - scoreBoardStateProvider.select( - (value) => value.showInningCompleteSheet), (previous, next) { - if (next != null) { - _showInningCompleteSheet(context); - } - }); + notifier.addBall( + run: 0, + extra: extra, + playerOutId: outBatsMan?.id, + wicketTakerId: wicketTakerId, + wicketType: type); } - void _observeShowMatchCompleteSheet( - BuildContext context, - WidgetRef ref, - ) { - ref.listen( - scoreBoardStateProvider.select((value) => value.showMatchCompleteSheet), - (previous, next) { - if (next != null) { - _showMatchCompleteSheet(context); - } - }); + Future _showStrikerSelectionSheet(BuildContext context) async { + final striker = await StrikerSelectionSheet.show(context); + if (striker != null && context.mounted) { + notifier.setOrSwitchStriker(batsManId: striker.id); + } } - void _observeShowBoundaryConfirmationDialogForSix( - BuildContext context, WidgetRef ref) { - ref.listen( - scoreBoardStateProvider - .select((value) => value.showBoundaryConfirmationDialogForSix), - (previous, next) { - if (next != null) { - _showBoundaryConfirmationDialog(context, 6); + Future _showOverCompleteSheet(BuildContext context) async { + final startNext = await OverCompleteSheet.show( + context, notifier.getCurrentOverStatics()); + if (startNext != null && context.mounted) { + if (startNext) { + notifier.startNextOver(); + } else { + notifier.undoLastBall(); } - }); + } } - void _observeShowBoundaryConfirmationDialogForFour( - BuildContext context, WidgetRef ref) { - ref.listen( - scoreBoardStateProvider - .select((value) => value.showBoundaryConfirmationDialogForFour), - (previous, next) { - if (next != null) { - _showBoundaryConfirmationDialog(context, 4); + Future _showInningCompleteSheet(BuildContext context) async { + final startNext = await InningCompleteSheet.show(context, + extra: notifier.getExtras(), + teamName: notifier.getTeamName() ?? + context.l10n.score_board_current_team_title, + overCountString: notifier.getOverCount()); + if (startNext != null && context.mounted) { + if (startNext) { + notifier.startNextInning(); + } else { + notifier.undoLastBall(); } - }); + } } - void _observeShowAddExtraSheetForNoBall(BuildContext context, WidgetRef ref) { - ref.listen( - scoreBoardStateProvider.select( - (value) => value.showAddExtraSheetForNoBall), (previous, next) { - if (next != null) { - _showAddExtraSheet(context, ExtrasType.noBall); + Future _showMatchCompleteSheet(BuildContext context) async { + final endMatch = await MatchCompleteSheet.show( + context, + firstTeamRunStat: notifier.getTeamRunDetails(true), + secondTeamRunStat: notifier.getTeamRunDetails(false), + ); + if (endMatch != null && context.mounted) { + if (endMatch) { + notifier.endMatch(); + } else { + notifier.undoLastBall(); } - }); + } } - void _observeShowAddExtraSheetForLegBye(BuildContext context, WidgetRef ref) { - ref.listen( - scoreBoardStateProvider.select( - (value) => value.showAddExtraSheetForLegBye), (previous, next) { - if (next != null) { - _showAddExtraSheet(context, ExtrasType.legBye); - } - }); + Future _showBoundaryConfirmationDialog( + BuildContext context, int run) async { + showConfirmationDialog( + context, + title: context.l10n.score_board_boundary_text, + message: context.l10n.score_board_is_boundary_text, + isDestructiveAction: true, + confirmBtnText: context.l10n.common_yes_title, + cancelBtnText: context.l10n.common_no_title, + onConfirm: () => + notifier.addBall(run: run, isSix: run == 6, isFour: run == 4), + onCancel: () => notifier.addBall(run: run), + ); } - void _observeShowAddExtraSheetForBye(BuildContext context, WidgetRef ref) { - ref.listen( - scoreBoardStateProvider.select( - (value) => value.showAddExtraSheetForBye), (previous, next) { - if (next != null) { - _showAddExtraSheet(context, ExtrasType.bye); - } - }); - } + Future _showAddExtraSheet( + BuildContext context, + ExtrasType? extra, + ) async { + final extraData = await AddExtraSheet.show<(int, bool, bool)>( + context, + extrasType: extra, + isFiveSeven: extra == null, + ); + if (context.mounted && extraData != null) { + int runs = extraData.$1; + bool isBoundary = extraData.$2; + bool notFromBat = extraData.$3; - void _observeShowAddExtraSheetForFiveSeven( - BuildContext context, WidgetRef ref) { - ref.listen( - scoreBoardStateProvider.select( - (value) => value.showAddExtraSheetForFiveSeven), (previous, next) { - if (next != null) { - _showAddExtraSheet(context, null); + if (extra == ExtrasType.noBall) { + notifier.addBall( + run: notFromBat ? 0 : runs, + extrasType: ExtrasType.noBall, + extra: notFromBat ? 1 + runs : 1, + isFour: isBoundary && runs == 4, + isSix: isBoundary && runs == 6, + ); + } else if (extra == ExtrasType.legBye || extra == ExtrasType.bye) { + notifier.addBall( + run: 0, + extrasType: extra, + extra: runs, + ); + } else { + notifier.addBall(run: runs); } - }); + } } - void _observePop(BuildContext context, WidgetRef ref) { - ref.listen(scoreBoardStateProvider.select((value) => value.pop), - (previous, next) { - if (next) { - context.pop(); - } - }); + Future _showAddPenaltyRunSheet(BuildContext context) async { + final penalty = + await AddPenaltyRunSheet.show<({String teamId, int runs})>(context); + + if (penalty != null && context.mounted) { + notifier.handlePenaltyRun(penalty); + } } - void _observeShowPauseScoringSheet(BuildContext context, WidgetRef ref) { - ref.listen( - scoreBoardStateProvider.select((value) => value.showPauseScoringSheet), + void _observeActionError(BuildContext context, WidgetRef ref) { + ref.listen(scoreBoardStateProvider.select((value) => value.actionError), (previous, next) { if (next != null) { - showConfirmationDialog(context, - title: context.l10n.score_board_pause_scoring_title, - message: context.l10n.score_board_pause_scoring_description_text, - confirmBtnText: context.l10n.score_board_pause_title, - onConfirm: notifier.onPauseScoring); + showErrorSnackBar(context: context, error: next); } }); } - void _observeShowAddPenaltyRunSheet(BuildContext context, WidgetRef ref) { + void _observeShowSelectBatsManSheet( + BuildContext context, + WidgetRef ref, + bool continueWithInjuredPlayers, + ) { ref.listen( - scoreBoardStateProvider.select((value) => value.showAddPenaltyRunSheet), + scoreBoardStateProvider.select((value) => value.showSelectBatsManSheet), (previous, next) { if (next != null) { - _showAddPenaltyRunSheet( + _showSelectPlayerSheet( context, + continueWithInjuredPlayers, + PlayerSelectionType.batsMan, ); } }); } - void _observeEndMatchSheet(BuildContext context, WidgetRef ref) { + void _observeShowSelectBowlerSheet( + BuildContext context, + WidgetRef ref, + bool continueWithInjuredPlayers, + ) { ref.listen( - scoreBoardStateProvider.select((value) => value.showEndMatchSheet), + scoreBoardStateProvider.select((value) => value.showSelectBowlerSheet), (previous, next) { if (next != null) { - showConfirmationDialog(context, - title: context.l10n.score_board_end_match_title, - message: context.l10n.score_board_end_match_description_text, - confirmBtnText: context.l10n.common_okay_title, - onConfirm: notifier.abandonMatch); + _showSelectPlayerSheet( + context, + continueWithInjuredPlayers, + PlayerSelectionType.bowler, + ); } }); } - void _observeInvalidUndoToast(BuildContext context, WidgetRef ref) { + void _observeShowSelectBowlerAndBatsManSheet( + BuildContext context, + WidgetRef ref, + bool continueWithInjuredPlayers, + ) { ref.listen( - scoreBoardStateProvider.select((value) => value.invalidUndoToast), + scoreBoardStateProvider + .select((value) => value.showSelectBowlerAndBatsManSheet), (previous, next) { if (next != null) { - showSnackBar( + _showSelectPlayerSheet( context, - context.l10n.score_board_can_undo_till_running_over_title, - length: SnackBarLength.long, + continueWithInjuredPlayers, + PlayerSelectionType.batsManAndBowler, ); } }); } - @override - void initState() { - super.initState(); - notifier = ref.read(scoreBoardStateProvider.notifier); - runPostFrame(() => notifier.setData(widget.matchId)); - } - - @override - Widget build(BuildContext context) { - final state = ref.watch(scoreBoardStateProvider); - - _observeActionError(context, ref); - _observeShowSelectBatsManSheet( - context, ref, state.continueWithInjuredPlayers); - _observeShowSelectBowlerSheet( - context, ref, state.continueWithInjuredPlayers); - _observeShowSelectBowlerAndBatsManSheet( - context, ref, state.continueWithInjuredPlayers); - _observeShowSelectPlayerSheet( - context, ref, state.continueWithInjuredPlayers); - _observeShowSelectWicketTypeSheet(context, ref); - _observeShowStrikerSelectionSheet(context, ref); - _observeShowUndoBallConfirmationDialog(context, ref); - _observeShowOverCompleteSheet(context, ref); - _observeShowInningCompleteSheet(context, ref); - _observeShowMatchCompleteSheet(context, ref); - _observeShowBoundaryConfirmationDialogForSix(context, ref); - _observeShowBoundaryConfirmationDialogForFour(context, ref); - _observeShowAddExtraSheetForNoBall(context, ref); - _observeShowAddExtraSheetForLegBye(context, ref); - _observeShowAddExtraSheetForBye(context, ref); - _observeShowAddExtraSheetForFiveSeven(context, ref); - _observePop(context, ref); - _observeShowPauseScoringSheet(context, ref); - _observeShowAddPenaltyRunSheet(context, ref); - _observeEndMatchSheet(context, ref); - _observeInvalidUndoToast(context, ref); - - return PopScope( - canPop: false, - child: AppPage( - title: context.l10n.score_board_screen_title, - actions: [_moreOptionButton(context, state)], - automaticallyImplyLeading: false, - resizeToAvoidBottomInset: false, - body: Builder(builder: (context) { - return _body(context, state); - }), - ), - ); - } - - Widget _moreOptionButton( - BuildContext context, - ScoreBoardViewState state, - ) { - return IconButton( - onPressed: () async { - showActionBottomSheet( - context: context, - items: MatchOption.values - .map( - (option) => BottomSheetAction( - title: option.getTitle(context), - onTap: () { - if (option != MatchOption.continueWithInjuredPlayer) { - context.pop(); - notifier.onMatchOptionSelect(option, true); - } - }, - child: option == MatchOption.continueWithInjuredPlayer - ? _toggleButton(context, state) - : null, - ), - ) - .toList()); - }, - icon: const Icon(Icons.more_horiz)); - } - - Widget _toggleButton( + void _observeShowSelectPlayerSheet( BuildContext context, - ScoreBoardViewState state, + WidgetRef ref, + bool continueWithInjuredPlayers, ) { - bool isContinue = state.continueWithInjuredPlayers; - - return StatefulBuilder( - builder: (context, setStateSwitch) { - return Theme( - data: context.brightness == Brightness.dark - ? materialThemeDataDark - : materialThemeDataLight, - child: SizedBox( - height: 22, - child: Switch( - inactiveTrackColor: context.colorScheme.containerHigh, - trackOutlineColor: WidgetStateColor.transparent, - thumbColor: WidgetStatePropertyAll(context.colorScheme.onPrimary), - value: isContinue, - onChanged: (value) { - setStateSwitch(() { - isContinue = value; - notifier.onContinueWithInjuredPlayersChange(value); - }); - }, - ), - ), + ref.listen( + scoreBoardStateProvider.select((value) => value.showSelectPlayerSheet), + (previous, next) { + if (next != null) { + _showSelectPlayerSheet( + context, + continueWithInjuredPlayers, + PlayerSelectionType.all, ); - }, - ); + } + }); } - Widget _body( - BuildContext context, - ScoreBoardViewState state, - ) { - if (state.loading) { - return const Center(child: AppProgressIndicator()); - } - if (state.error != null) { - return ErrorScreen( - error: state.error, - onRetryTap: notifier.onResume, - ); - } + void _observeShowSelectWicketTypeSheet(BuildContext context, WidgetRef ref) { + ref.listen( + scoreBoardStateProvider.select( + (value) => value.showSelectWicketTypeSheet), (previous, next) { + if (next != null) { + _showSelectWicketTypeSheet(context); + } + }); + } - return Column( - children: [ - ScoreDisplayView( - currentOverBall: notifier.getCurrentOverBall(), - overCountString: notifier.getOverCount(), - battingTeamName: notifier.getTeamName(), - bowlingTeamName: notifier.getTeamName(isBattingTeam: false), - ), - ScoreBoardButtons(onTap: notifier.onScoreButtonTap), - ], - ); + void _observeShowStrikerSelectionSheet(BuildContext context, WidgetRef ref) { + ref.listen( + scoreBoardStateProvider.select( + (value) => value.showStrikerSelectionSheet), (previous, next) { + if (next != null) { + _showStrikerSelectionSheet(context); + } + }); } - Future _showSelectPlayerSheet( - BuildContext context, - bool continueWithInjuredPlayers, - PlayerSelectionType type, - ) async { - final result = await SelectPlayerSheet.show< - ({ - List<({List players, String teamId})>? selectedPlayer, - bool contWithInjPlayer, - })>( - context, - type: type, - continueWithInjPlayer: continueWithInjuredPlayers, - batsManList: notifier.getFilteredPlayerList(PlayerSelectionType.batsMan), - bowlerList: notifier.getFilteredPlayerList(PlayerSelectionType.bowler), - ); - if (result != null && context.mounted) { - if (result.selectedPlayer != null) { - notifier.setPlayers( - currentPlayers: result.selectedPlayer!, - contWithInjPlayer: result.contWithInjPlayer); - } else { - notifier.onReviewMatchResult(result.contWithInjPlayer); + void _observeShowUndoBallConfirmationDialog( + BuildContext context, WidgetRef ref) { + ref.listen( + scoreBoardStateProvider.select( + (value) => value.showUndoBallConfirmationDialog), (previous, next) { + if (next != null) { + showConfirmationDialog(context, + title: context.l10n.score_board_undo_last_ball_title, + message: context.l10n.score_board_undo_last_ball_description_text, + confirmBtnText: context.l10n.score_board_undo_title, + onConfirm: notifier.undoLastBall); } - } + }); } - Future _showSelectWicketTypeSheet(BuildContext context) async { - final type = await SelectWicketTypeSheet.show(context); - if (type != null && context.mounted) { - _onWicketTypeSelect(context, type); - } + void _observeShowOverCompleteSheet(BuildContext context, WidgetRef ref) { + ref.listen( + scoreBoardStateProvider.select((value) => value.showOverCompleteSheet), + (previous, next) { + if (next != null) { + _showOverCompleteSheet(context); + } + }); } - Future _onWicketTypeSelect( - BuildContext context, WicketType type) async { - final outBatsMan = await StrikerSelectionSheet.show( - context, - isForStrikerSelection: false, - ); + void _observeShowInningCompleteSheet( + BuildContext context, + WidgetRef ref, + ) { + ref.listen( + scoreBoardStateProvider.select( + (value) => value.showInningCompleteSheet), (previous, next) { + if (next != null) { + _showInningCompleteSheet(context); + } + }); + } - String? wicketTakerId; - if ((type == WicketType.caught || - type == WicketType.bowled || - type == WicketType.stumped || - type == WicketType.runOut || - type == WicketType.caughtBehind) && - context.mounted) { - wicketTakerId = await SelectWicketTakerSheet.show(context, - fielderList: notifier.getFielderList()); - } + void _observeShowMatchCompleteSheet( + BuildContext context, + WidgetRef ref, + ) { + ref.listen( + scoreBoardStateProvider.select((value) => value.showMatchCompleteSheet), + (previous, next) { + if (next != null) { + _showMatchCompleteSheet(context); + } + }); + } - int? extra; - if (type == WicketType.runOut && context.mounted) { - final runBeforeWicket = await AddExtraSheet.show<(int, bool, bool)>( - context, - isOnWicket: true); - extra = runBeforeWicket?.$1; - } + void _observeShowBoundaryConfirmationDialogForSix( + BuildContext context, WidgetRef ref) { + ref.listen( + scoreBoardStateProvider + .select((value) => value.showBoundaryConfirmationDialogForSix), + (previous, next) { + if (next != null) { + _showBoundaryConfirmationDialog(context, 6); + } + }); + } - notifier.addBall( - run: 0, - extra: extra, - playerOutId: outBatsMan?.id, - wicketTakerId: wicketTakerId, - wicketType: type); + void _observeShowBoundaryConfirmationDialogForFour( + BuildContext context, WidgetRef ref) { + ref.listen( + scoreBoardStateProvider + .select((value) => value.showBoundaryConfirmationDialogForFour), + (previous, next) { + if (next != null) { + _showBoundaryConfirmationDialog(context, 4); + } + }); } - Future _showStrikerSelectionSheet(BuildContext context) async { - final striker = await StrikerSelectionSheet.show(context); - if (striker != null && context.mounted) { - notifier.setOrSwitchStriker(batsManId: striker.id); - } + void _observeShowAddExtraSheetForNoBall(BuildContext context, WidgetRef ref) { + ref.listen( + scoreBoardStateProvider.select( + (value) => value.showAddExtraSheetForNoBall), (previous, next) { + if (next != null) { + _showAddExtraSheet(context, ExtrasType.noBall); + } + }); } - Future _showOverCompleteSheet(BuildContext context) async { - final startNext = await OverCompleteSheet.show( - context, notifier.getCurrentOverStatics()); - if (startNext != null && context.mounted) { - if (startNext) { - notifier.startNextOver(); - } else { - notifier.undoLastBall(); + void _observeShowAddExtraSheetForLegBye(BuildContext context, WidgetRef ref) { + ref.listen( + scoreBoardStateProvider.select( + (value) => value.showAddExtraSheetForLegBye), (previous, next) { + if (next != null) { + _showAddExtraSheet(context, ExtrasType.legBye); } - } + }); } - Future _showInningCompleteSheet(BuildContext context) async { - final startNext = await InningCompleteSheet.show(context, - extra: notifier.getExtras(), - teamName: notifier.getTeamName() ?? - context.l10n.score_board_current_team_title, - overCountString: notifier.getOverCount()); - if (startNext != null && context.mounted) { - if (startNext) { - notifier.startNextInning(); - } else { - notifier.undoLastBall(); + void _observeShowAddExtraSheetForBye(BuildContext context, WidgetRef ref) { + ref.listen( + scoreBoardStateProvider.select( + (value) => value.showAddExtraSheetForBye), (previous, next) { + if (next != null) { + _showAddExtraSheet(context, ExtrasType.bye); } - } + }); } - Future _showMatchCompleteSheet(BuildContext context) async { - final endMatch = await MatchCompleteSheet.show( - context, - firstTeamRunStat: notifier.getTeamRunDetails(true), - secondTeamRunStat: notifier.getTeamRunDetails(false), - ); - if (endMatch != null && context.mounted) { - if (endMatch) { - notifier.endMatch(); - } else { - notifier.undoLastBall(); + void _observeShowAddExtraSheetForFiveSeven( + BuildContext context, WidgetRef ref) { + ref.listen( + scoreBoardStateProvider.select( + (value) => value.showAddExtraSheetForFiveSeven), (previous, next) { + if (next != null) { + _showAddExtraSheet(context, null); } - } + }); } - Future _showBoundaryConfirmationDialog( - BuildContext context, int run) async { - showConfirmationDialog( - context, - title: context.l10n.score_board_boundary_text, - message: context.l10n.score_board_is_boundary_text, - isDestructiveAction: true, - confirmBtnText: context.l10n.common_yes_title, - cancelBtnText: context.l10n.common_no_title, - onConfirm: () => - notifier.addBall(run: run, isSix: run == 6, isFour: run == 4), - onCancel: () => notifier.addBall(run: run), - ); + void _observePop(BuildContext context, WidgetRef ref) { + ref.listen(scoreBoardStateProvider.select((value) => value.pop), + (previous, next) { + if (next) { + context.pop(); + } + }); } - Future _showAddExtraSheet( - BuildContext context, - ExtrasType? extra, - ) async { - final extraData = await AddExtraSheet.show<(int, bool, bool)>( - context, - extrasType: extra, - isFiveSeven: extra == null, - ); - if (context.mounted && extraData != null) { - int runs = extraData.$1; - bool isBoundary = extraData.$2; - bool notFromBat = extraData.$3; + void _observeShowPauseScoringSheet(BuildContext context, WidgetRef ref) { + ref.listen( + scoreBoardStateProvider.select((value) => value.showPauseScoringSheet), + (previous, next) { + if (next != null) { + showConfirmationDialog(context, + title: context.l10n.score_board_pause_scoring_title, + message: context.l10n.score_board_pause_scoring_description_text, + confirmBtnText: context.l10n.score_board_pause_title, + onConfirm: notifier.onPauseScoring); + } + }); + } - if (extra == ExtrasType.noBall) { - notifier.addBall( - run: notFromBat ? 0 : runs, - extrasType: ExtrasType.noBall, - extra: notFromBat ? 1 + runs : 1, - isFour: isBoundary && runs == 4, - isSix: isBoundary && runs == 6, - ); - } else if (extra == ExtrasType.legBye || extra == ExtrasType.bye) { - notifier.addBall( - run: 0, - extrasType: extra, - extra: runs, + void _observeShowAddPenaltyRunSheet(BuildContext context, WidgetRef ref) { + ref.listen( + scoreBoardStateProvider.select((value) => value.showAddPenaltyRunSheet), + (previous, next) { + if (next != null) { + _showAddPenaltyRunSheet( + context, ); - } else { - notifier.addBall(run: runs); } - } + }); } - Future _showAddPenaltyRunSheet(BuildContext context) async { - final penalty = - await AddPenaltyRunSheet.show<({String teamId, int runs})>(context); + void _observeEndMatchSheet(BuildContext context, WidgetRef ref) { + ref.listen( + scoreBoardStateProvider.select((value) => value.showEndMatchSheet), + (previous, next) { + if (next != null) { + showConfirmationDialog(context, + title: context.l10n.score_board_end_match_title, + message: context.l10n.score_board_end_match_description_text, + confirmBtnText: context.l10n.common_okay_title, + onConfirm: notifier.abandonMatch); + } + }); + } - if (penalty != null && context.mounted) { - notifier.handlePenaltyRun(penalty); - } + void _observeInvalidUndoToast(BuildContext context, WidgetRef ref) { + ref.listen( + scoreBoardStateProvider.select((value) => value.invalidUndoToast), + (previous, next) { + if (next != null) { + showSnackBar( + context, + context.l10n.score_board_can_undo_till_running_over_title, + length: SnackBarLength.long, + ); + } + }); } } diff --git a/khelo/lib/ui/flow/settings/edit_profile/edit_profile_screen.dart b/khelo/lib/ui/flow/settings/edit_profile/edit_profile_screen.dart index ce891ce3..b50cfde8 100644 --- a/khelo/lib/ui/flow/settings/edit_profile/edit_profile_screen.dart +++ b/khelo/lib/ui/flow/settings/edit_profile/edit_profile_screen.dart @@ -33,28 +33,6 @@ class EditProfileScreen extends ConsumerWidget { final double profileViewHeight = 128; - void _observeActionError(BuildContext context, WidgetRef ref) { - ref.listen(editProfileStateProvider.select((value) => value.actionError), - (previous, next) { - if (next != null) { - showErrorSnackBar(context: context, error: next); - } - }); - } - - void _observeIsSaved(BuildContext context, WidgetRef ref) { - ref.listen(editProfileStateProvider.select((state) => state.isSaved), - (previous, next) { - if (next) { - if (isToCreateAccount) { - AppRoute.main.go(context); - } else { - context.pop(); - } - } - }); - } - @override Widget build(BuildContext context, WidgetRef ref) { final notifier = ref.watch(editProfileStateProvider.notifier); @@ -355,4 +333,26 @@ class EditProfileScreen extends ConsumerWidget { ), ); } + + void _observeActionError(BuildContext context, WidgetRef ref) { + ref.listen(editProfileStateProvider.select((value) => value.actionError), + (previous, next) { + if (next != null) { + showErrorSnackBar(context: context, error: next); + } + }); + } + + void _observeIsSaved(BuildContext context, WidgetRef ref) { + ref.listen(editProfileStateProvider.select((state) => state.isSaved), + (previous, next) { + if (next) { + if (isToCreateAccount) { + AppRoute.main.go(context); + } else { + context.pop(); + } + } + }); + } } diff --git a/khelo/lib/ui/flow/sign_in/phone_verification/phone_verification_screen.dart b/khelo/lib/ui/flow/sign_in/phone_verification/phone_verification_screen.dart index f0daf4a4..4ae1fccc 100644 --- a/khelo/lib/ui/flow/sign_in/phone_verification/phone_verification_screen.dart +++ b/khelo/lib/ui/flow/sign_in/phone_verification/phone_verification_screen.dart @@ -50,26 +50,6 @@ class _PhoneVerificationScreenState super.initState(); } - void _observeActionError(BuildContext context, WidgetRef ref) { - ref.listen( - phoneVerificationStateProvider.select((value) => value.actionError), - (previous, next) { - if (next != null) { - showErrorSnackBar(context: context, error: next); - } - }); - } - - void _observeVerificationComplete() { - ref.listen( - phoneVerificationStateProvider - .select((value) => value.isVerificationComplete), (previous, next) { - if (next) { - context.pop(next); - } - }); - } - @override Widget build(BuildContext context) { final state = ref.watch(phoneVerificationStateProvider); @@ -173,4 +153,24 @@ class _PhoneVerificationScreenState ], ); } + + void _observeActionError(BuildContext context, WidgetRef ref) { + ref.listen( + phoneVerificationStateProvider.select((value) => value.actionError), + (previous, next) { + if (next != null) { + showErrorSnackBar(context: context, error: next); + } + }); + } + + void _observeVerificationComplete() { + ref.listen( + phoneVerificationStateProvider + .select((value) => value.isVerificationComplete), (previous, next) { + if (next) { + context.pop(next); + } + }); + } } diff --git a/khelo/lib/ui/flow/sign_in/sign_in_with_phone/sign_in_with_phone_screen.dart b/khelo/lib/ui/flow/sign_in/sign_in_with_phone/sign_in_with_phone_screen.dart index f6846f21..829403f0 100644 --- a/khelo/lib/ui/flow/sign_in/sign_in_with_phone/sign_in_with_phone_screen.dart +++ b/khelo/lib/ui/flow/sign_in/sign_in_with_phone/sign_in_with_phone_screen.dart @@ -18,47 +18,6 @@ import 'components/sign_in_with_phone_country_picker.dart'; class SignInWithPhoneScreen extends ConsumerWidget { const SignInWithPhoneScreen({super.key}); - void _observeActionError(BuildContext context, WidgetRef ref) { - ref.listen( - signInWithPhoneStateProvider.select((value) => value.actionError), - (previous, next) { - if (next != null) { - showErrorSnackBar(context: context, error: next); - } - }); - } - - void _observeOtp({required BuildContext context, required WidgetRef ref}) { - ref.listen( - signInWithPhoneStateProvider.select((value) => value.verificationId), - (previous, current) async { - if (current != null) { - final state = ref.watch(signInWithPhoneStateProvider); - final bool? success = await AppRoute.verifyOTP( - countryCode: state.code.dialCode, - phoneNumber: state.phone, - verificationId: current, - ).push(context); - if (success != null && success && context.mounted) { - onSignInSuccess(context, ref); - } - } - }, - ); - } - - void _observeSignInSuccess({ - required BuildContext context, - required WidgetRef ref, - }) { - ref.listen( - signInWithPhoneStateProvider.select((value) => value.signInSuccess), - (previous, current) async { - if (current && context.mounted) onSignInSuccess(context, ref); - }, - ); - } - @override Widget build(BuildContext context, WidgetRef ref) { final notifier = ref.watch(signInWithPhoneStateProvider.notifier); @@ -156,4 +115,45 @@ class SignInWithPhoneScreen extends ConsumerWidget { AppRoute.main.go(context); } } + + void _observeActionError(BuildContext context, WidgetRef ref) { + ref.listen( + signInWithPhoneStateProvider.select((value) => value.actionError), + (previous, next) { + if (next != null) { + showErrorSnackBar(context: context, error: next); + } + }); + } + + void _observeOtp({required BuildContext context, required WidgetRef ref}) { + ref.listen( + signInWithPhoneStateProvider.select((value) => value.verificationId), + (previous, current) async { + if (current != null) { + final state = ref.watch(signInWithPhoneStateProvider); + final bool? success = await AppRoute.verifyOTP( + countryCode: state.code.dialCode, + phoneNumber: state.phone, + verificationId: current, + ).push(context); + if (success != null && success && context.mounted) { + onSignInSuccess(context, ref); + } + } + }, + ); + } + + void _observeSignInSuccess({ + required BuildContext context, + required WidgetRef ref, + }) { + ref.listen( + signInWithPhoneStateProvider.select((value) => value.signInSuccess), + (previous, current) async { + if (current && context.mounted) onSignInSuccess(context, ref); + }, + ); + } } diff --git a/khelo/lib/ui/flow/team/add_team/add_team_screen.dart b/khelo/lib/ui/flow/team/add_team/add_team_screen.dart index 91993939..6ae57e7a 100644 --- a/khelo/lib/ui/flow/team/add_team/add_team_screen.dart +++ b/khelo/lib/ui/flow/team/add_team/add_team_screen.dart @@ -45,37 +45,6 @@ class _AddTeamScreenState extends ConsumerState { runPostFrame(() => notifier.setData(editTeam: widget.editTeam)); } - void _observeActionError(BuildContext context, WidgetRef ref) { - ref.listen(addTeamStateProvider.select((value) => value.actionError), - (previous, next) { - if (next != null) { - showErrorSnackBar(context: context, error: next); - } - }); - } - - void _observeTeam(BuildContext context, WidgetRef ref) { - ref.listen( - addTeamStateProvider.select((value) => value.team), - (previous, current) async { - if (current != null) { - AppRoute.addTeamMember(team: current).pushReplacement(context); - } - }, - ); - } - - void _observePop(BuildContext context, WidgetRef ref) { - ref.listen( - addTeamStateProvider.select((value) => value.isPop), - (previous, current) async { - if (current && context.mounted) { - context.pop(); - } - }, - ); - } - @override Widget build(BuildContext context) { _observeActionError(context, ref); @@ -191,7 +160,8 @@ class _AddTeamScreenState extends ConsumerState { value: state.isAddMeCheckBoxEnable, contentPadding: EdgeInsets.zero, controlAffinity: ListTileControlAffinity.leading, - title: Text(context.l10n.add_team_add_as_member_description_text), + title: Text( + context.l10n.add_team_add_as_member_description_text), onChanged: (value) { if (value != null) { notifier.onAddMeCheckBoxTap(value); @@ -327,4 +297,35 @@ class _AddTeamScreenState extends ConsumerState { }, ); } + + void _observeActionError(BuildContext context, WidgetRef ref) { + ref.listen(addTeamStateProvider.select((value) => value.actionError), + (previous, next) { + if (next != null) { + showErrorSnackBar(context: context, error: next); + } + }); + } + + void _observeTeam(BuildContext context, WidgetRef ref) { + ref.listen( + addTeamStateProvider.select((value) => value.team), + (previous, current) async { + if (current != null) { + AppRoute.addTeamMember(team: current).pushReplacement(context); + } + }, + ); + } + + void _observePop(BuildContext context, WidgetRef ref) { + ref.listen( + addTeamStateProvider.select((value) => value.isPop), + (previous, current) async { + if (current && context.mounted) { + context.pop(); + } + }, + ); + } } diff --git a/khelo/lib/ui/flow/team/team_list_screen.dart b/khelo/lib/ui/flow/team/team_list_screen.dart index 701ee6a4..ee2a1e30 100644 --- a/khelo/lib/ui/flow/team/team_list_screen.dart +++ b/khelo/lib/ui/flow/team/team_list_screen.dart @@ -55,19 +55,6 @@ class _TeamListScreenState extends ConsumerState } } - void _observeShowFilterOptionSheet( - BuildContext context, - WidgetRef ref, - ) { - ref.listen( - teamListViewStateProvider - .select((value) => value.showFilterOptionSheet), (previous, next) { - if (next != null) { - _filterActionSheet(context); - } - }); - } - @override Widget build(BuildContext context) { super.build(context); @@ -216,4 +203,17 @@ class _TeamListScreenState extends ConsumerState ) .toList()); } + + void _observeShowFilterOptionSheet( + BuildContext context, + WidgetRef ref, + ) { + ref.listen( + teamListViewStateProvider + .select((value) => value.showFilterOptionSheet), (previous, next) { + if (next != null) { + _filterActionSheet(context); + } + }); + } }