Skip to content

Commit

Permalink
You can now add value to scenes
Browse files Browse the repository at this point in the history
  • Loading branch information
guyluz11 committed Feb 10, 2024
1 parent d2889e4 commit 40b3581
Show file tree
Hide file tree
Showing 9 changed files with 223 additions and 248 deletions.
29 changes: 0 additions & 29 deletions lib/presentation/core/ad_state.dart

This file was deleted.

4 changes: 1 addition & 3 deletions lib/presentation/organisms/empty_open_area_organism.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ class EmptyOpenAreaOrganism extends StatelessWidget {
),
),
TextButton(
onPressed: () {
context.router.pop();
},
onPressed: context.router.pop,
child: TextAtom(
'No device found',
style: TextStyle(
Expand Down
319 changes: 178 additions & 141 deletions lib/presentation/pages/add_action_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:cybearjinni/presentation/core/snack_bar_service.dart';
import 'package:cybearjinni/presentation/organisms/organisms.dart';
import 'package:flutter/material.dart';

@RoutePage<EntityActionObject?>()
@RoutePage<RequestActionObject?>()
class AddActionPage extends StatefulWidget {
const AddActionPage({required this.entities});

Expand All @@ -21,6 +21,9 @@ class _AddActionPageState extends State<AddActionPage> {
DeviceEntityBase? selectedEntity;
EntityProperties? selectedProperty;
EntityActions? selectedAction;
String? fieldValues;
ActionValues? actionType;
String? actionValue;

void onEntitySelect(String entityId) {
setState(() {
Expand All @@ -40,160 +43,194 @@ class _AddActionPageState extends State<AddActionPage> {
});
}

void onSelectedActionType(String value) {
setState(() {
actionType = ActionValues.values.elementAt(int.parse(value));
});
}

@override
Widget build(BuildContext context) {
return PageOrganism(
pageName: 'Add Action',
child: SingleChildScrollView(
child: Container(
margin: const EdgeInsets.symmetric(horizontal: 10),
child: Column(
children: [
const SizedBox(
height: 30,
),
const SizedBox(
height: 70,
),
const Row(
children: [
TextAtom(
'Choose Action',
style: TextStyle(fontSize: 27),
),
],
),
DropdownButton<String>(
dropdownColor: Colors.black,
style: const TextStyle(color: Colors.white),
icon: const Icon(Icons.arrow_drop_down),
hint: TextAtom(
selectedEntity?.cbjEntityName.getOrCrash() ?? 'Choose Entity',
style: const TextStyle(color: Colors.white),
),
elevation: 16,
underline: Container(
height: 2,
child: Container(
margin: const EdgeInsets.symmetric(horizontal: 10),
child: Column(
children: [
const SeparatorAtom(),
const Row(
children: [
TextAtom(
'Choose Action',
style: TextStyle(fontSize: 27),
),
onChanged: (value) => onEntitySelect(value!),
items:
widget.entities.values.map<DropdownMenuItem<String>>((e) {
return DropdownMenuItem<String>(
value: e.getCbjEntityId,
child: TextAtom(e.cbjEntityName.getOrCrash()!),
);
}).toList(),
),
const SizedBox(
height: 40,
),
DropdownButton<String>(
dropdownColor: Colors.black,
style: const TextStyle(color: Colors.white),
icon: const Icon(Icons.arrow_drop_down),
hint: TextAtom(
selectedProperty?.name ?? 'Select Property',
style: const TextStyle(color: Colors.white),
),
elevation: 16,
underline: Container(
height: 2,
),
onChanged: (value) => _onPropertySelected(value!),
items: selectedEntity
?.getListOfPropertiesToChange()
],
),
Expanded(
child: Column(
children: [
DropdownButton<String>(
dropdownColor: Colors.black,
style: const TextStyle(color: Colors.white),
icon: const Icon(Icons.arrow_drop_down),
hint: TextAtom(
selectedEntity?.cbjEntityName.getOrCrash() ?? 'Entity',
style: const TextStyle(color: Colors.white),
),
elevation: 16,
underline: Container(
height: 2,
),
onChanged: (value) => onEntitySelect(value!),
items: widget.entities.values
.map<DropdownMenuItem<String>>((e) {
return DropdownMenuItem<String>(
value: e.index.toString(),
child: TextAtom(e.name),
);
}).toList() ??
<DropdownMenuItem<String>>[
const DropdownMenuItem<String>(
value: 'Choose entity first',
child: TextAtom('Choose entity first'),
),
],
),
const SizedBox(
height: 40,
),
DropdownButton<String>(
dropdownColor: Colors.black,
style: const TextStyle(color: Colors.white),
icon: const Icon(Icons.arrow_drop_down),
hint: TextAtom(
selectedAction?.name ?? 'Choose Action',
style: const TextStyle(color: Colors.white),
),
elevation: 16,
underline: Container(
height: 2,
),
onChanged: (value) => onActionSelected(value!),
items: (selectedProperty != null &&
selectedProperty!.getActions.isNotEmpty)
? selectedProperty!.getActions
.map<DropdownMenuItem<String>>((e) {
return DropdownMenuItem<String>(
value: e.index.toString(),
child: TextAtom(e.name),
);
}).toList()
: const <DropdownMenuItem<String>>[
DropdownMenuItem<String>(
value: 'Choose property first',
child: TextAtom('Choose property first'),
),
],
),
const SizedBox(
height: 70,
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(
onPressed: () {
SnackBarService().show(context, 'Add action');
if (selectedEntity == null ||
selectedProperty == null ||
selectedAction == null) {
return;
}
final EntityActionObject entityActionObject =
EntityActionObject(
entity: selectedEntity!,
property: selectedProperty!,
action: selectedAction!,
value: e.getCbjEntityId,
child: TextAtom(e.cbjEntityName.getOrCrash()!),
);
// TODO: Add pop
context.router
.pop<EntityActionObject?>(entityActionObject);
},
child: const TextAtom(
'Done',
style: TextStyle(fontSize: 20),
}).toList(),
),
const SeparatorAtom(variant: SeparatorVariant.farAppart),
DropdownButton<String>(
dropdownColor: Colors.black,
style: const TextStyle(color: Colors.white),
icon: const Icon(Icons.arrow_drop_down),
hint: TextAtom(
selectedProperty?.name ?? 'Property',
style: const TextStyle(color: Colors.white),
),
elevation: 16,
underline: Container(
height: 2,
),
onChanged: (value) => _onPropertySelected(value!),
items: selectedEntity
?.getListOfPropertiesToChange()
.map<DropdownMenuItem<String>>((e) {
return DropdownMenuItem<String>(
value: e.index.toString(),
child: TextAtom(e.name),
);
}).toList() ??
<DropdownMenuItem<String>>[
const DropdownMenuItem<String>(
value: 'Choose entity first',
child: TextAtom('Choose entity first'),
),
],
),
const SeparatorAtom(variant: SeparatorVariant.farAppart),
DropdownButton<String>(
dropdownColor: Colors.black,
style: const TextStyle(color: Colors.white),
icon: const Icon(Icons.arrow_drop_down),
hint: TextAtom(
selectedAction?.name ?? 'Action',
style: const TextStyle(color: Colors.white),
),
elevation: 16,
underline: Container(
height: 2,
),
onChanged: (value) => onActionSelected(value!),
items: (selectedProperty != null &&
selectedProperty!.getActions.isNotEmpty)
? selectedProperty!.getActions
.map<DropdownMenuItem<String>>((e) {
return DropdownMenuItem<String>(
value: e.index.toString(),
child: TextAtom(e.name),
);
}).toList()
: const <DropdownMenuItem<String>>[
DropdownMenuItem<String>(
value: 'Choose property first',
child: TextAtom('Choose property first'),
),
],
),
const SeparatorAtom(variant: SeparatorVariant.farAppart),
const TextAtom('Field value'),
const SeparatorAtom(),
DropdownButton<String>(
dropdownColor: Colors.black,
style: const TextStyle(color: Colors.white),
icon: const Icon(Icons.arrow_drop_down),
hint: TextAtom(
actionType?.name ?? 'Value',
style: const TextStyle(color: Colors.white),
),
elevation: 16,
underline: Container(
height: 2,
),
onChanged: (value) => onSelectedActionType(value!),
items: (selectedAction != null)
? ActionValues.values
.map<DropdownMenuItem<String>>((e) {
return DropdownMenuItem<String>(
value: e.index.toString(),
child: TextAtom(e.name),
);
}).toList()
: const <DropdownMenuItem<String>>[
DropdownMenuItem<String>(
value: 'Choose action first',
child: TextAtom('Choose action first'),
),
],
),
const SeparatorAtom(),
Container(
margin: const EdgeInsets.symmetric(horizontal: 100),
child: TextFormFieldAtom(
onChanged: (c) {
fieldValues = c;
},
),
),
],
),
],
),
),
const SeparatorAtom(variant: SeparatorVariant.farAppart),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(
onPressed: () {
SnackBarService().show(context, 'Add action');
if (selectedEntity == null ||
selectedProperty == null ||
selectedAction == null) {
return;
}
final RequestActionObject entityActionObject =
RequestActionObject(
entityIds: HashSet.from([selectedEntity!.getCbjEntityId]),
property: selectedProperty!,
actionType: selectedAction!,
value: actionType == null ||
fieldValues == null ||
fieldValues!.isEmpty
? null
: HashMap.fromEntries(
[MapEntry(actionType!, fieldValues)],
),
);
context.router
.pop<RequestActionObject?>(entityActionObject);
},
child: const TextAtom(
'Done',
style: TextStyle(fontSize: 20),
),
),
],
),
const SeparatorAtom(),
],
),
),
);
}
}

class EntityActionObject {
EntityActionObject({
required this.entity,
required this.property,
required this.action,
});

final DeviceEntityBase entity;
final EntityProperties property;
final EntityActions action;
}
Loading

0 comments on commit 40b3581

Please sign in to comment.