Skip to content

Commit

Permalink
select team by default (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-sidhdhi-p authored Jun 19, 2024
1 parent 9181787 commit c488899
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
4 changes: 3 additions & 1 deletion khelo/lib/ui/app_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,12 @@ class AppRoute {
),
);

static AppRoute addMatch({String? matchId}) => AppRoute(
static AppRoute addMatch({String? matchId, TeamModel? defaultTeam}) =>
AppRoute(
pathAddMatch,
builder: (_) => AddMatchScreen(
matchId: matchId,
defaultTeam: defaultTeam,
),
);

Expand Down
12 changes: 7 additions & 5 deletions khelo/lib/ui/flow/matches/add_match/add_match_screen.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:data/api/team/team_model.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
Expand Down Expand Up @@ -34,8 +35,9 @@ import 'package:style/widgets/adaptive_outlined_tile.dart';

class AddMatchScreen extends ConsumerStatefulWidget {
final String? matchId;
final TeamModel? defaultTeam;

const AddMatchScreen({super.key, this.matchId});
const AddMatchScreen({super.key, this.matchId, this.defaultTeam});

@override
ConsumerState createState() => _AddMatchScreenState();
Expand All @@ -48,7 +50,7 @@ class _AddMatchScreenState extends ConsumerState<AddMatchScreen> {
void initState() {
super.initState();
notifier = ref.read(addMatchViewStateProvider.notifier);
runPostFrame(() => notifier.setData(widget.matchId));
runPostFrame(() => notifier.setData(widget.matchId, widget.defaultTeam));
}

@override
Expand Down Expand Up @@ -163,14 +165,14 @@ class _AddMatchScreenState extends ConsumerState<AddMatchScreen> {
context: context,
controller: state.groundController,
hintText: context.l10n.add_match_ground_title,
onChange: () => notifier.onTextChange(),
onChange: notifier.onTextChange,
),
const SizedBox(height: 16),
_inputField(
context: context,
controller: state.cityController,
hintText: context.l10n.common_city_title,
onChange: () => notifier.onTextChange(),
onChange: notifier.onTextChange,
),
_matchScheduleView(context, notifier, state),
BallSelectionView(notifier: notifier, state: state),
Expand Down Expand Up @@ -409,7 +411,7 @@ class _AddMatchScreenState extends ConsumerState<AddMatchScreen> {
context.l10n.common_delete_title.toLowerCase())),
actions: [
TextButton(
onPressed: () => context.pop(),
onPressed: context.pop,
child: Text(
context.l10n.common_cancel_title,
style: TextStyle(color: context.colorScheme.textSecondary),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ class AddMatchViewNotifier extends StateNotifier<AddMatchViewState> {
currentUserId: userId,
));

void setData(String? matchId) {
void setData(String? matchId, TeamModel? defaultTeam) {
this.matchId = matchId;
if (matchId != null) {
getMatchById();
} else if (defaultTeam != null) {
onTeamSelect(defaultTeam, TeamType.a);
} else {
onTextChange();
}
Expand Down
16 changes: 13 additions & 3 deletions khelo/lib/ui/flow/team/detail/team_detail_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,14 @@ class _TeamDetailScreenState extends ConsumerState<TeamDetailScreen> {
children: [
_teamProfileView(context, state),
const SizedBox(height: 16),
_tabView(context),
_tabView(
context,
onAddButtonTap: () => AppRoute.addMatch(
defaultTeam: (state.team?.players?.length ?? 0) >= 2
? state.team
: null)
.push(context),
),
_content(context),
],
);
Expand Down Expand Up @@ -120,7 +127,10 @@ class _TeamDetailScreenState extends ConsumerState<TeamDetailScreen> {
);
}

Widget _tabView(BuildContext context) {
Widget _tabView(
BuildContext context, {
required Function() onAddButtonTap,
}) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Row(
Expand All @@ -145,7 +155,7 @@ class _TeamDetailScreenState extends ConsumerState<TeamDetailScreen> {
if (_selectedTab == 0) ...[
const Spacer(),
actionButton(context,
onPressed: () => AppRoute.addMatch().push(context),
onPressed: onAddButtonTap,
icon: Icon(
Icons.add,
color: context.colorScheme.textPrimary,
Expand Down

0 comments on commit c488899

Please sign in to comment.