Skip to content

Commit

Permalink
empty view in home screen running match
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-sidhdhi-p committed Apr 9, 2024
1 parent 4b371a0 commit a7d52a9
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 98 deletions.
2 changes: 2 additions & 0 deletions khelo/assets/locales/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
"edit_profile_save_title": "SAVE",

"home_screen_title": "Home",
"home_screen_no_matches_title": "No matches are running currently",
"home_screen_no_matches_description_text": "Running matches will be shown here, Stay tuned for some intense matches.",

"image_picker_choose_option_title": "Choose an option.",
"image_picker_crop_image_title": "Crop Image",
Expand Down
47 changes: 41 additions & 6 deletions khelo/lib/ui/flow/home/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@ class HomeScreen extends ConsumerWidget {
return const Center(child: AppProgressIndicator());
}

return ListView(
padding: context.mediaQueryPadding,
children: [
_matchCardSlider(context, state),
],
);
if (state.matches.isNotEmpty) {
return ListView(
padding: context.mediaQueryPadding,
children: [
_matchCardSlider(context, state),
],
);
} else {
return _emptyMatchView(context);
}
}

Widget _matchCardSlider(
Expand Down Expand Up @@ -172,4 +176,35 @@ class HomeScreen extends ConsumerWidget {
],
);
}

