Skip to content

Commit

Permalink
feat(client): Tab groups (closes ##65)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustl22 committed Aug 20, 2024
1 parent 2d7f491 commit 869d2f6
Show file tree
Hide file tree
Showing 17 changed files with 159 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ class OrganizationsView extends StatelessWidget {
@override
Widget build(BuildContext context) {
final localizations = AppLocalizations.of(context)!;
return ResponsiveScrollView(
return ResponsiveContainer(
child: ManyConsumer<Organization, Null>(
builder: (BuildContext context, List<Organization> organizations) {
return ListGroup(
return GroupedList(
header: HeadingItem(
title: localizations.organizations,
trailing: IconButton(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import 'package:wrestling_scoreboard_client/localization/duration.dart';
import 'package:wrestling_scoreboard_client/provider/network_provider.dart';
import 'package:wrestling_scoreboard_client/view/screens/overview/common.dart';
import 'package:wrestling_scoreboard_client/view/widgets/consumer.dart';
import 'package:wrestling_scoreboard_client/view/widgets/font.dart';
import 'package:wrestling_scoreboard_client/view/widgets/grouped_list.dart';
import 'package:wrestling_scoreboard_client/view/widgets/info.dart';
import 'package:wrestling_scoreboard_client/view/widgets/tab_group.dart';
import 'package:wrestling_scoreboard_common/common.dart';

abstract class BoutOverview extends ConsumerWidget implements AbstractOverview<Bout> {
Expand Down Expand Up @@ -84,7 +86,10 @@ abstract class BoutOverview extends ConsumerWidget implements AbstractOverview<B
dataObject: data,
label: classLocale,
details: data.title(context),
body: GroupedList(items: [
tabs: [
Tab(child: HeadingText(localizations.info)),
],
body: TabGroup(items: [
description,
]),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import 'package:wrestling_scoreboard_client/view/screens/overview/common.dart';
import 'package:wrestling_scoreboard_client/view/screens/overview/membership_overview.dart';
import 'package:wrestling_scoreboard_client/view/screens/overview/team_overview.dart';
import 'package:wrestling_scoreboard_client/view/widgets/consumer.dart';
import 'package:wrestling_scoreboard_client/view/widgets/font.dart';
import 'package:wrestling_scoreboard_client/view/widgets/grouped_list.dart';
import 'package:wrestling_scoreboard_client/view/widgets/info.dart';
import 'package:wrestling_scoreboard_client/view/widgets/tab_group.dart';
import 'package:wrestling_scoreboard_common/common.dart';

class ClubOverview extends ConsumerWidget {
Expand Down Expand Up @@ -49,14 +51,19 @@ class ClubOverview extends ConsumerWidget {
dataObject: data,
label: localizations.club,
details: data.name,
body: GroupedList(items: [
tabs: [
Tab(child: HeadingText(localizations.info)),
Tab(child: HeadingText(localizations.teams)),
Tab(child: HeadingText(localizations.memberships)),
],
// TODO
body: TabGroup(items: [
description,
ManyConsumer<Team, Club>(
filterObject: data,
builder: (BuildContext context, List<Team> teams) {
return ListGroup(
return GroupedList(
header: HeadingItem(
title: localizations.teams,
trailing: IconButton(
icon: const Icon(Icons.add),
onPressed: () => Navigator.push(
Expand All @@ -82,9 +89,8 @@ class ClubOverview extends ConsumerWidget {
ManyConsumer<Membership, Club>(
filterObject: data,
builder: (BuildContext context, List<Membership> memberships) {
return ListGroup(
return GroupedList(
header: HeadingItem(
title: localizations.memberships,
trailing: IconButton(
icon: const Icon(Icons.add),
onPressed: () => Navigator.push(
Expand Down
52 changes: 29 additions & 23 deletions wrestling_scoreboard_client/lib/view/screens/overview/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,41 +47,47 @@ class OverviewScaffold<T extends DataObject> extends ConsumerWidget {
required this.details,
this.actions,
required this.dataObject,
required this.tabs,
});

final Widget body;
final String label;
final String details;
final List<Widget>? actions;
final T dataObject;
final List<Tab> tabs;

@override
Widget build(BuildContext context, WidgetRef ref) {
final localizations = AppLocalizations.of(context)!;
final tableName = getTableNameFromType(T);
return WindowStateScaffold(
appBarTitle: AppBarTitle(label: label, details: details),
actions: [
...?actions,
LoadingBuilder(
future: ref.watch(favoritesNotifierProvider),
builder: (BuildContext context, favorites) {
final isFavorite = favorites[tableName]?.contains(dataObject.id) ?? false;
return IconButton(
onPressed: () {
final notifier = ref.read(favoritesNotifierProvider.notifier);
if (isFavorite) {
notifier.removeFavorite(tableName, dataObject.id!);
} else {
notifier.addFavorite(tableName, dataObject.id!);
}
},
icon: isFavorite ? const Icon(Icons.star) : const Icon(Icons.star_outline),
tooltip: localizations.favorite,
);
}),
],
body: body,
return DefaultTabController(
length: tabs.length,
child: WindowStateScaffold(
appBarTitle: AppBarTitle(label: label, details: details),
appBarBottom: TabBar(tabs: tabs, tabAlignment: TabAlignment.center, isScrollable: true),
actions: [
...?actions,
LoadingBuilder(
future: ref.watch(favoritesNotifierProvider),
builder: (BuildContext context, favorites) {
final isFavorite = favorites[tableName]?.contains(dataObject.id) ?? false;
return IconButton(
onPressed: () {
final notifier = ref.read(favoritesNotifierProvider.notifier);
if (isFavorite) {
notifier.removeFavorite(tableName, dataObject.id!);
} else {
notifier.addFavorite(tableName, dataObject.id!);
}
},
icon: isFavorite ? const Icon(Icons.star) : const Icon(Icons.star_outline),
tooltip: localizations.favorite,
);
}),
],
body: body,
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import 'package:wrestling_scoreboard_client/view/screens/overview/common.dart';
import 'package:wrestling_scoreboard_client/view/screens/overview/shared/actions.dart';
import 'package:wrestling_scoreboard_client/view/screens/overview/team_match/division_overview.dart';
import 'package:wrestling_scoreboard_client/view/widgets/consumer.dart';
import 'package:wrestling_scoreboard_client/view/widgets/font.dart';
import 'package:wrestling_scoreboard_client/view/widgets/grouped_list.dart';
import 'package:wrestling_scoreboard_client/view/widgets/info.dart';
import 'package:wrestling_scoreboard_client/view/widgets/tab_group.dart';
import 'package:wrestling_scoreboard_common/common.dart';

class OrganizationOverview extends ConsumerWidget {
Expand Down Expand Up @@ -65,14 +67,20 @@ class OrganizationOverview extends ConsumerWidget {
label: localizations.organization,
details: data.name,
actions: [OrganizationImportAction(id: id, orgId: id, importType: OrganizationImportType.organization)],
body: GroupedList(items: [
tabs: [
Tab(child: HeadingText(localizations.info)),
Tab(child: HeadingText(localizations.organizations)),
Tab(child: HeadingText(localizations.divisions)),
Tab(child: HeadingText(localizations.clubs)),
Tab(child: HeadingText(localizations.competitions))
],
body: TabGroup(items: [
description,
ManyConsumer<Organization, Organization>(
filterObject: data,
builder: (BuildContext context, List<Organization> childOrganizations) {
return ListGroup(
return GroupedList(
header: HeadingItem(
title: localizations.organizations,
trailing: IconButton(
icon: const Icon(Icons.add),
onPressed: () => Navigator.push(
Expand Down Expand Up @@ -103,9 +111,8 @@ class OrganizationOverview extends ConsumerWidget {
ManyConsumer<Division, Organization>(
filterObject: data,
builder: (BuildContext context, List<Division> organizations) {
return ListGroup(
return GroupedList(
header: HeadingItem(
title: localizations.divisions,
trailing: IconButton(
icon: const Icon(Icons.add),
onPressed: () => Navigator.push(
Expand Down Expand Up @@ -136,9 +143,8 @@ class OrganizationOverview extends ConsumerWidget {
ManyConsumer<Club, Organization>(
filterObject: data,
builder: (BuildContext context, List<Club> clubs) {
return ListGroup(
return GroupedList(
header: HeadingItem(
title: localizations.clubs,
trailing: IconButton(
icon: const Icon(Icons.add),
onPressed: () => Navigator.push(
Expand Down Expand Up @@ -169,9 +175,8 @@ class OrganizationOverview extends ConsumerWidget {
ManyConsumer<Competition, Organization>(
filterObject: data,
builder: (BuildContext context, List<Competition> competitions) {
return ListGroup(
return GroupedList(
header: HeadingItem(
title: localizations.competitions,
trailing: IconButton(
icon: const Icon(Icons.add),
onPressed: () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import 'package:wrestling_scoreboard_client/view/screens/edit/person_edit.dart';
import 'package:wrestling_scoreboard_client/view/screens/overview/common.dart';
import 'package:wrestling_scoreboard_client/view/screens/overview/membership_overview.dart';
import 'package:wrestling_scoreboard_client/view/widgets/consumer.dart';
import 'package:wrestling_scoreboard_client/view/widgets/font.dart';
import 'package:wrestling_scoreboard_client/view/widgets/grouped_list.dart';
import 'package:wrestling_scoreboard_client/view/widgets/info.dart';
import 'package:wrestling_scoreboard_client/view/widgets/tab_group.dart';
import 'package:wrestling_scoreboard_common/common.dart';

abstract class AbstractPersonOverview extends ConsumerWidget implements AbstractOverview<Person> {
Expand All @@ -25,7 +27,7 @@ abstract class AbstractPersonOverview extends ConsumerWidget implements Abstract
required Widget editPage,
required VoidCallback onDelete,
List<Widget>? tiles,
List<Widget> Function(Person data)? buildRelations,
Map<Tab, Widget> Function(Person data)? buildRelations,
required int dataId,
Person? initialData,
}) {
Expand Down Expand Up @@ -73,13 +75,18 @@ abstract class AbstractPersonOverview extends ConsumerWidget implements Abstract
),
],
);
final relations = buildRelations != null ? buildRelations(person) : {};
return OverviewScaffold<Person>(
dataObject: person,
label: classLocale,
details: person.fullName,
body: GroupedList(items: [
tabs: [
Tab(child: HeadingText(localizations.info)),
...relations.keys,
],
body: TabGroup(items: [
description,
if (buildRelations != null) ...buildRelations(person),
...relations.values,
]),
);
},
Expand Down Expand Up @@ -110,13 +117,12 @@ class PersonOverview extends AbstractPersonOverview {
initialOrganization: person?.organization ?? initialOrganization,
),
onDelete: () async {},
buildRelations: (Person person) => [
ManyConsumer<Membership, Person>(
buildRelations: (Person person) => {
Tab(child: HeadingText(localizations.memberships)): ManyConsumer<Membership, Person>(
filterObject: person,
builder: (BuildContext context, List<Membership> memberships) {
return ListGroup(
return GroupedList(
header: HeadingItem(
title: localizations.memberships,
trailing: IconButton(
icon: const Icon(Icons.add),
onPressed: () => Navigator.push(
Expand All @@ -143,7 +149,7 @@ class PersonOverview extends AbstractPersonOverview {
);
},
),
],
},
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:go_router/go_router.dart';
import 'package:wrestling_scoreboard_client/localization/date_time.dart';
import 'package:wrestling_scoreboard_client/view/screens/display/match/match_display.dart';
Expand All @@ -16,13 +15,11 @@ class MatchesWidget<T extends DataObject?> extends StatelessWidget {

@override
Widget build(BuildContext context) {
final localizations = AppLocalizations.of(context)!;
return ManyConsumer<TeamMatch, T>(
filterObject: filterObject,
builder: (BuildContext context, List<TeamMatch> matches) {
return ListGroup(
return GroupedList(
header: HeadingItem(
title: localizations.matches,
trailing: IconButton(
icon: const Icon(Icons.add),
onPressed: () => Navigator.push(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import 'package:wrestling_scoreboard_client/view/screens/overview/common.dart';
import 'package:wrestling_scoreboard_client/view/screens/overview/team_match/division_weight_class_overview.dart';
import 'package:wrestling_scoreboard_client/view/screens/overview/team_match/league_overview.dart';
import 'package:wrestling_scoreboard_client/view/widgets/consumer.dart';
import 'package:wrestling_scoreboard_client/view/widgets/font.dart';
import 'package:wrestling_scoreboard_client/view/widgets/grouped_list.dart';
import 'package:wrestling_scoreboard_client/view/widgets/info.dart';
import 'package:wrestling_scoreboard_client/view/widgets/tab_group.dart';
import 'package:wrestling_scoreboard_common/common.dart';

class DivisionOverview extends ConsumerWidget {
Expand Down Expand Up @@ -76,14 +78,19 @@ class DivisionOverview extends ConsumerWidget {
dataObject: data,
label: localizations.division,
details: data.name,
body: GroupedList(items: [
tabs: [
Tab(child: HeadingText(localizations.info)),
Tab(child: HeadingText(localizations.divisions)),
Tab(child: HeadingText(localizations.leagues)),
Tab(child: HeadingText(localizations.weightClasses)),
],
body: TabGroup(items: [
description,
ManyConsumer<Division, Division>(
filterObject: data,
builder: (BuildContext context, List<Division> childDivisions) {
return ListGroup(
return GroupedList(
header: HeadingItem(
title: localizations.divisions,
trailing: IconButton(
icon: const Icon(Icons.add),
onPressed: () => Navigator.push(
Expand Down Expand Up @@ -114,9 +121,8 @@ class DivisionOverview extends ConsumerWidget {
ManyConsumer<League, Division>(
filterObject: data,
builder: (BuildContext context, List<League> leagues) {
return ListGroup(
return GroupedList(
header: HeadingItem(
title: localizations.leagues,
trailing: IconButton(
icon: const Icon(Icons.add),
onPressed: () => Navigator.push(
Expand Down Expand Up @@ -147,9 +153,8 @@ class DivisionOverview extends ConsumerWidget {
ManyConsumer<DivisionWeightClass, Division>(
filterObject: data,
builder: (BuildContext context, List<DivisionWeightClass> divisionWeightClasses) {
return ListGroup(
return GroupedList(
header: HeadingItem(
title: localizations.weightClasses,
trailing: IconButton(
icon: const Icon(Icons.add),
onPressed: () => Navigator.push(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import 'package:wrestling_scoreboard_client/view/screens/overview/shared/actions
import 'package:wrestling_scoreboard_client/view/screens/overview/shared/matches_widget.dart';
import 'package:wrestling_scoreboard_client/view/screens/overview/team_match/league_team_participation_overview.dart';
import 'package:wrestling_scoreboard_client/view/widgets/consumer.dart';
import 'package:wrestling_scoreboard_client/view/widgets/font.dart';
import 'package:wrestling_scoreboard_client/view/widgets/grouped_list.dart';
import 'package:wrestling_scoreboard_client/view/widgets/info.dart';
import 'package:wrestling_scoreboard_client/view/widgets/tab_group.dart';
import 'package:wrestling_scoreboard_common/common.dart';

class LeagueOverview extends ConsumerWidget {
Expand Down Expand Up @@ -67,14 +69,18 @@ class LeagueOverview extends ConsumerWidget {
actions: [
OrganizationImportAction(id: id, orgId: data.organization!.id!, importType: OrganizationImportType.league)
],
body: GroupedList(items: [
tabs: [
Tab(child: HeadingText(localizations.info)),
Tab(child: HeadingText(localizations.participatingTeams)),
Tab(child: HeadingText(localizations.matches)),
],
body: TabGroup(items: [
description,
ManyConsumer<LeagueTeamParticipation, League>(
filterObject: data,
builder: (BuildContext context, List<LeagueTeamParticipation> teamParticipations) {
return ListGroup(
return GroupedList(
header: HeadingItem(
title: localizations.participatingTeams,
trailing: IconButton(
icon: const Icon(Icons.add),
onPressed: () => Navigator.push(
Expand Down
Loading

0 comments on commit 869d2f6

Please sign in to comment.