Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-mayank committed Jul 1, 2024
1 parent fdd05fa commit 024914a
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 129 deletions.
59 changes: 32 additions & 27 deletions khelo/lib/components/empty_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,40 @@ class EmptyScreen extends StatelessWidget {

@override
Widget build(BuildContext context) {
return Center(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
title,
style: AppTextStyle.header2
.copyWith(color: context.colorScheme.textPrimary),
),
const SizedBox(height: 8),
Text(
description,
style: AppTextStyle.subtitle1
.copyWith(color: context.colorScheme.textDisabled),
textAlign: TextAlign.center,
),
if (isShowButton) ...[
const SizedBox(height: 24),
PrimaryButton(
buttonTitle ?? '',
edgeInsets:
const EdgeInsets.symmetric(horizontal: 24, vertical: 8),
expanded: false,
onPressed: onTap,
return SingleChildScrollView(
child: ConstrainedBox(
constraints:
BoxConstraints(minHeight: context.mediaQuerySize.height / 1.4),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
title,
style: AppTextStyle.header2
.copyWith(color: context.colorScheme.textPrimary),
textAlign: TextAlign.center,
),
const SizedBox(height: 8),
Text(
description,
style: AppTextStyle.subtitle1
.copyWith(color: context.colorScheme.textDisabled),
textAlign: TextAlign.center,
),
if (isShowButton) ...[
const SizedBox(height: 24),
PrimaryButton(
buttonTitle ?? '',
edgeInsets:
const EdgeInsets.symmetric(horizontal: 24, vertical: 8),
expanded: false,
onPressed: onTap,
),
],
],
],
),
),
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ class SearchUserViewNotifier extends StateNotifier<SearchUserViewState> {

Future<void> search(String searchKey) async {
try {
state = state.copyWith(error: null);
if (searchKey.isEmpty) {
state = state.copyWith(searchedUsers: [], error: null);
return;
}
final users = await _userService.searchUser(searchKey);
state = state.copyWith(searchedUsers: users);
} catch (e) {
Expand All @@ -39,9 +42,7 @@ class SearchUserViewNotifier extends StateNotifier<SearchUserViewState> {
}

_debounce = Timer(const Duration(milliseconds: 500), () async {
if (state.searchController.text.isNotEmpty) {
search(state.searchController.text.trim());
}
search(state.searchController.text.trim());
});
}

Expand Down
185 changes: 95 additions & 90 deletions khelo/lib/ui/flow/team/add_team_member/add_team_member_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,11 @@ class _AddTeamMemberScreenState extends ConsumerState<AddTeamMemberScreen> {
),
),
],
body: Builder(builder: (context) {
return Padding(
padding: context.mediaQueryPadding +
const EdgeInsets.symmetric(vertical: 8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_searchField(context, state),
if (state.selectedUsers.isNotEmpty) ...[
_selectedPlayerList(context, state),
],
_content(context, state),
],
),
);
}),
body: Builder(builder: (context) => _body(context, state)),
);
}

Widget _content(
Widget _body(
BuildContext context,
AddTeamMemberState state,
) {
Expand All @@ -97,83 +82,103 @@ class _AddTeamMemberScreenState extends ConsumerState<AddTeamMemberScreen> {
onRetryTap: notifier.onSearchChanged,
);
}

return Padding(
padding:
context.mediaQueryPadding + const EdgeInsets.symmetric(vertical: 8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_searchField(context, state),
if (state.selectedUsers.isNotEmpty) ...[
_selectedPlayerList(context, state),
],
_searchedPlayerList(context, state),
],
),
);
}

