Skip to content

Commit

Permalink
team list empty view
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-sidhdhi-p committed May 10, 2024
1 parent 9455f00 commit 5e96637
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 36 deletions.
14 changes: 10 additions & 4 deletions data/lib/service/team/team_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,10 @@ class TeamService {

Future<void> deleteTeam(String teamId) async {
try {
await _firestore.collection(FireStoreConst.teamsCollection).doc(teamId).delete();
await _firestore
.collection(FireStoreConst.teamsCollection)
.doc(teamId)
.delete();
} catch (error, stack) {
throw AppError.fromError(error, stack);
}
Expand All @@ -170,7 +173,8 @@ class TeamService {
_firestore.collection(FireStoreConst.teamsCollection).doc(teamId);

await teamRef.set(
{FireStoreConst.players: FieldValue.arrayUnion(players)}, SetOptions(merge: true));
{FireStoreConst.players: FieldValue.arrayUnion(players)},
SetOptions(merge: true));
} catch (error, stack) {
throw AppError.fromError(error, stack);
}
Expand All @@ -182,7 +186,8 @@ class TeamService {
DocumentReference teamRef =
_firestore.collection(FireStoreConst.teamsCollection).doc(teamId);

await teamRef.update({FireStoreConst.players: FieldValue.arrayRemove(playerIds)});
await teamRef
.update({FireStoreConst.players: FieldValue.arrayRemove(playerIds)});
} catch (error, stack) {
throw AppError.fromError(error, stack);
}
Expand All @@ -192,7 +197,8 @@ class TeamService {
try {
QuerySnapshot teamSnap = await _firestore
.collection(FireStoreConst.teamsCollection)
.where(FireStoreConst.nameLowercase, isEqualTo: teamName.caseAndSpaceInsensitive)
.where(FireStoreConst.nameLowercase,
isEqualTo: teamName.caseAndSpaceInsensitive)
.get();

return teamSnap.docs.isEmpty;
Expand Down
1 change: 1 addition & 0 deletions khelo/assets/locales/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"team_list_all_teams_title": "All teams",
"team_list_created_by_me_title": "Created by me",
"team_list_me_as_member_title": "Me as member",
"team_list_empty_list_description": "Tap on '+' button to create your team.",
"match_list_start_match_text": "Start a Match?",
"match_list_start_title": "Start",
"match_list_no_match_yet_title": "No Matches Yet",
Expand Down
86 changes: 54 additions & 32 deletions khelo/lib/ui/flow/team/team_list_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ class _TeamListScreenState extends ConsumerState<TeamListScreen>
final state = ref.watch(teamListViewStateProvider);

_observeShowFilterOptionSheet(context, ref);
return _teamList(context, notifier, state);
return _body(context, notifier, state);
}

Widget _teamList(
Widget _body(
BuildContext context,
TeamListViewNotifier notifier,
TeamListViewState state,
Expand All @@ -89,41 +89,63 @@ class _TeamListScreenState extends ConsumerState<TeamListScreen>

return Stack(
children: [
ListView.separated(
itemCount: state.filteredTeams.length,
padding: context.mediaQueryPadding +
const EdgeInsets.only(left: 16, right: 16, top: 16, bottom: 60),
separatorBuilder: (context, index) => const SizedBox(height: 16),
itemBuilder: (context, index) {
final team = state.filteredTeams[index];
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (index == 0) ...[
Text(
state.selectedFilter.getString(context),
style: AppTextStyle.subtitle1.copyWith(
color: context.colorScheme.textPrimary, fontSize: 20),
),
const SizedBox(
height: 16,
)
],
_teamListCell(
context,
notifier,
team,
showMoreOptionButton: state.currentUserId == team.created_by,
),
],
);
},
),
_teamList(context, notifier, state),
_floatingAddButton(context, notifier),
],
);
}

Widget _teamList(
BuildContext context,
TeamListViewNotifier notifier,
TeamListViewState state,
) {
if (state.filteredTeams.isEmpty) {
return Padding(
padding: const EdgeInsets.all(16.0),
child: Center(
child: Text(
context.l10n.team_list_empty_list_description,
textAlign: TextAlign.center,
style: AppTextStyle.subtitle1
.copyWith(color: context.colorScheme.textPrimary),
),
),
);
}

return ListView.separated(
itemCount: state.filteredTeams.length,
padding: context.mediaQueryPadding +
const EdgeInsets.only(left: 16, right: 16, top: 16, bottom: 60),
separatorBuilder: (context, index) => const SizedBox(height: 16),
itemBuilder: (context, index) {
final team = state.filteredTeams[index];
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (index == 0) ...[
Text(
state.selectedFilter.getString(context),
style: AppTextStyle.subtitle1.copyWith(
color: context.colorScheme.textPrimary, fontSize: 20),
),
const SizedBox(
height: 16,
)
],
_teamListCell(
context,
notifier,
team,
showMoreOptionButton: state.currentUserId == team.created_by,
),
],
);
},
);
}

Widget _teamListCell(
BuildContext context,
TeamListViewNotifier notifier,
Expand Down

0 comments on commit 5e96637

Please sign in to comment.