Skip to content

Commit 25a190e

Browse files
committed
Add chips to waypoint dialog
1 parent ef4e57e commit 25a190e

File tree

2 files changed

+121
-61
lines changed

2 files changed

+121
-61
lines changed

app/lib/l10n/app_en.arb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,5 +285,6 @@
285285
"addWaypoint": "Add waypoint",
286286
"editWaypoint": "Edit waypoint",
287287
"team": "Team",
288-
"public": "Public"
288+
"public": "Public",
289+
"noWaypoints": "There are no waypoints available"
289290
}

app/lib/pages/game/drawer.dart

Lines changed: 119 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:flutter/services.dart';
44
import 'package:flutter_bloc/flutter_bloc.dart';
55
import 'package:setonix/board/game.dart';
66
import 'package:setonix/pages/game/multiplayer/dialog.dart';
7+
import 'package:setonix/pages/game/waypoint.dart';
78
import 'package:setonix/src/generated/i18n/app_localizations.dart';
89
import 'package:go_router/go_router.dart';
910
import 'package:material_leap/material_leap.dart';
@@ -197,66 +198,7 @@ class GameDrawer extends StatelessWidget {
197198
onChanged: (value) => context.read<WorldBloc>().process(
198199
WaypointVisibilityChanged(value),
199200
),
200-
onTap: () {
201-
final bloc = context.read<WorldBloc>();
202-
final state = bloc.state;
203-
Widget buildWaypointTile(
204-
Waypoint waypoint, {
205-
String? team,
206-
}) => ContextRegion(
207-
builder: (ctx, button, controller) => ListTile(
208-
title: Text(waypoint.name),
209-
leading: Icon(
210-
team != null
211-
? PhosphorIconsLight.users
212-
: PhosphorIconsLight.mapPin,
213-
),
214-
trailing: button,
215-
onTap: () {
216-
Navigator.of(ctx).pop();
217-
game.teleport(waypoint.position);
218-
Scaffold.of(context).closeDrawer();
219-
},
220-
),
221-
menuChildren: [
222-
MenuItemButton(
223-
leadingIcon: const Icon(PhosphorIconsLight.pencil),
224-
child: Text(AppLocalizations.of(context).edit),
225-
onPressed: () {},
226-
),
227-
MenuItemButton(
228-
leadingIcon: const Icon(PhosphorIconsLight.trash),
229-
child: Text(AppLocalizations.of(context).delete),
230-
onPressed: () {
231-
bloc.add(
232-
WaypointRemoved(
233-
name: waypoint.name,
234-
team: team,
235-
),
236-
);
237-
},
238-
),
239-
],
240-
);
241-
showLeapBottomSheet(
242-
context: context,
243-
titleBuilder: (context) =>
244-
Text(AppLocalizations.of(context).waypoints),
245-
childrenBuilder: (context) => [
246-
...state.world.getTeams().expand(
247-
(e) =>
248-
state.info.teams[e]?.waypoints.map(
249-
(waypoint) =>
250-
buildWaypointTile(waypoint, team: e),
251-
) ??
252-
<Widget>[],
253-
),
254-
...state.info.waypoints.map(
255-
(e) => buildWaypointTile(e),
256-
),
257-
],
258-
);
259-
},
201+
onTap: () => _showWaypointsDialog(context),
260202
),
261203
);
262204
},
@@ -726,4 +668,121 @@ class GameDrawer extends StatelessWidget {
726668
],
727669
);
728670
}
671+
672+
void _showWaypointsDialog(BuildContext context) {
673+
final bloc = context.read<WorldBloc>();
674+
Widget buildWaypointTile(Waypoint waypoint, {String? team}) {
675+
final gameTeam = bloc.state.info.teams[team];
676+
return ContextRegion(
677+
builder: (ctx, button, controller) => ListTile(
678+
title: Text(waypoint.name),
679+
leading: Icon(
680+
team != null ? PhosphorIconsLight.users : PhosphorIconsLight.mapPin,
681+
color: gameTeam?.color?.color,
682+
),
683+
trailing: button,
684+
onTap: () {
685+
Navigator.of(ctx).pop();
686+
game.teleport(waypoint.position);
687+
Scaffold.of(context).closeDrawer();
688+
},
689+
),
690+
menuChildren: [
691+
MenuItemButton(
692+
leadingIcon: const Icon(PhosphorIconsLight.pencil),
693+
child: Text(AppLocalizations.of(context).edit),
694+
onPressed: () => showDialog(
695+
context: context,
696+
builder: (context) => BlocProvider.value(
697+
value: bloc,
698+
child: WaypointDialog(waypoint: waypoint, team: team),
699+
),
700+
),
701+
),
702+
MenuItemButton(
703+
leadingIcon: const Icon(PhosphorIconsLight.trash),
704+
child: Text(AppLocalizations.of(context).delete),
705+
onPressed: () {
706+
bloc.add(WaypointRemoved(name: waypoint.name, team: team));
707+
},
708+
),
709+
],
710+
);
711+
}
712+
713+
bool showPublic = true, showTeams = true;
714+
715+
showLeapBottomSheet(
716+
context: context,
717+
titleBuilder: (context) => Text(AppLocalizations.of(context).waypoints),
718+
childrenBuilder: (context) => [
719+
StatefulBuilder(
720+
builder: (context, setLocalState) {
721+
return BlocBuilder<WorldBloc, ClientWorldState>(
722+
bloc: bloc,
723+
buildWhen: (previous, current) =>
724+
previous.info.waypoints != current.info.waypoints ||
725+
previous.info.teams != current.info.teams ||
726+
previous.teamMembers != current.teamMembers,
727+
builder: (context, state) {
728+
final List<Widget> waypointTiles = [];
729+
730+
if (showTeams) {
731+
waypointTiles.addAll(
732+
state.world.getTeams().expand(
733+
(e) =>
734+
state.info.teams[e]?.waypoints.map(
735+
(waypoint) => buildWaypointTile(waypoint, team: e),
736+
) ??
737+
<Widget>[],
738+
),
739+
);
740+
}
741+
742+
if (showPublic) {
743+
waypointTiles.addAll(
744+
state.info.waypoints.map((e) => buildWaypointTile(e)),
745+
);
746+
}
747+
748+
return Column(
749+
mainAxisSize: MainAxisSize.min,
750+
crossAxisAlignment: CrossAxisAlignment.stretch,
751+
children: [
752+
Wrap(
753+
spacing: 8,
754+
runSpacing: 4,
755+
children: [
756+
FilterChip(
757+
label: Text(AppLocalizations.of(context).teams),
758+
selected: showTeams,
759+
onSelected: (v) => setLocalState(() => showTeams = v),
760+
),
761+
FilterChip(
762+
label: const Text('Public'),
763+
selected: showPublic,
764+
onSelected: (v) =>
765+
setLocalState(() => showPublic = v),
766+
),
767+
],
768+
),
769+
const SizedBox(height: 8),
770+
if (waypointTiles.isEmpty)
771+
Padding(
772+
padding: const EdgeInsets.symmetric(vertical: 12),
773+
child: Center(
774+
child: Text(AppLocalizations.of(context).noWaypoints),
775+
),
776+
)
777+
else
778+
...waypointTiles,
779+
],
780+
);
781+
},
782+
);
783+
},
784+
),
785+
],
786+
);
787+
}
729788
}

0 commit comments

Comments
 (0)