Skip to content

Commit

Permalink
Mr changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-mayank committed May 31, 2024
1 parent 1d1133f commit 8e787a4
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,21 @@ import 'package:style/animations/on_tap_scale.dart';
import 'package:style/extensions/context_extensions.dart';
import 'package:style/text/app_text_style.dart';

class TeamMemberDialog extends StatelessWidget {
class TeamMemberSheet extends StatelessWidget {
static Future<T?> show<T>(
BuildContext context, {
required TeamModel team,
bool isForVerification = false,
}) {
return showDialog(
return showModalBottomSheet(
context: context,
isScrollControlled: true,
enableDrag: false,
showDragHandle: true,
useRootNavigator: true,
backgroundColor: context.colorScheme.surface,
builder: (context) {
return TeamMemberDialog(
return TeamMemberSheet(
team: team,
isForVerification: isForVerification,
);
Expand All @@ -29,34 +34,42 @@ class TeamMemberDialog extends StatelessWidget {
final TeamModel team;
final bool isForVerification;

const TeamMemberDialog({
const TeamMemberSheet({
super.key,
required this.team,
this.isForVerification = false,
});

@override
Widget build(BuildContext context) {
return AlertDialog(
backgroundColor: context.colorScheme.containerLowOnSurface,
title: Text(
team.name,
style: AppTextStyle.subtitle1
.copyWith(color: context.colorScheme.textPrimary),
),
content: SingleChildScrollView(
child: Wrap(
runSpacing: 16,
children: (team.players ?? [])
.map(
(member) => UserDetailCell(
user: member,
trailing: isForVerification
? _selectButton(context, member)
: null,
),
)
.toList()),
return Container(
padding: context.mediaQueryPadding +
const EdgeInsets.only(bottom: 24, left: 16, right: 16),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
team.name,
style: AppTextStyle.subtitle1
.copyWith(color: context.colorScheme.textPrimary),
),
const SizedBox(height: 16),
Wrap(
runSpacing: 16,
children: (team.players ?? [])
.map(
(member) => UserDetailCell(
user: member,
trailing: isForVerification
? _selectButton(context, member)
: null,
),
)
.toList()),
],
),
),
);
}
Expand Down
17 changes: 15 additions & 2 deletions khelo/lib/ui/flow/team/search_team/search_team_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:khelo/components/app_page.dart';
import 'package:khelo/components/error_screen.dart';
import 'package:khelo/components/error_snackbar.dart';
import 'package:khelo/components/image_avatar.dart';
import 'package:khelo/domain/extensions/context_extensions.dart';
import 'package:khelo/domain/extensions/widget_extension.dart';
Expand Down Expand Up @@ -43,6 +44,7 @@ class _SearchTeamScreenState extends ConsumerState<SearchTeamScreen> {
@override
Widget build(BuildContext context) {
final state = ref.watch(searchTeamViewStateProvider);
_observeActionError();

return AppPage(
title: context.l10n.search_team_screen_title,
Expand All @@ -55,7 +57,7 @@ class _SearchTeamScreenState extends ConsumerState<SearchTeamScreen> {
.contains(state.selectedTeam?.id)) {
context.pop(state.selectedTeam);
} else {
final res = await TeamMemberDialog.show<bool>(
final res = await TeamMemberSheet.show<bool>(
context,
team: state.selectedTeam!,
isForVerification: true,
Expand Down Expand Up @@ -169,7 +171,7 @@ class _SearchTeamScreenState extends ConsumerState<SearchTeamScreen> {
) {
return OnTapScale(
onTap: () => notifier.onTeamCellTap(team),
onLongTap: () => TeamMemberDialog.show<bool>(context, team: team),
onLongTap: () => TeamMemberSheet.show<bool>(context, team: team),
child: Material(
type: MaterialType.transparency,
child: ListTile(
Expand Down Expand Up @@ -218,4 +220,15 @@ class _SearchTeamScreenState extends ConsumerState<SearchTeamScreen> {
),
);
}

void _observeActionError() {
ref.listen(
searchTeamViewStateProvider.select((value) => value.actionError),
(previous, next) {
if (next != null) {
showErrorSnackBar(context: context, error: next);
}
},
);
}
}
10 changes: 9 additions & 1 deletion khelo/lib/ui/flow/team/search_team/search_team_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,14 @@ class SearchTeamViewNotifier extends StateNotifier<SearchTeamState> {
}

void onTeamCellTap(TeamModel team) {
state = state.copyWith(selectedTeam: team);
state = state.copyWith(actionError: null);
final playersCount = (team.players ?? []).length;
if (playersCount >= 2) {
state = state.copyWith(selectedTeam: team);
} else {
state =
state.copyWith(actionError: "The team must have at least 2 players.");
}
}

@override
Expand All @@ -104,6 +111,7 @@ class SearchTeamState with _$SearchTeamState {
const factory SearchTeamState({
required TextEditingController searchController,
Object? error,
String? actionError,
TeamModel? selectedTeam,
@Default([]) List<TeamModel> searchResults,
@Default([]) List<TeamModel> userTeams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ mixin _$SearchTeamState {
TextEditingController get searchController =>
throw _privateConstructorUsedError;
Object? get error => throw _privateConstructorUsedError;
String? get actionError => throw _privateConstructorUsedError;
TeamModel? get selectedTeam => throw _privateConstructorUsedError;
List<TeamModel> get searchResults => throw _privateConstructorUsedError;
List<TeamModel> get userTeams => throw _privateConstructorUsedError;
Expand All @@ -39,6 +40,7 @@ abstract class $SearchTeamStateCopyWith<$Res> {
$Res call(
{TextEditingController searchController,
Object? error,
String? actionError,
TeamModel? selectedTeam,
List<TeamModel> searchResults,
List<TeamModel> userTeams,
Expand All @@ -63,6 +65,7 @@ class _$SearchTeamStateCopyWithImpl<$Res, $Val extends SearchTeamState>
$Res call({
Object? searchController = null,
Object? error = freezed,
Object? actionError = freezed,
Object? selectedTeam = freezed,
Object? searchResults = null,
Object? userTeams = null,
Expand All @@ -75,6 +78,10 @@ class _$SearchTeamStateCopyWithImpl<$Res, $Val extends SearchTeamState>
: searchController // ignore: cast_nullable_to_non_nullable
as TextEditingController,
error: freezed == error ? _value.error : error,
actionError: freezed == actionError
? _value.actionError
: actionError // ignore: cast_nullable_to_non_nullable
as String?,
selectedTeam: freezed == selectedTeam
? _value.selectedTeam
: selectedTeam // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -122,6 +129,7 @@ abstract class _$$SearchTeamStateImplCopyWith<$Res>
$Res call(
{TextEditingController searchController,
Object? error,
String? actionError,
TeamModel? selectedTeam,
List<TeamModel> searchResults,
List<TeamModel> userTeams,
Expand All @@ -145,6 +153,7 @@ class __$$SearchTeamStateImplCopyWithImpl<$Res>
$Res call({
Object? searchController = null,
Object? error = freezed,
Object? actionError = freezed,
Object? selectedTeam = freezed,
Object? searchResults = null,
Object? userTeams = null,
Expand All @@ -157,6 +166,10 @@ class __$$SearchTeamStateImplCopyWithImpl<$Res>
: searchController // ignore: cast_nullable_to_non_nullable
as TextEditingController,
error: freezed == error ? _value.error : error,
actionError: freezed == actionError
? _value.actionError
: actionError // ignore: cast_nullable_to_non_nullable
as String?,
selectedTeam: freezed == selectedTeam
? _value.selectedTeam
: selectedTeam // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -187,6 +200,7 @@ class _$SearchTeamStateImpl implements _SearchTeamState {
const _$SearchTeamStateImpl(
{required this.searchController,
this.error,
this.actionError,
this.selectedTeam,
final List<TeamModel> searchResults = const [],
final List<TeamModel> userTeams = const [],
Expand All @@ -200,6 +214,8 @@ class _$SearchTeamStateImpl implements _SearchTeamState {
@override
final Object? error;
@override
final String? actionError;
@override
final TeamModel? selectedTeam;
final List<TeamModel> _searchResults;
@override
Expand Down Expand Up @@ -228,7 +244,7 @@ class _$SearchTeamStateImpl implements _SearchTeamState {

@override
String toString() {
return 'SearchTeamState(searchController: $searchController, error: $error, selectedTeam: $selectedTeam, searchResults: $searchResults, userTeams: $userTeams, loading: $loading, searchInProgress: $searchInProgress)';
return 'SearchTeamState(searchController: $searchController, error: $error, actionError: $actionError, selectedTeam: $selectedTeam, searchResults: $searchResults, userTeams: $userTeams, loading: $loading, searchInProgress: $searchInProgress)';
}

@override
Expand All @@ -239,6 +255,8 @@ class _$SearchTeamStateImpl implements _SearchTeamState {
(identical(other.searchController, searchController) ||
other.searchController == searchController) &&
const DeepCollectionEquality().equals(other.error, error) &&
(identical(other.actionError, actionError) ||
other.actionError == actionError) &&
(identical(other.selectedTeam, selectedTeam) ||
other.selectedTeam == selectedTeam) &&
const DeepCollectionEquality()
Expand All @@ -255,6 +273,7 @@ class _$SearchTeamStateImpl implements _SearchTeamState {
runtimeType,
searchController,
const DeepCollectionEquality().hash(error),
actionError,
selectedTeam,
const DeepCollectionEquality().hash(_searchResults),
const DeepCollectionEquality().hash(_userTeams),
Expand All @@ -273,6 +292,7 @@ abstract class _SearchTeamState implements SearchTeamState {
const factory _SearchTeamState(
{required final TextEditingController searchController,
final Object? error,
final String? actionError,
final TeamModel? selectedTeam,
final List<TeamModel> searchResults,
final List<TeamModel> userTeams,
Expand All @@ -284,6 +304,8 @@ abstract class _SearchTeamState implements SearchTeamState {
@override
Object? get error;
@override
String? get actionError;
@override
TeamModel? get selectedTeam;
@override
List<TeamModel> get searchResults;
Expand Down

0 comments on commit 8e787a4

Please sign in to comment.