Skip to content

Commit

Permalink
Merge pull request #35 from canopas/Mayank/make-common-tab-button
Browse files Browse the repository at this point in the history
Make common tab button
  • Loading branch information
cp-mayank authored Jun 6, 2024
2 parents 485c66b + d747fea commit afc7df9
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 89 deletions.
34 changes: 5 additions & 29 deletions khelo/lib/ui/flow/my_game/my_game_tab_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import 'package:khelo/ui/flow/matches/match_list_screen.dart';
import 'package:khelo/ui/flow/my_game/my_game_tab_view_model.dart';
import 'package:khelo/ui/flow/team/team_list_screen.dart';
import 'package:khelo/ui/flow/team/team_list_view_model.dart';
import 'package:style/animations/on_tap_scale.dart';
import 'package:style/button/action_button.dart';
import 'package:style/button/large_icon_button.dart';
import 'package:style/button/tab_button.dart';
import 'package:style/extensions/context_extensions.dart';
import 'package:style/text/app_text_style.dart';

class MyGameTabScreen extends ConsumerStatefulWidget {
const MyGameTabScreen({super.key});
Expand Down Expand Up @@ -109,17 +108,17 @@ class _MyGameTabScreenState extends ConsumerState<MyGameTabScreen>
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: Row(
children: [
_tabButton(
TabButton(
context.l10n.common_matches_title,
_selectedTab == 0,
selected: _selectedTab == 0,
onTap: () {
_controller.jumpToPage(0);
},
),
const SizedBox(width: 8),
_tabButton(
TabButton(
context.l10n.my_game_teams_tab_title,
_selectedTab == 1,
selected: _selectedTab == 1,
onTap: () {
_controller.jumpToPage(1);
},
Expand All @@ -141,29 +140,6 @@ class _MyGameTabScreenState extends ConsumerState<MyGameTabScreen>
);
}

Widget _tabButton(String title, bool selected, {VoidCallback? onTap}) {
return OnTapScale(
onTap: onTap,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
decoration: BoxDecoration(
color: selected
? context.colorScheme.primary
: context.colorScheme.containerLow,
borderRadius: BorderRadius.circular(56),
),
child: Text(
title,
style: AppTextStyle.body2.copyWith(
color: selected
? context.colorScheme.onPrimary
: context.colorScheme.textSecondary,
),
),
),
);
}

Widget _floatingAddButton(
BuildContext context,
) {
Expand Down
35 changes: 5 additions & 30 deletions khelo/lib/ui/flow/stats/my_stats_tab_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import 'package:khelo/domain/extensions/context_extensions.dart';
import 'package:khelo/ui/flow/stats/my_stats_tab_view_model.dart';
import 'package:khelo/ui/flow/stats/user_match/user_match_list_screen.dart';
import 'package:khelo/ui/flow/stats/user_stat/user_stat_screen.dart';
import 'package:style/animations/on_tap_scale.dart';
import 'package:style/extensions/context_extensions.dart';
import 'package:style/text/app_text_style.dart';
import 'package:style/button/tab_button.dart';

class MyStatsTabScreen extends ConsumerStatefulWidget {
const MyStatsTabScreen({super.key});
Expand Down Expand Up @@ -98,17 +96,17 @@ class _MyStatsTabScreenState extends ConsumerState<MyStatsTabScreen>
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: Row(
children: [
_tabButton(
TabButton(
context.l10n.common_matches_title,
_selectedTab == 0,
selected: _selectedTab == 0,
onTap: () {
_controller.jumpToPage(0);
},
),
const SizedBox(width: 8),
_tabButton(
TabButton(
context.l10n.tab_stats_title,
_selectedTab == 1,
selected: _selectedTab == 1,
onTap: () {
_controller.jumpToPage(1);
},
Expand All @@ -117,27 +115,4 @@ class _MyStatsTabScreenState extends ConsumerState<MyStatsTabScreen>
),
);
}

Widget _tabButton(String title, bool selected, {VoidCallback? onTap}) {
return OnTapScale(
onTap: onTap,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
decoration: BoxDecoration(
color: selected
? context.colorScheme.primary
: context.colorScheme.containerLow,
borderRadius: BorderRadius.circular(56),
),
child: Text(
title,
style: AppTextStyle.body2.copyWith(
color: selected
? context.colorScheme.onPrimary
: context.colorScheme.textSecondary,
),
),
),
);
}
}
37 changes: 7 additions & 30 deletions khelo/lib/ui/flow/team/detail/team_detail_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import 'package:khelo/domain/formatter/date_formatter.dart';
import 'package:khelo/ui/app_route.dart';
import 'package:khelo/ui/flow/team/detail/components/team_detail_member_content.dart';
import 'package:khelo/ui/flow/team/detail/team_detail_view_model.dart';
import 'package:style/animations/on_tap_scale.dart';
import 'package:style/button/action_button.dart';
import 'package:style/button/tab_button.dart';
import 'package:style/extensions/context_extensions.dart';
import 'package:style/indicator/progress_indicator.dart';
import 'package:style/text/app_text_style.dart';
Expand Down Expand Up @@ -129,25 +129,25 @@ class _TeamDetailScreenState extends ConsumerState<TeamDetailScreen> {
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Row(
children: [
_tabButton(
TabButton(
context.l10n.team_detail_match_tab_title,
_selectedTab == 0,
selected: _selectedTab == 0,
onTap: () {
_controller.jumpToPage(0);
},
),
const SizedBox(width: 8),
_tabButton(
TabButton(
context.l10n.team_detail_member_tab_title,
_selectedTab == 1,
selected: _selectedTab == 1,
onTap: () {
_controller.jumpToPage(1);
},
),
const SizedBox(width: 8),
_tabButton(
TabButton(
context.l10n.team_detail_stat_tab_title,
_selectedTab == 2,
selected: _selectedTab == 2,
onTap: () {
_controller.jumpToPage(2);
},
Expand All @@ -166,29 +166,6 @@ class _TeamDetailScreenState extends ConsumerState<TeamDetailScreen> {
);
}

Widget _tabButton(String title, bool selected, {VoidCallback? onTap}) {
return OnTapScale(
onTap: onTap,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
decoration: BoxDecoration(
color: selected
? context.colorScheme.primary
: context.colorScheme.containerLow,
borderRadius: BorderRadius.circular(56),
),
child: Text(
title,
style: AppTextStyle.body2.copyWith(
color: selected
? context.colorScheme.onPrimary
: context.colorScheme.textSecondary,
),
),
),
);
}

Widget _content(BuildContext context) {
return Expanded(
child: PageView(
Expand Down
41 changes: 41 additions & 0 deletions style/lib/button/tab_button.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import 'package:flutter/material.dart';
import 'package:style/animations/on_tap_scale.dart';
import 'package:style/extensions/context_extensions.dart';
import 'package:style/text/app_text_style.dart';

class TabButton extends StatelessWidget {
final Function() onTap;
final String text;
final bool selected;

const TabButton(
this.text, {
super.key,
required this.onTap,
this.selected = false,
});

@override
Widget build(BuildContext context) {
return OnTapScale(
onTap: onTap,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
decoration: BoxDecoration(
color: selected
? context.colorScheme.primary
: context.colorScheme.containerLow,
borderRadius: BorderRadius.circular(30),
),
child: Text(
text,
style: AppTextStyle.body2.copyWith(
color: selected
? context.colorScheme.onPrimary
: context.colorScheme.textSecondary,
),
),
),
);
}
}

0 comments on commit afc7df9

Please sign in to comment.