Widget _emptyMatchView(BuildContext context) {
return Container(
padding: const EdgeInsets.all(16),
margin: const EdgeInsets.all(16),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
border: Border.all(color: context.colorScheme.primary)),
child: IntrinsicHeight(
child: Column(
children: [
Text(
context.l10n.home_screen_no_matches_title,
textAlign: TextAlign.center,
style: AppTextStyle.header2
.copyWith(color: context.colorScheme.textPrimary),
),
const SizedBox(
height: 8,
),
Text(
context.l10n.home_screen_no_matches_description_text,
textAlign: TextAlign.center,
style: AppTextStyle.subtitle1
.copyWith(color: context.colorScheme.textSecondary),
),
],
),
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,24 @@ import 'package:style/extensions/context_extensions.dart';
import 'package:style/text/app_text_style.dart';

class InningCompleteDialog extends ConsumerWidget {
static Future<T?> show<T>(BuildContext context) {
static Future<T?> show<T>(
BuildContext context, {
required bool showUndoButton,
}) {
return showDialog(
barrierDismissible: false,
context: context,
builder: (context) {
return const InningCompleteDialog();
return InningCompleteDialog(
showUndoButton: showUndoButton,
);
},
);
}

const InningCompleteDialog({super.key});
final bool showUndoButton;

const InningCompleteDialog({super.key, required this.showUndoButton});

@override
Widget build(BuildContext context, WidgetRef ref) {
Expand All @@ -34,11 +41,13 @@ class InningCompleteDialog extends ConsumerWidget {
content: _inningContent(context, state),
actionsOverflowButtonSpacing: 8,
actions: [
PrimaryButton(
expanded: false,
context.l10n.score_board_undo_last_ball_title,
onPressed: () => context.pop(false),
),
if (showUndoButton) ...[
PrimaryButton(
context.l10n.score_board_undo_last_ball_title,
expanded: false,
onPressed: () => context.pop(false),
),
],
PrimaryButton(
context.l10n.score_board_start_next_inning_title,
expanded: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,24 @@ import 'package:style/extensions/context_extensions.dart';
import 'package:style/text/app_text_style.dart';

class MatchCompleteDialog extends ConsumerWidget {
static Future<T?> show<T>(BuildContext context) {
static Future<T?> show<T>(
BuildContext context, {
required bool showUndoButton,
}) {
return showDialog(
barrierDismissible: false,
context: context,
builder: (context) {
return const MatchCompleteDialog();
return MatchCompleteDialog(
showUndoButton: showUndoButton,
);
},
);
}

const MatchCompleteDialog({super.key});
final bool showUndoButton;

const MatchCompleteDialog({super.key, required this.showUndoButton});

@override
Widget build(BuildContext context, WidgetRef ref) {
Expand All @@ -36,11 +43,13 @@ class MatchCompleteDialog extends ConsumerWidget {
content: _matchContent(context, state),
actionsOverflowButtonSpacing: 8,
actions: [
PrimaryButton(
expanded: false,
context.l10n.score_board_undo_last_ball_title,
onPressed: () => context.pop(false),
),
if (showUndoButton) ...[
PrimaryButton(
context.l10n.score_board_undo_last_ball_title,
expanded: false,
onPressed: () => context.pop(false),
),
],
PrimaryButton(
context.l10n.score_board_end_match_title,
expanded: false,
Expand Down
88 changes: 48 additions & 40 deletions khelo/lib/ui/flow/score_board/components/select_player_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ class SelectPlayerSheet extends ConsumerStatefulWidget {
backgroundColor: context.colorScheme.surface,
builder: (context) {
return SelectPlayerSheet(
type: type,
playerSelectionType: type,
continueWithInjPlayer: continueWithInjPlayer,
);
},
);
}

final PlayerSelectionType type;
final PlayerSelectionType playerSelectionType;
final bool continueWithInjPlayer;

const SelectPlayerSheet({
super.key,
required this.type,
required this.playerSelectionType,
required this.continueWithInjPlayer,
});

Expand Down Expand Up @@ -78,12 +78,17 @@ class _SelectPlayerSheetState extends ConsumerState<SelectPlayerSheet> {
BuildContext context,
ScoreBoardViewState state,
) {
final batsManList =
getFilteredList(state, type: PlayerSelectionType.batsMan);
final bowlerList = getFilteredList(state, type: PlayerSelectionType.bowler);
final List<MatchPlayer> batsManList =
widget.playerSelectionType != PlayerSelectionType.bowler
? _getFilteredList(state, type: PlayerSelectionType.batsMan)
: [];
final List<MatchPlayer> bowlerList =
widget.playerSelectionType != PlayerSelectionType.batsMan
? _getFilteredList(state, type: PlayerSelectionType.bowler)
: [];

final showCheckBox =
batsManList.map((e) => e.status).contains(PlayerStatus.injured);
batsManList.any((element) => element.status == PlayerStatus.injured);

final injuredPlayerRemained =
batsManList.every((e) => e.status == PlayerStatus.injured);
Expand All @@ -93,11 +98,11 @@ class _SelectPlayerSheetState extends ConsumerState<SelectPlayerSheet> {
ListView(
children: [
// batsman
if (widget.type != PlayerSelectionType.bowler &&
if (widget.playerSelectionType != PlayerSelectionType.bowler &&
batsManList.isNotEmpty) ...[
_sectionTitle(
context,
(widget.type == PlayerSelectionType.all)
(widget.playerSelectionType == PlayerSelectionType.all)
? context.l10n.score_board_choose_opening_batsmen_title
: context.l10n.score_board_choose_batsman_title(
state.lastAssignedIndex + 1)),
Expand All @@ -110,7 +115,7 @@ class _SelectPlayerSheetState extends ConsumerState<SelectPlayerSheet> {
],

// bowler
if (widget.type != PlayerSelectionType.batsMan) ...[
if (widget.playerSelectionType != PlayerSelectionType.batsMan) ...[
_sectionTitle(
context,
context.l10n.score_board_choose_bowler_for_over_title(
Expand All @@ -129,7 +134,7 @@ class _SelectPlayerSheetState extends ConsumerState<SelectPlayerSheet> {
);
}

List<MatchPlayer> getFilteredList(
List<MatchPlayer> _getFilteredList(
ScoreBoardViewState state, {
required PlayerSelectionType type,
}) {
Expand All @@ -145,12 +150,14 @@ class _SelectPlayerSheetState extends ConsumerState<SelectPlayerSheet> {
.firstWhere((element) => element.team.id == teamId)
.squad;

return teamPlayers
?.where((element) => (type == PlayerSelectionType.batsMan)
? _isPlayerEligibleForBatsman(element.status)
: true)
.toList() ??
[];
if (type == PlayerSelectionType.bowler) {
return teamPlayers ?? [];
} else {
return teamPlayers
?.where((element) => _isPlayerEligibleForBatsman(element.status))
.toList() ??
[];
}
}

bool _isPlayerEligibleForBatsman(PlayerStatus? status) {
Expand Down Expand Up @@ -190,43 +197,45 @@ class _SelectPlayerSheetState extends ConsumerState<SelectPlayerSheet> {
childAspectRatio: 0.7),
itemCount: list.length,
itemBuilder: (context, index) {
final player = list[index];

return _userCellWithTag(
context: context,
state: state,
showOverCount: type == PlayerSelectionType.bowler,
user: list[index].player,
tag: list[index].status == PlayerStatus.injured &&
user: player.player,
tag: player.status == PlayerStatus.injured &&
type == PlayerSelectionType.batsMan
? context.l10n.score_board_injured_tag_title
: null,
isSelected: type == PlayerSelectionType.batsMan
? [batsMan1?.player.id, batsMan2?.player.id]
.contains(list[index].player.id)
: bowler?.player.id == list[index].player.id,
disableCell: list[index].status == PlayerStatus.injured &&
.contains(player.player.id)
: bowler?.player.id == player.player.id,
disableCell: player.status == PlayerStatus.injured &&
type == PlayerSelectionType.batsMan &&
!isEnabled,
onTap: () {
setState(() {
if (type == PlayerSelectionType.batsMan) {
if (widget.type == PlayerSelectionType.all) {
if (batsMan1?.player.id == list[index].player.id) {
if (widget.playerSelectionType == PlayerSelectionType.all) {
if (batsMan1?.player.id == player.player.id) {
batsMan1 = null;
} else if (batsMan2?.player.id == list[index].player.id) {
} else if (batsMan2?.player.id == player.player.id) {
batsMan2 = null;
} else if (batsMan1 == null) {
batsMan1 = list[index];
batsMan1 = player;
} else if (batsMan2 == null) {
batsMan2 = list[index];
batsMan2 = player;
} else {
return;
// extra else to suppress lint suggestion of using ??= for batsMan2 assignment
}
} else {
batsMan1 = list[index];
batsMan1 = player;
}
} else {
bowler = list[index];
bowler = player;
}
});
},
Expand All @@ -245,10 +254,8 @@ class _SelectPlayerSheetState extends ConsumerState<SelectPlayerSheet> {
required bool disableCell,
required Function() onTap,
}) {
int overCount = 0;
if (showOverCount) {
overCount = _getOverCount(state, user?.id ?? "INVALID ID");
}
final overCount =
showOverCount ? _getOverCount(state, user?.id ?? "INVALID ID") : 0;

return OnTapScale(
enabled: !disableCell,
Expand Down Expand Up @@ -368,7 +375,8 @@ class _SelectPlayerSheetState extends ConsumerState<SelectPlayerSheet> {
if (!isEnabled) {
if (batsMan1?.status == PlayerStatus.injured) {
batsMan1 = null;
} else if (batsMan2?.status == PlayerStatus.injured) {
}
if (batsMan2?.status == PlayerStatus.injured) {
batsMan2 = null;
}
}
Expand Down Expand Up @@ -407,12 +415,12 @@ class _SelectPlayerSheetState extends ConsumerState<SelectPlayerSheet> {
}

bool _isStickyButtonEnable(bool injuredPlayerRemained) {
return widget.type == PlayerSelectionType.all
return widget.playerSelectionType == PlayerSelectionType.all
? (batsMan1 != null && batsMan2 != null && bowler != null)
: widget.type == PlayerSelectionType.batsManAndBowler
: widget.playerSelectionType == PlayerSelectionType.batsManAndBowler
? (((injuredPlayerRemained && !isEnabled) || batsMan1 != null) &&
bowler != null)
: widget.type == PlayerSelectionType.batsMan
: widget.playerSelectionType == PlayerSelectionType.batsMan
? (injuredPlayerRemained && !isEnabled) || batsMan1 != null
: bowler != null;
}
Expand All @@ -432,7 +440,7 @@ class _SelectPlayerSheetState extends ConsumerState<SelectPlayerSheet> {
final List<({List<MatchPlayer> players, String teamId})> selectedPlayer =
[];

if (widget.type != PlayerSelectionType.batsMan) {
if (widget.playerSelectionType != PlayerSelectionType.batsMan) {
selectedPlayer.add(
(
teamId: state.otherInning?.team_id ?? "INVALID ID",
Expand All @@ -441,10 +449,10 @@ class _SelectPlayerSheetState extends ConsumerState<SelectPlayerSheet> {
);
}

if (widget.type != PlayerSelectionType.bowler) {
if (widget.playerSelectionType != PlayerSelectionType.bowler) {
List<MatchPlayer> players = [batsMan1!];

if (widget.type == PlayerSelectionType.all) {
if (widget.playerSelectionType == PlayerSelectionType.all) {
players.add(batsMan2!);
}

Expand Down
Loading

0 comments on commit a7d52a9

Please sign in to comment.