Skip to content

Commit

Permalink
Fix tab placement (#56)
Browse files Browse the repository at this point in the history
* fix tab placement

* change secondary button

* change secondary button

* use dummy user for deactivated user

* change primary dark, container dark and action button color

* remove unused code and cancel stream on signout

* remove boundary confirmation

* add import

* remove unnecessary import
  • Loading branch information
cp-sidhdhi-p authored Jun 27, 2024
1 parent 421b9f8 commit ecd4c67
Show file tree
Hide file tree
Showing 34 changed files with 299 additions and 383 deletions.
12 changes: 11 additions & 1 deletion data/lib/service/user/user_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,23 @@ class UserService {
for (final tenIds in ids.chunked(10)) {
QuerySnapshot<Map<String, dynamic>> snapshot = await _firestore
.collection(FireStoreConst.usersCollection)
.where('id', whereIn: tenIds)
.where(FireStoreConst.id, whereIn: tenIds)
.get();

users.addAll(snapshot.docs.map((doc) {
final data = doc.data();
return UserModel.fromJson(data).copyWith(id: doc.id);
}).toList());

final deactivatedUserIds =
tenIds.where((id) => !users.map((user) => user.id).contains(id));
users.addAll(deactivatedUserIds.map(
(id) => UserModel(
id: id,
name: "Deactivated User",
created_at: DateTime(1950),
location: "--"),
));
}

return users;
Expand Down
1 change: 0 additions & 1 deletion khelo/assets/locales/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,6 @@
"score_board_runs_title": "Runs",
"score_board_not_from_bat_text": "Not from bat?",
"score_board_is_boundary_text": "Is that a boundary?",
"score_board_boundary_text": "Boundary",
"score_board_over_complete_title": "Over Complete",
"score_board_inning_complete_title": "Inning Complete",
"score_board_match_complete_title": "Match Complete",
Expand Down
14 changes: 13 additions & 1 deletion khelo/lib/ui/flow/home/home_view_model.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';
import 'package:data/api/match/match_model.dart';
import 'package:data/service/match/match_service.dart';
import 'package:data/storage/app_preferences.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
Expand All @@ -9,7 +10,12 @@ part 'home_view_model.freezed.dart';

final homeViewStateProvider =
StateNotifierProvider.autoDispose<HomeViewNotifier, HomeViewState>(
(ref) => HomeViewNotifier(ref.read(matchServiceProvider)),
(ref) {
final notifier = HomeViewNotifier(ref.read(matchServiceProvider));
ref.listen(
hasUserSession, (_, next) => notifier._onUserSessionUpdate(next));
return notifier;
},
);

class HomeViewNotifier extends StateNotifier<HomeViewState> {
Expand All @@ -20,6 +26,12 @@ class HomeViewNotifier extends StateNotifier<HomeViewState> {
_loadMatches();
}

void _onUserSessionUpdate(bool hasSession) {
if (!hasSession) {
_streamSubscription.cancel();
}
}

void _loadMatches() async {
state = state.copyWith(loading: state.matches.isEmpty);

Expand Down
17 changes: 2 additions & 15 deletions khelo/lib/ui/flow/main/main_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class MainScreen extends ConsumerStatefulWidget {
}

class _MainScreenState extends ConsumerState<MainScreen>
with AutomaticKeepAliveClientMixin, WidgetsBindingObserver {
with WidgetsBindingObserver {
static final List<Widget> _widgets = <Widget>[
const HomeScreen(),
const MyGameTabScreen(),
Expand All @@ -31,10 +31,6 @@ class _MainScreenState extends ConsumerState<MainScreen>

final _materialPageController = PageController();
final _cupertinoTabController = CupertinoTabController();
bool _wantKeepAlive = true;

@override
bool get wantKeepAlive => _wantKeepAlive;

@override
void initState() {
Expand All @@ -44,15 +40,7 @@ class _MainScreenState extends ConsumerState<MainScreen>

@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.paused) {
setState(() {
_wantKeepAlive = false;
});
} else if (state == AppLifecycleState.resumed) {
setState(() {
_wantKeepAlive = true;
});
} else if (state == AppLifecycleState.detached) {
if (state == AppLifecycleState.detached) {
// deallocate resources
_materialPageController.dispose();
_cupertinoTabController.dispose();
Expand All @@ -62,7 +50,6 @@ class _MainScreenState extends ConsumerState<MainScreen>

@override
Widget build(BuildContext context) {
super.build(context);
if (Platform.isIOS) {
return _cupertinoTabs(context);
}
Expand Down
8 changes: 4 additions & 4 deletions khelo/lib/ui/flow/matches/add_match/add_match_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ class _AddMatchScreenState extends ConsumerState<AddMatchScreen> {
? context.l10n.add_match_screen_edit_match_title
: context.l10n.add_match_screen_title,
actions: [
if (widget.matchId != null)
_deleteMatchButton(context, onDelete: notifier.deleteMatch),
_scheduleMatchButton(
context,
saveBtnError: state.saveBtnError,
onSchedule: () => notifier.addMatch(),
),
if (widget.matchId != null)
_deleteMatchButton(context, onDelete: notifier.deleteMatch),
],
body: Builder(builder: (context) {
return Stack(
Expand Down Expand Up @@ -104,7 +104,7 @@ class _AddMatchScreenState extends ConsumerState<AddMatchScreen> {
height: 24,
colorFilter: ColorFilter.mode(
saveBtnError == null
? context.colorScheme.primary
? context.colorScheme.textPrimary
: context.colorScheme.textDisabled,
BlendMode.srcIn),
),
Expand All @@ -126,7 +126,7 @@ class _AddMatchScreenState extends ConsumerState<AddMatchScreen> {
width: 24,
fit: BoxFit.contain,
colorFilter:
ColorFilter.mode(context.colorScheme.primary, BlendMode.srcATop),
ColorFilter.mode(context.colorScheme.alert, BlendMode.srcATop),
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:khelo/domain/extensions/context_extensions.dart';
import 'package:khelo/domain/extensions/widget_extension.dart';
import 'package:khelo/ui/flow/matches/add_match/match_officials/components/officials_cell_view.dart';
import 'package:khelo/ui/flow/matches/add_match/match_officials/search_user/search_user_screen.dart';
import 'package:style/button/back_button.dart';
import 'package:style/button/bottom_sticky_overlay.dart';
import 'package:style/button/primary_button.dart';
import 'package:style/extensions/context_extensions.dart';
Expand Down Expand Up @@ -43,6 +44,7 @@ class _AddMatchOfficialsScreenState

return AppPage(
title: context.l10n.add_match_officials_screen_title,
leading: backButton(context, onPressed: context.pop),
body: Builder(builder: (context) {
return Stack(
children: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:khelo/domain/extensions/context_extensions.dart';
import 'package:khelo/ui/flow/matches/add_match/match_officials/search_user/search_user_view_model.dart';
import 'package:khelo/ui/flow/matches/add_match/select_squad/components/user_detail_sheet.dart';
import 'package:khelo/ui/flow/team/add_team_member/components/verify_team_member_sheet.dart';
import 'package:style/animations/on_tap_scale.dart';
import 'package:style/button/secondary_button.dart';
import 'package:style/extensions/context_extensions.dart';
import 'package:style/text/app_text_style.dart';
import 'package:style/text/search_text_field.dart';
Expand Down Expand Up @@ -126,8 +126,9 @@ class SearchUserBottomSheet extends ConsumerWidget {
}

Widget _addButton(BuildContext context, UserModel user) {
return OnTapScale(
onTap: () async {
return SecondaryButton(
context.l10n.common_add_title,
onPressed: () async {
if (user.phone != null) {
final res = await VerifyTeamMemberSheet.show(context,
phoneNumber: user.phone!);
Expand All @@ -136,17 +137,6 @@ class SearchUserBottomSheet extends ConsumerWidget {
}
}
},
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
decoration: BoxDecoration(
color: context.colorScheme.containerLow,
borderRadius: BorderRadius.circular(30)),
child: Text(
context.l10n.common_add_title,
style: AppTextStyle.body2
.copyWith(color: context.colorScheme.textDisabled),
),
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:khelo/domain/extensions/context_extensions.dart';
import 'package:khelo/domain/extensions/widget_extension.dart';
import 'package:khelo/ui/flow/matches/add_match/power_play/power_play_view_model.dart';
import 'package:style/animations/on_tap_scale.dart';
import 'package:style/button/back_button.dart';
import 'package:style/button/bottom_sticky_overlay.dart';
import 'package:style/button/primary_button.dart';
import 'package:style/extensions/context_extensions.dart';
Expand Down Expand Up @@ -56,6 +57,7 @@ class _PowerPlayScreenState extends ConsumerState<PowerPlayScreen> {

return AppPage(
title: context.l10n.common_power_play_title,
leading: backButton(context, onPressed: context.pop),
body: Builder(builder: (context) {
return Stack(
children: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import 'package:khelo/gen/assets.gen.dart';
import 'package:khelo/ui/flow/matches/add_match/select_squad/components/select_admin_and_captain_dialog.dart';
import 'package:khelo/ui/flow/matches/add_match/select_squad/components/user_detail_sheet.dart';
import 'package:khelo/ui/flow/matches/add_match/select_squad/select_squad_view_model.dart';
import 'package:style/animations/on_tap_scale.dart';
import 'package:style/button/action_button.dart';
import 'package:style/extensions/context_extensions.dart';
import 'package:style/text/app_text_style.dart';
Expand Down Expand Up @@ -70,7 +69,7 @@ class _SelectSquadScreenState extends ConsumerState<SelectSquadScreen> {
Assets.images.icCheck,
colorFilter: ColorFilter.mode(
state.isDoneBtnEnable
? context.colorScheme.primary
? context.colorScheme.textPrimary
: context.colorScheme.textDisabled,
BlendMode.srcIn),
)),
Expand Down Expand Up @@ -224,17 +223,17 @@ class _SelectSquadScreenState extends ConsumerState<SelectSquadScreen> {
required MatchPlayer member,
required bool isRemove,
}) {
return OnTapScale(
onTap: () => isRemove
? notifier.removeFromSquad(member.player)
: notifier.addToSquad(member),
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Icon(
isRemove ? Icons.close : Icons.add,
size: 16,
color: context.colorScheme.textDisabled,
),
));
return actionButton(
context,
onPressed: () => isRemove
? notifier.removeFromSquad(member.player)
: notifier.addToSquad(member),
padding: const EdgeInsets.only(left: 10, top: 10, bottom: 10),
icon: Icon(
isRemove ? Icons.close : Icons.add,
size: 16,
color: context.colorScheme.textDisabled,
),
);
}
}
17 changes: 2 additions & 15 deletions khelo/lib/ui/flow/matches/match_list_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@ class MatchListScreen extends ConsumerStatefulWidget {
}

class _MatchListScreenState extends ConsumerState<MatchListScreen>
with AutomaticKeepAliveClientMixin, WidgetsBindingObserver {
with WidgetsBindingObserver {
late MatchListViewNotifier notifier;
bool _wantKeepAlive = true;

@override
bool get wantKeepAlive => _wantKeepAlive;

@override
void initState() {
Expand All @@ -34,15 +30,7 @@ class _MatchListScreenState extends ConsumerState<MatchListScreen>

@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.paused) {
setState(() {
_wantKeepAlive = false;
});
} else if (state == AppLifecycleState.resumed) {
setState(() {
_wantKeepAlive = true;
});
} else if (state == AppLifecycleState.detached) {
if (state == AppLifecycleState.detached) {
// deallocate resources
notifier.dispose();
WidgetsBinding.instance.removeObserver(this);
Expand All @@ -51,7 +39,6 @@ class _MatchListScreenState extends ConsumerState<MatchListScreen>

@override
Widget build(BuildContext context) {
super.build(context);
final state = ref.watch(matchListStateProvider);
notifier = ref.watch(matchListStateProvider.notifier);

Expand Down
3 changes: 3 additions & 0 deletions khelo/lib/ui/flow/matches/match_list_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class MatchListViewNotifier extends StateNotifier<MatchListViewState> {
}

void setUserId(String? userId) {
if (userId == null) {
_cancelStreamSubscription();
}
state = state.copyWith(currentUserId: userId);
}

Expand Down
23 changes: 5 additions & 18 deletions khelo/lib/ui/flow/my_game/my_game_tab_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MyGameTabScreen extends ConsumerStatefulWidget {
}

class _MyGameTabScreenState extends ConsumerState<MyGameTabScreen>
with AutomaticKeepAliveClientMixin, WidgetsBindingObserver {
with WidgetsBindingObserver {
final List<Widget> _tabs = [
const MatchListScreen(),
const TeamListScreen(),
Expand All @@ -31,10 +31,6 @@ class _MyGameTabScreenState extends ConsumerState<MyGameTabScreen>
int get _selectedTab => _controller.hasClients
? _controller.page?.round() ?? 0
: _controller.initialPage;
bool _wantKeepAlive = true;

@override
bool get wantKeepAlive => _wantKeepAlive;

@override
void initState() {
Expand All @@ -48,15 +44,7 @@ class _MyGameTabScreenState extends ConsumerState<MyGameTabScreen>

@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.paused) {
setState(() {
_wantKeepAlive = false;
});
} else if (state == AppLifecycleState.resumed) {
setState(() {
_wantKeepAlive = true;
});
} else if (state == AppLifecycleState.detached) {
if (state == AppLifecycleState.detached) {
// deallocate resources
_controller.dispose();
WidgetsBinding.instance.removeObserver(this);
Expand All @@ -65,8 +53,6 @@ class _MyGameTabScreenState extends ConsumerState<MyGameTabScreen>

@override
Widget build(BuildContext context) {
super.build(context);

final notifier = ref.watch(myGameTabViewStateProvider.notifier);

return AppPage(
Expand Down Expand Up @@ -126,13 +112,14 @@ class _MyGameTabScreenState extends ConsumerState<MyGameTabScreen>
.read(teamListViewStateProvider.notifier)
.onFilterButtonTap(),
icon: Icon(CupertinoIcons.slider_horizontal_3,
color: context.colorScheme.primary)),
color: context.colorScheme.textPrimary)),
],
actionButton(context,
onPressed: () => _selectedTab == 1
? AppRoute.addTeam().push(context)
: AppRoute.addMatch().push(context),
icon: Icon(Icons.add, color: context.colorScheme.primary)),
icon: Icon(Icons.add, color: context.colorScheme.textPrimary)),
const SizedBox(width: 8),
],
),
);
Expand Down
Loading

0 comments on commit ecd4c67

Please sign in to comment.