Skip to content

Commit

Permalink
feat(mobile/library): Popup menu setup (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
RezaRahemtola authored Oct 30, 2023
1 parent 8748000 commit 69d254c
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 15 deletions.
65 changes: 53 additions & 12 deletions frontend/mobile/lib/components/library/workflow_tile.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,58 @@
import 'package:area_mobile/pages/editor.dart';
import 'package:area_mobile/services/dio.dart';
import 'package:area_mobile/types/services.dart';
import 'package:area_mobile/types/workflows/workflows.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_svg/svg.dart';

class WorkflowTile extends StatelessWidget {
class WorkflowTile extends StatefulWidget {
final Workflow workflow;

const WorkflowTile({
required this.workflow,
Key? key,
}) : super(key: key);

@override
State<WorkflowTile> createState() => _WorkflowTileState();
}

class _WorkflowTileState extends State<WorkflowTile> {
final GlobalKey _menuKey = GlobalKey();

_showPopupMenu(Offset offset) async {
double left = offset.dx - 100;
double top = offset.dy + 25;
await showMenu(
context: context,
position: RelativeRect.fromLTRB(left, top, 0, 0),
items: [
PopupMenuItem(
value: "rename",
child: ListTile(
leading: const Icon(Icons.title),
title: Text(AppLocalizations.of(context)!.rename),
),
),
PopupMenuItem(
value: "edit",
child: ListTile(
leading: const Icon(Icons.edit),
title: Text(AppLocalizations.of(context)!.edit),
),
),
PopupMenuItem(
value: "delete",
child: ListTile(
leading: const Icon(Icons.delete),
title: Text(AppLocalizations.of(context)!.delete),
),
),
],
elevation: 8.0,
);
}

@override
Widget build(BuildContext context) {
return Card(
Expand All @@ -31,13 +70,15 @@ class WorkflowTile extends StatelessWidget {
} else {
final List<Service> services = snapshot.data!.data!;
return ListTile(
title: Text(workflow.name),
title: GestureDetector(
onTapDown: (TapDownDetails details) {
_showPopupMenu(details.globalPosition);
},
child: Text(widget.workflow.name),
),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
Editor(workflow: workflow)));
dynamic popUpMenustate = _menuKey.currentState;
popUpMenustate.showButtonMenu();
},
leading: SizedBox(
height: 128,
Expand All @@ -46,13 +87,13 @@ class WorkflowTile extends StatelessWidget {
ListView(scrollDirection: Axis.horizontal, children: [
SvgPicture.network(
services
.firstWhere(
(s) => s.id == workflow.action.areaServiceId)
.firstWhere((s) =>
s.id == widget.workflow.action.areaServiceId)
.imageUrl,
width: 32,
height: 32,
),
...workflow.reactions
...widget.workflow.reactions
.map((reaction) => SvgPicture.network(
services
.firstWhere(
Expand All @@ -67,7 +108,7 @@ class WorkflowTile extends StatelessWidget {
height: 75,
width: 75,
child: Switch(
value: workflow.active,
value: widget.workflow.active,
onChanged: (bool value) {},
),
));
Expand Down
5 changes: 4 additions & 1 deletion frontend/mobile/lib/locales/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@
"navbarLibrary": "Library",
"language": "Language",
"theme": "Theme",
"save": "Save"
"save": "Save",
"rename": "Rename",
"edit": "Edit",
"delete": "Delete"
}
5 changes: 4 additions & 1 deletion frontend/mobile/lib/locales/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@
"navbarLibrary": "Librarie",
"language": "Langage",
"theme": "Thème",
"save": "Sauvegarder"
"save": "Sauvegarder",
"rename": "Renommer",
"edit": "Modifier",
"delete": "Supprimer"
}
5 changes: 4 additions & 1 deletion frontend/mobile/lib/locales/app_is.arb
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@
"navbarLibrary": "Bókasafn",
"language": "Tungumál",
"theme": "Þema",
"save": "Vista"
"save": "Vista",
"rename": "Endurnefna",
"edit": "Til að breyta",
"delete": "EYÐA"
}

0 comments on commit 69d254c

Please sign in to comment.