Widget _searchedPlayerList(
BuildContext context,
AddTeamMemberState state,
) {
return Expanded(
child:
(state.searchedUsers.isEmpty && state.searchController.text.isEmpty)
? EmptyScreen(
title: (state.searchController.text.isNotEmpty)
? context.l10n.add_team_member_search_no_result_title
: context.l10n.add_team_member_empty_title,
description: (state.searchController.text.isNotEmpty)
? context.l10n.add_team_member_search_description_text
: context.l10n.add_team_member_empty_description_text,
isShowButton: false,
)
: ListView.separated(
itemCount: state.searchedUsers.length,
itemBuilder: (context, index) {
UserModel user = state.searchedUsers[index];
return Column(
children: [
if (index == 0) ...[
Divider(
height: 32,
color: context.colorScheme.outline,
)
],
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: UserDetailCell(
user: user,
onTap: () => UserDetailSheet.show(
context,
user,
actionButtonTitle:
widget.team.players?.contains(user) == true ||
state.selectedUsers.contains(user)
? null
: context.l10n.common_select_title,
onButtonTap: () async {
if (user.phone != null) {
final res = await VerifyTeamMemberSheet.show(
context,
phoneNumber: user.phone!);
if (res != null && res && context.mounted) {
notifier.selectUser(user);
}
}
},
),
trailing: SecondaryButton(
child: (state.searchedUsers.isEmpty)
? EmptyScreen(
title: (state.searchController.text.isNotEmpty)
? context.l10n.add_team_member_search_no_result_title
: context.l10n.add_team_member_empty_title,
description: (state.searchController.text.isNotEmpty)
? context.l10n.add_team_member_search_description_text
: context.l10n.add_team_member_empty_description_text,
isShowButton: false,
)
: ListView.separated(
itemCount: state.searchedUsers.length,
itemBuilder: (context, index) {
UserModel user = state.searchedUsers[index];
return Column(
children: [
if (index == 0) ...[
Divider(
height: 32,
color: context.colorScheme.outline,
)
],
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: UserDetailCell(
user: user,
onTap: () => UserDetailSheet.show(
context,
user,
actionButtonTitle:
widget.team.players?.contains(user) == true ||
state.selectedUsers.contains(user)
? context.l10n.add_team_member_added_text
: context.l10n.common_add_title.toUpperCase(),
enabled:
widget.team.players?.contains(user) != true &&
!state.selectedUsers.contains(user),
onPressed: () async {
if (user.phone != null) {
final res = await VerifyTeamMemberSheet.show(
context,
phoneNumber: user.phone!
.substring(user.phone!.length - 5));
if (res != null && res && context.mounted) {
notifier.selectUser(user);
}
}
},
),
),
? null
: context.l10n.common_select_title,
onButtonTap: () async {
if (user.phone != null) {
final res = await VerifyTeamMemberSheet.show(
context,
phoneNumber: user.phone!);
if (res != null && res && context.mounted) {
notifier.selectUser(user);
}
}
},
),
],
);
},
separatorBuilder: (context, index) => Divider(
height: 32,
color: context.colorScheme.outline,
),
),
trailing: SecondaryButton(
widget.team.players?.contains(user) == true ||
state.selectedUsers.contains(user)
? context.l10n.add_team_member_added_text
: context.l10n.common_add_title.toUpperCase(),
enabled:
widget.team.players?.contains(user) != true &&
!state.selectedUsers.contains(user),
onPressed: () async {
if (user.phone != null) {
final res = await VerifyTeamMemberSheet.show(
context,
phoneNumber: user.phone!
.substring(user.phone!.length - 5));
if (res != null && res && context.mounted) {
notifier.selectUser(user);
}
}
},
),
),
),
],
);
},
separatorBuilder: (context, index) => Divider(
height: 32,
color: context.colorScheme.outline,
),
),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class AddTeamMemberViewNotifier extends StateNotifier<AddTeamMemberState> {

Future<void> search(String searchKey) async {
try {
if (searchKey.isEmpty) {
state = state.copyWith(searchedUsers: []);
return;
}
final users = await _userService.searchUser(searchKey);
state = state.copyWith(searchedUsers: users, error: null);
} catch (e) {
Expand All @@ -41,9 +45,7 @@ class AddTeamMemberViewNotifier extends StateNotifier<AddTeamMemberState> {
}

_debounce = Timer(const Duration(milliseconds: 500), () async {
if (state.searchController.text.isNotEmpty) {
search(state.searchController.text.trim());
}
search(state.searchController.text.trim());
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,19 @@ class TeamDetailMatchContent extends ConsumerWidget {
);
} else {
return EmptyScreen(
title: context.l10n.team_detail_empty_matches_title,
description: context.l10n.team_detail_empty_matches_description_text,
buttonTitle: context.l10n.add_match_screen_title,
onTap: () => AppRoute.addMatch(defaultTeam: state.team).push(context),
);
title: context.l10n.team_detail_empty_matches_title,
description: context.l10n.team_detail_empty_matches_description_text,
buttonTitle: context.l10n.add_match_screen_title,
onTap: () async {
bool? isUpdated = await AppRoute.addMatch(
defaultTeam: (state.team?.players?.length ?? 0) >= 2
? state.team
: null)
.push<bool>(context);
if (isUpdated == true && context.mounted) {
ref.read(teamDetailStateProvider.notifier).loadTeamById();
}
});
}
}
}

0 comments on commit 024914a

Please sign in to comment.