mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-14 17:25:47 +00:00
Compare commits
86 Commits
c159ecdb8a
...
SP-1477-FE
Author | SHA1 | Date | |
---|---|---|---|
a7080248cb | |||
25893e3bbd | |||
c90f0874c2 | |||
214ec78a95 | |||
ed9f98e653 | |||
a37236c8d2 | |||
1f1a8a7208 | |||
e7efd2b3a1 | |||
2b0e504f05 | |||
a656d5981e | |||
3f49a18130 | |||
a51c4d9679 | |||
caeed8e73f | |||
dc5ac9be5b | |||
5c9b30895f | |||
06b14a3964 | |||
3c92ea3047 | |||
73d28a1800 | |||
5493ca6fb0 | |||
7005d8ba83 | |||
cb79627038 | |||
1cff69d496 | |||
60df77efad | |||
9e84048f81 | |||
99adb1c286 | |||
f2412aa867 | |||
e4768c95aa | |||
f25b4dbf6d | |||
9eff9ab371 | |||
a2e68d6194 | |||
94c94b170f | |||
253cf15559 | |||
443eea9421 | |||
87a2c08f64 | |||
dd66e7c747 | |||
7af61d2f65 | |||
f37eacb0ee | |||
c7dcc297aa | |||
aefe5ad081 | |||
8d9af8519d | |||
b1d52937c9 | |||
5fedf37421 | |||
ccde857c29 | |||
b2a8086e0e | |||
408e78962c | |||
dcdbc02ca0 | |||
31025e9176 | |||
8219de6821 | |||
fbdf3817ab | |||
17422edd0d | |||
4c8f2c72df | |||
fb867e5df3 | |||
9472390284 | |||
731ba0f3d6 | |||
56407c6426 | |||
02d61ca0bb | |||
99ee4b9878 | |||
19edd0a275 | |||
ef5e7c3154 | |||
80dd0f696f | |||
a64a41548f | |||
0d50aa68fa | |||
88aac86b10 | |||
0673548745 | |||
c2fc8fa0ae | |||
cbf10bbf78 | |||
d95588ce84 | |||
7e2e591d71 | |||
2ec81bda9c | |||
3b0f51473c | |||
13757d89ee | |||
d3068b8e14 | |||
7c5d7e1dda | |||
0a97a4867d | |||
6e55b488aa | |||
22789234fe | |||
8393ec353a | |||
0b45d61b25 | |||
450b773921 | |||
3f7f7ce49f | |||
2dc4e16a75 | |||
cd41720244 | |||
67209961b4 | |||
9098276223 | |||
36dfe2c85e | |||
efed5f55a7 |
5
.env.dev
5
.env.dev
@ -1,2 +1,5 @@
|
|||||||
ENV_NAME=development
|
ENV_NAME=development
|
||||||
BASE_URL=https://syncrow-dev.azurewebsites.net
|
BASE_URL=https://syncrow-dev.azurewebsites.net
|
||||||
|
PROJECT_ID=0e62577c-06fa-41b9-8a92-99a21fbaf51c
|
||||||
|
CLIENT_ID=c024573d191a327ce74db7d4502fdc29
|
||||||
|
CLIENT_SECRET=fec6ccbc33664f94a3b84a45c7cceef3f3ebd1613ef4307db8946ede530cd1ed
|
@ -1,2 +1,3 @@
|
|||||||
ENV_NAME=production
|
ENV_NAME=production
|
||||||
BASE_URL=https://syncrow-staging.azurewebsites.net
|
BASE_URL=https://syncrow-staging.azurewebsites.net
|
||||||
|
PROJECT_ID=bcda711e-9fc2-4168-a05e-171b4026d1ff
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
ENV_NAME=staging
|
ENV_NAME=staging
|
||||||
BASE_URL=https://syncrow-staging.azurewebsites.net
|
BASE_URL=https://syncrow-staging.azurewebsites.net
|
||||||
|
PROJECT_ID=bcda711e-9fc2-4168-a05e-171b4026d1ff
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -42,3 +42,4 @@ app.*.map.json
|
|||||||
/android/app/debug
|
/android/app/debug
|
||||||
/android/app/profile
|
/android/app/profile
|
||||||
/android/app/release
|
/android/app/release
|
||||||
|
/android/app/.cxx/
|
||||||
|
10
assets/icons/cancel_icon.svg
Normal file
10
assets/icons/cancel_icon.svg
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<g clip-path="url(#clip0_7302_4118)">
|
||||||
|
<path d="M11.1049 10.0001L19.7712 1.33381C20.0763 1.02869 20.0763 0.534007 19.7712 0.228929C19.4661 -0.0761485 18.9714 -0.0761876 18.6663 0.228929L9.99999 8.89524L1.33372 0.228929C1.0286 -0.0761876 0.533915 -0.0761876 0.228837 0.228929C-0.0762401 0.534046 -0.0762792 1.02873 0.228837 1.33381L8.89511 10.0001L0.228837 18.6664C-0.0762792 18.9715 -0.0762792 19.4662 0.228837 19.7713C0.381376 19.9238 0.581337 20.0001 0.781297 20.0001C0.981258 20.0001 1.18118 19.9238 1.33376 19.7713L9.99999 11.105L18.6663 19.7713C18.8188 19.9238 19.0188 20.0001 19.2187 20.0001C19.4187 20.0001 19.6186 19.9238 19.7712 19.7713C20.0763 19.4662 20.0763 18.9715 19.7712 18.6664L11.1049 10.0001Z" fill="#999999"/>
|
||||||
|
</g>
|
||||||
|
<defs>
|
||||||
|
<clipPath id="clip0_7302_4118">
|
||||||
|
<rect width="20" height="20" fill="white"/>
|
||||||
|
</clipPath>
|
||||||
|
</defs>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 939 B |
15
assets/icons/empty_routines.svg
Normal file
15
assets/icons/empty_routines.svg
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<svg width="100" height="100" viewBox="0 0 100 100" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M11.5419 20.2424C11.1182 19.3486 10.0545 18.9678 9.16647 19.3935L1.38334 23.1268C0.591819 23.3098 0 24.0197 0 24.8727V33.8466C0 34.8381 0.797668 35.6413 1.78229 35.6413C2.76668 35.6413 3.56412 34.8381 3.56412 33.8466V27.6644L9.16647 30.3516C9.41376 30.4704 9.67449 30.5264 9.93112 30.5264C10.5974 30.5264 11.2359 30.1484 11.5419 29.5025C11.9643 28.6076 11.5875 27.5367 10.699 27.1103L6.03295 24.8725L10.699 22.6346C11.5877 22.2085 11.9643 21.1376 11.5419 20.2424Z" fill="#D5D5D5"/>
|
||||||
|
<path d="M20.6084 17.6894C20.8655 17.6894 21.1257 17.6334 21.3737 17.5146L32.0481 12.3951C32.9366 11.9685 33.3141 10.8974 32.891 10.0024C32.4682 9.10864 31.4052 8.72813 30.5156 9.15359L19.8408 14.2736C18.9522 14.6999 18.5754 15.7706 18.998 16.6658C19.3038 17.3112 19.9423 17.6894 20.6084 17.6894Z" fill="#D5D5D5"/>
|
||||||
|
<path d="M42.7227 7.27445L48.1841 4.65449V10.9114C48.1841 11.9027 48.9818 12.7061 49.9659 12.7061C50.9503 12.7061 51.7478 11.9027 51.7478 10.9114V4.62192L57.2779 7.27445C57.5259 7.39303 57.7862 7.44922 58.0433 7.44922C58.7091 7.44922 59.3478 7.07124 59.6534 6.42537C60.0763 5.53041 59.6994 4.45953 58.8106 4.03316L50.7663 0.174427C50.2813 -0.0581424 49.7189 -0.0581424 49.2338 0.174427L41.19 4.03316C40.3015 4.45953 39.9244 5.53018 40.3472 6.42537C40.771 7.32101 41.8362 7.70198 42.7227 7.27445Z" fill="#D5D5D5"/>
|
||||||
|
<path d="M67.9533 12.3944L78.6281 17.5146C78.875 17.6334 79.1361 17.6894 79.3932 17.6894C80.059 17.6894 80.6978 17.3114 81.0034 16.6655C81.426 15.7706 81.0494 14.6997 80.1606 14.2733L69.4856 9.1529C68.5982 8.72721 67.5345 9.10726 67.1105 10.0018C66.6875 10.8967 67.0645 11.9676 67.9533 12.3944Z" fill="#D5D5D5"/>
|
||||||
|
<path d="M81.539 34.8099C82.4275 34.3837 82.8046 33.3128 82.3815 32.4177C81.9587 31.5232 80.8946 31.1424 80.0065 31.5695L73.167 34.8509L51.7477 24.577V16.5765C51.7477 15.5846 50.9503 14.7818 49.9659 14.7818C48.9817 14.7818 48.1841 15.5848 48.1841 16.5765V24.6096L26.8346 34.85L20.6999 31.9073C19.8093 31.481 18.7482 31.8612 18.3244 32.7564C17.9016 33.6514 18.2787 34.7225 19.1672 35.1489L25.8031 38.3319V61.6684L19.0593 64.9031C18.1707 65.3295 17.7939 66.4001 18.2165 67.2955C18.5221 67.9412 19.1606 68.3192 19.8266 68.3192C20.0837 68.3192 20.3447 68.2632 20.5917 68.1444L26.8349 65.1499L48.1841 75.3903V81.5075C48.1841 82.4993 48.9817 83.3022 49.9659 83.3022C50.9503 83.3022 51.7477 82.499 51.7477 81.5075V75.4233L73.1657 65.1501L79.6524 68.2616C79.9002 68.3802 80.1607 68.4364 80.4175 68.4364C81.0834 68.4364 81.7221 68.0584 82.0277 67.4125C82.4508 66.5175 82.0735 65.4467 81.1849 65.0201L74.1977 61.6687V38.3319L81.539 34.8099ZM70.634 62.3879L51.7479 71.4467V49.0994L70.634 40.0402V62.3879ZM29.4788 61.8939C29.4472 61.8269 29.4053 61.7691 29.3668 61.7081V40.0404L48.1841 49.0663V71.4141L29.6409 62.5198C29.6239 62.3086 29.5745 62.0964 29.4788 61.8939ZM50.0003 27.7151L69.0207 36.8383L50.0003 45.9611L30.9799 36.8383L50.0003 27.7151Z" fill="#D5D5D5"/>
|
||||||
|
<path d="M78.6271 82.486L67.9525 87.6062C67.0639 88.0328 66.6864 89.1036 67.1095 89.9979C67.4153 90.644 68.054 91.0215 68.7199 91.0215C68.9767 91.0215 69.2379 90.9656 69.485 90.8477L80.1598 85.7273C81.0483 85.3009 81.4252 84.2295 81.0025 83.3346C80.579 82.4401 79.5149 82.0616 78.6271 82.486Z" fill="#D5D5D5"/>
|
||||||
|
<path d="M57.2782 92.7266L51.748 95.3793V88.227C51.748 87.2357 50.9506 86.4323 49.9662 86.4323C48.982 86.4323 48.1844 87.2357 48.1844 88.227V95.3468L42.723 92.7266C41.8335 92.3023 40.7713 92.6807 40.3475 93.5759C39.9246 94.4709 40.3015 95.5413 41.1903 95.9676L49.2346 99.8259C49.4769 99.9417 49.7387 100 50.0008 100C50.2629 100 50.5248 99.9417 50.7671 99.8259L58.8114 95.9676C59.6999 95.5413 60.077 94.4709 59.6541 93.5759C59.2304 92.6807 58.166 92.3032 57.2782 92.7266Z" fill="#D5D5D5"/>
|
||||||
|
<path d="M32.0476 87.6061L21.3728 82.4859C20.4863 82.0605 19.4217 82.4394 18.9975 83.3343C18.5749 84.2293 18.9517 85.3006 19.8403 85.727L30.5153 90.8474C30.7622 90.9653 31.0233 91.0213 31.2802 91.0213C31.946 91.0213 32.5847 90.6438 32.8903 89.9977C33.3132 89.1036 32.9361 88.0328 32.0476 87.6061Z" fill="#D5D5D5"/>
|
||||||
|
<path d="M11.5419 70.4974C11.1182 69.6029 10.0545 69.224 9.16647 69.6488L3.56412 72.3355V65.6178C3.56412 64.6265 2.76668 63.823 1.78229 63.823C0.797668 63.823 0 64.6265 0 65.6178V74.5919C0 74.8162 0.0457694 75.0284 0.120686 75.2263C0.156892 75.8784 0.53193 76.4651 1.12215 76.7486L9.16647 80.6073C9.41376 80.7254 9.67449 80.7818 9.93112 80.7818C10.5974 80.7818 11.2359 80.4038 11.5419 79.7582C11.9643 78.8632 11.5875 77.7924 10.699 77.3655L6.03295 75.1281L10.699 72.8903C11.5877 72.4637 11.9643 71.3923 11.5419 70.4974Z" fill="#D5D5D5"/>
|
||||||
|
<path d="M1.78229 56.8226C2.76668 56.8226 3.56412 56.0193 3.56412 55.0274V44.4374C3.56412 43.4461 2.76668 42.6427 1.78229 42.6427C0.797668 42.6427 0 43.4461 0 44.4374V55.0274C0.00022771 56.0193 0.797896 56.8226 1.78229 56.8226Z" fill="#D5D5D5"/>
|
||||||
|
<path d="M98.6173 23.1268L90.8342 19.3935C89.9443 18.9667 88.8825 19.3479 88.4589 20.2424C88.0363 21.1378 88.4132 22.2084 89.3017 22.6351L93.9677 24.8729L89.3017 27.1108C88.4132 27.5371 88.0363 28.6078 88.4589 29.503C88.7645 30.1488 89.4032 30.5268 90.0691 30.5268C90.3262 30.5268 90.5873 30.4709 90.8342 30.3521L96.4365 27.6649V33.847C96.4365 34.8385 97.234 35.6418 98.2184 35.6418C99.2027 35.6418 100 34.8385 100 33.847V24.8731C100 24.0197 99.4088 23.3098 98.6173 23.1268Z" fill="#D5D5D5"/>
|
||||||
|
<path d="M98.2184 42.642C97.2337 42.642 96.4365 43.4455 96.4365 44.4367V55.0267C96.4365 56.0187 97.234 56.8214 98.2184 56.8214C99.2027 56.8214 100 56.0184 100 55.0267V44.4367C100 43.4455 99.203 42.642 98.2184 42.642Z" fill="#D5D5D5"/>
|
||||||
|
<path d="M98.2184 63.8228C97.2337 63.8228 96.4365 64.6263 96.4365 65.6175V72.3352L90.8342 69.6485C89.9443 69.2231 88.8825 69.6022 88.4589 70.4971C88.0363 71.3921 88.4132 72.4634 89.3017 72.8898L93.9677 75.1277L89.3017 77.3651C88.4132 77.7919 88.0363 78.8628 88.4589 79.7577C88.7645 80.4034 89.4032 80.7814 90.0691 80.7814C90.3262 80.7814 90.5873 80.7249 90.8342 80.6068L98.8785 76.7481C99.4687 76.4646 99.8438 75.8779 99.88 75.2258C99.9546 75.0279 100 74.8157 100 74.5914V65.6173C100 64.6263 99.203 63.8228 98.2184 63.8228Z" fill="#D5D5D5"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 6.0 KiB |
10
assets/icons/save_routines_icon.svg
Normal file
10
assets/icons/save_routines_icon.svg
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<g clip-path="url(#clip0_7302_4149)">
|
||||||
|
<path d="M19.9969 4.94279C19.986 4.83232 19.943 4.72146 19.8674 4.62924C19.8382 4.59358 20.1367 4.89431 15.4141 0.17176C15.3015 0.0591838 15.1487 8.30277e-05 14.9996 0.00012209C14.6443 0.00012209 2.11177 0.00012209 1.75779 0.00012209C0.788544 0.00012209 0 0.788666 0 1.75791V18.2421C0 19.2113 0.788544 19.9998 1.75779 19.9998H18.2419C19.2112 19.9998 19.9997 19.2113 19.9997 18.2421C19.9998 4.01624 20.0013 4.98771 19.9969 4.94279ZM13.4764 1.17198V5.00005C13.4764 5.32314 13.2136 5.58598 12.8905 5.58598H12.1483V1.17198H13.4764ZM10.9765 1.17198V5.58598H5.54684C5.22376 5.58598 4.96091 5.32314 4.96091 5.00005V1.17198H10.9765ZM13.4764 12.539H4.96091V11.7968C4.96091 11.4738 5.22376 11.2109 5.54684 11.2109H12.8905C13.2136 11.2109 13.4764 11.4738 13.4764 11.7968V12.539ZM4.96091 18.828V13.7109H13.4764V18.828H4.96091ZM18.8279 18.2421C18.8279 18.5651 18.5651 18.828 18.242 18.828H14.6483C14.6483 18.0641 14.6483 12.6676 14.6483 11.7968C14.6483 10.8276 13.8597 10.039 12.8905 10.039H5.54684C4.57759 10.039 3.78905 10.8276 3.78905 11.7968V18.828H1.75783C1.43475 18.828 1.1719 18.5651 1.1719 18.2421V1.75791C1.1719 1.43483 1.43475 1.17198 1.75783 1.17198H3.78905V5.00005C3.78905 5.9693 4.57759 6.75784 5.54684 6.75784H12.8905C13.8597 6.75784 14.6483 5.9693 14.6483 5.00005V1.17198H14.7571L18.8279 5.24278V18.2421Z" fill="#023DFE" fill-opacity="0.6"/>
|
||||||
|
</g>
|
||||||
|
<defs>
|
||||||
|
<clipPath id="clip0_7302_4149">
|
||||||
|
<rect width="20" height="20" fill="white"/>
|
||||||
|
</clipPath>
|
||||||
|
</defs>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 1.6 KiB |
@ -10,6 +10,7 @@ import 'package:share_plus/share_plus.dart';
|
|||||||
import 'package:syncrow_app/features/app_layout/model/permission_model.dart';
|
import 'package:syncrow_app/features/app_layout/model/permission_model.dart';
|
||||||
import 'package:syncrow_app/features/app_layout/model/space_model.dart';
|
import 'package:syncrow_app/features/app_layout/model/space_model.dart';
|
||||||
import 'package:syncrow_app/features/app_layout/view/widgets/app_bar_home_dropdown.dart';
|
import 'package:syncrow_app/features/app_layout/view/widgets/app_bar_home_dropdown.dart';
|
||||||
|
import 'package:syncrow_app/features/auth/model/project_model.dart';
|
||||||
import 'package:syncrow_app/features/auth/model/user_model.dart';
|
import 'package:syncrow_app/features/auth/model/user_model.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/subspace_model.dart';
|
import 'package:syncrow_app/features/devices/model/subspace_model.dart';
|
||||||
@ -21,13 +22,14 @@ import 'package:syncrow_app/features/scene/bloc/effective_period/effect_period_e
|
|||||||
import 'package:syncrow_app/features/scene/bloc/smart_scene/smart_scene_select_dart_bloc.dart';
|
import 'package:syncrow_app/features/scene/bloc/smart_scene/smart_scene_select_dart_bloc.dart';
|
||||||
import 'package:syncrow_app/features/scene/enum/create_scene_enum.dart';
|
import 'package:syncrow_app/features/scene/enum/create_scene_enum.dart';
|
||||||
import 'package:syncrow_app/features/scene/model/scene_settings_route_arguments.dart';
|
import 'package:syncrow_app/features/scene/model/scene_settings_route_arguments.dart';
|
||||||
import 'package:syncrow_app/features/scene/view/scene_view.dart';
|
import 'package:syncrow_app/features/scene/view/routines_view.dart';
|
||||||
import 'package:syncrow_app/generated/assets.dart';
|
import 'package:syncrow_app/generated/assets.dart';
|
||||||
import 'package:syncrow_app/navigation/navigation_service.dart';
|
import 'package:syncrow_app/navigation/navigation_service.dart';
|
||||||
import 'package:syncrow_app/navigation/routing_constants.dart';
|
import 'package:syncrow_app/navigation/routing_constants.dart';
|
||||||
import 'package:syncrow_app/services/api/devices_api.dart';
|
import 'package:syncrow_app/services/api/devices_api.dart';
|
||||||
import 'package:syncrow_app/services/api/profile_api.dart';
|
import 'package:syncrow_app/services/api/profile_api.dart';
|
||||||
import 'package:syncrow_app/services/api/spaces_api.dart';
|
import 'package:syncrow_app/services/api/spaces_api.dart';
|
||||||
|
import 'package:syncrow_app/utils/constants/temp_const.dart';
|
||||||
import 'package:syncrow_app/utils/helpers/snack_bar.dart';
|
import 'package:syncrow_app/utils/helpers/snack_bar.dart';
|
||||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||||
part 'home_state.dart';
|
part 'home_state.dart';
|
||||||
@ -67,6 +69,8 @@ class HomeCubit extends Cubit<HomeState> {
|
|||||||
var uuid =
|
var uuid =
|
||||||
await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
|
await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
|
||||||
user = await ProfileApi().fetchUserInfo(uuid);
|
user = await ProfileApi().fetchUserInfo(uuid);
|
||||||
|
project = user?.project;
|
||||||
|
|
||||||
emit(HomeUserInfoLoaded(user!));
|
emit(HomeUserInfoLoaded(user!));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return;
|
return;
|
||||||
@ -175,6 +179,8 @@ class HomeCubit extends Cubit<HomeState> {
|
|||||||
|
|
||||||
SubSpaceModel? selectedRoom;
|
SubSpaceModel? selectedRoom;
|
||||||
|
|
||||||
|
Project? project;
|
||||||
|
|
||||||
PageController devicesPageController = PageController();
|
PageController devicesPageController = PageController();
|
||||||
|
|
||||||
PageController roomsPageController = PageController();
|
PageController roomsPageController = PageController();
|
||||||
@ -324,8 +330,8 @@ class HomeCubit extends Cubit<HomeState> {
|
|||||||
//////////////////////////////////////// API ////////////////////////////////////////
|
//////////////////////////////////////// API ////////////////////////////////////////
|
||||||
generateInvitation(SpaceModel unit) async {
|
generateInvitation(SpaceModel unit) async {
|
||||||
try {
|
try {
|
||||||
final invitationCode =
|
final invitationCode = await SpacesAPI.generateInvitationCode(unit.id,
|
||||||
await SpacesAPI.generateInvitationCode(unit.id, unit.community.uuid);
|
unit.community.uuid, project?.uuid ?? TempConst.projectIdDev);
|
||||||
if (invitationCode.isNotEmpty) {
|
if (invitationCode.isNotEmpty) {
|
||||||
Share.share('The invitation code is $invitationCode');
|
Share.share('The invitation code is $invitationCode');
|
||||||
CustomSnackBar.displaySnackBar(
|
CustomSnackBar.displaySnackBar(
|
||||||
@ -380,8 +386,10 @@ class HomeCubit extends Cubit<HomeState> {
|
|||||||
fetchRoomsByUnitId(SpaceModel space) async {
|
fetchRoomsByUnitId(SpaceModel space) async {
|
||||||
emitSafe(GetSpaceRoomsLoading());
|
emitSafe(GetSpaceRoomsLoading());
|
||||||
try {
|
try {
|
||||||
space.subspaces =
|
space.subspaces = await SpacesAPI.getSubSpaceBySpaceId(
|
||||||
await SpacesAPI.getSubSpaceBySpaceId(space.community.uuid, space.id);
|
space.community.uuid,
|
||||||
|
space.id,
|
||||||
|
project?.uuid ?? TempConst.projectIdDev);
|
||||||
} catch (failure) {
|
} catch (failure) {
|
||||||
emitSafe(GetSpaceRoomsError(failure.toString()));
|
emitSafe(GetSpaceRoomsError(failure.toString()));
|
||||||
return;
|
return;
|
||||||
@ -414,7 +422,6 @@ class HomeCubit extends Cubit<HomeState> {
|
|||||||
emitSafe(ActivationError(errMessage: errorMsg));
|
emitSafe(ActivationError(errMessage: errorMsg));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////// Nav ///////////////////////////////////////
|
/////////////////////////////////////// Nav ///////////////////////////////////////
|
||||||
@ -573,7 +580,7 @@ class HomeCubit extends Cubit<HomeState> {
|
|||||||
create: (context) => DevicesCubit.getInstance(),
|
create: (context) => DevicesCubit.getInstance(),
|
||||||
child: const DevicesViewBody(),
|
child: const DevicesViewBody(),
|
||||||
),
|
),
|
||||||
const SceneView(),
|
const RoutinesView(),
|
||||||
const MenuView(),
|
const MenuView(),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||||
import 'package:syncrow_app/features/auth/model/login_with_email_model.dart';
|
import 'package:syncrow_app/features/auth/model/login_with_email_model.dart';
|
||||||
import 'package:syncrow_app/features/auth/model/signup_model.dart';
|
import 'package:syncrow_app/features/auth/model/signup_model.dart';
|
||||||
@ -217,9 +218,22 @@ class AuthCubit extends Cubit<AuthState> {
|
|||||||
signUp() async {
|
signUp() async {
|
||||||
emit(AuthLoginLoading());
|
emit(AuthLoginLoading());
|
||||||
final response;
|
final response;
|
||||||
|
|
||||||
|
final clientId = dotenv.env['CLIENT_ID'] ?? '';
|
||||||
|
final clientSecret = dotenv.env['CLIENT_SECRET'] ?? '';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
List<String> userFullName = fullName.split(' ');
|
List<String> userFullName = fullName.split(' ');
|
||||||
|
|
||||||
|
final clientToken = await AuthenticationAPI.fetchClientToken(
|
||||||
|
clientId: clientId,
|
||||||
|
clientSecret: clientSecret,
|
||||||
|
);
|
||||||
|
|
||||||
|
final accessToken = clientToken['accessToken'];
|
||||||
|
|
||||||
response = await AuthenticationAPI.signUp(
|
response = await AuthenticationAPI.signUp(
|
||||||
|
accessToken: accessToken,
|
||||||
model: SignUpModel(
|
model: SignUpModel(
|
||||||
hasAcceptedAppAgreement: true,
|
hasAcceptedAppAgreement: true,
|
||||||
email: email.toLowerCase(),
|
email: email.toLowerCase(),
|
||||||
|
27
lib/features/auth/model/project_model.dart
Normal file
27
lib/features/auth/model/project_model.dart
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
class Project {
|
||||||
|
final String uuid;
|
||||||
|
final String name;
|
||||||
|
final String description;
|
||||||
|
|
||||||
|
const Project({
|
||||||
|
required this.uuid,
|
||||||
|
required this.name,
|
||||||
|
required this.description,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory Project.fromJson(Map<String, dynamic> json) {
|
||||||
|
return Project(
|
||||||
|
uuid: json['uuid'] as String,
|
||||||
|
name: json['name'] as String,
|
||||||
|
description: json['description'] as String,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
return {
|
||||||
|
'uuid': uuid,
|
||||||
|
'name': name,
|
||||||
|
'description': description,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:syncrow_app/features/auth/model/project_model.dart';
|
||||||
import 'package:syncrow_app/features/auth/model/token.dart';
|
import 'package:syncrow_app/features/auth/model/token.dart';
|
||||||
|
|
||||||
class UserModel {
|
class UserModel {
|
||||||
@ -20,6 +21,7 @@ class UserModel {
|
|||||||
final bool? hasAcceptedAppAgreement;
|
final bool? hasAcceptedAppAgreement;
|
||||||
final DateTime? appAgreementAcceptedAt;
|
final DateTime? appAgreementAcceptedAt;
|
||||||
final Role? role;
|
final Role? role;
|
||||||
|
final Project? project;
|
||||||
|
|
||||||
UserModel({
|
UserModel({
|
||||||
required this.uuid,
|
required this.uuid,
|
||||||
@ -38,6 +40,7 @@ class UserModel {
|
|||||||
required this.hasAcceptedAppAgreement,
|
required this.hasAcceptedAppAgreement,
|
||||||
required this.appAgreementAcceptedAt,
|
required this.appAgreementAcceptedAt,
|
||||||
required this.role,
|
required this.role,
|
||||||
|
required this.project,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory UserModel.fromJson(Map<String, dynamic> json) {
|
factory UserModel.fromJson(Map<String, dynamic> json) {
|
||||||
@ -62,33 +65,35 @@ class UserModel {
|
|||||||
? DateTime.parse(json['appAgreementAcceptedAt'])
|
? DateTime.parse(json['appAgreementAcceptedAt'])
|
||||||
: null,
|
: null,
|
||||||
role: json['role'] != null ? Role.fromJson(json['role']) : null,
|
role: json['role'] != null ? Role.fromJson(json['role']) : null,
|
||||||
|
project:
|
||||||
|
json['project'] != null ? Project.fromJson(json['project']) : null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
factory UserModel.fromToken(Token token) {
|
factory UserModel.fromToken(Token token) {
|
||||||
Map<String, dynamic> tempJson = Token.decodeToken(token.accessToken);
|
Map<String, dynamic> tempJson = Token.decodeToken(token.accessToken);
|
||||||
return UserModel(
|
return UserModel(
|
||||||
uuid: tempJson['uuid'].toString(),
|
uuid: tempJson['uuid'].toString(),
|
||||||
email: tempJson['email'],
|
email: tempJson['email'],
|
||||||
lastName: tempJson['lastName'],
|
lastName: tempJson['lastName'],
|
||||||
firstName: tempJson['firstName'],
|
firstName: tempJson['firstName'],
|
||||||
profilePicture: UserModel.decodeBase64Image(tempJson['profilePicture']),
|
profilePicture: UserModel.decodeBase64Image(tempJson['profilePicture']),
|
||||||
phoneNumber: null,
|
phoneNumber: null,
|
||||||
isEmailVerified: null,
|
isEmailVerified: null,
|
||||||
isAgreementAccepted: null,
|
isAgreementAccepted: null,
|
||||||
regionUuid: null,
|
regionUuid: null,
|
||||||
regionName: tempJson['region']?['regionName'],
|
regionName: tempJson['region']?['regionName'],
|
||||||
timeZone: tempJson['timezone']?['timeZoneOffset'],
|
timeZone: tempJson['timezone']?['timeZoneOffset'],
|
||||||
hasAcceptedWebAgreement: tempJson['hasAcceptedWebAgreement'],
|
hasAcceptedWebAgreement: tempJson['hasAcceptedWebAgreement'],
|
||||||
webAgreementAcceptedAt: tempJson['webAgreementAcceptedAt'] != null
|
webAgreementAcceptedAt: tempJson['webAgreementAcceptedAt'] != null
|
||||||
? DateTime.parse(tempJson['webAgreementAcceptedAt'])
|
? DateTime.parse(tempJson['webAgreementAcceptedAt'])
|
||||||
: null,
|
: null,
|
||||||
hasAcceptedAppAgreement: tempJson['hasAcceptedAppAgreement'],
|
hasAcceptedAppAgreement: tempJson['hasAcceptedAppAgreement'],
|
||||||
appAgreementAcceptedAt: tempJson['appAgreementAcceptedAt'] != null
|
appAgreementAcceptedAt: tempJson['appAgreementAcceptedAt'] != null
|
||||||
? DateTime.parse(tempJson['appAgreementAcceptedAt'])
|
? DateTime.parse(tempJson['appAgreementAcceptedAt'])
|
||||||
: null,
|
: null,
|
||||||
role: tempJson['role'] != null ? Role.fromJson(tempJson['role']) : null,
|
role: tempJson['role'] != null ? Role.fromJson(tempJson['role']) : null,
|
||||||
);
|
project: null);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Uint8List? decodeBase64Image(String? base64String) {
|
static Uint8List? decodeBase64Image(String? base64String) {
|
||||||
@ -137,8 +142,10 @@ class Role {
|
|||||||
factory Role.fromJson(Map<String, dynamic> json) {
|
factory Role.fromJson(Map<String, dynamic> json) {
|
||||||
return Role(
|
return Role(
|
||||||
uuid: json['uuid'],
|
uuid: json['uuid'],
|
||||||
createdAt: json['createdAt'] != null ? DateTime.parse(json['createdAt']) : null,
|
createdAt:
|
||||||
updatedAt: json['updatedAt'] != null ? DateTime.parse(json['updatedAt']) : null,
|
json['createdAt'] != null ? DateTime.parse(json['createdAt']) : null,
|
||||||
|
updatedAt:
|
||||||
|
json['updatedAt'] != null ? DateTime.parse(json['updatedAt']) : null,
|
||||||
type: json['type'],
|
type: json['type'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
19
lib/features/common/bloc/project_cubit.dart
Normal file
19
lib/features/common/bloc/project_cubit.dart
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||||
|
|
||||||
|
class ProjectCubit extends Cubit<String?> {
|
||||||
|
final FlutterSecureStorage storage;
|
||||||
|
static const String projectKey = "selected_project_uuid";
|
||||||
|
|
||||||
|
ProjectCubit(this.storage) : super(null);
|
||||||
|
|
||||||
|
Future<void> setProjectUUID(String newUUID) async {
|
||||||
|
await storage.write(key: projectKey, value: newUUID);
|
||||||
|
emit(newUUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> clearProjectUUID() async {
|
||||||
|
await storage.delete(key: projectKey);
|
||||||
|
emit(null);
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,7 @@ import 'dart:async';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||||
|
import 'package:syncrow_app/features/auth/model/project_model.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/6_scene_switch_bloc/6_scene_event.dart';
|
import 'package:syncrow_app/features/devices/bloc/6_scene_switch_bloc/6_scene_event.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/6_scene_switch_bloc/6_scene_state.dart';
|
import 'package:syncrow_app/features/devices/bloc/6_scene_switch_bloc/6_scene_state.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
||||||
@ -16,6 +17,7 @@ import 'package:syncrow_app/services/api/devices_api.dart';
|
|||||||
import 'package:syncrow_app/services/api/home_management_api.dart';
|
import 'package:syncrow_app/services/api/home_management_api.dart';
|
||||||
import 'package:syncrow_app/services/api/scene_api.dart';
|
import 'package:syncrow_app/services/api/scene_api.dart';
|
||||||
import 'package:syncrow_app/services/api/spaces_api.dart';
|
import 'package:syncrow_app/services/api/spaces_api.dart';
|
||||||
|
import 'package:syncrow_app/utils/constants/temp_const.dart';
|
||||||
import 'package:syncrow_app/utils/helpers/snack_bar.dart';
|
import 'package:syncrow_app/utils/helpers/snack_bar.dart';
|
||||||
|
|
||||||
class SixSceneBloc extends Bloc<SixSceneEvent, SixSceneState> {
|
class SixSceneBloc extends Bloc<SixSceneEvent, SixSceneState> {
|
||||||
@ -112,8 +114,9 @@ class SixSceneBloc extends Bloc<SixSceneEvent, SixSceneState> {
|
|||||||
FetchRoomsEvent event, Emitter<SixSceneState> emit) async {
|
FetchRoomsEvent event, Emitter<SixSceneState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(SixSceneLoadingState());
|
emit(SixSceneLoadingState());
|
||||||
|
Project? project = HomeCubit.getInstance().project;
|
||||||
roomsList = await SpacesAPI.getSubSpaceBySpaceId(
|
roomsList = await SpacesAPI.getSubSpaceBySpaceId(
|
||||||
event.unit.community.uuid, event.unit.id);
|
event.unit.community.uuid, event.unit.id, project?.uuid ?? TempConst.projectIdDev);
|
||||||
emit(FetchRoomsState(devicesList: allDevices, roomsList: roomsList));
|
emit(FetchRoomsState(devicesList: allDevices, roomsList: roomsList));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(SixSceneFailedState(errorMessage: e.toString()));
|
emit(SixSceneFailedState(errorMessage: e.toString()));
|
||||||
@ -125,12 +128,14 @@ class SixSceneBloc extends Bloc<SixSceneEvent, SixSceneState> {
|
|||||||
try {
|
try {
|
||||||
emit(SixSceneLoadingState());
|
emit(SixSceneLoadingState());
|
||||||
if (_hasSelectionChanged) {
|
if (_hasSelectionChanged) {
|
||||||
|
Project? project = HomeCubit.getInstance().project;
|
||||||
await HomeManagementAPI.assignDeviceToRoom(
|
await HomeManagementAPI.assignDeviceToRoom(
|
||||||
event.unit.community.uuid, event.unit.id, event.roomId, sixSceneId);
|
event.unit.community.uuid, event.unit.id, event.roomId, sixSceneId, project?.uuid ?? TempConst.projectIdDev);
|
||||||
final devicesList = await DevicesAPI.getDevicesByRoomId(
|
final devicesList = await DevicesAPI.getDevicesByRoomId(
|
||||||
communityUuid: event.unit.community.uuid,
|
communityUuid: event.unit.community.uuid,
|
||||||
spaceUuid: event.unit.id,
|
spaceUuid: event.unit.id,
|
||||||
roomId: event.roomId);
|
roomId: event.roomId,
|
||||||
|
projectId: project?.uuid ?? TempConst.projectIdDev);
|
||||||
List<String> allDevicesIds = [];
|
List<String> allDevicesIds = [];
|
||||||
allDevices.forEach((element) {
|
allDevices.forEach((element) {
|
||||||
allDevicesIds.add(element.uuid!);
|
allDevicesIds.add(element.uuid!);
|
||||||
@ -341,8 +346,10 @@ class SixSceneBloc extends Bloc<SixSceneEvent, SixSceneState> {
|
|||||||
emit(SixSceneLoadingState());
|
emit(SixSceneLoadingState());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
Project? project = HomeCubit.getInstance().project;
|
||||||
|
|
||||||
allScenes = await SceneApi.getScenesByUnitId(
|
allScenes = await SceneApi.getScenesByUnitId(
|
||||||
event.unitId, event.unit.community.uuid,
|
event.unitId, event.unit.community.uuid, project?.uuid ?? TempConst.projectIdDev,
|
||||||
showInDevice: event.showInDevice);
|
showInDevice: event.showInDevice);
|
||||||
|
|
||||||
filteredScenes = allScenes;
|
filteredScenes = allScenes;
|
||||||
|
@ -4,7 +4,6 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
|||||||
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_event.dart';
|
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_event.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.dart';
|
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
|
||||||
import 'package:syncrow_app/features/devices/model/ac_model.dart';
|
import 'package:syncrow_app/features/devices/model/ac_model.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||||
@ -28,7 +27,7 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
|||||||
bool allAcsPage = false;
|
bool allAcsPage = false;
|
||||||
bool allAcsOn = true;
|
bool allAcsOn = true;
|
||||||
bool allTempSame = true;
|
bool allTempSame = true;
|
||||||
int globalTemp = 25;
|
int globalTemp = 250;
|
||||||
Timer? _timer;
|
Timer? _timer;
|
||||||
|
|
||||||
ACsBloc({required this.acId}) : super(AcsInitialState()) {
|
ACsBloc({required this.acId}) : super(AcsInitialState()) {
|
||||||
@ -69,11 +68,10 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
|||||||
for (var status in response['status']) {
|
for (var status in response['status']) {
|
||||||
statusModelList.add(StatusModel.fromJson(status));
|
statusModelList.add(StatusModel.fromJson(status));
|
||||||
}
|
}
|
||||||
deviceStatus =
|
deviceStatus = AcStatusModel.fromJson(response['productUuid'], statusModelList);
|
||||||
AcStatusModel.fromJson(response['productUuid'], statusModelList);
|
|
||||||
emit(GetAcStatusState(acStatusModel: deviceStatus));
|
emit(GetAcStatusState(acStatusModel: deviceStatus));
|
||||||
Future.delayed(const Duration(milliseconds: 500));
|
Future.delayed(const Duration(milliseconds: 500));
|
||||||
// _listenToChanges();
|
_listenToChanges(acId);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(AcsFailedState(errorMessage: e.toString()));
|
emit(AcsFailedState(errorMessage: e.toString()));
|
||||||
@ -81,29 +79,38 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_listenToChanges() {
|
StreamSubscription<DatabaseEvent>? _streamSubscription;
|
||||||
|
|
||||||
|
void _listenToChanges(acId) {
|
||||||
try {
|
try {
|
||||||
|
_streamSubscription?.cancel();
|
||||||
DatabaseReference ref =
|
DatabaseReference ref =
|
||||||
FirebaseDatabase.instance.ref('device-status/$acId');
|
FirebaseDatabase.instance.ref('device-status/$acId');
|
||||||
Stream<DatabaseEvent> stream = ref.onValue;
|
Stream<DatabaseEvent> stream = ref.onValue;
|
||||||
|
|
||||||
stream.listen((DatabaseEvent event) {
|
_streamSubscription = stream.listen((DatabaseEvent event) {
|
||||||
Map<dynamic, dynamic> usersMap =
|
Map<dynamic, dynamic> usersMap =
|
||||||
event.snapshot.value as Map<dynamic, dynamic>;
|
event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
List<StatusModel> statusList = [];
|
List<StatusModel> statusList = [];
|
||||||
|
|
||||||
usersMap['status'].forEach((element) {
|
usersMap['status'].forEach((element) {
|
||||||
statusList
|
statusList.add(StatusModel(code: element['code'], value: element['value']));
|
||||||
.add(StatusModel(code: element['code'], value: element['value']));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
deviceStatus =
|
deviceStatus =
|
||||||
AcStatusModel.fromJson(usersMap['productUuid'], statusList);
|
AcStatusModel.fromJson(usersMap['productUuid'], statusList);
|
||||||
|
|
||||||
add(AcUpdated());
|
add(AcUpdated());
|
||||||
});
|
});
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> close() async {
|
||||||
|
_streamSubscription?.cancel();
|
||||||
|
_streamSubscription = null;
|
||||||
|
return super.close();
|
||||||
|
}
|
||||||
|
|
||||||
_onAcUpdated(AcUpdated event, Emitter<AcsState> emit) {
|
_onAcUpdated(AcUpdated event, Emitter<AcsState> emit) {
|
||||||
emit(GetAcStatusState(acStatusModel: deviceStatus));
|
emit(GetAcStatusState(acStatusModel: deviceStatus));
|
||||||
}
|
}
|
||||||
@ -115,15 +122,16 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
|||||||
HomeCubit.getInstance().selectedSpace?.id ?? '', 'AC');
|
HomeCubit.getInstance().selectedSpace?.id ?? '', 'AC');
|
||||||
|
|
||||||
for (int i = 0; i < devicesList.length; i++) {
|
for (int i = 0; i < devicesList.length; i++) {
|
||||||
|
_listenToChanges(devicesList[i].uuid);
|
||||||
var response =
|
var response =
|
||||||
await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
||||||
List<StatusModel> statusModelList = [];
|
List<StatusModel> statusModelList = [];
|
||||||
for (var status in response['status']) {
|
for (var status in response['status']) {
|
||||||
statusModelList.add(StatusModel.fromJson(status));
|
statusModelList.add(StatusModel.fromJson(status));
|
||||||
}
|
}
|
||||||
deviceStatusList.add(
|
deviceStatusList.add(AcStatusModel.fromJson(devicesList[i].uuid ?? '', statusModelList));
|
||||||
AcStatusModel.fromJson(response['productUuid'], statusModelList));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_setAllAcsTempsAndSwitches();
|
_setAllAcsTempsAndSwitches();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,7 +140,7 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
|||||||
if (allAcsPage) {
|
if (allAcsPage) {
|
||||||
emit(AcsLoadingState());
|
emit(AcsLoadingState());
|
||||||
for (AcStatusModel ac in deviceStatusList) {
|
for (AcStatusModel ac in deviceStatusList) {
|
||||||
if (ac.uuid == event.productId) {
|
if (ac.uuid == event.deviceId) {
|
||||||
ac.acSwitch = acSwitchValue;
|
ac.acSwitch = acSwitchValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -145,8 +153,7 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
|||||||
emit(AcModifyingState(acStatusModel: deviceStatus));
|
emit(AcModifyingState(acStatusModel: deviceStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
await _runDeBouncerForOneDevice(
|
await _runDeBouncerForOneDevice(deviceId: event.deviceId, code: 'switch', value: acSwitchValue);
|
||||||
deviceId: event.deviceId, code: 'switch', value: acSwitchValue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeAllAcSwitch(ChangeAllSwitch event, Emitter<AcsState> emit) async {
|
void _changeAllAcSwitch(ChangeAllSwitch event, Emitter<AcsState> emit) async {
|
||||||
@ -207,8 +214,7 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
|||||||
deviceStatus.childLock = lockValue;
|
deviceStatus.childLock = lockValue;
|
||||||
emit(AcModifyingState(acStatusModel: deviceStatus));
|
emit(AcModifyingState(acStatusModel: deviceStatus));
|
||||||
|
|
||||||
await _runDeBouncerForOneDevice(
|
await _runDeBouncerForOneDevice(deviceId: acId, code: 'child_lock', value: lockValue);
|
||||||
deviceId: acId, code: 'child_lock', value: lockValue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _increaseCoolTo(IncreaseCoolToTemp event, Emitter<AcsState> emit) async {
|
void _increaseCoolTo(IncreaseCoolToTemp event, Emitter<AcsState> emit) async {
|
||||||
@ -224,7 +230,7 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
|||||||
if (allAcsPage) {
|
if (allAcsPage) {
|
||||||
emit(AcsLoadingState());
|
emit(AcsLoadingState());
|
||||||
for (AcStatusModel ac in deviceStatusList) {
|
for (AcStatusModel ac in deviceStatusList) {
|
||||||
if (ac.uuid == event.productId) {
|
if (ac.uuid == event.deviceId) {
|
||||||
ac.tempSet = value;
|
ac.tempSet = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -236,8 +242,7 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
|||||||
emit(AcModifyingState(acStatusModel: deviceStatus));
|
emit(AcModifyingState(acStatusModel: deviceStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
await _runDeBouncerForOneDevice(
|
await _runDeBouncerForOneDevice(deviceId: event.deviceId, code: 'temp_set', value: value);
|
||||||
deviceId: event.deviceId, code: 'temp_set', value: value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _decreaseCoolTo(DecreaseCoolToTemp event, Emitter<AcsState> emit) async {
|
void _decreaseCoolTo(DecreaseCoolToTemp event, Emitter<AcsState> emit) async {
|
||||||
@ -253,7 +258,7 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
|||||||
if (allAcsPage) {
|
if (allAcsPage) {
|
||||||
emit(AcsLoadingState());
|
emit(AcsLoadingState());
|
||||||
for (AcStatusModel ac in deviceStatusList) {
|
for (AcStatusModel ac in deviceStatusList) {
|
||||||
if (ac.uuid == event.productId) {
|
if (ac.uuid == event.deviceId) {
|
||||||
ac.tempSet = value;
|
ac.tempSet = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -265,8 +270,7 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
|||||||
emit(AcModifyingState(acStatusModel: deviceStatus));
|
emit(AcModifyingState(acStatusModel: deviceStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
await _runDeBouncerForOneDevice(
|
await _runDeBouncerForOneDevice(deviceId: event.deviceId, code: 'temp_set', value: value);
|
||||||
deviceId: event.deviceId, code: 'temp_set', value: value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeAcMode(ChangeAcMode event, Emitter<AcsState> emit) async {
|
void _changeAcMode(ChangeAcMode event, Emitter<AcsState> emit) async {
|
||||||
@ -274,7 +278,7 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
|||||||
if (allAcsPage) {
|
if (allAcsPage) {
|
||||||
emit(AcsLoadingState());
|
emit(AcsLoadingState());
|
||||||
for (AcStatusModel ac in deviceStatusList) {
|
for (AcStatusModel ac in deviceStatusList) {
|
||||||
if (ac.uuid == event.productId) {
|
if (ac.uuid == event.deviceId) {
|
||||||
ac.modeString = getACModeString(tempMode);
|
ac.modeString = getACModeString(tempMode);
|
||||||
ac.acMode = AcStatusModel.getACMode(getACModeString(tempMode));
|
ac.acMode = AcStatusModel.getACMode(getACModeString(tempMode));
|
||||||
}
|
}
|
||||||
@ -288,9 +292,7 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await _runDeBouncerForOneDevice(
|
await _runDeBouncerForOneDevice(
|
||||||
deviceId: event.deviceId,
|
deviceId: event.deviceId, code: 'mode', value: getACModeString(tempMode));
|
||||||
code: 'mode',
|
|
||||||
value: getACModeString(tempMode));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeFanSpeed(ChangeFanSpeed event, Emitter<AcsState> emit) async {
|
void _changeFanSpeed(ChangeFanSpeed event, Emitter<AcsState> emit) async {
|
||||||
@ -301,25 +303,21 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
|||||||
if (allAcsPage) {
|
if (allAcsPage) {
|
||||||
emit(AcsLoadingState());
|
emit(AcsLoadingState());
|
||||||
for (AcStatusModel ac in deviceStatusList) {
|
for (AcStatusModel ac in deviceStatusList) {
|
||||||
if (ac.uuid == event.productId) {
|
if (ac.uuid == event.deviceId) {
|
||||||
ac.fanSpeedsString = getNextFanSpeedKey(fanSpeed);
|
ac.fanSpeedsString = getNextFanSpeedKey(fanSpeed);
|
||||||
ac.acFanSpeed =
|
ac.acFanSpeed = AcStatusModel.getFanSpeed(getNextFanSpeedKey(fanSpeed));
|
||||||
AcStatusModel.getFanSpeed(getNextFanSpeedKey(fanSpeed));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_emitAcsStatus(emit);
|
_emitAcsStatus(emit);
|
||||||
} else {
|
} else {
|
||||||
emit(AcChangeLoading(acStatusModel: deviceStatus));
|
emit(AcChangeLoading(acStatusModel: deviceStatus));
|
||||||
deviceStatus.fanSpeedsString = getNextFanSpeedKey(fanSpeed);
|
deviceStatus.fanSpeedsString = getNextFanSpeedKey(fanSpeed);
|
||||||
deviceStatus.acFanSpeed =
|
deviceStatus.acFanSpeed = AcStatusModel.getFanSpeed(getNextFanSpeedKey(fanSpeed));
|
||||||
AcStatusModel.getFanSpeed(getNextFanSpeedKey(fanSpeed));
|
|
||||||
emit(AcModifyingState(acStatusModel: deviceStatus));
|
emit(AcModifyingState(acStatusModel: deviceStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
await _runDeBouncerForOneDevice(
|
await _runDeBouncerForOneDevice(
|
||||||
deviceId: event.deviceId,
|
deviceId: event.deviceId, code: 'level', value: getNextFanSpeedKey(fanSpeed));
|
||||||
code: 'level',
|
|
||||||
value: getNextFanSpeedKey(fanSpeed));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String getACModeString(TempModes value) {
|
String getACModeString(TempModes value) {
|
||||||
@ -338,17 +336,15 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
|||||||
allAcsOn = true;
|
allAcsOn = true;
|
||||||
allTempSame = true;
|
allTempSame = true;
|
||||||
if (deviceStatusList.isNotEmpty) {
|
if (deviceStatusList.isNotEmpty) {
|
||||||
int temp = deviceStatusList[0].tempSet;
|
int temp = deviceStatusList.first.tempSet;
|
||||||
deviceStatusList.firstWhere((element) {
|
for (var element in deviceStatusList) {
|
||||||
if (!element.acSwitch) {
|
if (!element.acSwitch) {
|
||||||
allAcsOn = false;
|
allAcsOn = false;
|
||||||
}
|
}
|
||||||
if (element.tempSet != temp) {
|
if (element.tempSet != temp) {
|
||||||
allTempSame = false;
|
allTempSame = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
|
||||||
});
|
|
||||||
if (allTempSame) {
|
if (allTempSame) {
|
||||||
globalTemp = temp;
|
globalTemp = temp;
|
||||||
}
|
}
|
||||||
@ -364,8 +360,7 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
|||||||
for (int i = 0; i < deviceStatusList.length; i++) {
|
for (int i = 0; i < deviceStatusList.length; i++) {
|
||||||
try {
|
try {
|
||||||
await DevicesAPI.controlDevice(
|
await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(deviceId: devicesList[i].uuid, code: code, value: value),
|
||||||
deviceId: devicesList[i].uuid, code: code, value: value),
|
|
||||||
devicesList[i].uuid ?? '');
|
devicesList[i].uuid ?? '');
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
await Future.delayed(const Duration(milliseconds: 500));
|
await Future.delayed(const Duration(milliseconds: 500));
|
||||||
@ -387,10 +382,7 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
|||||||
_timer = Timer(const Duration(seconds: 1), () async {
|
_timer = Timer(const Duration(seconds: 1), () async {
|
||||||
try {
|
try {
|
||||||
final response = await DevicesAPI.controlDevice(
|
final response = await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(deviceId: allAcsPage ? deviceId : acId, code: code, value: value),
|
||||||
deviceId: allAcsPage ? deviceId : acId,
|
|
||||||
code: code,
|
|
||||||
value: value),
|
|
||||||
allAcsPage ? deviceId : acId);
|
allAcsPage ? deviceId : acId);
|
||||||
|
|
||||||
if (!response['success']) {
|
if (!response['success']) {
|
||||||
@ -407,8 +399,7 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
|||||||
if (value >= 20 && value <= 30) {
|
if (value >= 20 && value <= 30) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
emit(const AcsFailedState(
|
emit(const AcsFailedState(errorMessage: 'The temperature must be between 20 and 30'));
|
||||||
errorMessage: 'The temperature must be between 20 and 30'));
|
|
||||||
emit(GetAllAcsStatusState(
|
emit(GetAllAcsStatusState(
|
||||||
allAcsStatues: deviceStatusList,
|
allAcsStatues: deviceStatusList,
|
||||||
allAcs: devicesList,
|
allAcs: devicesList,
|
||||||
@ -434,9 +425,7 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
|||||||
try {
|
try {
|
||||||
seconds = event.seconds;
|
seconds = event.seconds;
|
||||||
final response = await DevicesAPI.controlDevice(
|
final response = await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(deviceId: acId, code: 'countdown_time', value: event.duration), acId);
|
||||||
deviceId: acId, code: 'countdown_time', value: event.duration),
|
|
||||||
acId);
|
|
||||||
|
|
||||||
if (response['success'] ?? false) {
|
if (response['success'] ?? false) {
|
||||||
deviceStatus.countdown1 = seconds;
|
deviceStatus.countdown1 = seconds;
|
||||||
@ -463,8 +452,7 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
|||||||
for (var status in response['status']) {
|
for (var status in response['status']) {
|
||||||
statusModelList.add(StatusModel.fromJson(status));
|
statusModelList.add(StatusModel.fromJson(status));
|
||||||
}
|
}
|
||||||
deviceStatus =
|
deviceStatus = AcStatusModel.fromJson(response['productUuid'], statusModelList);
|
||||||
AcStatusModel.fromJson(response['productUuid'], statusModelList);
|
|
||||||
deviceStatus.countdown1;
|
deviceStatus.countdown1;
|
||||||
var duration;
|
var duration;
|
||||||
if (deviceStatus.countdown1 == 5) {
|
if (deviceStatus.countdown1 == 5) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import 'dart:convert';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:firebase_database/firebase_database.dart';
|
import 'package:firebase_database/firebase_database.dart';
|
||||||
@ -35,35 +35,49 @@ class CeilingSensorBloc extends Bloc<CeilingSensorEvent, CeilingSensorState> {
|
|||||||
}
|
}
|
||||||
deviceStatus = CeilingSensorModel.fromJson(statusModelList);
|
deviceStatus = CeilingSensorModel.fromJson(statusModelList);
|
||||||
emit(UpdateState(ceilingSensorModel: deviceStatus));
|
emit(UpdateState(ceilingSensorModel: deviceStatus));
|
||||||
// _listenToChanges();
|
_listenToChanges();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(FailedState(error: e.toString()));
|
emit(FailedState(error: e.toString()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_listenToChanges() {
|
StreamSubscription<DatabaseEvent>? _streamSubscription;
|
||||||
|
Timer? _timer;
|
||||||
|
|
||||||
|
void _listenToChanges() {
|
||||||
try {
|
try {
|
||||||
|
_streamSubscription?.cancel();
|
||||||
DatabaseReference ref =
|
DatabaseReference ref =
|
||||||
FirebaseDatabase.instance.ref('device-status/$deviceId');
|
FirebaseDatabase.instance.ref('device-status/$deviceId');
|
||||||
Stream<DatabaseEvent> stream = ref.onValue;
|
Stream<DatabaseEvent> stream = ref.onValue;
|
||||||
|
|
||||||
stream.listen((DatabaseEvent event) {
|
_streamSubscription = stream.listen((DatabaseEvent event) async {
|
||||||
|
if (_timer != null) {
|
||||||
|
await Future.delayed(const Duration(seconds: 2));
|
||||||
|
}
|
||||||
Map<dynamic, dynamic> usersMap =
|
Map<dynamic, dynamic> usersMap =
|
||||||
event.snapshot.value as Map<dynamic, dynamic>;
|
event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
List<StatusModel> statusList = [];
|
List<StatusModel> statusList = [];
|
||||||
|
|
||||||
usersMap['status'].forEach((element) {
|
usersMap['status'].forEach((element) {
|
||||||
statusList
|
statusList
|
||||||
.add(StatusModel(code: element['code'], value: element['value']));
|
.add(StatusModel(code: element['code'], value: element['value']));
|
||||||
});
|
});
|
||||||
|
|
||||||
deviceStatus = CeilingSensorModel.fromJson(statusList);
|
deviceStatus = CeilingSensorModel.fromJson(statusList);
|
||||||
add(CeilingSensorUpdated());
|
if (!isClosed) {
|
||||||
|
add(CeilingSensorUpdated());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> close() async {
|
||||||
|
_streamSubscription?.cancel();
|
||||||
|
_streamSubscription = null;
|
||||||
|
return super.close();
|
||||||
|
}
|
||||||
|
|
||||||
_onCeilingSensorUpdated(
|
_onCeilingSensorUpdated(
|
||||||
CeilingSensorUpdated event, Emitter<CeilingSensorState> emit) {
|
CeilingSensorUpdated event, Emitter<CeilingSensorState> emit) {
|
||||||
emit(UpdateState(ceilingSensorModel: deviceStatus));
|
emit(UpdateState(ceilingSensorModel: deviceStatus));
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
import 'package:firebase_database/firebase_database.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/curtain_bloc/curtain_event.dart';
|
import 'package:syncrow_app/features/devices/bloc/curtain_bloc/curtain_event.dart';
|
||||||
@ -30,6 +32,7 @@ class CurtainBloc extends Bloc<CurtainEvent, CurtainState> {
|
|||||||
on<InitialWizardEvent>(_fetchWizardStatus);
|
on<InitialWizardEvent>(_fetchWizardStatus);
|
||||||
on<GroupAllOffEvent>(_groupAllOff);
|
on<GroupAllOffEvent>(_groupAllOff);
|
||||||
on<GroupAllOnEvent>(_groupAllOn);
|
on<GroupAllOnEvent>(_groupAllOn);
|
||||||
|
on<UpdateCurtainEvent>(_updateCurtain);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onOpenCurtain(
|
Future<void> _onOpenCurtain(
|
||||||
@ -161,7 +164,10 @@ class CurtainBloc extends Bloc<CurtainEvent, CurtainState> {
|
|||||||
void _fetchStatus(InitCurtain event, Emitter<CurtainState> emit) async {
|
void _fetchStatus(InitCurtain event, Emitter<CurtainState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(CurtainLoadingState());
|
emit(CurtainLoadingState());
|
||||||
|
_listenToChanges(curtainId);
|
||||||
|
|
||||||
var response = await DevicesAPI.getDeviceStatus(curtainId);
|
var response = await DevicesAPI.getDeviceStatus(curtainId);
|
||||||
|
|
||||||
List<StatusModel> statusModelList = [];
|
List<StatusModel> statusModelList = [];
|
||||||
for (var status in response['status']) {
|
for (var status in response['status']) {
|
||||||
statusModelList.add(StatusModel.fromJson(status));
|
statusModelList.add(StatusModel.fromJson(status));
|
||||||
@ -169,7 +175,6 @@ class CurtainBloc extends Bloc<CurtainEvent, CurtainState> {
|
|||||||
openPercentage = double.tryParse(statusModelList[1].value.toString())!;
|
openPercentage = double.tryParse(statusModelList[1].value.toString())!;
|
||||||
curtainWidth = 270 - (openPercentage / 100) * curtainOpeningSpace;
|
curtainWidth = 270 - (openPercentage / 100) * curtainOpeningSpace;
|
||||||
blindHeight = 310 - (openPercentage / 100) * blindOpeningSpace;
|
blindHeight = 310 - (openPercentage / 100) * blindOpeningSpace;
|
||||||
|
|
||||||
emit(CurtainsOpening(
|
emit(CurtainsOpening(
|
||||||
curtainWidth: curtainWidth,
|
curtainWidth: curtainWidth,
|
||||||
blindHeight: blindHeight,
|
blindHeight: blindHeight,
|
||||||
@ -181,6 +186,76 @@ class CurtainBloc extends Bloc<CurtainEvent, CurtainState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StreamSubscription<DatabaseEvent>? _streamSubscription;
|
||||||
|
|
||||||
|
void _listenToChanges(curtainId) {
|
||||||
|
try {
|
||||||
|
_streamSubscription?.cancel();
|
||||||
|
DatabaseReference ref =
|
||||||
|
FirebaseDatabase.instance.ref('device-status/$curtainId');
|
||||||
|
Stream<DatabaseEvent> stream = ref.onValue;
|
||||||
|
|
||||||
|
_streamSubscription = stream.listen((DatabaseEvent event) {
|
||||||
|
Map<dynamic, dynamic> usersMap =
|
||||||
|
event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
|
List<StatusModel> statusList = [];
|
||||||
|
|
||||||
|
usersMap['status'].forEach((element) {
|
||||||
|
statusList
|
||||||
|
.add(StatusModel(code: element['code'], value: element['value']));
|
||||||
|
});
|
||||||
|
openPercentage = double.tryParse(statusList[1].value.toString())!;
|
||||||
|
curtainWidth = 270 - (openPercentage / 100) * curtainOpeningSpace;
|
||||||
|
blindHeight = 310 - (openPercentage / 100) * blindOpeningSpace;
|
||||||
|
add(UpdateCurtainEvent());
|
||||||
|
});
|
||||||
|
} catch (_) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> close() async {
|
||||||
|
_streamSubscription?.cancel();
|
||||||
|
_streamSubscription = null;
|
||||||
|
return super.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// _listenToChanges(curtainId) {
|
||||||
|
// try {
|
||||||
|
// print('curtainId=$curtainId');
|
||||||
|
// DatabaseReference ref =
|
||||||
|
// FirebaseDatabase.instance.ref('device-status/$curtainId');
|
||||||
|
// Stream<DatabaseEvent> stream = ref.onValue;
|
||||||
|
|
||||||
|
// stream.listen((DatabaseEvent event) async {
|
||||||
|
// if (_timer != null) {
|
||||||
|
// await Future.delayed(const Duration(seconds: 2));
|
||||||
|
// }
|
||||||
|
// Map<dynamic, dynamic> usersMap =
|
||||||
|
// event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
|
// List<StatusModel> statusModelList = [];
|
||||||
|
// for (var status in usersMap['status']) {
|
||||||
|
// statusModelList.add(StatusModel.fromJson(status));
|
||||||
|
// print('statusModelList==${statusModelList}');
|
||||||
|
// }
|
||||||
|
|
||||||
|
// openPercentage = double.tryParse(statusModelList[1].value.toString())!;
|
||||||
|
// curtainWidth = 270 - (openPercentage / 100) * curtainOpeningSpace;
|
||||||
|
// blindHeight = 310 - (openPercentage / 100) * blindOpeningSpace;
|
||||||
|
// add(UpdateCurtainEvent());
|
||||||
|
// });
|
||||||
|
// } catch (_) {}
|
||||||
|
// }
|
||||||
|
|
||||||
|
_updateCurtain(UpdateCurtainEvent event, Emitter<CurtainState> emit) {
|
||||||
|
curtainWidth = 270 - (openPercentage / 100) * curtainOpeningSpace;
|
||||||
|
blindHeight = 310 - (openPercentage / 100) * blindOpeningSpace;
|
||||||
|
emit(CurtainsOpening(
|
||||||
|
curtainWidth: curtainWidth,
|
||||||
|
blindHeight: blindHeight,
|
||||||
|
openPercentage: openPercentage,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
List<GroupCurtainModel> groupList = [];
|
List<GroupCurtainModel> groupList = [];
|
||||||
bool allSwitchesOn = true;
|
bool allSwitchesOn = true;
|
||||||
List<DeviceModel> devicesList = [];
|
List<DeviceModel> devicesList = [];
|
||||||
|
@ -33,6 +33,7 @@ class InitCurtain extends CurtainEvent {}
|
|||||||
class PauseCurtain extends CurtainEvent {}
|
class PauseCurtain extends CurtainEvent {}
|
||||||
class useCurtainEvent extends CurtainEvent {}
|
class useCurtainEvent extends CurtainEvent {}
|
||||||
class InitialWizardEvent extends CurtainEvent {}
|
class InitialWizardEvent extends CurtainEvent {}
|
||||||
|
class UpdateCurtainEvent extends CurtainEvent {}
|
||||||
|
|
||||||
|
|
||||||
class ChangeFirstWizardSwitchStatusEvent extends CurtainEvent {
|
class ChangeFirstWizardSwitchStatusEvent extends CurtainEvent {
|
||||||
|
@ -2,6 +2,8 @@ import 'dart:async';
|
|||||||
|
|
||||||
import 'package:bloc/bloc.dart';
|
import 'package:bloc/bloc.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||||
|
import 'package:syncrow_app/features/auth/model/project_model.dart';
|
||||||
|
|
||||||
import 'package:syncrow_app/features/devices/bloc/device_manager_bloc/device_manager_event.dart';
|
import 'package:syncrow_app/features/devices/bloc/device_manager_bloc/device_manager_event.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/device_manager_bloc/device_manager_state.dart';
|
import 'package:syncrow_app/features/devices/bloc/device_manager_bloc/device_manager_state.dart';
|
||||||
@ -10,6 +12,7 @@ import 'package:syncrow_app/features/devices/model/device_model.dart';
|
|||||||
|
|
||||||
import 'package:syncrow_app/services/api/devices_api.dart';
|
import 'package:syncrow_app/services/api/devices_api.dart';
|
||||||
import 'package:syncrow_app/services/api/home_management_api.dart';
|
import 'package:syncrow_app/services/api/home_management_api.dart';
|
||||||
|
import 'package:syncrow_app/utils/constants/temp_const.dart';
|
||||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||||
|
|
||||||
class DeviceManagerBloc extends Bloc<DeviceManagerEvent, DeviceManagerState> {
|
class DeviceManagerBloc extends Bloc<DeviceManagerEvent, DeviceManagerState> {
|
||||||
@ -27,11 +30,16 @@ class DeviceManagerBloc extends Bloc<DeviceManagerEvent, DeviceManagerState> {
|
|||||||
|
|
||||||
static List<DevicesCategoryModel>? allCategories;
|
static List<DevicesCategoryModel>? allCategories;
|
||||||
|
|
||||||
Future<void> _onFetchAllDevices(FetchAllDevices event, Emitter<DeviceManagerState> emit) async {
|
Future<void> _onFetchAllDevices(
|
||||||
|
FetchAllDevices event, Emitter<DeviceManagerState> emit) async {
|
||||||
emit(state.copyWith(loading: true));
|
emit(state.copyWith(loading: true));
|
||||||
try {
|
try {
|
||||||
final allDevices = await HomeManagementAPI.fetchDevicesByUnitId();
|
Project? project = HomeCubit.getInstance().project;
|
||||||
emit(state.copyWith(devices: _getOnlyImplementedDevices(allDevices), loading: false));
|
|
||||||
|
final allDevices = await HomeManagementAPI.fetchDevicesByUnitId(
|
||||||
|
project?.uuid ?? TempConst.projectIdDev);
|
||||||
|
emit(state.copyWith(
|
||||||
|
devices: _getOnlyImplementedDevices(allDevices), loading: false));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(state.copyWith(error: e.toString(), loading: false));
|
emit(state.copyWith(error: e.toString(), loading: false));
|
||||||
}
|
}
|
||||||
@ -41,26 +49,31 @@ class DeviceManagerBloc extends Bloc<DeviceManagerEvent, DeviceManagerState> {
|
|||||||
FetchDevicesByRoomId event, Emitter<DeviceManagerState> emit) async {
|
FetchDevicesByRoomId event, Emitter<DeviceManagerState> emit) async {
|
||||||
emit(state.copyWith(loading: true));
|
emit(state.copyWith(loading: true));
|
||||||
try {
|
try {
|
||||||
final devices = await DevicesAPI.getDevicesByRoomId(
|
Project? project = HomeCubit.getInstance().project;
|
||||||
communityUuid: event.unit.community.uuid,
|
|
||||||
spaceUuid: event.unit.id,
|
|
||||||
roomId: event.roomId,
|
|
||||||
);
|
|
||||||
|
|
||||||
emit(state.copyWith(devices: _getOnlyImplementedDevices(devices), loading: false));
|
final devices = await DevicesAPI.getDevicesByRoomId(
|
||||||
|
communityUuid: event.unit.community.uuid,
|
||||||
|
spaceUuid: event.unit.id,
|
||||||
|
roomId: event.roomId,
|
||||||
|
projectId: project?.uuid ?? TempConst.projectIdDev);
|
||||||
|
|
||||||
|
emit(state.copyWith(
|
||||||
|
devices: _getOnlyImplementedDevices(devices), loading: false));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(state.copyWith(error: e.toString(), loading: false));
|
emit(state.copyWith(error: e.toString(), loading: false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onSelectCategory(SelectCategory event, Emitter<DeviceManagerState> emit) {
|
void _onSelectCategory(
|
||||||
|
SelectCategory event, Emitter<DeviceManagerState> emit) {
|
||||||
for (var i = 0; i < allCategories!.length; i++) {
|
for (var i = 0; i < allCategories!.length; i++) {
|
||||||
allCategories![i].isSelected = i == event.index;
|
allCategories![i].isSelected = i == event.index;
|
||||||
}
|
}
|
||||||
emit(state.copyWith(categoryChanged: true));
|
emit(state.copyWith(categoryChanged: true));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onUnselectAllCategories(UnselectAllCategories event, Emitter<DeviceManagerState> emit) {
|
void _onUnselectAllCategories(
|
||||||
|
UnselectAllCategories event, Emitter<DeviceManagerState> emit) {
|
||||||
for (var category in allCategories!) {
|
for (var category in allCategories!) {
|
||||||
category.isSelected = false;
|
category.isSelected = false;
|
||||||
}
|
}
|
||||||
@ -104,7 +117,8 @@ class DeviceManagerBloc extends Bloc<DeviceManagerEvent, DeviceManagerState> {
|
|||||||
_updateDevicesStatus(category, emit);
|
_updateDevicesStatus(category, emit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onTurnOnOffDevice(TurnOnOffDevice event, Emitter<DeviceManagerState> emit) {
|
void _onTurnOnOffDevice(
|
||||||
|
TurnOnOffDevice event, Emitter<DeviceManagerState> emit) {
|
||||||
var device = event.device;
|
var device = event.device;
|
||||||
device.isOnline = !device.isOnline!;
|
device.isOnline = !device.isOnline!;
|
||||||
DevicesCategoryModel category = allCategories!.firstWhere((category) {
|
DevicesCategoryModel category = allCategories!.firstWhere((category) {
|
||||||
@ -127,7 +141,8 @@ class DeviceManagerBloc extends Bloc<DeviceManagerEvent, DeviceManagerState> {
|
|||||||
emit(state.copyWith(categoryChanged: true)); // Set category changed state
|
emit(state.copyWith(categoryChanged: true)); // Set category changed state
|
||||||
}
|
}
|
||||||
|
|
||||||
void _updateDevicesStatus(DevicesCategoryModel category, Emitter<DeviceManagerState> emit) {
|
void _updateDevicesStatus(
|
||||||
|
DevicesCategoryModel category, Emitter<DeviceManagerState> emit) {
|
||||||
if (category.devices != null && category.devices!.isNotEmpty) {
|
if (category.devices != null && category.devices!.isNotEmpty) {
|
||||||
bool? tempStatus = category.devices![0].isOnline;
|
bool? tempStatus = category.devices![0].isOnline;
|
||||||
for (var device in category.devices!) {
|
for (var device in category.devices!) {
|
||||||
@ -147,24 +162,27 @@ class DeviceManagerBloc extends Bloc<DeviceManagerEvent, DeviceManagerState> {
|
|||||||
try {
|
try {
|
||||||
final deviceFunctions = await DevicesAPI.deviceFunctions(event.deviceId);
|
final deviceFunctions = await DevicesAPI.deviceFunctions(event.deviceId);
|
||||||
|
|
||||||
emit(state.copyWith(functionsLoading: false, deviceFunctions: deviceFunctions));
|
emit(state.copyWith(
|
||||||
|
functionsLoading: false, deviceFunctions: deviceFunctions));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(state.copyWith(functionsLoading: false, error: e.toString()));
|
emit(state.copyWith(functionsLoading: false, error: e.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_getOnlyImplementedDevices(List<DeviceModel> devices) {
|
List<DeviceModel> _getOnlyImplementedDevices(List<DeviceModel> devices) {
|
||||||
List<DeviceModel> implementedDevices = [];
|
const allowedDeviceTypes = {
|
||||||
for (int i = 0; i < devices.length; i++) {
|
DeviceType.AC,
|
||||||
if (devices[i].productType == DeviceType.AC ||
|
DeviceType.DoorLock,
|
||||||
devices[i].productType == DeviceType.DoorLock ||
|
DeviceType.Gateway,
|
||||||
devices[i].productType == DeviceType.Gateway ||
|
DeviceType.WallSensor,
|
||||||
devices[i].productType == DeviceType.WallSensor ||
|
DeviceType.CeilingSensor,
|
||||||
devices[i].productType == DeviceType.CeilingSensor ||
|
DeviceType.ThreeGang,
|
||||||
devices[i].productType == DeviceType.ThreeGang) {
|
DeviceType.OneGang,
|
||||||
implementedDevices.add(devices[i]);
|
DeviceType.TwoGang
|
||||||
}
|
};
|
||||||
}
|
|
||||||
return implementedDevices;
|
return devices
|
||||||
|
.where((device) => allowedDeviceTypes.contains(device.productType))
|
||||||
|
.toList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ import 'dart:async';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||||
|
import 'package:syncrow_app/features/auth/model/project_model.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/device_settings_bloc/device_scene_event.dart';
|
import 'package:syncrow_app/features/devices/bloc/device_settings_bloc/device_scene_event.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/device_settings_bloc/device_scene_state.dart';
|
import 'package:syncrow_app/features/devices/bloc/device_settings_bloc/device_scene_state.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||||
@ -18,6 +19,7 @@ import 'package:syncrow_app/generated/assets.dart';
|
|||||||
import 'package:syncrow_app/services/api/devices_api.dart';
|
import 'package:syncrow_app/services/api/devices_api.dart';
|
||||||
import 'package:syncrow_app/services/api/home_management_api.dart';
|
import 'package:syncrow_app/services/api/home_management_api.dart';
|
||||||
import 'package:syncrow_app/services/api/spaces_api.dart';
|
import 'package:syncrow_app/services/api/spaces_api.dart';
|
||||||
|
import 'package:syncrow_app/utils/constants/temp_const.dart';
|
||||||
import 'package:syncrow_app/utils/helpers/snack_bar.dart';
|
import 'package:syncrow_app/utils/helpers/snack_bar.dart';
|
||||||
|
|
||||||
class DeviceSettingBloc extends Bloc<DeviceSettingEvent, DeviceSettingState> {
|
class DeviceSettingBloc extends Bloc<DeviceSettingEvent, DeviceSettingState> {
|
||||||
@ -349,13 +351,20 @@ class DeviceSettingBloc extends Bloc<DeviceSettingEvent, DeviceSettingState> {
|
|||||||
AssignRoomEvent event, Emitter<DeviceSettingState> emit) async {
|
AssignRoomEvent event, Emitter<DeviceSettingState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(DeviceSettingLoadingState());
|
emit(DeviceSettingLoadingState());
|
||||||
|
Project? project = HomeCubit.getInstance().project;
|
||||||
|
|
||||||
if (_hasSelectionChanged) {
|
if (_hasSelectionChanged) {
|
||||||
await HomeManagementAPI.assignDeviceToRoom(
|
await HomeManagementAPI.assignDeviceToRoom(
|
||||||
event.unit.community.uuid, event.unit.id, event.roomId, deviceId);
|
event.unit.community.uuid,
|
||||||
|
event.unit.id,
|
||||||
|
event.roomId,
|
||||||
|
deviceId,
|
||||||
|
project?.uuid ?? TempConst.projectIdDev);
|
||||||
final devicesList = await DevicesAPI.getDevicesByRoomId(
|
final devicesList = await DevicesAPI.getDevicesByRoomId(
|
||||||
communityUuid: event.unit.community.uuid,
|
communityUuid: event.unit.community.uuid,
|
||||||
spaceUuid: event.unit.id,
|
spaceUuid: event.unit.id,
|
||||||
roomId: event.roomId);
|
roomId: event.roomId,
|
||||||
|
projectId: project?.uuid ?? TempConst.projectIdDev);
|
||||||
List<String> allDevicesIds = [];
|
List<String> allDevicesIds = [];
|
||||||
allDevices.forEach((element) {
|
allDevices.forEach((element) {
|
||||||
allDevicesIds.add(element.uuid!);
|
allDevicesIds.add(element.uuid!);
|
||||||
@ -375,8 +384,12 @@ class DeviceSettingBloc extends Bloc<DeviceSettingEvent, DeviceSettingState> {
|
|||||||
FetchRoomsEvent event, Emitter<DeviceSettingState> emit) async {
|
FetchRoomsEvent event, Emitter<DeviceSettingState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(DeviceSettingLoadingState());
|
emit(DeviceSettingLoadingState());
|
||||||
|
Project? project = HomeCubit.getInstance().project;
|
||||||
|
|
||||||
roomsList = await SpacesAPI.getSubSpaceBySpaceId(
|
roomsList = await SpacesAPI.getSubSpaceBySpaceId(
|
||||||
event.unit.community.uuid, event.unit.id);
|
event.unit.community.uuid,
|
||||||
|
event.unit.id,
|
||||||
|
project?.uuid ?? TempConst.projectIdDev);
|
||||||
emit(FetchRoomsState(devicesList: allDevices, roomsList: roomsList));
|
emit(FetchRoomsState(devicesList: allDevices, roomsList: roomsList));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(
|
emit(
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
// ignore_for_file: constant_identifier_names, unused_import
|
// ignore_for_file: constant_identifier_names, unused_import
|
||||||
|
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:firebase_database/firebase_database.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||||
import 'package:syncrow_app/features/app_layout/model/space_model.dart';
|
import 'package:syncrow_app/features/app_layout/model/space_model.dart';
|
||||||
|
import 'package:syncrow_app/features/auth/model/project_model.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/device_category_model.dart';
|
import 'package:syncrow_app/features/devices/model/device_category_model.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||||
@ -19,6 +23,7 @@ import 'package:syncrow_app/services/api/devices_api.dart';
|
|||||||
import 'package:syncrow_app/services/api/home_management_api.dart';
|
import 'package:syncrow_app/services/api/home_management_api.dart';
|
||||||
import 'package:syncrow_app/services/api/network_exception.dart';
|
import 'package:syncrow_app/services/api/network_exception.dart';
|
||||||
import 'package:syncrow_app/services/api/spaces_api.dart';
|
import 'package:syncrow_app/services/api/spaces_api.dart';
|
||||||
|
import 'package:syncrow_app/utils/constants/temp_const.dart';
|
||||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||||
part 'devices_state.dart';
|
part 'devices_state.dart';
|
||||||
|
|
||||||
@ -61,6 +66,43 @@ class DevicesCubit extends Cubit<DevicesState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Timer? _timer;
|
||||||
|
|
||||||
|
final Map<String, StreamSubscription<DatabaseEvent>> _deviceSubscriptions =
|
||||||
|
{};
|
||||||
|
|
||||||
|
void _listenToChanges(deviceId) {
|
||||||
|
try {
|
||||||
|
if (_deviceSubscriptions.containsKey(deviceId)) {
|
||||||
|
_deviceSubscriptions[deviceId]?.cancel();
|
||||||
|
_deviceSubscriptions.remove(deviceId);
|
||||||
|
}
|
||||||
|
DatabaseReference ref =
|
||||||
|
FirebaseDatabase.instance.ref('device-status/$deviceId');
|
||||||
|
Stream<DatabaseEvent> stream = ref.onValue;
|
||||||
|
final subscription = stream.listen((DatabaseEvent event) async {
|
||||||
|
if (_timer != null) {
|
||||||
|
await Future.delayed(const Duration(seconds: 2));
|
||||||
|
}
|
||||||
|
Map<dynamic, dynamic> usersMap =
|
||||||
|
event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
|
// print('object-----${usersMap['status']}');
|
||||||
|
List<StatusModel> statusList = [];
|
||||||
|
usersMap['status'].forEach((element) {
|
||||||
|
statusList
|
||||||
|
.add(StatusModel(code: element['code'], value: element['value']));
|
||||||
|
});
|
||||||
|
emitSafe(GetDevicesLoading());
|
||||||
|
final deviceIndex = allDevices.indexWhere((d) => d.uuid == deviceId);
|
||||||
|
if (deviceIndex != -1) {
|
||||||
|
allDevices[deviceIndex].status = statusList;
|
||||||
|
}
|
||||||
|
emitSafe(GetDevicesSuccess(allDevices));
|
||||||
|
});
|
||||||
|
_deviceSubscriptions[deviceId] = subscription;
|
||||||
|
} catch (_) {}
|
||||||
|
}
|
||||||
|
|
||||||
static DevicesCubit get(context) => BlocProvider.of(context);
|
static DevicesCubit get(context) => BlocProvider.of(context);
|
||||||
|
|
||||||
List<DevicesCategoryModel>? allCategories;
|
List<DevicesCategoryModel>? allCategories;
|
||||||
@ -309,11 +351,14 @@ class DevicesCubit extends Cubit<DevicesState> {
|
|||||||
.subspaces
|
.subspaces
|
||||||
.indexWhere((element) => element.id == roomId);
|
.indexWhere((element) => element.id == roomId);
|
||||||
try {
|
try {
|
||||||
|
Project? project = HomeCubit.getInstance().project;
|
||||||
|
|
||||||
HomeCubit.getInstance().selectedSpace!.subspaces[roomIndex].devices =
|
HomeCubit.getInstance().selectedSpace!.subspaces[roomIndex].devices =
|
||||||
await DevicesAPI.getDevicesByRoomId(
|
await DevicesAPI.getDevicesByRoomId(
|
||||||
communityUuid: unit!.community.uuid,
|
communityUuid: unit!.community.uuid,
|
||||||
spaceUuid: unit.id,
|
spaceUuid: unit.id,
|
||||||
roomId: roomId);
|
roomId: roomId,
|
||||||
|
projectId: project?.uuid ?? TempConst.projectIdDev);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emitSafe(GetDevicesError(e.toString()));
|
emitSafe(GetDevicesError(e.toString()));
|
||||||
return;
|
return;
|
||||||
@ -410,11 +455,26 @@ class DevicesCubit extends Cubit<DevicesState> {
|
|||||||
Future<void> fetchAllDevices(SpaceModel? unit) async {
|
Future<void> fetchAllDevices(SpaceModel? unit) async {
|
||||||
emitSafe(GetDevicesLoading());
|
emitSafe(GetDevicesLoading());
|
||||||
try {
|
try {
|
||||||
|
Project? project = HomeCubit.getInstance().project;
|
||||||
|
|
||||||
final devices = await DevicesAPI.getAllDevices(
|
final devices = await DevicesAPI.getAllDevices(
|
||||||
communityUuid: unit!.community.uuid,
|
communityUuid: unit!.community.uuid,
|
||||||
spaceUuid: unit.id,
|
spaceUuid: unit.id,
|
||||||
);
|
projectId: project?.uuid ?? TempConst.projectIdDev);
|
||||||
allDevices = devices;
|
allDevices = devices;
|
||||||
|
for (var deviceId in allDevices) {
|
||||||
|
if (deviceId.type == "3G" ||
|
||||||
|
deviceId.type == "2G" ||
|
||||||
|
deviceId.type == "1G" ||
|
||||||
|
deviceId.type == "3GT" ||
|
||||||
|
deviceId.type == "2GT" ||
|
||||||
|
deviceId.type == "1GT" ||
|
||||||
|
deviceId.type == "WH" ||
|
||||||
|
deviceId.type == "CUR" ||
|
||||||
|
deviceId.type == "AC") {
|
||||||
|
_listenToChanges(deviceId.uuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
emitSafe(GetDevicesSuccess(allDevices));
|
emitSafe(GetDevicesSuccess(allDevices));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emitSafe(GetDevicesError(e.toString()));
|
emitSafe(GetDevicesError(e.toString()));
|
||||||
@ -473,25 +533,35 @@ class DevicesCubit extends Cubit<DevicesState> {
|
|||||||
}
|
}
|
||||||
final device = allDevices[deviceIndex];
|
final device = allDevices[deviceIndex];
|
||||||
final switches = ['switch_1', 'switch_2', 'switch_3'];
|
final switches = ['switch_1', 'switch_2', 'switch_3'];
|
||||||
|
final anySwitchOff = device.status.any(
|
||||||
|
(s) => (s.code?.startsWith('switch_') ?? false) && (s.value == false),
|
||||||
|
);
|
||||||
|
final targetState = anySwitchOff ? true : false;
|
||||||
|
|
||||||
for (final switchCode in switches) {
|
for (final switchCode in switches) {
|
||||||
final statusIndex =
|
final statusIndex =
|
||||||
device.status.indexWhere((s) => s.code == switchCode);
|
device.status.indexWhere((s) => s.code == switchCode);
|
||||||
if (statusIndex != -1) {
|
if (statusIndex != -1) {
|
||||||
final toggledValue = control.value;
|
final currentValue = device.status[statusIndex].value ?? false;
|
||||||
|
|
||||||
|
if (!targetState && !currentValue) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
final controlRequest = DeviceControlModel(
|
final controlRequest = DeviceControlModel(
|
||||||
code: switchCode, value: toggledValue, deviceId: deviceUuid);
|
code: switchCode, value: targetState, deviceId: deviceUuid);
|
||||||
final response =
|
final response =
|
||||||
await DevicesAPI.controlDevice(controlRequest, deviceUuid);
|
await DevicesAPI.controlDevice(controlRequest, deviceUuid);
|
||||||
if (response['success'] != true) {
|
if (response['success'] != true) {
|
||||||
throw Exception('Failed to toggle $switchCode');
|
throw Exception('Failed to toggle $switchCode');
|
||||||
}
|
}
|
||||||
device.status[statusIndex].value = toggledValue;
|
|
||||||
|
device.status[statusIndex].value = targetState;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final anySwitchOff = device.status.any(
|
device.toggleStatus = device.status.every(
|
||||||
(s) => (s.code?.startsWith('switch_') ?? false) && (s.value == false),
|
(s) => (s.code?.startsWith('switch_') ?? false) && (s.value == true),
|
||||||
);
|
);
|
||||||
device.toggleStatus = !anySwitchOff;
|
|
||||||
allDevices[deviceIndex] = device;
|
allDevices[deviceIndex] = device;
|
||||||
emit(DeviceControlSuccess(code: control.code));
|
emit(DeviceControlSuccess(code: control.code));
|
||||||
} catch (failure) {
|
} catch (failure) {
|
||||||
@ -590,7 +660,6 @@ class DevicesCubit extends Cubit<DevicesState> {
|
|||||||
code: 'switch_1', value: toggledValue, deviceId: deviceUuid);
|
code: 'switch_1', value: toggledValue, deviceId: deviceUuid);
|
||||||
final response =
|
final response =
|
||||||
await DevicesAPI.controlDevice(controlRequest, deviceUuid);
|
await DevicesAPI.controlDevice(controlRequest, deviceUuid);
|
||||||
print(response);
|
|
||||||
if (response['result'] != true) {
|
if (response['result'] != true) {
|
||||||
throw Exception('Failed to toggle switch_1');
|
throw Exception('Failed to toggle switch_1');
|
||||||
}
|
}
|
||||||
|
@ -21,13 +21,14 @@ class DoorSensorBloc extends Bloc<DoorSensorEvent, DoorSensorState> {
|
|||||||
on<ToggleClosingReminderEvent>(_toggleClosingReminder);
|
on<ToggleClosingReminderEvent>(_toggleClosingReminder);
|
||||||
on<ToggleDoorAlarmEvent>(_toggleDoorAlarm);
|
on<ToggleDoorAlarmEvent>(_toggleDoorAlarm);
|
||||||
}
|
}
|
||||||
Timer? _timer;
|
|
||||||
bool lowBattery = false;
|
bool lowBattery = false;
|
||||||
bool closingReminder = false;
|
bool closingReminder = false;
|
||||||
bool doorAlarm = false;
|
bool doorAlarm = false;
|
||||||
DoorSensorModel deviceStatus = DoorSensorModel(doorContactState: false, batteryPercentage: 0);
|
DoorSensorModel deviceStatus =
|
||||||
|
DoorSensorModel(doorContactState: false, batteryPercentage: 0);
|
||||||
|
|
||||||
void _fetchStatus(DoorSensorInitial event, Emitter<DoorSensorState> emit) async {
|
void _fetchStatus(
|
||||||
|
DoorSensorInitial event, Emitter<DoorSensorState> emit) async {
|
||||||
emit(DoorSensorLoadingState());
|
emit(DoorSensorLoadingState());
|
||||||
try {
|
try {
|
||||||
var response = await DevicesAPI.getDeviceStatus(DSId);
|
var response = await DevicesAPI.getDeviceStatus(DSId);
|
||||||
@ -40,7 +41,7 @@ class DoorSensorBloc extends Bloc<DoorSensorEvent, DoorSensorState> {
|
|||||||
);
|
);
|
||||||
emit(UpdateState(doorSensor: deviceStatus));
|
emit(UpdateState(doorSensor: deviceStatus));
|
||||||
Future.delayed(const Duration(milliseconds: 500));
|
Future.delayed(const Duration(milliseconds: 500));
|
||||||
// _listenToChanges();
|
_listenToChanges();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(DoorSensorFailedState(errorMessage: e.toString()));
|
emit(DoorSensorFailedState(errorMessage: e.toString()));
|
||||||
return;
|
return;
|
||||||
@ -48,7 +49,8 @@ class DoorSensorBloc extends Bloc<DoorSensorEvent, DoorSensorState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Toggle functions for each switch
|
// Toggle functions for each switch
|
||||||
void _toggleLowBattery(ToggleLowBatteryEvent event, Emitter<DoorSensorState> emit) async {
|
void _toggleLowBattery(
|
||||||
|
ToggleLowBatteryEvent event, Emitter<DoorSensorState> emit) async {
|
||||||
emit(LoadingNewSate(doorSensor: deviceStatus));
|
emit(LoadingNewSate(doorSensor: deviceStatus));
|
||||||
try {
|
try {
|
||||||
lowBattery = event.isLowBatteryEnabled;
|
lowBattery = event.isLowBatteryEnabled;
|
||||||
@ -89,7 +91,8 @@ class DoorSensorBloc extends Bloc<DoorSensorEvent, DoorSensorState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _toggleDoorAlarm(ToggleDoorAlarmEvent event, Emitter<DoorSensorState> emit) async {
|
void _toggleDoorAlarm(
|
||||||
|
ToggleDoorAlarmEvent event, Emitter<DoorSensorState> emit) async {
|
||||||
emit(LoadingNewSate(doorSensor: deviceStatus));
|
emit(LoadingNewSate(doorSensor: deviceStatus));
|
||||||
try {
|
try {
|
||||||
doorAlarm = event.isDoorAlarmEnabled;
|
doorAlarm = event.isDoorAlarmEnabled;
|
||||||
@ -108,9 +111,11 @@ class DoorSensorBloc extends Bloc<DoorSensorEvent, DoorSensorState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceReport recordGroups = DeviceReport(startTime: '0', endTime: '0', data: []);
|
DeviceReport recordGroups =
|
||||||
|
DeviceReport(startTime: '0', endTime: '0', data: []);
|
||||||
|
|
||||||
Future<void> fetchLogsForLastMonth(ReportLogsInitial event, Emitter<DoorSensorState> emit) async {
|
Future<void> fetchLogsForLastMonth(
|
||||||
|
ReportLogsInitial event, Emitter<DoorSensorState> emit) async {
|
||||||
DateTime now = DateTime.now();
|
DateTime now = DateTime.now();
|
||||||
|
|
||||||
DateTime lastMonth = DateTime(now.year, now.month - 1, now.day);
|
DateTime lastMonth = DateTime(now.year, now.month - 1, now.day);
|
||||||
@ -133,22 +138,27 @@ class DoorSensorBloc extends Bloc<DoorSensorEvent, DoorSensorState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_listenToChanges() {
|
// real-time database
|
||||||
|
Timer? _timer;
|
||||||
|
StreamSubscription<DatabaseEvent>? _streamSubscription;
|
||||||
|
void _listenToChanges() {
|
||||||
try {
|
try {
|
||||||
DatabaseReference ref = FirebaseDatabase.instance.ref('device-status/$DSId');
|
_streamSubscription?.cancel();
|
||||||
|
DatabaseReference ref =
|
||||||
|
FirebaseDatabase.instance.ref('device-status/$DSId');
|
||||||
Stream<DatabaseEvent> stream = ref.onValue;
|
Stream<DatabaseEvent> stream = ref.onValue;
|
||||||
|
|
||||||
stream.listen((DatabaseEvent event) async {
|
_streamSubscription = stream.listen((DatabaseEvent event) async {
|
||||||
if (_timer != null) {
|
if (_timer != null) {
|
||||||
await Future.delayed(const Duration(seconds: 2));
|
await Future.delayed(const Duration(seconds: 2));
|
||||||
}
|
}
|
||||||
Map<dynamic, dynamic> usersMap = event.snapshot.value as Map<dynamic, dynamic>;
|
Map<dynamic, dynamic> usersMap =
|
||||||
|
event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
List<StatusModel> statusList = [];
|
List<StatusModel> statusList = [];
|
||||||
|
|
||||||
usersMap['status'].forEach((element) {
|
usersMap['status'].forEach((element) {
|
||||||
statusList.add(StatusModel(code: element['code'], value: true));
|
statusList
|
||||||
|
.add(StatusModel(code: element['code'], value: element['value']));
|
||||||
});
|
});
|
||||||
|
|
||||||
deviceStatus = DoorSensorModel.fromJson(statusList);
|
deviceStatus = DoorSensorModel.fromJson(statusList);
|
||||||
if (!isClosed) {
|
if (!isClosed) {
|
||||||
add(
|
add(
|
||||||
@ -158,4 +168,11 @@ class DoorSensorBloc extends Bloc<DoorSensorEvent, DoorSensorState> {
|
|||||||
});
|
});
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> close() async {
|
||||||
|
_streamSubscription?.cancel();
|
||||||
|
_streamSubscription = null;
|
||||||
|
return super.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||||
|
import 'package:syncrow_app/features/auth/model/project_model.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/four_scene_bloc/four_scene_event.dart';
|
import 'package:syncrow_app/features/devices/bloc/four_scene_bloc/four_scene_event.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/four_scene_bloc/four_scene_state.dart';
|
import 'package:syncrow_app/features/devices/bloc/four_scene_bloc/four_scene_state.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
||||||
@ -14,6 +16,7 @@ import 'package:syncrow_app/features/devices/model/subspace_model.dart';
|
|||||||
import 'package:syncrow_app/features/scene/model/scenes_model.dart';
|
import 'package:syncrow_app/features/scene/model/scenes_model.dart';
|
||||||
import 'package:syncrow_app/services/api/devices_api.dart';
|
import 'package:syncrow_app/services/api/devices_api.dart';
|
||||||
import 'package:syncrow_app/services/api/scene_api.dart';
|
import 'package:syncrow_app/services/api/scene_api.dart';
|
||||||
|
import 'package:syncrow_app/utils/constants/temp_const.dart';
|
||||||
import 'package:syncrow_app/utils/helpers/snack_bar.dart';
|
import 'package:syncrow_app/utils/helpers/snack_bar.dart';
|
||||||
|
|
||||||
class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||||
@ -230,6 +233,7 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
|||||||
deviceStatus = FourSceneModelState.fromJson(
|
deviceStatus = FourSceneModelState.fromJson(
|
||||||
statusModelList,
|
statusModelList,
|
||||||
);
|
);
|
||||||
|
// _listenToChanges();
|
||||||
add(const FourSceneSwitchInitial());
|
add(const FourSceneSwitchInitial());
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(FourSceneFailedState(errorMessage: e.toString()));
|
emit(FourSceneFailedState(errorMessage: e.toString()));
|
||||||
@ -299,9 +303,11 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
|||||||
LoadScenes event, Emitter<FourSceneState> emit) async {
|
LoadScenes event, Emitter<FourSceneState> emit) async {
|
||||||
emit(FourSceneLoadingState());
|
emit(FourSceneLoadingState());
|
||||||
try {
|
try {
|
||||||
|
Project? project = HomeCubit.getInstance().project;
|
||||||
|
|
||||||
if (event.unitId.isNotEmpty) {
|
if (event.unitId.isNotEmpty) {
|
||||||
allScenes = await SceneApi.getScenesByUnitId(
|
allScenes = await SceneApi.getScenesByUnitId(
|
||||||
event.unitId, event.unit.community.uuid,
|
event.unitId, event.unit.community.uuid, project?.uuid ?? TempConst.projectIdDev,
|
||||||
showInDevice: event.showInDevice);
|
showInDevice: event.showInDevice);
|
||||||
|
|
||||||
filteredScenes = allScenes;
|
filteredScenes = allScenes;
|
||||||
@ -327,4 +333,33 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
|||||||
}).toList();
|
}).toList();
|
||||||
emit(SearchResultsState());
|
emit(SearchResultsState());
|
||||||
}
|
}
|
||||||
|
// Real-time database
|
||||||
|
// Timer? _timer;
|
||||||
|
// _listenToChanges() {
|
||||||
|
// try {
|
||||||
|
// DatabaseReference ref =
|
||||||
|
// FirebaseDatabase.instance.ref('device-status/$fourSceneId');
|
||||||
|
// Stream<DatabaseEvent> stream = ref.onValue;
|
||||||
|
|
||||||
|
// stream.listen((DatabaseEvent event) async {
|
||||||
|
// if (_timer != null) {
|
||||||
|
// await Future.delayed(const Duration(seconds: 2));
|
||||||
|
// }
|
||||||
|
// Map<dynamic, dynamic> usersMap =
|
||||||
|
// event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
|
// List<StatusModel> statusList = [];
|
||||||
|
|
||||||
|
// usersMap['status'].forEach((element) {
|
||||||
|
// statusList.add(StatusModel(code: element['code'], value: true));
|
||||||
|
// });
|
||||||
|
|
||||||
|
// deviceStatus = FourSceneModelState.fromJson(statusList);
|
||||||
|
// // if (!isClosed) {
|
||||||
|
// // add(
|
||||||
|
// // DoorSensorSwitch(switchD: deviceStatus.doorContactState),
|
||||||
|
// // );
|
||||||
|
// // }
|
||||||
|
// });
|
||||||
|
// } catch (_) {}
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,8 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorSensorState> {
|
|||||||
on<ChangeFirstWizardSwitchStatusEvent>(_changeFirstWizardSwitch);
|
on<ChangeFirstWizardSwitchStatusEvent>(_changeFirstWizardSwitch);
|
||||||
on<ToggleAlarmEvent>(_toggleAlarmEvent);
|
on<ToggleAlarmEvent>(_toggleAlarmEvent);
|
||||||
on<DeleteScheduleEvent>(deleteSchedule);
|
on<DeleteScheduleEvent>(deleteSchedule);
|
||||||
//_toggleAlarmEvent
|
|
||||||
|
on<UpdateStateEvent>(_updateState);
|
||||||
}
|
}
|
||||||
void _onClose(OnClose event, Emitter<GarageDoorSensorState> emit) {
|
void _onClose(OnClose event, Emitter<GarageDoorSensorState> emit) {
|
||||||
_timer?.cancel();
|
_timer?.cancel();
|
||||||
@ -81,7 +82,7 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorSensorState> {
|
|||||||
toggleDoor = deviceStatus.switch1;
|
toggleDoor = deviceStatus.switch1;
|
||||||
emit(UpdateState(garageSensor: deviceStatus));
|
emit(UpdateState(garageSensor: deviceStatus));
|
||||||
Future.delayed(const Duration(milliseconds: 500));
|
Future.delayed(const Duration(milliseconds: 500));
|
||||||
// _listenToChanges();
|
_listenToChanges();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(GarageDoorFailedState(errorMessage: e.toString()));
|
emit(GarageDoorFailedState(errorMessage: e.toString()));
|
||||||
return;
|
return;
|
||||||
@ -180,33 +181,59 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorSensorState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_listenToChanges() {
|
// Real-time db
|
||||||
|
StreamSubscription<DatabaseEvent>? _streamSubscription;
|
||||||
|
void _listenToChanges() {
|
||||||
try {
|
try {
|
||||||
|
_streamSubscription?.cancel();
|
||||||
DatabaseReference ref =
|
DatabaseReference ref =
|
||||||
FirebaseDatabase.instance.ref('device-status/$GDId');
|
FirebaseDatabase.instance.ref('device-status/$GDId');
|
||||||
Stream<DatabaseEvent> stream = ref.onValue;
|
Stream<DatabaseEvent> stream = ref.onValue;
|
||||||
|
|
||||||
stream.listen((DatabaseEvent event) async {
|
_streamSubscription = stream.listen((DatabaseEvent event) async {
|
||||||
if (_timer != null) {
|
if (_timer != null) {
|
||||||
await Future.delayed(const Duration(seconds: 2));
|
await Future.delayed(const Duration(seconds: 1));
|
||||||
}
|
}
|
||||||
Map<dynamic, dynamic> usersMap =
|
|
||||||
event.snapshot.value as Map<dynamic, dynamic>;
|
|
||||||
List<StatusModel> statusList = [];
|
|
||||||
usersMap['status'].forEach((element) {
|
|
||||||
statusList.add(StatusModel(code: element['code'], value: true));
|
|
||||||
});
|
|
||||||
|
|
||||||
deviceStatus = GarageDoorModel.fromJson(statusList);
|
if (event.snapshot.value != null) {
|
||||||
if (!isClosed) {
|
Map<dynamic, dynamic> usersMap =
|
||||||
// add(
|
event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
// DoorSensorSwitch(switchD: deviceStatus.doorContactState),
|
List<StatusModel> statusList = [];
|
||||||
// );
|
|
||||||
|
usersMap['status'].forEach((element) {
|
||||||
|
statusList.add(
|
||||||
|
StatusModel(code: element['code'], value: element['value']));
|
||||||
|
});
|
||||||
|
deviceStatus.tr_timecon = statusList
|
||||||
|
.firstWhere((status) => status.code == "tr_timecon",
|
||||||
|
orElse: () => StatusModel(code: "tr_timecon", value: 0))
|
||||||
|
.value as int;
|
||||||
|
|
||||||
|
deviceStatus.switch1 = statusList
|
||||||
|
.firstWhere((status) => status.code == "switch_1",
|
||||||
|
orElse: () => StatusModel(code: "switch_1", value: false))
|
||||||
|
.value as bool;
|
||||||
|
secondSelected = deviceStatus.tr_timecon;
|
||||||
|
toggleDoor = deviceStatus.switch1;
|
||||||
|
add(UpdateStateEvent());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _updateState(
|
||||||
|
UpdateStateEvent event, Emitter<GarageDoorSensorState> emit) async {
|
||||||
|
emit(GarageDoorLoadingState());
|
||||||
|
emit(UpdateState(garageSensor: deviceStatus));
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> close() async {
|
||||||
|
_streamSubscription?.cancel();
|
||||||
|
_streamSubscription = null;
|
||||||
|
return super.close();
|
||||||
|
}
|
||||||
|
|
||||||
List<Map<String, String>> days = [
|
List<Map<String, String>> days = [
|
||||||
{"day": "Sun", "key": "Sun"},
|
{"day": "Sun", "key": "Sun"},
|
||||||
{"day": "Mon", "key": "Mon"},
|
{"day": "Mon", "key": "Mon"},
|
||||||
|
@ -109,6 +109,8 @@ class GetScheduleEvent extends GarageDoorEvent {}
|
|||||||
|
|
||||||
class ScheduleSaveapp extends GarageDoorEvent {}
|
class ScheduleSaveapp extends GarageDoorEvent {}
|
||||||
|
|
||||||
|
class UpdateStateEvent extends GarageDoorEvent {}
|
||||||
|
|
||||||
class ToggleScheduleEvent extends GarageDoorEvent {
|
class ToggleScheduleEvent extends GarageDoorEvent {
|
||||||
final String id;
|
final String id;
|
||||||
final bool toggle;
|
final bool toggle;
|
||||||
|
@ -26,7 +26,8 @@ class OneGangBloc extends Bloc<OneGangEvent, OneGangState> {
|
|||||||
bool oneGangGroup = false;
|
bool oneGangGroup = false;
|
||||||
List<DeviceModel> devicesList = [];
|
List<DeviceModel> devicesList = [];
|
||||||
|
|
||||||
OneGangBloc({required this.oneGangId, required this.switchCode}) : super(InitialState()) {
|
OneGangBloc({required this.oneGangId, required this.switchCode})
|
||||||
|
: super(InitialState()) {
|
||||||
on<InitialEvent>(_fetchOneGangStatus);
|
on<InitialEvent>(_fetchOneGangStatus);
|
||||||
on<OneGangUpdated>(_oneGangUpdated);
|
on<OneGangUpdated>(_oneGangUpdated);
|
||||||
on<ChangeFirstSwitchStatusEvent>(_changeFirstSwitch);
|
on<ChangeFirstSwitchStatusEvent>(_changeFirstSwitch);
|
||||||
@ -49,7 +50,8 @@ class OneGangBloc extends Bloc<OneGangEvent, OneGangState> {
|
|||||||
on<GroupAllOffEvent>(_groupAllOff);
|
on<GroupAllOffEvent>(_groupAllOff);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _fetchOneGangStatus(InitialEvent event, Emitter<OneGangState> emit) async {
|
void _fetchOneGangStatus(
|
||||||
|
InitialEvent event, Emitter<OneGangState> emit) async {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
try {
|
try {
|
||||||
var response = await DevicesAPI.getDeviceStatus(oneGangId);
|
var response = await DevicesAPI.getDeviceStatus(oneGangId);
|
||||||
@ -59,42 +61,51 @@ class OneGangBloc extends Bloc<OneGangEvent, OneGangState> {
|
|||||||
}
|
}
|
||||||
deviceStatus = OneGangModel.fromJson(statusModelList);
|
deviceStatus = OneGangModel.fromJson(statusModelList);
|
||||||
emit(UpdateState(oneGangModel: deviceStatus));
|
emit(UpdateState(oneGangModel: deviceStatus));
|
||||||
// _listenToChanges();
|
_listenToChanges(oneGangId);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(FailedState(error: e.toString()));
|
emit(FailedState(error: e.toString()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_listenToChanges() {
|
// Real-time db
|
||||||
|
StreamSubscription<DatabaseEvent>? _streamSubscription;
|
||||||
|
void _listenToChanges(String id) {
|
||||||
try {
|
try {
|
||||||
DatabaseReference ref = FirebaseDatabase.instance.ref('device-status/$oneGangId');
|
_streamSubscription?.cancel();
|
||||||
|
DatabaseReference ref =
|
||||||
|
FirebaseDatabase.instance.ref('device-status/$id');
|
||||||
Stream<DatabaseEvent> stream = ref.onValue;
|
Stream<DatabaseEvent> stream = ref.onValue;
|
||||||
|
|
||||||
stream.listen((DatabaseEvent event) async {
|
_streamSubscription = stream.listen((DatabaseEvent event) {
|
||||||
if (_timer != null) {
|
Map<dynamic, dynamic> usersMap =
|
||||||
await Future.delayed(const Duration(seconds: 2));
|
event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
}
|
|
||||||
Map<dynamic, dynamic> usersMap = event.snapshot.value as Map<dynamic, dynamic>;
|
|
||||||
List<StatusModel> statusList = [];
|
List<StatusModel> statusList = [];
|
||||||
|
|
||||||
usersMap['status'].forEach((element) {
|
usersMap['status'].forEach((element) {
|
||||||
statusList.add(StatusModel(code: element['code'], value: element['value']));
|
statusList
|
||||||
|
.add(StatusModel(code: element['code'], value: element['value']));
|
||||||
});
|
});
|
||||||
|
|
||||||
deviceStatus = OneGangModel.fromJson(statusList);
|
deviceStatus = OneGangModel.fromJson(statusList);
|
||||||
if (!isClosed) {
|
add(OneGangUpdated());
|
||||||
add(OneGangUpdated());
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> close() async {
|
||||||
|
_streamSubscription?.cancel();
|
||||||
|
_streamSubscription = null;
|
||||||
|
return super.close();
|
||||||
|
}
|
||||||
|
|
||||||
_oneGangUpdated(OneGangUpdated event, Emitter<OneGangState> emit) {
|
_oneGangUpdated(OneGangUpdated event, Emitter<OneGangState> emit) {
|
||||||
|
emit(LoadingInitialState());
|
||||||
emit(UpdateState(oneGangModel: deviceStatus));
|
emit(UpdateState(oneGangModel: deviceStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeFirstSwitch(ChangeFirstSwitchStatusEvent event, Emitter<OneGangState> emit) async {
|
void _changeFirstSwitch(
|
||||||
|
ChangeFirstSwitchStatusEvent event, Emitter<OneGangState> emit) async {
|
||||||
emit(LoadingNewSate(oneGangModel: deviceStatus));
|
emit(LoadingNewSate(oneGangModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
deviceStatus.firstSwitch = !event.value;
|
deviceStatus.firstSwitch = !event.value;
|
||||||
@ -119,17 +130,20 @@ class OneGangBloc extends Bloc<OneGangEvent, OneGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeSliding(ChangeSlidingSegment event, Emitter<OneGangState> emit) async {
|
void _changeSliding(
|
||||||
|
ChangeSlidingSegment event, Emitter<OneGangState> emit) async {
|
||||||
emit(ChangeSlidingSegmentState(value: event.value));
|
emit(ChangeSlidingSegmentState(value: event.value));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _setCounterValue(SetCounterValue event, Emitter<OneGangState> emit) async {
|
void _setCounterValue(
|
||||||
|
SetCounterValue event, Emitter<OneGangState> emit) async {
|
||||||
emit(LoadingNewSate(oneGangModel: deviceStatus));
|
emit(LoadingNewSate(oneGangModel: deviceStatus));
|
||||||
int seconds = 0;
|
int seconds = 0;
|
||||||
try {
|
try {
|
||||||
seconds = event.duration.inSeconds;
|
seconds = event.duration.inSeconds;
|
||||||
final response = await DevicesAPI.controlDevice(
|
final response = await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(deviceId: oneGangId, code: event.deviceCode, value: seconds),
|
DeviceControlModel(
|
||||||
|
deviceId: oneGangId, code: event.deviceCode, value: seconds),
|
||||||
oneGangId);
|
oneGangId);
|
||||||
|
|
||||||
if (response['success'] ?? false) {
|
if (response['success'] ?? false) {
|
||||||
@ -152,7 +166,8 @@ class OneGangBloc extends Bloc<OneGangEvent, OneGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _getCounterValue(GetCounterEvent event, Emitter<OneGangState> emit) async {
|
void _getCounterValue(
|
||||||
|
GetCounterEvent event, Emitter<OneGangState> emit) async {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
try {
|
try {
|
||||||
var response = await DevicesAPI.getDeviceStatus(oneGangId);
|
var response = await DevicesAPI.getDeviceStatus(oneGangId);
|
||||||
@ -241,7 +256,8 @@ class OneGangBloc extends Bloc<OneGangEvent, OneGangState> {
|
|||||||
deviceId: oneGangId,
|
deviceId: oneGangId,
|
||||||
);
|
);
|
||||||
List<dynamic> jsonData = response;
|
List<dynamic> jsonData = response;
|
||||||
listSchedule = jsonData.map((item) => ScheduleModel.fromJson(item)).toList();
|
listSchedule =
|
||||||
|
jsonData.map((item) => ScheduleModel.fromJson(item)).toList();
|
||||||
emit(InitialState());
|
emit(InitialState());
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
final errorData = e.response!.data;
|
final errorData = e.response!.data;
|
||||||
@ -252,12 +268,13 @@ class OneGangBloc extends Bloc<OneGangEvent, OneGangState> {
|
|||||||
|
|
||||||
int? getTimeStampWithoutSeconds(DateTime? dateTime) {
|
int? getTimeStampWithoutSeconds(DateTime? dateTime) {
|
||||||
if (dateTime == null) return null;
|
if (dateTime == null) return null;
|
||||||
DateTime dateTimeWithoutSeconds =
|
DateTime dateTimeWithoutSeconds = DateTime(dateTime.year, dateTime.month,
|
||||||
DateTime(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute);
|
dateTime.day, dateTime.hour, dateTime.minute);
|
||||||
return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000;
|
return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future toggleChange(ToggleScheduleEvent event, Emitter<OneGangState> emit) async {
|
Future toggleChange(
|
||||||
|
ToggleScheduleEvent event, Emitter<OneGangState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
final response = await DevicesAPI.changeSchedule(
|
final response = await DevicesAPI.changeSchedule(
|
||||||
@ -276,7 +293,8 @@ class OneGangBloc extends Bloc<OneGangEvent, OneGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future deleteSchedule(DeleteScheduleEvent event, Emitter<OneGangState> emit) async {
|
Future deleteSchedule(
|
||||||
|
DeleteScheduleEvent event, Emitter<OneGangState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
final response = await DevicesAPI.deleteSchedule(
|
final response = await DevicesAPI.deleteSchedule(
|
||||||
@ -296,7 +314,8 @@ class OneGangBloc extends Bloc<OneGangEvent, OneGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggleCreateSchedule(ToggleCreateScheduleEvent event, Emitter<OneGangState> emit) {
|
void toggleCreateSchedule(
|
||||||
|
ToggleCreateScheduleEvent event, Emitter<OneGangState> emit) {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
createSchedule = !createSchedule;
|
createSchedule = !createSchedule;
|
||||||
selectedDays.clear();
|
selectedDays.clear();
|
||||||
@ -325,7 +344,8 @@ class OneGangBloc extends Bloc<OneGangEvent, OneGangState> {
|
|||||||
|
|
||||||
int selectedTabIndex = 0;
|
int selectedTabIndex = 0;
|
||||||
|
|
||||||
void toggleSelectedIndex(ToggleSelectedEvent event, Emitter<OneGangState> emit) {
|
void toggleSelectedIndex(
|
||||||
|
ToggleSelectedEvent event, Emitter<OneGangState> emit) {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
selectedTabIndex = event.index;
|
selectedTabIndex = event.index;
|
||||||
emit(ChangeSlidingSegmentState(value: selectedTabIndex));
|
emit(ChangeSlidingSegmentState(value: selectedTabIndex));
|
||||||
@ -334,7 +354,8 @@ class OneGangBloc extends Bloc<OneGangEvent, OneGangState> {
|
|||||||
List<GroupOneGangModel> groupOneGangList = [];
|
List<GroupOneGangModel> groupOneGangList = [];
|
||||||
bool allSwitchesOn = true;
|
bool allSwitchesOn = true;
|
||||||
|
|
||||||
void _fetchOneGangWizardStatus(InitialWizardEvent event, Emitter<OneGangState> emit) async {
|
void _fetchOneGangWizardStatus(
|
||||||
|
InitialWizardEvent event, Emitter<OneGangState> emit) async {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
try {
|
try {
|
||||||
devicesList = [];
|
devicesList = [];
|
||||||
@ -344,7 +365,8 @@ class OneGangBloc extends Bloc<OneGangEvent, OneGangState> {
|
|||||||
HomeCubit.getInstance().selectedSpace?.id ?? '', '1G');
|
HomeCubit.getInstance().selectedSpace?.id ?? '', '1G');
|
||||||
|
|
||||||
for (int i = 0; i < devicesList.length; i++) {
|
for (int i = 0; i < devicesList.length; i++) {
|
||||||
var response = await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
var response =
|
||||||
|
await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
||||||
List<StatusModel> statusModelList = [];
|
List<StatusModel> statusModelList = [];
|
||||||
for (var status in response['status']) {
|
for (var status in response['status']) {
|
||||||
statusModelList.add(StatusModel.fromJson(status));
|
statusModelList.add(StatusModel.fromJson(status));
|
||||||
@ -365,15 +387,16 @@ class OneGangBloc extends Bloc<OneGangEvent, OneGangState> {
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
emit(UpdateGroupState(oneGangList: groupOneGangList, allSwitches: allSwitchesOn));
|
emit(UpdateGroupState(
|
||||||
|
oneGangList: groupOneGangList, allSwitches: allSwitchesOn));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(FailedState(error: e.toString()));
|
emit(FailedState(error: e.toString()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeFirstWizardSwitch(
|
void _changeFirstWizardSwitch(ChangeFirstWizardSwitchStatusEvent event,
|
||||||
ChangeFirstWizardSwitchStatusEvent event, Emitter<OneGangState> emit) async {
|
Emitter<OneGangState> emit) async {
|
||||||
emit(LoadingNewSate(oneGangModel: deviceStatus));
|
emit(LoadingNewSate(oneGangModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
bool allSwitchesValue = true;
|
bool allSwitchesValue = true;
|
||||||
@ -386,7 +409,8 @@ class OneGangBloc extends Bloc<OneGangEvent, OneGangState> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
emit(UpdateGroupState(oneGangList: groupOneGangList, allSwitches: allSwitchesValue));
|
emit(UpdateGroupState(
|
||||||
|
oneGangList: groupOneGangList, allSwitches: allSwitchesValue));
|
||||||
|
|
||||||
final response = await DevicesAPI.deviceBatchController(
|
final response = await DevicesAPI.deviceBatchController(
|
||||||
code: 'switch_1',
|
code: 'switch_1',
|
||||||
@ -414,7 +438,8 @@ class OneGangBloc extends Bloc<OneGangEvent, OneGangState> {
|
|||||||
emit(UpdateGroupState(oneGangList: groupOneGangList, allSwitches: true));
|
emit(UpdateGroupState(oneGangList: groupOneGangList, allSwitches: true));
|
||||||
|
|
||||||
// Get a list of all device IDs
|
// Get a list of all device IDs
|
||||||
List<String> allDeviceIds = groupOneGangList.map((device) => device.deviceId).toList();
|
List<String> allDeviceIds =
|
||||||
|
groupOneGangList.map((device) => device.deviceId).toList();
|
||||||
|
|
||||||
// First call for switch_1
|
// First call for switch_1
|
||||||
final response = await DevicesAPI.deviceBatchController(
|
final response = await DevicesAPI.deviceBatchController(
|
||||||
@ -446,7 +471,8 @@ class OneGangBloc extends Bloc<OneGangEvent, OneGangState> {
|
|||||||
emit(UpdateGroupState(oneGangList: groupOneGangList, allSwitches: false));
|
emit(UpdateGroupState(oneGangList: groupOneGangList, allSwitches: false));
|
||||||
|
|
||||||
// Get a list of all device IDs
|
// Get a list of all device IDs
|
||||||
List<String> allDeviceIds = groupOneGangList.map((device) => device.deviceId).toList();
|
List<String> allDeviceIds =
|
||||||
|
groupOneGangList.map((device) => device.deviceId).toList();
|
||||||
|
|
||||||
// First call for switch_1
|
// First call for switch_1
|
||||||
final response = await DevicesAPI.deviceBatchController(
|
final response = await DevicesAPI.deviceBatchController(
|
||||||
|
@ -30,7 +30,8 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
|||||||
bool oneTouchGroup = false;
|
bool oneTouchGroup = false;
|
||||||
List<DeviceModel> devicesList = [];
|
List<DeviceModel> devicesList = [];
|
||||||
|
|
||||||
OneTouchBloc({required this.oneTouchId, required this.switchCode}) : super(InitialState()) {
|
OneTouchBloc({required this.oneTouchId, required this.switchCode})
|
||||||
|
: super(InitialState()) {
|
||||||
on<InitialEvent>(_fetchOneTouchStatus);
|
on<InitialEvent>(_fetchOneTouchStatus);
|
||||||
on<OneTouchUpdated>(_oneTouchUpdated);
|
on<OneTouchUpdated>(_oneTouchUpdated);
|
||||||
on<ChangeFirstSwitchStatusEvent>(_changeFirstSwitch);
|
on<ChangeFirstSwitchStatusEvent>(_changeFirstSwitch);
|
||||||
@ -53,7 +54,8 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
|||||||
on<ChangeStatusEvent>(_changeStatus);
|
on<ChangeStatusEvent>(_changeStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _fetchOneTouchStatus(InitialEvent event, Emitter<OneTouchState> emit) async {
|
void _fetchOneTouchStatus(
|
||||||
|
InitialEvent event, Emitter<OneTouchState> emit) async {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
try {
|
try {
|
||||||
var response = await DevicesAPI.getDeviceStatus(oneTouchId);
|
var response = await DevicesAPI.getDeviceStatus(oneTouchId);
|
||||||
@ -62,43 +64,59 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
|||||||
statusModelList.add(StatusModel.fromJson(status));
|
statusModelList.add(StatusModel.fromJson(status));
|
||||||
}
|
}
|
||||||
deviceStatus = OneTouchModel.fromJson(statusModelList);
|
deviceStatus = OneTouchModel.fromJson(statusModelList);
|
||||||
|
_listenToChanges(oneTouchId);
|
||||||
|
|
||||||
emit(UpdateState(oneTouchModel: deviceStatus));
|
emit(UpdateState(oneTouchModel: deviceStatus));
|
||||||
// _listenToChanges();
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(FailedState(error: e.toString()));
|
emit(FailedState(error: e.toString()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_listenToChanges() {
|
StreamSubscription<DatabaseEvent>? _streamSubscription;
|
||||||
|
void _listenToChanges(String id) {
|
||||||
try {
|
try {
|
||||||
DatabaseReference ref = FirebaseDatabase.instance.ref('device-status/$oneTouchId');
|
_streamSubscription?.cancel();
|
||||||
|
DatabaseReference ref =
|
||||||
|
FirebaseDatabase.instance.ref('device-status/$id');
|
||||||
Stream<DatabaseEvent> stream = ref.onValue;
|
Stream<DatabaseEvent> stream = ref.onValue;
|
||||||
|
|
||||||
stream.listen((DatabaseEvent event) async {
|
_streamSubscription = stream.listen((DatabaseEvent event) {
|
||||||
if (_timer != null) {
|
if (event.snapshot.value != null) {
|
||||||
await Future.delayed(const Duration(seconds: 2));
|
Map<dynamic, dynamic> usersMap =
|
||||||
}
|
event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
Map<dynamic, dynamic> usersMap = event.snapshot.value as Map<dynamic, dynamic>;
|
List<StatusModel> statusList = [];
|
||||||
List<StatusModel> statusList = [];
|
|
||||||
|
|
||||||
usersMap['status'].forEach((element) {
|
usersMap['status'].forEach((element) {
|
||||||
statusList.add(StatusModel(code: element['code'], value: element['value']));
|
statusList.add(
|
||||||
});
|
StatusModel(code: element['code'], value: element['value']));
|
||||||
|
});
|
||||||
|
var switchStatus = statusList.firstWhere(
|
||||||
|
(status) => status.code == "switch_1",
|
||||||
|
orElse: () => StatusModel(code: "switch_1", value: false));
|
||||||
|
|
||||||
deviceStatus = OneTouchModel.fromJson(statusList);
|
deviceStatus.firstSwitch = switchStatus.value as bool;
|
||||||
if (!isClosed) {
|
|
||||||
add(OneTouchUpdated());
|
add(OneTouchUpdated());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (_) {}
|
} catch (_) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> close() async {
|
||||||
|
_streamSubscription?.cancel();
|
||||||
|
_streamSubscription = null;
|
||||||
|
return super.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
_oneTouchUpdated(OneTouchUpdated event, Emitter<OneTouchState> emit) {
|
_oneTouchUpdated(OneTouchUpdated event, Emitter<OneTouchState> emit) {
|
||||||
|
emit(LoadingNewSate(oneTouchModel: deviceStatus));
|
||||||
emit(UpdateState(oneTouchModel: deviceStatus));
|
emit(UpdateState(oneTouchModel: deviceStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeFirstSwitch(ChangeFirstSwitchStatusEvent event, Emitter<OneTouchState> emit) async {
|
void _changeFirstSwitch(
|
||||||
|
ChangeFirstSwitchStatusEvent event, Emitter<OneTouchState> emit) async {
|
||||||
emit(LoadingNewSate(oneTouchModel: deviceStatus));
|
emit(LoadingNewSate(oneTouchModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
deviceStatus.firstSwitch = !event.value;
|
deviceStatus.firstSwitch = !event.value;
|
||||||
@ -123,17 +141,20 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeSliding(ChangeSlidingSegment event, Emitter<OneTouchState> emit) async {
|
void _changeSliding(
|
||||||
|
ChangeSlidingSegment event, Emitter<OneTouchState> emit) async {
|
||||||
emit(ChangeSlidingSegmentState(value: event.value));
|
emit(ChangeSlidingSegmentState(value: event.value));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _setCounterValue(SetCounterValue event, Emitter<OneTouchState> emit) async {
|
void _setCounterValue(
|
||||||
|
SetCounterValue event, Emitter<OneTouchState> emit) async {
|
||||||
emit(LoadingNewSate(oneTouchModel: deviceStatus));
|
emit(LoadingNewSate(oneTouchModel: deviceStatus));
|
||||||
int seconds = 0;
|
int seconds = 0;
|
||||||
try {
|
try {
|
||||||
seconds = event.duration.inSeconds;
|
seconds = event.duration.inSeconds;
|
||||||
final response = await DevicesAPI.controlDevice(
|
final response = await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(deviceId: oneTouchId, code: event.deviceCode, value: seconds),
|
DeviceControlModel(
|
||||||
|
deviceId: oneTouchId, code: event.deviceCode, value: seconds),
|
||||||
oneTouchId);
|
oneTouchId);
|
||||||
|
|
||||||
if (response['success'] ?? false) {
|
if (response['success'] ?? false) {
|
||||||
@ -156,7 +177,8 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _getCounterValue(GetCounterEvent event, Emitter<OneTouchState> emit) async {
|
void _getCounterValue(
|
||||||
|
GetCounterEvent event, Emitter<OneTouchState> emit) async {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
try {
|
try {
|
||||||
var response = await DevicesAPI.getDeviceStatus(oneTouchId);
|
var response = await DevicesAPI.getDeviceStatus(oneTouchId);
|
||||||
@ -245,7 +267,8 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
|||||||
deviceId: oneTouchId,
|
deviceId: oneTouchId,
|
||||||
);
|
);
|
||||||
List<dynamic> jsonData = response;
|
List<dynamic> jsonData = response;
|
||||||
listSchedule = jsonData.map((item) => ScheduleModel.fromJson(item)).toList();
|
listSchedule =
|
||||||
|
jsonData.map((item) => ScheduleModel.fromJson(item)).toList();
|
||||||
emit(InitialState());
|
emit(InitialState());
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
final errorData = e.response!.data;
|
final errorData = e.response!.data;
|
||||||
@ -256,12 +279,13 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
|||||||
|
|
||||||
int? getTimeStampWithoutSeconds(DateTime? dateTime) {
|
int? getTimeStampWithoutSeconds(DateTime? dateTime) {
|
||||||
if (dateTime == null) return null;
|
if (dateTime == null) return null;
|
||||||
DateTime dateTimeWithoutSeconds =
|
DateTime dateTimeWithoutSeconds = DateTime(dateTime.year, dateTime.month,
|
||||||
DateTime(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute);
|
dateTime.day, dateTime.hour, dateTime.minute);
|
||||||
return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000;
|
return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future toggleChange(ToggleScheduleEvent event, Emitter<OneTouchState> emit) async {
|
Future toggleChange(
|
||||||
|
ToggleScheduleEvent event, Emitter<OneTouchState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
final response = await DevicesAPI.changeSchedule(
|
final response = await DevicesAPI.changeSchedule(
|
||||||
@ -280,7 +304,8 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future deleteSchedule(DeleteScheduleEvent event, Emitter<OneTouchState> emit) async {
|
Future deleteSchedule(
|
||||||
|
DeleteScheduleEvent event, Emitter<OneTouchState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
final response = await DevicesAPI.deleteSchedule(
|
final response = await DevicesAPI.deleteSchedule(
|
||||||
@ -300,7 +325,8 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggleCreateSchedule(ToggleCreateScheduleEvent event, Emitter<OneTouchState> emit) {
|
void toggleCreateSchedule(
|
||||||
|
ToggleCreateScheduleEvent event, Emitter<OneTouchState> emit) {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
createSchedule = !createSchedule;
|
createSchedule = !createSchedule;
|
||||||
selectedDays.clear();
|
selectedDays.clear();
|
||||||
@ -329,7 +355,8 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
|||||||
|
|
||||||
int selectedTabIndex = 0;
|
int selectedTabIndex = 0;
|
||||||
|
|
||||||
void toggleSelectedIndex(ToggleSelectedEvent event, Emitter<OneTouchState> emit) {
|
void toggleSelectedIndex(
|
||||||
|
ToggleSelectedEvent event, Emitter<OneTouchState> emit) {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
selectedTabIndex = event.index;
|
selectedTabIndex = event.index;
|
||||||
emit(ChangeSlidingSegmentState(value: selectedTabIndex));
|
emit(ChangeSlidingSegmentState(value: selectedTabIndex));
|
||||||
@ -338,7 +365,8 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
|||||||
List<GroupOneTouchModel> groupOneTouchList = [];
|
List<GroupOneTouchModel> groupOneTouchList = [];
|
||||||
bool allSwitchesOn = true;
|
bool allSwitchesOn = true;
|
||||||
|
|
||||||
void _fetchOneTouchWizardStatus(InitialWizardEvent event, Emitter<OneTouchState> emit) async {
|
void _fetchOneTouchWizardStatus(
|
||||||
|
InitialWizardEvent event, Emitter<OneTouchState> emit) async {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
try {
|
try {
|
||||||
devicesList = [];
|
devicesList = [];
|
||||||
@ -348,7 +376,8 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
|||||||
HomeCubit.getInstance().selectedSpace?.id ?? '', '1GT');
|
HomeCubit.getInstance().selectedSpace?.id ?? '', '1GT');
|
||||||
|
|
||||||
for (int i = 0; i < devicesList.length; i++) {
|
for (int i = 0; i < devicesList.length; i++) {
|
||||||
var response = await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
var response =
|
||||||
|
await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
||||||
List<StatusModel> statusModelList = [];
|
List<StatusModel> statusModelList = [];
|
||||||
for (var status in response['status']) {
|
for (var status in response['status']) {
|
||||||
statusModelList.add(StatusModel.fromJson(status));
|
statusModelList.add(StatusModel.fromJson(status));
|
||||||
@ -369,15 +398,16 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
emit(UpdateGroupState(oneTouchList: groupOneTouchList, allSwitches: allSwitchesOn));
|
emit(UpdateGroupState(
|
||||||
|
oneTouchList: groupOneTouchList, allSwitches: allSwitchesOn));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(FailedState(error: e.toString()));
|
emit(FailedState(error: e.toString()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeFirstWizardSwitch(
|
void _changeFirstWizardSwitch(ChangeFirstWizardSwitchStatusEvent event,
|
||||||
ChangeFirstWizardSwitchStatusEvent event, Emitter<OneTouchState> emit) async {
|
Emitter<OneTouchState> emit) async {
|
||||||
emit(LoadingNewSate(oneTouchModel: deviceStatus));
|
emit(LoadingNewSate(oneTouchModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
bool allSwitchesValue = true;
|
bool allSwitchesValue = true;
|
||||||
@ -395,7 +425,8 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
|||||||
value: !event.value,
|
value: !event.value,
|
||||||
);
|
);
|
||||||
|
|
||||||
emit(UpdateGroupState(oneTouchList: groupOneTouchList, allSwitches: allSwitchesValue));
|
emit(UpdateGroupState(
|
||||||
|
oneTouchList: groupOneTouchList, allSwitches: allSwitchesValue));
|
||||||
if (response['success']) {
|
if (response['success']) {
|
||||||
add(InitialEvent(groupScreen: oneTouchGroup));
|
add(InitialEvent(groupScreen: oneTouchGroup));
|
||||||
}
|
}
|
||||||
@ -413,10 +444,12 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Emit the state with updated values
|
// Emit the state with updated values
|
||||||
emit(UpdateGroupState(oneTouchList: groupOneTouchList, allSwitches: true));
|
emit(
|
||||||
|
UpdateGroupState(oneTouchList: groupOneTouchList, allSwitches: true));
|
||||||
|
|
||||||
// Get a list of all device IDs
|
// Get a list of all device IDs
|
||||||
List<String> allDeviceIds = groupOneTouchList.map((device) => device.deviceId).toList();
|
List<String> allDeviceIds =
|
||||||
|
groupOneTouchList.map((device) => device.deviceId).toList();
|
||||||
|
|
||||||
// First call for switch_1
|
// First call for switch_1
|
||||||
final response1 = await DevicesAPI.deviceBatchController(
|
final response1 = await DevicesAPI.deviceBatchController(
|
||||||
@ -445,10 +478,12 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Emit the state with updated values
|
// Emit the state with updated values
|
||||||
emit(UpdateGroupState(oneTouchList: groupOneTouchList, allSwitches: false));
|
emit(UpdateGroupState(
|
||||||
|
oneTouchList: groupOneTouchList, allSwitches: false));
|
||||||
|
|
||||||
// Get a list of all device IDs
|
// Get a list of all device IDs
|
||||||
List<String> allDeviceIds = groupOneTouchList.map((device) => device.deviceId).toList();
|
List<String> allDeviceIds =
|
||||||
|
groupOneTouchList.map((device) => device.deviceId).toList();
|
||||||
|
|
||||||
// First call for switch_1
|
// First call for switch_1
|
||||||
final response1 = await DevicesAPI.deviceBatchController(
|
final response1 = await DevicesAPI.deviceBatchController(
|
||||||
@ -472,7 +507,8 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
|||||||
String statusSelected = '';
|
String statusSelected = '';
|
||||||
String optionSelected = '';
|
String optionSelected = '';
|
||||||
|
|
||||||
Future<void> _changeStatus(ChangeStatusEvent event, Emitter<OneTouchState> emit) async {
|
Future<void> _changeStatus(
|
||||||
|
ChangeStatusEvent event, Emitter<OneTouchState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
|
|
||||||
@ -497,7 +533,10 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
|||||||
final selectedControl = controlMap[optionSelected]?[statusSelected];
|
final selectedControl = controlMap[optionSelected]?[statusSelected];
|
||||||
if (selectedControl != null) {
|
if (selectedControl != null) {
|
||||||
await DevicesAPI.controlDevice(
|
await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(deviceId: oneTouchId, code: optionSelected, value: selectedControl),
|
DeviceControlModel(
|
||||||
|
deviceId: oneTouchId,
|
||||||
|
code: optionSelected,
|
||||||
|
value: selectedControl),
|
||||||
oneTouchId,
|
oneTouchId,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import 'dart:async';
|
||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
import 'package:firebase_database/firebase_database.dart';
|
import 'package:firebase_database/firebase_database.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@ -37,7 +38,8 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
|
|||||||
on<SelectTimeEvent>(selectTimeOfLinePassword);
|
on<SelectTimeEvent>(selectTimeOfLinePassword);
|
||||||
on<SelectTimeOnlinePasswordEvent>(selectTimeOnlinePassword);
|
on<SelectTimeOnlinePasswordEvent>(selectTimeOnlinePassword);
|
||||||
on<DeletePasswordEvent>(deletePassword);
|
on<DeletePasswordEvent>(deletePassword);
|
||||||
on<GenerateAndSavePasswordTimeLimitEvent>(generateAndSavePasswordTimeLimited);
|
on<GenerateAndSavePasswordTimeLimitEvent>(
|
||||||
|
generateAndSavePasswordTimeLimited);
|
||||||
on<GenerateAndSavePasswordOneTimeEvent>(generateAndSavePasswordOneTime);
|
on<GenerateAndSavePasswordOneTimeEvent>(generateAndSavePasswordOneTime);
|
||||||
on<ToggleDaySelectionEvent>(toggleDaySelection);
|
on<ToggleDaySelectionEvent>(toggleDaySelection);
|
||||||
on<RenamePasswordEvent>(_renamePassword);
|
on<RenamePasswordEvent>(_renamePassword);
|
||||||
@ -59,7 +61,8 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
|
|||||||
List<OfflinePasswordModel>? oneTimePasswords = [];
|
List<OfflinePasswordModel>? oneTimePasswords = [];
|
||||||
List<OfflinePasswordModel>? timeLimitPasswords = [];
|
List<OfflinePasswordModel>? timeLimitPasswords = [];
|
||||||
|
|
||||||
Future generate7DigitNumber(GeneratePasswordEvent event, Emitter<SmartDoorState> emit) async {
|
Future generate7DigitNumber(
|
||||||
|
GeneratePasswordEvent event, Emitter<SmartDoorState> emit) async {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
passwordController.clear();
|
passwordController.clear();
|
||||||
Random random = Random();
|
Random random = Random();
|
||||||
@ -71,7 +74,8 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future generateAndSavePasswordOneTime(
|
Future generateAndSavePasswordOneTime(
|
||||||
GenerateAndSavePasswordOneTimeEvent event, Emitter<SmartDoorState> emit) async {
|
GenerateAndSavePasswordOneTimeEvent event,
|
||||||
|
Emitter<SmartDoorState> emit) async {
|
||||||
try {
|
try {
|
||||||
if (isSavingPassword) return;
|
if (isSavingPassword) return;
|
||||||
isSavingPassword = true;
|
isSavingPassword = true;
|
||||||
@ -92,7 +96,8 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _fetchSmartDoorStatus(InitialEvent event, Emitter<SmartDoorState> emit) async {
|
void _fetchSmartDoorStatus(
|
||||||
|
InitialEvent event, Emitter<SmartDoorState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
var response = await DevicesAPI.getDeviceStatus(deviceId);
|
var response = await DevicesAPI.getDeviceStatus(deviceId);
|
||||||
@ -102,42 +107,63 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
|
|||||||
}
|
}
|
||||||
deviceStatus = SmartDoorModel.fromJson(statusModelList);
|
deviceStatus = SmartDoorModel.fromJson(statusModelList);
|
||||||
emit(UpdateState(smartDoorModel: deviceStatus));
|
emit(UpdateState(smartDoorModel: deviceStatus));
|
||||||
// _listenToChanges();
|
_listenToChanges();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(FailedState(errorMessage: e.toString()));
|
emit(FailedState(errorMessage: e.toString()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_listenToChanges() {
|
StreamSubscription<DatabaseEvent>? _streamSubscription;
|
||||||
|
Timer? _timer;
|
||||||
|
|
||||||
|
void _listenToChanges() {
|
||||||
try {
|
try {
|
||||||
DatabaseReference ref = FirebaseDatabase.instance.ref('device-status/$deviceId');
|
_streamSubscription?.cancel();
|
||||||
|
DatabaseReference ref =
|
||||||
|
FirebaseDatabase.instance.ref('device-status/$deviceId');
|
||||||
Stream<DatabaseEvent> stream = ref.onValue;
|
Stream<DatabaseEvent> stream = ref.onValue;
|
||||||
|
|
||||||
stream.listen((DatabaseEvent event) {
|
_streamSubscription = stream.listen((DatabaseEvent event) async {
|
||||||
Map<dynamic, dynamic> usersMap = event.snapshot.value as Map<dynamic, dynamic>;
|
if (_timer != null) {
|
||||||
|
await Future.delayed(const Duration(seconds: 2));
|
||||||
|
}
|
||||||
|
Map<dynamic, dynamic> usersMap =
|
||||||
|
event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
List<StatusModel> statusList = [];
|
List<StatusModel> statusList = [];
|
||||||
|
|
||||||
usersMap['status'].forEach((element) {
|
usersMap['status'].forEach((element) {
|
||||||
statusList.add(StatusModel(code: element['code'], value: element['value']));
|
statusList
|
||||||
|
.add(StatusModel(code: element['code'], value: element['value']));
|
||||||
});
|
});
|
||||||
|
|
||||||
deviceStatus = SmartDoorModel.fromJson(statusList);
|
deviceStatus = SmartDoorModel.fromJson(statusList);
|
||||||
add(DoorLockUpdated());
|
if (!isClosed) {
|
||||||
|
add(DoorLockUpdated());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> close() async {
|
||||||
|
_streamSubscription?.cancel();
|
||||||
|
_streamSubscription = null;
|
||||||
|
return super.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
_doorLockUpdated(DoorLockUpdated event, Emitter<SmartDoorState> emit) {
|
_doorLockUpdated(DoorLockUpdated event, Emitter<SmartDoorState> emit) {
|
||||||
unlockRequest = deviceStatus.unlockRequest;
|
unlockRequest = deviceStatus.unlockRequest;
|
||||||
emit(UpdateState(smartDoorModel: deviceStatus));
|
emit(UpdateState(smartDoorModel: deviceStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _renamePassword(RenamePasswordEvent event, Emitter<SmartDoorState> emit) async {
|
void _renamePassword(
|
||||||
|
RenamePasswordEvent event, Emitter<SmartDoorState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
await DevicesAPI.renamePass(
|
await DevicesAPI.renamePass(
|
||||||
name: passwordNameController.text, doorLockUuid: deviceId, passwordId: passwordId);
|
name: passwordNameController.text,
|
||||||
|
doorLockUuid: deviceId,
|
||||||
|
passwordId: passwordId);
|
||||||
add(InitialOneTimePassword());
|
add(InitialOneTimePassword());
|
||||||
add(InitialTimeLimitPassword());
|
add(InitialTimeLimitPassword());
|
||||||
emit(UpdateState(smartDoorModel: deviceStatus));
|
emit(UpdateState(smartDoorModel: deviceStatus));
|
||||||
@ -147,46 +173,58 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void getTemporaryPasswords(InitialPasswordsPage event, Emitter<SmartDoorState> emit) async {
|
void getTemporaryPasswords(
|
||||||
|
InitialPasswordsPage event, Emitter<SmartDoorState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
var response = await DevicesAPI.getTemporaryPasswords(
|
var response = await DevicesAPI.getTemporaryPasswords(
|
||||||
deviceId,
|
deviceId,
|
||||||
);
|
);
|
||||||
if (response is List) {
|
if (response is List) {
|
||||||
temporaryPasswords = response.map((item) => TemporaryPassword.fromJson(item)).toList();
|
|
||||||
} else if (response is Map && response.containsKey('data')) {
|
|
||||||
temporaryPasswords =
|
temporaryPasswords =
|
||||||
(response['data'] as List).map((item) => TemporaryPassword.fromJson(item)).toList();
|
response.map((item) => TemporaryPassword.fromJson(item)).toList();
|
||||||
|
} else if (response is Map && response.containsKey('data')) {
|
||||||
|
temporaryPasswords = (response['data'] as List)
|
||||||
|
.map((item) => TemporaryPassword.fromJson(item))
|
||||||
|
.toList();
|
||||||
}
|
}
|
||||||
emit(TemporaryPasswordsLoadedState(temporaryPassword: temporaryPasswords!));
|
emit(TemporaryPasswordsLoadedState(
|
||||||
|
temporaryPassword: temporaryPasswords!));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(FailedState(errorMessage: e.toString()));
|
emit(FailedState(errorMessage: e.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void getOneTimePasswords(InitialOneTimePassword event, Emitter<SmartDoorState> emit) async {
|
void getOneTimePasswords(
|
||||||
|
InitialOneTimePassword event, Emitter<SmartDoorState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
var response = await DevicesAPI.getOneTimePasswords(deviceId);
|
var response = await DevicesAPI.getOneTimePasswords(deviceId);
|
||||||
if (response is List) {
|
if (response is List) {
|
||||||
oneTimePasswords = response.map((item) => OfflinePasswordModel.fromJson(item)).toList();
|
oneTimePasswords = response
|
||||||
|
.map((item) => OfflinePasswordModel.fromJson(item))
|
||||||
|
.toList();
|
||||||
}
|
}
|
||||||
emit(TemporaryPasswordsLoadedState(temporaryPassword: temporaryPasswords!));
|
emit(TemporaryPasswordsLoadedState(
|
||||||
|
temporaryPassword: temporaryPasswords!));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(FailedState(errorMessage: e.toString()));
|
emit(FailedState(errorMessage: e.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void getTimeLimitPasswords(InitialTimeLimitPassword event, Emitter<SmartDoorState> emit) async {
|
void getTimeLimitPasswords(
|
||||||
|
InitialTimeLimitPassword event, Emitter<SmartDoorState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
var response = await DevicesAPI.getTimeLimitPasswords(deviceId);
|
var response = await DevicesAPI.getTimeLimitPasswords(deviceId);
|
||||||
if (response is List) {
|
if (response is List) {
|
||||||
timeLimitPasswords = response.map((item) => OfflinePasswordModel.fromJson(item)).toList();
|
timeLimitPasswords = response
|
||||||
|
.map((item) => OfflinePasswordModel.fromJson(item))
|
||||||
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
emit(TemporaryPasswordsLoadedState(temporaryPassword: temporaryPasswords!));
|
emit(TemporaryPasswordsLoadedState(
|
||||||
|
temporaryPassword: temporaryPasswords!));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(FailedState(errorMessage: e.toString()));
|
emit(FailedState(errorMessage: e.toString()));
|
||||||
}
|
}
|
||||||
@ -207,7 +245,8 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
|
|||||||
return repeat;
|
return repeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool setStartEndTime(SetStartEndTimeEvent event, Emitter<SmartDoorState> emit) {
|
bool setStartEndTime(
|
||||||
|
SetStartEndTimeEvent event, Emitter<SmartDoorState> emit) {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
isStartEndTime = event.val;
|
isStartEndTime = event.val;
|
||||||
emit(IsStartEndState(isStartEndTime: isStartEndTime));
|
emit(IsStartEndState(isStartEndTime: isStartEndTime));
|
||||||
@ -230,7 +269,8 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
|
|||||||
emit(UpdateState(smartDoorModel: deviceStatus));
|
emit(UpdateState(smartDoorModel: deviceStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> selectTimeOfLinePassword(SelectTimeEvent event, Emitter<SmartDoorState> emit) async {
|
Future<void> selectTimeOfLinePassword(
|
||||||
|
SelectTimeEvent event, Emitter<SmartDoorState> emit) async {
|
||||||
emit(ChangeTimeState());
|
emit(ChangeTimeState());
|
||||||
final DateTime? picked = await showDatePicker(
|
final DateTime? picked = await showDatePicker(
|
||||||
context: event.context,
|
context: event.context,
|
||||||
@ -260,20 +300,27 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
|
|||||||
).millisecondsSinceEpoch ~/
|
).millisecondsSinceEpoch ~/
|
||||||
1000; // Divide by 1000 to remove milliseconds
|
1000; // Divide by 1000 to remove milliseconds
|
||||||
if (event.isEffective) {
|
if (event.isEffective) {
|
||||||
if (expirationTimeTimeStamp != null && selectedTimestamp > expirationTimeTimeStamp!) {
|
if (expirationTimeTimeStamp != null &&
|
||||||
CustomSnackBar.displaySnackBar('Effective Time cannot be later than Expiration Time.');
|
selectedTimestamp > expirationTimeTimeStamp!) {
|
||||||
|
CustomSnackBar.displaySnackBar(
|
||||||
|
'Effective Time cannot be later than Expiration Time.');
|
||||||
} else {
|
} else {
|
||||||
effectiveTime =
|
effectiveTime = selectedDateTime
|
||||||
selectedDateTime.toString().split('.').first; // Remove seconds and milliseconds
|
.toString()
|
||||||
|
.split('.')
|
||||||
|
.first; // Remove seconds and milliseconds
|
||||||
effectiveTimeTimeStamp = selectedTimestamp;
|
effectiveTimeTimeStamp = selectedTimestamp;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (effectiveTimeTimeStamp != null && selectedTimestamp < effectiveTimeTimeStamp!) {
|
if (effectiveTimeTimeStamp != null &&
|
||||||
|
selectedTimestamp < effectiveTimeTimeStamp!) {
|
||||||
CustomSnackBar.displaySnackBar(
|
CustomSnackBar.displaySnackBar(
|
||||||
'Expiration Time cannot be earlier than Effective Time.');
|
'Expiration Time cannot be earlier than Effective Time.');
|
||||||
} else {
|
} else {
|
||||||
expirationTime =
|
expirationTime = selectedDateTime
|
||||||
selectedDateTime.toString().split('.').first; // Remove seconds and milliseconds
|
.toString()
|
||||||
|
.split('.')
|
||||||
|
.first; // Remove seconds and milliseconds
|
||||||
expirationTimeTimeStamp = selectedTimestamp;
|
expirationTimeTimeStamp = selectedTimestamp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -329,20 +376,27 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
|
|||||||
).millisecondsSinceEpoch ~/
|
).millisecondsSinceEpoch ~/
|
||||||
1000; // Divide by 1000 to remove milliseconds
|
1000; // Divide by 1000 to remove milliseconds
|
||||||
if (event.isEffective) {
|
if (event.isEffective) {
|
||||||
if (expirationTimeTimeStamp != null && selectedTimestamp > expirationTimeTimeStamp!) {
|
if (expirationTimeTimeStamp != null &&
|
||||||
CustomSnackBar.displaySnackBar('Effective Time cannot be later than Expiration Time.');
|
selectedTimestamp > expirationTimeTimeStamp!) {
|
||||||
|
CustomSnackBar.displaySnackBar(
|
||||||
|
'Effective Time cannot be later than Expiration Time.');
|
||||||
} else {
|
} else {
|
||||||
effectiveTime =
|
effectiveTime = selectedDateTime
|
||||||
selectedDateTime.toString().split('.').first; // Remove seconds and milliseconds
|
.toString()
|
||||||
|
.split('.')
|
||||||
|
.first; // Remove seconds and milliseconds
|
||||||
effectiveTimeTimeStamp = selectedTimestamp;
|
effectiveTimeTimeStamp = selectedTimestamp;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (effectiveTimeTimeStamp != null && selectedTimestamp < effectiveTimeTimeStamp!) {
|
if (effectiveTimeTimeStamp != null &&
|
||||||
|
selectedTimestamp < effectiveTimeTimeStamp!) {
|
||||||
CustomSnackBar.displaySnackBar(
|
CustomSnackBar.displaySnackBar(
|
||||||
'Expiration Time cannot be earlier than Effective Time.');
|
'Expiration Time cannot be earlier than Effective Time.');
|
||||||
} else {
|
} else {
|
||||||
expirationTime =
|
expirationTime = selectedDateTime
|
||||||
selectedDateTime.toString().split('.').first; // Remove seconds and milliseconds
|
.toString()
|
||||||
|
.split('.')
|
||||||
|
.first; // Remove seconds and milliseconds
|
||||||
expirationTimeTimeStamp = selectedTimestamp;
|
expirationTimeTimeStamp = selectedTimestamp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -351,7 +405,8 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> savePassword(SavePasswordEvent event, Emitter<SmartDoorState> emit) async {
|
Future<void> savePassword(
|
||||||
|
SavePasswordEvent event, Emitter<SmartDoorState> emit) async {
|
||||||
if (_validateInputs() || isSavingPassword) return;
|
if (_validateInputs() || isSavingPassword) return;
|
||||||
try {
|
try {
|
||||||
isSavingPassword = true;
|
isSavingPassword = true;
|
||||||
@ -381,7 +436,8 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> generateAndSavePasswordTimeLimited(
|
Future<void> generateAndSavePasswordTimeLimited(
|
||||||
GenerateAndSavePasswordTimeLimitEvent event, Emitter<SmartDoorState> emit) async {
|
GenerateAndSavePasswordTimeLimitEvent event,
|
||||||
|
Emitter<SmartDoorState> emit) async {
|
||||||
if (timeLimitValidate() || isSavingPassword) return;
|
if (timeLimitValidate() || isSavingPassword) return;
|
||||||
try {
|
try {
|
||||||
isSavingPassword = true;
|
isSavingPassword = true;
|
||||||
@ -407,10 +463,12 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> deletePassword(DeletePasswordEvent event, Emitter<SmartDoorState> emit) async {
|
Future<void> deletePassword(
|
||||||
|
DeletePasswordEvent event, Emitter<SmartDoorState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
await DevicesAPI.deletePassword(deviceId: deviceId, passwordId: event.passwordId)
|
await DevicesAPI.deletePassword(
|
||||||
|
deviceId: deviceId, passwordId: event.passwordId)
|
||||||
.then((value) async {
|
.then((value) async {
|
||||||
add(InitialPasswordsPage());
|
add(InitialPasswordsPage());
|
||||||
});
|
});
|
||||||
@ -445,7 +503,8 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (repeat == true && (endTime == null || startTime == null)) {
|
if (repeat == true && (endTime == null || startTime == null)) {
|
||||||
CustomSnackBar.displaySnackBar('Start Time and End time and the days required ');
|
CustomSnackBar.displaySnackBar(
|
||||||
|
'Start Time and End time and the days required ');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:firebase_database/firebase_database.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||||
import 'package:syncrow_app/features/app_layout/model/community_model.dart';
|
import 'package:syncrow_app/features/app_layout/model/community_model.dart';
|
||||||
import 'package:syncrow_app/features/app_layout/model/space_model.dart';
|
import 'package:syncrow_app/features/app_layout/model/space_model.dart';
|
||||||
|
import 'package:syncrow_app/features/auth/model/project_model.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/sos_bloc/sos_event.dart';
|
import 'package:syncrow_app/features/devices/bloc/sos_bloc/sos_event.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/sos_bloc/sos_state.dart';
|
import 'package:syncrow_app/features/devices/bloc/sos_bloc/sos_state.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
||||||
@ -19,6 +21,7 @@ import 'package:syncrow_app/navigation/routing_constants.dart';
|
|||||||
import 'package:syncrow_app/services/api/devices_api.dart';
|
import 'package:syncrow_app/services/api/devices_api.dart';
|
||||||
import 'package:syncrow_app/services/api/home_management_api.dart';
|
import 'package:syncrow_app/services/api/home_management_api.dart';
|
||||||
import 'package:syncrow_app/services/api/spaces_api.dart';
|
import 'package:syncrow_app/services/api/spaces_api.dart';
|
||||||
|
import 'package:syncrow_app/utils/constants/temp_const.dart';
|
||||||
import 'package:syncrow_app/utils/helpers/snack_bar.dart';
|
import 'package:syncrow_app/utils/helpers/snack_bar.dart';
|
||||||
|
|
||||||
class SosBloc extends Bloc<SosEvent, SosState> {
|
class SosBloc extends Bloc<SosEvent, SosState> {
|
||||||
@ -171,6 +174,7 @@ class SosBloc extends Bloc<SosEvent, SosState> {
|
|||||||
);
|
);
|
||||||
emit(UpdateState(sensor: deviceStatus));
|
emit(UpdateState(sensor: deviceStatus));
|
||||||
Future.delayed(const Duration(milliseconds: 500));
|
Future.delayed(const Duration(milliseconds: 500));
|
||||||
|
// _listenToChanges();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(SosFailedState(errorMessage: e.toString()));
|
emit(SosFailedState(errorMessage: e.toString()));
|
||||||
return;
|
return;
|
||||||
@ -184,8 +188,12 @@ class SosBloc extends Bloc<SosEvent, SosState> {
|
|||||||
FetchRoomsEvent event, Emitter<SosState> emit) async {
|
FetchRoomsEvent event, Emitter<SosState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(SosLoadingState());
|
emit(SosLoadingState());
|
||||||
|
Project? project = HomeCubit.getInstance().project;
|
||||||
|
|
||||||
roomsList = await SpacesAPI.getSubSpaceBySpaceId(
|
roomsList = await SpacesAPI.getSubSpaceBySpaceId(
|
||||||
event.unit.community.uuid, event.unit.id);
|
event.unit.community.uuid,
|
||||||
|
event.unit.id,
|
||||||
|
project?.uuid ?? TempConst.projectIdDev);
|
||||||
emit(FetchRoomsState(devicesList: allDevices, roomsList: roomsList));
|
emit(FetchRoomsState(devicesList: allDevices, roomsList: roomsList));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(const SosFailedState(errorMessage: 'Something went wrong'));
|
emit(const SosFailedState(errorMessage: 'Something went wrong'));
|
||||||
@ -223,13 +231,19 @@ class SosBloc extends Bloc<SosEvent, SosState> {
|
|||||||
void _assignDevice(AssignRoomEvent event, Emitter<SosState> emit) async {
|
void _assignDevice(AssignRoomEvent event, Emitter<SosState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(SosLoadingState());
|
emit(SosLoadingState());
|
||||||
|
Project? project = HomeCubit.getInstance().project;
|
||||||
|
|
||||||
await HomeManagementAPI.assignDeviceToRoom(
|
await HomeManagementAPI.assignDeviceToRoom(
|
||||||
event.unit.community.uuid, event.unit.id, event.roomId, sosId);
|
event.unit.community.uuid,
|
||||||
|
event.unit.id,
|
||||||
|
event.roomId,
|
||||||
|
sosId,
|
||||||
|
project?.uuid ?? TempConst.projectIdDev);
|
||||||
final devicesList = await DevicesAPI.getDevicesByRoomId(
|
final devicesList = await DevicesAPI.getDevicesByRoomId(
|
||||||
communityUuid: event.unit.community.uuid,
|
communityUuid: event.unit.community.uuid,
|
||||||
spaceUuid: event.unit.id,
|
spaceUuid: event.unit.id,
|
||||||
roomId: event.roomId);
|
roomId: event.roomId,
|
||||||
|
projectId: project?.uuid ?? TempConst.projectIdDev);
|
||||||
|
|
||||||
List<String> allDevicesIds = [];
|
List<String> allDevicesIds = [];
|
||||||
|
|
||||||
@ -249,13 +263,16 @@ class SosBloc extends Bloc<SosEvent, SosState> {
|
|||||||
void _unassignDevice(UnassignRoomEvent event, Emitter<SosState> emit) async {
|
void _unassignDevice(UnassignRoomEvent event, Emitter<SosState> emit) async {
|
||||||
try {
|
try {
|
||||||
Map<String, bool> roomDevicesId = {};
|
Map<String, bool> roomDevicesId = {};
|
||||||
|
Project? project = HomeCubit.getInstance().project;
|
||||||
|
|
||||||
emit(SosLoadingState());
|
emit(SosLoadingState());
|
||||||
await HomeManagementAPI.unAssignDeviceToRoom(
|
await HomeManagementAPI.unAssignDeviceToRoom(
|
||||||
event.unit.community.uuid, event.unit.id, event.roomId, sosId);
|
event.unit.community.uuid, event.unit.id, event.roomId, sosId, project?.uuid ?? TempConst.projectIdDev);
|
||||||
final devicesList = await DevicesAPI.getDevicesByRoomId(
|
final devicesList = await DevicesAPI.getDevicesByRoomId(
|
||||||
communityUuid: event.unit.community.uuid,
|
communityUuid: event.unit.community.uuid,
|
||||||
spaceUuid: event.unit.id,
|
spaceUuid: event.unit.id,
|
||||||
roomId: event.roomId);
|
roomId: event.roomId,
|
||||||
|
projectId: project?.uuid ?? TempConst.projectIdDev);
|
||||||
|
|
||||||
List<String> allDevicesIds = [];
|
List<String> allDevicesIds = [];
|
||||||
|
|
||||||
@ -419,4 +436,39 @@ class SosBloc extends Bloc<SosEvent, SosState> {
|
|||||||
emit(SosFailedState(errorMessage: e.toString()));
|
emit(SosFailedState(errorMessage: e.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//real-time db
|
||||||
|
// StreamSubscription<DatabaseEvent>? _streamSubscription;
|
||||||
|
// Timer? _timer;
|
||||||
|
|
||||||
|
// void _listenToChanges() {
|
||||||
|
// try {
|
||||||
|
// _streamSubscription?.cancel();
|
||||||
|
// DatabaseReference ref =
|
||||||
|
// FirebaseDatabase.instance.ref('device-status/$sosId');
|
||||||
|
// Stream<DatabaseEvent> stream = ref.onValue;
|
||||||
|
|
||||||
|
// _streamSubscription = stream.listen((DatabaseEvent event) async {
|
||||||
|
// if (_timer != null) {
|
||||||
|
// await Future.delayed(const Duration(seconds: 2));
|
||||||
|
// }
|
||||||
|
// Map<dynamic, dynamic> usersMap =
|
||||||
|
// event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
|
// List<StatusModel> statusList = [];
|
||||||
|
// usersMap['status'].forEach((element) {
|
||||||
|
// statusList
|
||||||
|
// .add(StatusModel(code: element['code'], value: element['value']));
|
||||||
|
// });
|
||||||
|
// deviceStatus = SosModel.fromJson(statusList);
|
||||||
|
// });
|
||||||
|
// } catch (_) {}
|
||||||
|
// }
|
||||||
|
|
||||||
|
// @override
|
||||||
|
// Future<void> close() async {
|
||||||
|
// _streamSubscription?.cancel();
|
||||||
|
// _streamSubscription = null;
|
||||||
|
// return super.close();
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,8 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
List<GroupThreeGangModel> groupThreeGangList = [];
|
List<GroupThreeGangModel> groupThreeGangList = [];
|
||||||
bool allSwitchesOn = true;
|
bool allSwitchesOn = true;
|
||||||
|
|
||||||
ThreeGangBloc({required this.threeGangId, required this.switchCode}) : super(InitialState()) {
|
ThreeGangBloc({required this.threeGangId, required this.switchCode})
|
||||||
|
: super(InitialState()) {
|
||||||
on<InitialEvent>(_fetchThreeGangStatus);
|
on<InitialEvent>(_fetchThreeGangStatus);
|
||||||
on<ThreeGangUpdated>(_threeGangUpdated);
|
on<ThreeGangUpdated>(_threeGangUpdated);
|
||||||
on<ChangeFirstSwitchStatusEvent>(_changeFirstSwitch);
|
on<ChangeFirstSwitchStatusEvent>(_changeFirstSwitch);
|
||||||
@ -57,7 +58,8 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
on<ToggleCreateScheduleEvent>(toggleCreateSchedule);
|
on<ToggleCreateScheduleEvent>(toggleCreateSchedule);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _fetchThreeGangStatus(InitialEvent event, Emitter<ThreeGangState> emit) async {
|
void _fetchThreeGangStatus(
|
||||||
|
InitialEvent event, Emitter<ThreeGangState> emit) async {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
try {
|
try {
|
||||||
threeGangGroup = event.groupScreen;
|
threeGangGroup = event.groupScreen;
|
||||||
@ -69,7 +71,8 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
HomeCubit.getInstance().selectedSpace?.id ?? '', '3G');
|
HomeCubit.getInstance().selectedSpace?.id ?? '', '3G');
|
||||||
|
|
||||||
for (int i = 0; i < devicesList.length; i++) {
|
for (int i = 0; i < devicesList.length; i++) {
|
||||||
var response = await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
var response =
|
||||||
|
await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
||||||
List<StatusModel> statusModelList = [];
|
List<StatusModel> statusModelList = [];
|
||||||
for (var status in response['status']) {
|
for (var status in response['status']) {
|
||||||
statusModelList.add(StatusModel.fromJson(status));
|
statusModelList.add(StatusModel.fromJson(status));
|
||||||
@ -86,13 +89,16 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
|
|
||||||
if (groupThreeGangList.isNotEmpty) {
|
if (groupThreeGangList.isNotEmpty) {
|
||||||
groupThreeGangList.firstWhere((element) {
|
groupThreeGangList.firstWhere((element) {
|
||||||
if (!element.firstSwitch || !element.secondSwitch || !element.thirdSwitch) {
|
if (!element.firstSwitch ||
|
||||||
|
!element.secondSwitch ||
|
||||||
|
!element.thirdSwitch) {
|
||||||
allSwitchesOn = false;
|
allSwitchesOn = false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
emit(UpdateGroupState(threeGangList: groupThreeGangList, allSwitches: allSwitchesOn));
|
emit(UpdateGroupState(
|
||||||
|
threeGangList: groupThreeGangList, allSwitches: allSwitchesOn));
|
||||||
} else {
|
} else {
|
||||||
var response = await DevicesAPI.getDeviceStatus(threeGangId);
|
var response = await DevicesAPI.getDeviceStatus(threeGangId);
|
||||||
List<StatusModel> statusModelList = [];
|
List<StatusModel> statusModelList = [];
|
||||||
@ -101,7 +107,7 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
}
|
}
|
||||||
deviceStatus = ThreeGangModel.fromJson(statusModelList);
|
deviceStatus = ThreeGangModel.fromJson(statusModelList);
|
||||||
emit(UpdateState(threeGangModel: deviceStatus));
|
emit(UpdateState(threeGangModel: deviceStatus));
|
||||||
// _listenToChanges();
|
_listenToChanges();
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(FailedState(error: e.toString()));
|
emit(FailedState(error: e.toString()));
|
||||||
@ -109,22 +115,26 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_listenToChanges() {
|
StreamSubscription<DatabaseEvent>? _streamSubscription;
|
||||||
|
|
||||||
|
void _listenToChanges() {
|
||||||
try {
|
try {
|
||||||
DatabaseReference ref = FirebaseDatabase.instance.ref('device-status/$threeGangId');
|
_streamSubscription?.cancel();
|
||||||
|
DatabaseReference ref =
|
||||||
|
FirebaseDatabase.instance.ref('device-status/$threeGangId');
|
||||||
Stream<DatabaseEvent> stream = ref.onValue;
|
Stream<DatabaseEvent> stream = ref.onValue;
|
||||||
|
|
||||||
stream.listen((DatabaseEvent event) async {
|
_streamSubscription = stream.listen((DatabaseEvent event) async {
|
||||||
if (_timer != null) {
|
if (_timer != null) {
|
||||||
await Future.delayed(const Duration(seconds: 2));
|
await Future.delayed(const Duration(seconds: 1));
|
||||||
}
|
}
|
||||||
Map<dynamic, dynamic> usersMap = event.snapshot.value as Map<dynamic, dynamic>;
|
Map<dynamic, dynamic> usersMap =
|
||||||
|
event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
List<StatusModel> statusList = [];
|
List<StatusModel> statusList = [];
|
||||||
|
|
||||||
usersMap['status'].forEach((element) {
|
usersMap['status'].forEach((element) {
|
||||||
statusList.add(StatusModel(code: element['code'], value: element['value']));
|
statusList
|
||||||
|
.add(StatusModel(code: element['code'], value: element['value']));
|
||||||
});
|
});
|
||||||
|
|
||||||
deviceStatus = ThreeGangModel.fromJson(statusList);
|
deviceStatus = ThreeGangModel.fromJson(statusList);
|
||||||
if (!isClosed) {
|
if (!isClosed) {
|
||||||
add(ThreeGangUpdated());
|
add(ThreeGangUpdated());
|
||||||
@ -133,11 +143,19 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> close() async {
|
||||||
|
_streamSubscription?.cancel();
|
||||||
|
_streamSubscription = null;
|
||||||
|
return super.close();
|
||||||
|
}
|
||||||
|
|
||||||
_threeGangUpdated(ThreeGangUpdated event, Emitter<ThreeGangState> emit) {
|
_threeGangUpdated(ThreeGangUpdated event, Emitter<ThreeGangState> emit) {
|
||||||
emit(UpdateState(threeGangModel: deviceStatus));
|
emit(UpdateState(threeGangModel: deviceStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeFirstSwitch(ChangeFirstSwitchStatusEvent event, Emitter<ThreeGangState> emit) async {
|
void _changeFirstSwitch(
|
||||||
|
ChangeFirstSwitchStatusEvent event, Emitter<ThreeGangState> emit) async {
|
||||||
emit(LoadingNewSate(threeGangModel: deviceStatus));
|
emit(LoadingNewSate(threeGangModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
if (threeGangGroup) {
|
if (threeGangGroup) {
|
||||||
@ -146,11 +164,14 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
if (element.deviceId == event.deviceId) {
|
if (element.deviceId == event.deviceId) {
|
||||||
element.firstSwitch = !event.value;
|
element.firstSwitch = !event.value;
|
||||||
}
|
}
|
||||||
if (!element.firstSwitch || !element.secondSwitch || !element.thirdSwitch) {
|
if (!element.firstSwitch ||
|
||||||
|
!element.secondSwitch ||
|
||||||
|
!element.thirdSwitch) {
|
||||||
allSwitchesValue = false;
|
allSwitchesValue = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
emit(UpdateGroupState(threeGangList: groupThreeGangList, allSwitches: allSwitchesValue));
|
emit(UpdateGroupState(
|
||||||
|
threeGangList: groupThreeGangList, allSwitches: allSwitchesValue));
|
||||||
} else {
|
} else {
|
||||||
deviceStatus.firstSwitch = !event.value;
|
deviceStatus.firstSwitch = !event.value;
|
||||||
emit(UpdateState(threeGangModel: deviceStatus));
|
emit(UpdateState(threeGangModel: deviceStatus));
|
||||||
@ -187,11 +208,14 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
if (element.deviceId == event.deviceId) {
|
if (element.deviceId == event.deviceId) {
|
||||||
element.secondSwitch = !event.value;
|
element.secondSwitch = !event.value;
|
||||||
}
|
}
|
||||||
if (!element.firstSwitch || !element.secondSwitch || !element.thirdSwitch) {
|
if (!element.firstSwitch ||
|
||||||
|
!element.secondSwitch ||
|
||||||
|
!element.thirdSwitch) {
|
||||||
allSwitchesValue = false;
|
allSwitchesValue = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
emit(UpdateGroupState(threeGangList: groupThreeGangList, allSwitches: allSwitchesValue));
|
emit(UpdateGroupState(
|
||||||
|
threeGangList: groupThreeGangList, allSwitches: allSwitchesValue));
|
||||||
} else {
|
} else {
|
||||||
deviceStatus.secondSwitch = !event.value;
|
deviceStatus.secondSwitch = !event.value;
|
||||||
emit(UpdateState(threeGangModel: deviceStatus));
|
emit(UpdateState(threeGangModel: deviceStatus));
|
||||||
@ -217,7 +241,8 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeThirdSwitch(ChangeThirdSwitchStatusEvent event, Emitter<ThreeGangState> emit) async {
|
void _changeThirdSwitch(
|
||||||
|
ChangeThirdSwitchStatusEvent event, Emitter<ThreeGangState> emit) async {
|
||||||
emit(LoadingNewSate(threeGangModel: deviceStatus));
|
emit(LoadingNewSate(threeGangModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
if (threeGangGroup) {
|
if (threeGangGroup) {
|
||||||
@ -226,11 +251,14 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
if (element.deviceId == event.deviceId) {
|
if (element.deviceId == event.deviceId) {
|
||||||
element.thirdSwitch = !event.value;
|
element.thirdSwitch = !event.value;
|
||||||
}
|
}
|
||||||
if (!element.firstSwitch || !element.secondSwitch || !element.thirdSwitch) {
|
if (!element.firstSwitch ||
|
||||||
|
!element.secondSwitch ||
|
||||||
|
!element.thirdSwitch) {
|
||||||
allSwitchesValue = false;
|
allSwitchesValue = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
emit(UpdateGroupState(threeGangList: groupThreeGangList, allSwitches: allSwitchesValue));
|
emit(UpdateGroupState(
|
||||||
|
threeGangList: groupThreeGangList, allSwitches: allSwitchesValue));
|
||||||
} else {
|
} else {
|
||||||
deviceStatus.thirdSwitch = !event.value;
|
deviceStatus.thirdSwitch = !event.value;
|
||||||
emit(UpdateState(threeGangModel: deviceStatus));
|
emit(UpdateState(threeGangModel: deviceStatus));
|
||||||
@ -269,15 +297,21 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
final response = await Future.wait([
|
final response = await Future.wait([
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: threeGangId, code: 'switch_1', value: deviceStatus.firstSwitch),
|
deviceId: threeGangId,
|
||||||
|
code: 'switch_1',
|
||||||
|
value: deviceStatus.firstSwitch),
|
||||||
threeGangId),
|
threeGangId),
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: threeGangId, code: 'switch_2', value: deviceStatus.secondSwitch),
|
deviceId: threeGangId,
|
||||||
|
code: 'switch_2',
|
||||||
|
value: deviceStatus.secondSwitch),
|
||||||
threeGangId),
|
threeGangId),
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: threeGangId, code: 'switch_3', value: deviceStatus.thirdSwitch),
|
deviceId: threeGangId,
|
||||||
|
code: 'switch_3',
|
||||||
|
value: deviceStatus.thirdSwitch),
|
||||||
threeGangId),
|
threeGangId),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -303,15 +337,21 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
final response = await Future.wait([
|
final response = await Future.wait([
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: threeGangId, code: 'switch_1', value: deviceStatus.firstSwitch),
|
deviceId: threeGangId,
|
||||||
|
code: 'switch_1',
|
||||||
|
value: deviceStatus.firstSwitch),
|
||||||
threeGangId),
|
threeGangId),
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: threeGangId, code: 'switch_2', value: deviceStatus.secondSwitch),
|
deviceId: threeGangId,
|
||||||
|
code: 'switch_2',
|
||||||
|
value: deviceStatus.secondSwitch),
|
||||||
threeGangId),
|
threeGangId),
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: threeGangId, code: 'switch_3', value: deviceStatus.thirdSwitch),
|
deviceId: threeGangId,
|
||||||
|
code: 'switch_3',
|
||||||
|
value: deviceStatus.thirdSwitch),
|
||||||
threeGangId),
|
threeGangId),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -333,9 +373,11 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
groupThreeGangList[i].secondSwitch = true;
|
groupThreeGangList[i].secondSwitch = true;
|
||||||
groupThreeGangList[i].thirdSwitch = true;
|
groupThreeGangList[i].thirdSwitch = true;
|
||||||
}
|
}
|
||||||
emit(UpdateGroupState(threeGangList: groupThreeGangList, allSwitches: true));
|
emit(UpdateGroupState(
|
||||||
|
threeGangList: groupThreeGangList, allSwitches: true));
|
||||||
|
|
||||||
List<String> allDeviceIds = groupThreeGangList.map((device) => device.deviceId).toList();
|
List<String> allDeviceIds =
|
||||||
|
groupThreeGangList.map((device) => device.deviceId).toList();
|
||||||
|
|
||||||
final response1 = await DevicesAPI.deviceBatchController(
|
final response1 = await DevicesAPI.deviceBatchController(
|
||||||
code: 'switch_1',
|
code: 'switch_1',
|
||||||
@ -365,7 +407,8 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _groupAllOff(GroupAllOffEvent event, Emitter<ThreeGangState> emit) async {
|
void _groupAllOff(
|
||||||
|
GroupAllOffEvent event, Emitter<ThreeGangState> emit) async {
|
||||||
emit(LoadingNewSate(threeGangModel: deviceStatus));
|
emit(LoadingNewSate(threeGangModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
for (int i = 0; i < groupThreeGangList.length; i++) {
|
for (int i = 0; i < groupThreeGangList.length; i++) {
|
||||||
@ -373,8 +416,10 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
groupThreeGangList[i].secondSwitch = false;
|
groupThreeGangList[i].secondSwitch = false;
|
||||||
groupThreeGangList[i].thirdSwitch = false;
|
groupThreeGangList[i].thirdSwitch = false;
|
||||||
}
|
}
|
||||||
emit(UpdateGroupState(threeGangList: groupThreeGangList, allSwitches: false));
|
emit(UpdateGroupState(
|
||||||
List<String> allDeviceIds = groupThreeGangList.map((device) => device.deviceId).toList();
|
threeGangList: groupThreeGangList, allSwitches: false));
|
||||||
|
List<String> allDeviceIds =
|
||||||
|
groupThreeGangList.map((device) => device.deviceId).toList();
|
||||||
|
|
||||||
final response1 = await DevicesAPI.deviceBatchController(
|
final response1 = await DevicesAPI.deviceBatchController(
|
||||||
code: 'switch_1',
|
code: 'switch_1',
|
||||||
@ -404,17 +449,20 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeSliding(ChangeSlidingSegment event, Emitter<ThreeGangState> emit) async {
|
void _changeSliding(
|
||||||
|
ChangeSlidingSegment event, Emitter<ThreeGangState> emit) async {
|
||||||
emit(ChangeSlidingSegmentState(value: event.value));
|
emit(ChangeSlidingSegmentState(value: event.value));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _setCounterValue(SetCounterValue event, Emitter<ThreeGangState> emit) async {
|
void _setCounterValue(
|
||||||
|
SetCounterValue event, Emitter<ThreeGangState> emit) async {
|
||||||
emit(LoadingNewSate(threeGangModel: deviceStatus));
|
emit(LoadingNewSate(threeGangModel: deviceStatus));
|
||||||
int seconds = 0;
|
int seconds = 0;
|
||||||
try {
|
try {
|
||||||
seconds = event.duration.inSeconds;
|
seconds = event.duration.inSeconds;
|
||||||
final response = await DevicesAPI.controlDevice(
|
final response = await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(deviceId: threeGangId, code: event.deviceCode, value: seconds),
|
DeviceControlModel(
|
||||||
|
deviceId: threeGangId, code: event.deviceCode, value: seconds),
|
||||||
threeGangId);
|
threeGangId);
|
||||||
|
|
||||||
if (response['success'] ?? false) {
|
if (response['success'] ?? false) {
|
||||||
@ -441,7 +489,8 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _getCounterValue(GetCounterEvent event, Emitter<ThreeGangState> emit) async {
|
void _getCounterValue(
|
||||||
|
GetCounterEvent event, Emitter<ThreeGangState> emit) async {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
try {
|
try {
|
||||||
var response = await DevicesAPI.getDeviceStatus(threeGangId);
|
var response = await DevicesAPI.getDeviceStatus(threeGangId);
|
||||||
@ -551,7 +600,8 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
deviceId: threeGangId,
|
deviceId: threeGangId,
|
||||||
);
|
);
|
||||||
List<dynamic> jsonData = response;
|
List<dynamic> jsonData = response;
|
||||||
listSchedule = jsonData.map((item) => ScheduleModel.fromJson(item)).toList();
|
listSchedule =
|
||||||
|
jsonData.map((item) => ScheduleModel.fromJson(item)).toList();
|
||||||
emit(InitialState());
|
emit(InitialState());
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
final errorData = e.response!.data;
|
final errorData = e.response!.data;
|
||||||
@ -562,12 +612,13 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
|
|
||||||
int? getTimeStampWithoutSeconds(DateTime? dateTime) {
|
int? getTimeStampWithoutSeconds(DateTime? dateTime) {
|
||||||
if (dateTime == null) return null;
|
if (dateTime == null) return null;
|
||||||
DateTime dateTimeWithoutSeconds =
|
DateTime dateTimeWithoutSeconds = DateTime(dateTime.year, dateTime.month,
|
||||||
DateTime(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute);
|
dateTime.day, dateTime.hour, dateTime.minute);
|
||||||
return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000;
|
return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future toggleChange(ToggleScheduleEvent event, Emitter<ThreeGangState> emit) async {
|
Future toggleChange(
|
||||||
|
ToggleScheduleEvent event, Emitter<ThreeGangState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
final response = await DevicesAPI.changeSchedule(
|
final response = await DevicesAPI.changeSchedule(
|
||||||
@ -586,7 +637,8 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future deleteSchedule(DeleteScheduleEvent event, Emitter<ThreeGangState> emit) async {
|
Future deleteSchedule(
|
||||||
|
DeleteScheduleEvent event, Emitter<ThreeGangState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
final response = await DevicesAPI.deleteSchedule(
|
final response = await DevicesAPI.deleteSchedule(
|
||||||
@ -606,13 +658,15 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggleSelectedIndex(ToggleSelectedEvent event, Emitter<ThreeGangState> emit) {
|
void toggleSelectedIndex(
|
||||||
|
ToggleSelectedEvent event, Emitter<ThreeGangState> emit) {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
selectedTabIndex = event.index;
|
selectedTabIndex = event.index;
|
||||||
emit(ChangeSlidingSegmentState(value: selectedTabIndex));
|
emit(ChangeSlidingSegmentState(value: selectedTabIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggleCreateSchedule(ToggleCreateScheduleEvent event, Emitter<ThreeGangState> emit) {
|
void toggleCreateSchedule(
|
||||||
|
ToggleCreateScheduleEvent event, Emitter<ThreeGangState> emit) {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
createSchedule = !createSchedule;
|
createSchedule = !createSchedule;
|
||||||
selectedDays.clear();
|
selectedDays.clear();
|
||||||
|
@ -38,7 +38,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
List<GroupThreeTouchModel> groupThreeTouchList = [];
|
List<GroupThreeTouchModel> groupThreeTouchList = [];
|
||||||
bool allSwitchesOn = true;
|
bool allSwitchesOn = true;
|
||||||
|
|
||||||
ThreeTouchBloc({required this.threeTouchId, required this.switchCode}) : super(InitialState()) {
|
ThreeTouchBloc({required this.threeTouchId, required this.switchCode})
|
||||||
|
: super(InitialState()) {
|
||||||
on<InitialEvent>(_fetchThreeTouchStatus);
|
on<InitialEvent>(_fetchThreeTouchStatus);
|
||||||
on<ThreeTouchUpdated>(_threeTouchUpdated);
|
on<ThreeTouchUpdated>(_threeTouchUpdated);
|
||||||
on<ChangeFirstSwitchStatusEvent>(_changeFirstSwitch);
|
on<ChangeFirstSwitchStatusEvent>(_changeFirstSwitch);
|
||||||
@ -63,7 +64,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
on<ChangeStatusEvent>(_changeStatus);
|
on<ChangeStatusEvent>(_changeStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _fetchThreeTouchStatus(InitialEvent event, Emitter<ThreeTouchState> emit) async {
|
void _fetchThreeTouchStatus(
|
||||||
|
InitialEvent event, Emitter<ThreeTouchState> emit) async {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
try {
|
try {
|
||||||
threeTouchGroup = event.groupScreen;
|
threeTouchGroup = event.groupScreen;
|
||||||
@ -75,7 +77,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
HomeCubit.getInstance().selectedSpace?.id ?? '', '3GT');
|
HomeCubit.getInstance().selectedSpace?.id ?? '', '3GT');
|
||||||
|
|
||||||
for (int i = 0; i < devicesList.length; i++) {
|
for (int i = 0; i < devicesList.length; i++) {
|
||||||
var response = await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
var response =
|
||||||
|
await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
||||||
List<StatusModel> statusModelList = [];
|
List<StatusModel> statusModelList = [];
|
||||||
for (var status in response['status']) {
|
for (var status in response['status']) {
|
||||||
statusModelList.add(StatusModel.fromJson(status));
|
statusModelList.add(StatusModel.fromJson(status));
|
||||||
@ -92,13 +95,16 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
|
|
||||||
if (groupThreeTouchList.isNotEmpty) {
|
if (groupThreeTouchList.isNotEmpty) {
|
||||||
groupThreeTouchList.firstWhere((element) {
|
groupThreeTouchList.firstWhere((element) {
|
||||||
if (!element.firstSwitch || !element.secondSwitch || !element.thirdSwitch) {
|
if (!element.firstSwitch ||
|
||||||
|
!element.secondSwitch ||
|
||||||
|
!element.thirdSwitch) {
|
||||||
allSwitchesOn = false;
|
allSwitchesOn = false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
emit(UpdateGroupState(threeTouchList: groupThreeTouchList, allSwitches: allSwitchesOn));
|
emit(UpdateGroupState(
|
||||||
|
threeTouchList: groupThreeTouchList, allSwitches: allSwitchesOn));
|
||||||
} else {
|
} else {
|
||||||
var response = await DevicesAPI.getDeviceStatus(threeTouchId);
|
var response = await DevicesAPI.getDeviceStatus(threeTouchId);
|
||||||
List<StatusModel> statusModelList = [];
|
List<StatusModel> statusModelList = [];
|
||||||
@ -107,7 +113,7 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
}
|
}
|
||||||
deviceStatus = ThreeTouchModel.fromJson(statusModelList);
|
deviceStatus = ThreeTouchModel.fromJson(statusModelList);
|
||||||
emit(UpdateState(threeTouchModel: deviceStatus));
|
emit(UpdateState(threeTouchModel: deviceStatus));
|
||||||
// _listenToChanges();
|
_listenToChanges();
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(FailedState(error: e.toString()));
|
emit(FailedState(error: e.toString()));
|
||||||
@ -117,18 +123,21 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
|
|
||||||
_listenToChanges() {
|
_listenToChanges() {
|
||||||
try {
|
try {
|
||||||
DatabaseReference ref = FirebaseDatabase.instance.ref('device-status/$threeTouchId');
|
DatabaseReference ref =
|
||||||
|
FirebaseDatabase.instance.ref('device-status/$threeTouchId');
|
||||||
Stream<DatabaseEvent> stream = ref.onValue;
|
Stream<DatabaseEvent> stream = ref.onValue;
|
||||||
|
|
||||||
stream.listen((DatabaseEvent event) async {
|
stream.listen((DatabaseEvent event) async {
|
||||||
if (_timer != null) {
|
if (_timer != null) {
|
||||||
await Future.delayed(const Duration(seconds: 2));
|
await Future.delayed(const Duration(seconds: 2));
|
||||||
}
|
}
|
||||||
Map<dynamic, dynamic> usersMap = event.snapshot.value as Map<dynamic, dynamic>;
|
Map<dynamic, dynamic> usersMap =
|
||||||
|
event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
List<StatusModel> statusList = [];
|
List<StatusModel> statusList = [];
|
||||||
|
|
||||||
usersMap['status'].forEach((element) {
|
usersMap['status'].forEach((element) {
|
||||||
statusList.add(StatusModel(code: element['code'], value: element['value']));
|
statusList
|
||||||
|
.add(StatusModel(code: element['code'], value: element['value']));
|
||||||
});
|
});
|
||||||
|
|
||||||
deviceStatus = ThreeTouchModel.fromJson(statusList);
|
deviceStatus = ThreeTouchModel.fromJson(statusList);
|
||||||
@ -143,7 +152,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
emit(UpdateState(threeTouchModel: deviceStatus));
|
emit(UpdateState(threeTouchModel: deviceStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeFirstSwitch(ChangeFirstSwitchStatusEvent event, Emitter<ThreeTouchState> emit) async {
|
void _changeFirstSwitch(
|
||||||
|
ChangeFirstSwitchStatusEvent event, Emitter<ThreeTouchState> emit) async {
|
||||||
emit(LoadingNewSate(threeTouchModel: deviceStatus));
|
emit(LoadingNewSate(threeTouchModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
if (threeTouchGroup) {
|
if (threeTouchGroup) {
|
||||||
@ -152,11 +162,15 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
if (element.deviceId == event.deviceId) {
|
if (element.deviceId == event.deviceId) {
|
||||||
element.firstSwitch = !event.value;
|
element.firstSwitch = !event.value;
|
||||||
}
|
}
|
||||||
if (!element.firstSwitch || !element.secondSwitch || !element.thirdSwitch) {
|
if (!element.firstSwitch ||
|
||||||
|
!element.secondSwitch ||
|
||||||
|
!element.thirdSwitch) {
|
||||||
allSwitchesValue = false;
|
allSwitchesValue = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
emit(UpdateGroupState(threeTouchList: groupThreeTouchList, allSwitches: allSwitchesValue));
|
emit(UpdateGroupState(
|
||||||
|
threeTouchList: groupThreeTouchList,
|
||||||
|
allSwitches: allSwitchesValue));
|
||||||
} else {
|
} else {
|
||||||
deviceStatus.firstSwitch = !event.value;
|
deviceStatus.firstSwitch = !event.value;
|
||||||
emit(UpdateState(threeTouchModel: deviceStatus));
|
emit(UpdateState(threeTouchModel: deviceStatus));
|
||||||
@ -183,8 +197,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeSecondSwitch(
|
void _changeSecondSwitch(ChangeSecondSwitchStatusEvent event,
|
||||||
ChangeSecondSwitchStatusEvent event, Emitter<ThreeTouchState> emit) async {
|
Emitter<ThreeTouchState> emit) async {
|
||||||
emit(LoadingNewSate(threeTouchModel: deviceStatus));
|
emit(LoadingNewSate(threeTouchModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
if (threeTouchGroup) {
|
if (threeTouchGroup) {
|
||||||
@ -193,11 +207,15 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
if (element.deviceId == event.deviceId) {
|
if (element.deviceId == event.deviceId) {
|
||||||
element.secondSwitch = !event.value;
|
element.secondSwitch = !event.value;
|
||||||
}
|
}
|
||||||
if (!element.firstSwitch || !element.secondSwitch || !element.thirdSwitch) {
|
if (!element.firstSwitch ||
|
||||||
|
!element.secondSwitch ||
|
||||||
|
!element.thirdSwitch) {
|
||||||
allSwitchesValue = false;
|
allSwitchesValue = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
emit(UpdateGroupState(threeTouchList: groupThreeTouchList, allSwitches: allSwitchesValue));
|
emit(UpdateGroupState(
|
||||||
|
threeTouchList: groupThreeTouchList,
|
||||||
|
allSwitches: allSwitchesValue));
|
||||||
} else {
|
} else {
|
||||||
deviceStatus.secondSwitch = !event.value;
|
deviceStatus.secondSwitch = !event.value;
|
||||||
emit(UpdateState(threeTouchModel: deviceStatus));
|
emit(UpdateState(threeTouchModel: deviceStatus));
|
||||||
@ -223,7 +241,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeThirdSwitch(ChangeThirdSwitchStatusEvent event, Emitter<ThreeTouchState> emit) async {
|
void _changeThirdSwitch(
|
||||||
|
ChangeThirdSwitchStatusEvent event, Emitter<ThreeTouchState> emit) async {
|
||||||
emit(LoadingNewSate(threeTouchModel: deviceStatus));
|
emit(LoadingNewSate(threeTouchModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
if (threeTouchGroup) {
|
if (threeTouchGroup) {
|
||||||
@ -232,11 +251,15 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
if (element.deviceId == event.deviceId) {
|
if (element.deviceId == event.deviceId) {
|
||||||
element.thirdSwitch = !event.value;
|
element.thirdSwitch = !event.value;
|
||||||
}
|
}
|
||||||
if (!element.firstSwitch || !element.secondSwitch || !element.thirdSwitch) {
|
if (!element.firstSwitch ||
|
||||||
|
!element.secondSwitch ||
|
||||||
|
!element.thirdSwitch) {
|
||||||
allSwitchesValue = false;
|
allSwitchesValue = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
emit(UpdateGroupState(threeTouchList: groupThreeTouchList, allSwitches: allSwitchesValue));
|
emit(UpdateGroupState(
|
||||||
|
threeTouchList: groupThreeTouchList,
|
||||||
|
allSwitches: allSwitchesValue));
|
||||||
} else {
|
} else {
|
||||||
deviceStatus.thirdSwitch = !event.value;
|
deviceStatus.thirdSwitch = !event.value;
|
||||||
emit(UpdateState(threeTouchModel: deviceStatus));
|
emit(UpdateState(threeTouchModel: deviceStatus));
|
||||||
@ -275,15 +298,21 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
final response = await Future.wait([
|
final response = await Future.wait([
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: threeTouchId, code: 'switch_1', value: deviceStatus.firstSwitch),
|
deviceId: threeTouchId,
|
||||||
|
code: 'switch_1',
|
||||||
|
value: deviceStatus.firstSwitch),
|
||||||
threeTouchId),
|
threeTouchId),
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: threeTouchId, code: 'switch_2', value: deviceStatus.secondSwitch),
|
deviceId: threeTouchId,
|
||||||
|
code: 'switch_2',
|
||||||
|
value: deviceStatus.secondSwitch),
|
||||||
threeTouchId),
|
threeTouchId),
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: threeTouchId, code: 'switch_3', value: deviceStatus.thirdSwitch),
|
deviceId: threeTouchId,
|
||||||
|
code: 'switch_3',
|
||||||
|
value: deviceStatus.thirdSwitch),
|
||||||
threeTouchId),
|
threeTouchId),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -309,15 +338,21 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
final response = await Future.wait([
|
final response = await Future.wait([
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: threeTouchId, code: 'switch_1', value: deviceStatus.firstSwitch),
|
deviceId: threeTouchId,
|
||||||
|
code: 'switch_1',
|
||||||
|
value: deviceStatus.firstSwitch),
|
||||||
threeTouchId),
|
threeTouchId),
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: threeTouchId, code: 'switch_2', value: deviceStatus.secondSwitch),
|
deviceId: threeTouchId,
|
||||||
|
code: 'switch_2',
|
||||||
|
value: deviceStatus.secondSwitch),
|
||||||
threeTouchId),
|
threeTouchId),
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: threeTouchId, code: 'switch_3', value: deviceStatus.thirdSwitch),
|
deviceId: threeTouchId,
|
||||||
|
code: 'switch_3',
|
||||||
|
value: deviceStatus.thirdSwitch),
|
||||||
threeTouchId),
|
threeTouchId),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -339,8 +374,10 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
groupThreeTouchList[i].secondSwitch = true;
|
groupThreeTouchList[i].secondSwitch = true;
|
||||||
groupThreeTouchList[i].thirdSwitch = true;
|
groupThreeTouchList[i].thirdSwitch = true;
|
||||||
}
|
}
|
||||||
emit(UpdateGroupState(threeTouchList: groupThreeTouchList, allSwitches: true));
|
emit(UpdateGroupState(
|
||||||
List<String> allDeviceIds = groupThreeTouchList.map((device) => device.deviceId).toList();
|
threeTouchList: groupThreeTouchList, allSwitches: true));
|
||||||
|
List<String> allDeviceIds =
|
||||||
|
groupThreeTouchList.map((device) => device.deviceId).toList();
|
||||||
final response1 = await DevicesAPI.deviceBatchController(
|
final response1 = await DevicesAPI.deviceBatchController(
|
||||||
code: 'switch_1',
|
code: 'switch_1',
|
||||||
devicesUuid: allDeviceIds,
|
devicesUuid: allDeviceIds,
|
||||||
@ -369,7 +406,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _groupAllOff(GroupAllOffEvent event, Emitter<ThreeTouchState> emit) async {
|
void _groupAllOff(
|
||||||
|
GroupAllOffEvent event, Emitter<ThreeTouchState> emit) async {
|
||||||
emit(LoadingNewSate(threeTouchModel: deviceStatus));
|
emit(LoadingNewSate(threeTouchModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
for (int i = 0; i < groupThreeTouchList.length; i++) {
|
for (int i = 0; i < groupThreeTouchList.length; i++) {
|
||||||
@ -377,8 +415,10 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
groupThreeTouchList[i].secondSwitch = false;
|
groupThreeTouchList[i].secondSwitch = false;
|
||||||
groupThreeTouchList[i].thirdSwitch = false;
|
groupThreeTouchList[i].thirdSwitch = false;
|
||||||
}
|
}
|
||||||
List<String> allDeviceIds = groupThreeTouchList.map((device) => device.deviceId).toList();
|
List<String> allDeviceIds =
|
||||||
emit(UpdateGroupState(threeTouchList: groupThreeTouchList, allSwitches: false));
|
groupThreeTouchList.map((device) => device.deviceId).toList();
|
||||||
|
emit(UpdateGroupState(
|
||||||
|
threeTouchList: groupThreeTouchList, allSwitches: false));
|
||||||
final response1 = await DevicesAPI.deviceBatchController(
|
final response1 = await DevicesAPI.deviceBatchController(
|
||||||
code: 'switch_1',
|
code: 'switch_1',
|
||||||
devicesUuid: allDeviceIds,
|
devicesUuid: allDeviceIds,
|
||||||
@ -407,17 +447,20 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeSliding(ChangeSlidingSegment event, Emitter<ThreeTouchState> emit) async {
|
void _changeSliding(
|
||||||
|
ChangeSlidingSegment event, Emitter<ThreeTouchState> emit) async {
|
||||||
emit(ChangeSlidingSegmentState(value: event.value));
|
emit(ChangeSlidingSegmentState(value: event.value));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _setCounterValue(SetCounterValue event, Emitter<ThreeTouchState> emit) async {
|
void _setCounterValue(
|
||||||
|
SetCounterValue event, Emitter<ThreeTouchState> emit) async {
|
||||||
emit(LoadingNewSate(threeTouchModel: deviceStatus));
|
emit(LoadingNewSate(threeTouchModel: deviceStatus));
|
||||||
int seconds = 0;
|
int seconds = 0;
|
||||||
try {
|
try {
|
||||||
seconds = event.duration.inSeconds;
|
seconds = event.duration.inSeconds;
|
||||||
final response = await DevicesAPI.controlDevice(
|
final response = await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(deviceId: threeTouchId, code: event.deviceCode, value: seconds),
|
DeviceControlModel(
|
||||||
|
deviceId: threeTouchId, code: event.deviceCode, value: seconds),
|
||||||
threeTouchId);
|
threeTouchId);
|
||||||
|
|
||||||
if (response['success'] ?? false) {
|
if (response['success'] ?? false) {
|
||||||
@ -444,7 +487,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _getCounterValue(GetCounterEvent event, Emitter<ThreeTouchState> emit) async {
|
void _getCounterValue(
|
||||||
|
GetCounterEvent event, Emitter<ThreeTouchState> emit) async {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
try {
|
try {
|
||||||
var response = await DevicesAPI.getDeviceStatus(threeTouchId);
|
var response = await DevicesAPI.getDeviceStatus(threeTouchId);
|
||||||
@ -554,7 +598,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
deviceId: threeTouchId,
|
deviceId: threeTouchId,
|
||||||
);
|
);
|
||||||
List<dynamic> jsonData = response;
|
List<dynamic> jsonData = response;
|
||||||
listSchedule = jsonData.map((item) => ScheduleModel.fromJson(item)).toList();
|
listSchedule =
|
||||||
|
jsonData.map((item) => ScheduleModel.fromJson(item)).toList();
|
||||||
emit(InitialState());
|
emit(InitialState());
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
final errorData = e.response!.data;
|
final errorData = e.response!.data;
|
||||||
@ -565,12 +610,13 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
|
|
||||||
int? getTimeStampWithoutSeconds(DateTime? dateTime) {
|
int? getTimeStampWithoutSeconds(DateTime? dateTime) {
|
||||||
if (dateTime == null) return null;
|
if (dateTime == null) return null;
|
||||||
DateTime dateTimeWithoutSeconds =
|
DateTime dateTimeWithoutSeconds = DateTime(dateTime.year, dateTime.month,
|
||||||
DateTime(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute);
|
dateTime.day, dateTime.hour, dateTime.minute);
|
||||||
return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000;
|
return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future toggleChange(ToggleScheduleEvent event, Emitter<ThreeTouchState> emit) async {
|
Future toggleChange(
|
||||||
|
ToggleScheduleEvent event, Emitter<ThreeTouchState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
final response = await DevicesAPI.changeSchedule(
|
final response = await DevicesAPI.changeSchedule(
|
||||||
@ -589,7 +635,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future deleteSchedule(DeleteScheduleEvent event, Emitter<ThreeTouchState> emit) async {
|
Future deleteSchedule(
|
||||||
|
DeleteScheduleEvent event, Emitter<ThreeTouchState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
final response = await DevicesAPI.deleteSchedule(
|
final response = await DevicesAPI.deleteSchedule(
|
||||||
@ -609,13 +656,15 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggleSelectedIndex(ToggleSelectedEvent event, Emitter<ThreeTouchState> emit) {
|
void toggleSelectedIndex(
|
||||||
|
ToggleSelectedEvent event, Emitter<ThreeTouchState> emit) {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
selectedTabIndex = event.index;
|
selectedTabIndex = event.index;
|
||||||
emit(ChangeSlidingSegmentState(value: selectedTabIndex));
|
emit(ChangeSlidingSegmentState(value: selectedTabIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggleCreateSchedule(ToggleCreateScheduleEvent event, Emitter<ThreeTouchState> emit) {
|
void toggleCreateSchedule(
|
||||||
|
ToggleCreateScheduleEvent event, Emitter<ThreeTouchState> emit) {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
createSchedule = !createSchedule;
|
createSchedule = !createSchedule;
|
||||||
selectedDays.clear();
|
selectedDays.clear();
|
||||||
@ -633,7 +682,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
String statusSelected = '';
|
String statusSelected = '';
|
||||||
String optionSelected = '';
|
String optionSelected = '';
|
||||||
|
|
||||||
Future<void> _changeStatus(ChangeStatusEvent event, Emitter<ThreeTouchState> emit) async {
|
Future<void> _changeStatus(
|
||||||
|
ChangeStatusEvent event, Emitter<ThreeTouchState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
final Map<String, Map<String, String>> controlMap = {
|
final Map<String, Map<String, String>> controlMap = {
|
||||||
@ -667,11 +717,15 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
final selectedControl = controlMap[optionSelected]?[statusSelected];
|
final selectedControl = controlMap[optionSelected]?[statusSelected];
|
||||||
if (selectedControl != null) {
|
if (selectedControl != null) {
|
||||||
await DevicesAPI.controlDevice(
|
await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(deviceId: threeTouchId, code: optionSelected, value: selectedControl),
|
DeviceControlModel(
|
||||||
|
deviceId: threeTouchId,
|
||||||
|
code: optionSelected,
|
||||||
|
value: selectedControl),
|
||||||
threeTouchId,
|
threeTouchId,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
emit(const FailedState(error: 'Invalid statusSelected or optionSelected'));
|
emit(const FailedState(
|
||||||
|
error: 'Invalid statusSelected or optionSelected'));
|
||||||
}
|
}
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
final errorData = e.response!.data;
|
final errorData = e.response!.data;
|
||||||
|
@ -35,7 +35,8 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
bool createSchedule = false;
|
bool createSchedule = false;
|
||||||
List<ScheduleModel> listSchedule = [];
|
List<ScheduleModel> listSchedule = [];
|
||||||
|
|
||||||
TwoGangBloc({required this.twoGangId, required this.switchCode}) : super(InitialState()) {
|
TwoGangBloc({required this.twoGangId, required this.switchCode})
|
||||||
|
: super(InitialState()) {
|
||||||
on<InitialEvent>(_fetchTwoGangStatus);
|
on<InitialEvent>(_fetchTwoGangStatus);
|
||||||
on<TwoGangUpdated>(_twoGangUpdated);
|
on<TwoGangUpdated>(_twoGangUpdated);
|
||||||
on<ChangeFirstSwitchStatusEvent>(_changeFirstSwitch);
|
on<ChangeFirstSwitchStatusEvent>(_changeFirstSwitch);
|
||||||
@ -65,13 +66,15 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
|
|
||||||
int selectedTabIndex = 0;
|
int selectedTabIndex = 0;
|
||||||
|
|
||||||
void toggleSelectedIndex(ToggleSelectedEvent event, Emitter<TwoGangState> emit) {
|
void toggleSelectedIndex(
|
||||||
|
ToggleSelectedEvent event, Emitter<TwoGangState> emit) {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
selectedTabIndex = event.index;
|
selectedTabIndex = event.index;
|
||||||
emit(ChangeSlidingSegmentState(value: selectedTabIndex));
|
emit(ChangeSlidingSegmentState(value: selectedTabIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggleCreateSchedule(ToggleCreateScheduleEvent event, Emitter<TwoGangState> emit) {
|
void toggleCreateSchedule(
|
||||||
|
ToggleCreateScheduleEvent event, Emitter<TwoGangState> emit) {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
createSchedule = !createSchedule;
|
createSchedule = !createSchedule;
|
||||||
selectedDays.clear();
|
selectedDays.clear();
|
||||||
@ -79,7 +82,8 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
emit(UpdateCreateScheduleState(createSchedule));
|
emit(UpdateCreateScheduleState(createSchedule));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _fetchTwoGangStatus(InitialEvent event, Emitter<TwoGangState> emit) async {
|
void _fetchTwoGangStatus(
|
||||||
|
InitialEvent event, Emitter<TwoGangState> emit) async {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
try {
|
try {
|
||||||
var response = await DevicesAPI.getDeviceStatus(twoGangId);
|
var response = await DevicesAPI.getDeviceStatus(twoGangId);
|
||||||
@ -89,42 +93,50 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
}
|
}
|
||||||
deviceStatus = TwoGangModel.fromJson(statusModelList);
|
deviceStatus = TwoGangModel.fromJson(statusModelList);
|
||||||
emit(UpdateState(twoGangModel: deviceStatus));
|
emit(UpdateState(twoGangModel: deviceStatus));
|
||||||
// _listenToChanges();
|
_listenToChanges(twoGangId);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(FailedState(error: e.toString()));
|
emit(FailedState(error: e.toString()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_listenToChanges() {
|
StreamSubscription<DatabaseEvent>? _streamSubscription;
|
||||||
|
void _listenToChanges(String id) {
|
||||||
try {
|
try {
|
||||||
DatabaseReference ref = FirebaseDatabase.instance.ref('device-status/$twoGangId');
|
_streamSubscription?.cancel();
|
||||||
|
DatabaseReference ref =
|
||||||
|
FirebaseDatabase.instance.ref('device-status/$id');
|
||||||
Stream<DatabaseEvent> stream = ref.onValue;
|
Stream<DatabaseEvent> stream = ref.onValue;
|
||||||
|
_streamSubscription = stream.listen((DatabaseEvent event) {
|
||||||
stream.listen((DatabaseEvent event) async {
|
Map<dynamic, dynamic> usersMap =
|
||||||
if (_timer != null) {
|
event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
await Future.delayed(const Duration(seconds: 2));
|
|
||||||
}
|
|
||||||
Map<dynamic, dynamic> usersMap = event.snapshot.value as Map<dynamic, dynamic>;
|
|
||||||
List<StatusModel> statusList = [];
|
List<StatusModel> statusList = [];
|
||||||
|
|
||||||
usersMap['status'].forEach((element) {
|
usersMap['status'].forEach((element) {
|
||||||
statusList.add(StatusModel(code: element['code'], value: element['value']));
|
statusList
|
||||||
|
.add(StatusModel(code: element['code'], value: element['value']));
|
||||||
});
|
});
|
||||||
|
|
||||||
deviceStatus = TwoGangModel.fromJson(statusList);
|
deviceStatus = TwoGangModel.fromJson(statusList);
|
||||||
if (!isClosed) {
|
add(TwoGangUpdated());
|
||||||
add(TwoGangUpdated());
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> close() async {
|
||||||
|
_streamSubscription?.cancel();
|
||||||
|
_streamSubscription = null;
|
||||||
|
return super.close();
|
||||||
|
}
|
||||||
|
|
||||||
_twoGangUpdated(TwoGangUpdated event, Emitter<TwoGangState> emit) {
|
_twoGangUpdated(TwoGangUpdated event, Emitter<TwoGangState> emit) {
|
||||||
|
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
||||||
|
|
||||||
emit(UpdateState(twoGangModel: deviceStatus));
|
emit(UpdateState(twoGangModel: deviceStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeFirstSwitch(ChangeFirstSwitchStatusEvent event, Emitter<TwoGangState> emit) async {
|
void _changeFirstSwitch(
|
||||||
|
ChangeFirstSwitchStatusEvent event, Emitter<TwoGangState> emit) async {
|
||||||
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
deviceStatus.firstSwitch = !event.value;
|
deviceStatus.firstSwitch = !event.value;
|
||||||
@ -135,7 +147,8 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
|
|
||||||
_timer = Timer(const Duration(milliseconds: 100), () async {
|
_timer = Timer(const Duration(milliseconds: 100), () async {
|
||||||
final response = await DevicesAPI.controlDevice(
|
final response = await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(deviceId: twoGangId, code: 'switch_1', value: !event.value),
|
DeviceControlModel(
|
||||||
|
deviceId: twoGangId, code: 'switch_1', value: !event.value),
|
||||||
twoGangId);
|
twoGangId);
|
||||||
|
|
||||||
if (!response['success']) {
|
if (!response['success']) {
|
||||||
@ -147,7 +160,8 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeSecondSwitch(ChangeSecondSwitchStatusEvent event, Emitter<TwoGangState> emit) async {
|
void _changeSecondSwitch(
|
||||||
|
ChangeSecondSwitchStatusEvent event, Emitter<TwoGangState> emit) async {
|
||||||
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
deviceStatus.secondSwitch = !event.value;
|
deviceStatus.secondSwitch = !event.value;
|
||||||
@ -157,7 +171,8 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
}
|
}
|
||||||
_timer = Timer(const Duration(milliseconds: 100), () async {
|
_timer = Timer(const Duration(milliseconds: 100), () async {
|
||||||
final response = await DevicesAPI.controlDevice(
|
final response = await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(deviceId: twoGangId, code: 'switch_2', value: !event.value),
|
DeviceControlModel(
|
||||||
|
deviceId: twoGangId, code: 'switch_2', value: !event.value),
|
||||||
twoGangId);
|
twoGangId);
|
||||||
|
|
||||||
if (!response['success']) {
|
if (!response['success']) {
|
||||||
@ -180,11 +195,15 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
final response = await Future.wait([
|
final response = await Future.wait([
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: twoGangId, code: 'switch_1', value: deviceStatus.firstSwitch),
|
deviceId: twoGangId,
|
||||||
|
code: 'switch_1',
|
||||||
|
value: deviceStatus.firstSwitch),
|
||||||
twoGangId),
|
twoGangId),
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: twoGangId, code: 'switch_2', value: deviceStatus.secondSwitch),
|
deviceId: twoGangId,
|
||||||
|
code: 'switch_2',
|
||||||
|
value: deviceStatus.secondSwitch),
|
||||||
twoGangId),
|
twoGangId),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -207,11 +226,15 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
final response = await Future.wait([
|
final response = await Future.wait([
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: twoGangId, code: 'switch_1', value: deviceStatus.firstSwitch),
|
deviceId: twoGangId,
|
||||||
|
code: 'switch_1',
|
||||||
|
value: deviceStatus.firstSwitch),
|
||||||
twoGangId),
|
twoGangId),
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: twoGangId, code: 'switch_2', value: deviceStatus.secondSwitch),
|
deviceId: twoGangId,
|
||||||
|
code: 'switch_2',
|
||||||
|
value: deviceStatus.secondSwitch),
|
||||||
twoGangId),
|
twoGangId),
|
||||||
]);
|
]);
|
||||||
if (response.every((element) => !element['success'])) {
|
if (response.every((element) => !element['success'])) {
|
||||||
@ -232,7 +255,8 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
groupTwoGangList[i].secondSwitch = true;
|
groupTwoGangList[i].secondSwitch = true;
|
||||||
}
|
}
|
||||||
emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: true));
|
emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: true));
|
||||||
List<String> allDeviceIds = groupTwoGangList.map((device) => device.deviceId).toList();
|
List<String> allDeviceIds =
|
||||||
|
groupTwoGangList.map((device) => device.deviceId).toList();
|
||||||
|
|
||||||
final response1 = await DevicesAPI.deviceBatchController(
|
final response1 = await DevicesAPI.deviceBatchController(
|
||||||
code: 'switch_1',
|
code: 'switch_1',
|
||||||
@ -267,7 +291,8 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
|
|
||||||
emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: false));
|
emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: false));
|
||||||
|
|
||||||
List<String> allDeviceIds = groupTwoGangList.map((device) => device.deviceId).toList();
|
List<String> allDeviceIds =
|
||||||
|
groupTwoGangList.map((device) => device.deviceId).toList();
|
||||||
|
|
||||||
final response1 = await DevicesAPI.deviceBatchController(
|
final response1 = await DevicesAPI.deviceBatchController(
|
||||||
code: 'switch_1',
|
code: 'switch_1',
|
||||||
@ -292,17 +317,20 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeSliding(ChangeSlidingSegment event, Emitter<TwoGangState> emit) async {
|
void _changeSliding(
|
||||||
|
ChangeSlidingSegment event, Emitter<TwoGangState> emit) async {
|
||||||
emit(ChangeSlidingSegmentState(value: event.value));
|
emit(ChangeSlidingSegmentState(value: event.value));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _setCounterValue(SetCounterValue event, Emitter<TwoGangState> emit) async {
|
void _setCounterValue(
|
||||||
|
SetCounterValue event, Emitter<TwoGangState> emit) async {
|
||||||
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
||||||
int seconds = 0;
|
int seconds = 0;
|
||||||
try {
|
try {
|
||||||
seconds = event.duration.inSeconds;
|
seconds = event.duration.inSeconds;
|
||||||
final response = await DevicesAPI.controlDevice(
|
final response = await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(deviceId: twoGangId, code: event.deviceCode, value: seconds),
|
DeviceControlModel(
|
||||||
|
deviceId: twoGangId, code: event.deviceCode, value: seconds),
|
||||||
twoGangId);
|
twoGangId);
|
||||||
|
|
||||||
if (response['success'] ?? false) {
|
if (response['success'] ?? false) {
|
||||||
@ -327,7 +355,8 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _getCounterValue(GetCounterEvent event, Emitter<TwoGangState> emit) async {
|
void _getCounterValue(
|
||||||
|
GetCounterEvent event, Emitter<TwoGangState> emit) async {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
try {
|
try {
|
||||||
add(GetScheduleEvent());
|
add(GetScheduleEvent());
|
||||||
@ -435,7 +464,8 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
deviceId: twoGangId,
|
deviceId: twoGangId,
|
||||||
);
|
);
|
||||||
List<dynamic> jsonData = response;
|
List<dynamic> jsonData = response;
|
||||||
listSchedule = jsonData.map((item) => ScheduleModel.fromJson(item)).toList();
|
listSchedule =
|
||||||
|
jsonData.map((item) => ScheduleModel.fromJson(item)).toList();
|
||||||
emit(InitialState());
|
emit(InitialState());
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
final errorData = e.response!.data;
|
final errorData = e.response!.data;
|
||||||
@ -446,12 +476,13 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
|
|
||||||
int? getTimeStampWithoutSeconds(DateTime? dateTime) {
|
int? getTimeStampWithoutSeconds(DateTime? dateTime) {
|
||||||
if (dateTime == null) return null;
|
if (dateTime == null) return null;
|
||||||
DateTime dateTimeWithoutSeconds =
|
DateTime dateTimeWithoutSeconds = DateTime(dateTime.year, dateTime.month,
|
||||||
DateTime(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute);
|
dateTime.day, dateTime.hour, dateTime.minute);
|
||||||
return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000;
|
return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future toggleRepeat(ToggleScheduleEvent event, Emitter<TwoGangState> emit) async {
|
Future toggleRepeat(
|
||||||
|
ToggleScheduleEvent event, Emitter<TwoGangState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
final response = await DevicesAPI.changeSchedule(
|
final response = await DevicesAPI.changeSchedule(
|
||||||
@ -470,7 +501,8 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future deleteSchedule(DeleteScheduleEvent event, Emitter<TwoGangState> emit) async {
|
Future deleteSchedule(
|
||||||
|
DeleteScheduleEvent event, Emitter<TwoGangState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
final response = await DevicesAPI.deleteSchedule(
|
final response = await DevicesAPI.deleteSchedule(
|
||||||
@ -490,7 +522,8 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _fetchTwoGangWizardStatus(InitialWizardEvent event, Emitter<TwoGangState> emit) async {
|
void _fetchTwoGangWizardStatus(
|
||||||
|
InitialWizardEvent event, Emitter<TwoGangState> emit) async {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
try {
|
try {
|
||||||
devicesList = [];
|
devicesList = [];
|
||||||
@ -500,7 +533,8 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
HomeCubit.getInstance().selectedSpace?.id ?? '', '2G');
|
HomeCubit.getInstance().selectedSpace?.id ?? '', '2G');
|
||||||
|
|
||||||
for (int i = 0; i < devicesList.length; i++) {
|
for (int i = 0; i < devicesList.length; i++) {
|
||||||
var response = await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
var response =
|
||||||
|
await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
||||||
List<StatusModel> statusModelList = [];
|
List<StatusModel> statusModelList = [];
|
||||||
for (var status in response['status']) {
|
for (var status in response['status']) {
|
||||||
statusModelList.add(StatusModel.fromJson(status));
|
statusModelList.add(StatusModel.fromJson(status));
|
||||||
@ -523,15 +557,16 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: allSwitchesOn));
|
emit(UpdateGroupState(
|
||||||
|
twoGangList: groupTwoGangList, allSwitches: allSwitchesOn));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(FailedState(error: e.toString()));
|
emit(FailedState(error: e.toString()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeFirstWizardSwitch(
|
void _changeFirstWizardSwitch(ChangeFirstWizardSwitchStatusEvent event,
|
||||||
ChangeFirstWizardSwitchStatusEvent event, Emitter<TwoGangState> emit) async {
|
Emitter<TwoGangState> emit) async {
|
||||||
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
bool allSwitchesValue = true;
|
bool allSwitchesValue = true;
|
||||||
@ -544,9 +579,11 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: allSwitchesValue));
|
emit(UpdateGroupState(
|
||||||
|
twoGangList: groupTwoGangList, allSwitches: allSwitchesValue));
|
||||||
|
|
||||||
List<String> allDeviceIds = groupTwoGangList.map((device) => device.deviceId).toList();
|
List<String> allDeviceIds =
|
||||||
|
groupTwoGangList.map((device) => device.deviceId).toList();
|
||||||
final response = await DevicesAPI.deviceBatchController(
|
final response = await DevicesAPI.deviceBatchController(
|
||||||
code: 'switch_1',
|
code: 'switch_1',
|
||||||
devicesUuid: allDeviceIds,
|
devicesUuid: allDeviceIds,
|
||||||
@ -561,8 +598,8 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeSecondWizardSwitch(
|
void _changeSecondWizardSwitch(ChangeSecondWizardSwitchStatusEvent event,
|
||||||
ChangeSecondWizardSwitchStatusEvent event, Emitter<TwoGangState> emit) async {
|
Emitter<TwoGangState> emit) async {
|
||||||
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
bool allSwitchesValue = true;
|
bool allSwitchesValue = true;
|
||||||
@ -574,9 +611,11 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
allSwitchesValue = false;
|
allSwitchesValue = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
List<String> allDeviceIds = groupTwoGangList.map((device) => device.deviceId).toList();
|
List<String> allDeviceIds =
|
||||||
|
groupTwoGangList.map((device) => device.deviceId).toList();
|
||||||
|
|
||||||
emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: allSwitchesValue));
|
emit(UpdateGroupState(
|
||||||
|
twoGangList: groupTwoGangList, allSwitches: allSwitchesValue));
|
||||||
|
|
||||||
final response = await DevicesAPI.deviceBatchController(
|
final response = await DevicesAPI.deviceBatchController(
|
||||||
code: 'switch_2',
|
code: 'switch_2',
|
||||||
|
@ -99,41 +99,61 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
|||||||
}
|
}
|
||||||
deviceStatus = TwoTouchModel.fromJson(statusModelList);
|
deviceStatus = TwoTouchModel.fromJson(statusModelList);
|
||||||
emit(UpdateState(twoTouchModel: deviceStatus));
|
emit(UpdateState(twoTouchModel: deviceStatus));
|
||||||
// _listenToChanges();
|
_listenToChanges();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(FailedState(error: e.toString()));
|
emit(FailedState(error: e.toString()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_listenToChanges() {
|
StreamSubscription<DatabaseEvent>? _streamSubscription;
|
||||||
|
|
||||||
|
void _listenToChanges() {
|
||||||
try {
|
try {
|
||||||
|
_streamSubscription?.cancel();
|
||||||
DatabaseReference ref =
|
DatabaseReference ref =
|
||||||
FirebaseDatabase.instance.ref('device-status/$twoTouchId');
|
FirebaseDatabase.instance.ref('device-status/$twoTouchId');
|
||||||
Stream<DatabaseEvent> stream = ref.onValue;
|
Stream<DatabaseEvent> stream = ref.onValue;
|
||||||
|
|
||||||
stream.listen((DatabaseEvent event) async {
|
_streamSubscription = stream.listen((DatabaseEvent event) async {
|
||||||
if (_timer != null) {
|
if (_timer != null) {
|
||||||
await Future.delayed(const Duration(seconds: 2));
|
await Future.delayed(const Duration(seconds: 1));
|
||||||
}
|
}
|
||||||
Map<dynamic, dynamic> usersMap =
|
if (event.snapshot.value != null) {
|
||||||
event.snapshot.value as Map<dynamic, dynamic>;
|
Map<dynamic, dynamic> usersMap =
|
||||||
List<StatusModel> statusList = [];
|
event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
|
List<StatusModel> statusList = [];
|
||||||
|
|
||||||
usersMap['status'].forEach((element) {
|
usersMap['status'].forEach((element) {
|
||||||
statusList
|
statusList.add(
|
||||||
.add(StatusModel(code: element['code'], value: element['value']));
|
StatusModel(code: element['code'], value: element['value']));
|
||||||
});
|
});
|
||||||
|
var switch1Status = statusList.firstWhere(
|
||||||
|
(status) => status.code == "switch_1",
|
||||||
|
orElse: () => StatusModel(code: "switch_1", value: false));
|
||||||
|
|
||||||
|
var switch2Status = statusList.firstWhere(
|
||||||
|
(status) => status.code == "switch_2",
|
||||||
|
orElse: () => StatusModel(code: "switch_2", value: false));
|
||||||
|
deviceStatus.firstSwitch = switch1Status.value as bool;
|
||||||
|
deviceStatus.secondSwitch = switch2Status.value as bool;
|
||||||
|
|
||||||
deviceStatus = TwoTouchModel.fromJson(statusList);
|
|
||||||
if (!isClosed) {
|
|
||||||
add(TwoTouchUpdated());
|
add(TwoTouchUpdated());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (_) {}
|
} catch (_) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> close() async {
|
||||||
|
_streamSubscription?.cancel();
|
||||||
|
_streamSubscription = null;
|
||||||
|
return super.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
_twoTouchUpdated(TwoTouchUpdated event, Emitter<TwoTouchState> emit) {
|
_twoTouchUpdated(TwoTouchUpdated event, Emitter<TwoTouchState> emit) {
|
||||||
|
emit(LoadingInitialState());
|
||||||
emit(UpdateState(twoTouchModel: deviceStatus));
|
emit(UpdateState(twoTouchModel: deviceStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:firebase_database/firebase_database.dart';
|
import 'package:firebase_database/firebase_database.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/wall_sensor_bloc/wall_sensor_state.dart';
|
import 'package:syncrow_app/features/devices/bloc/wall_sensor_bloc/wall_sensor_state.dart';
|
||||||
@ -21,7 +23,8 @@ class WallSensorBloc extends Bloc<WallSensorEvent, WallSensorState> {
|
|||||||
on<GetDeviceReportsEvent>(_getDeviceReports);
|
on<GetDeviceReportsEvent>(_getDeviceReports);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _fetchCeilingSensorStatus(InitialEvent event, Emitter<WallSensorState> emit) async {
|
void _fetchCeilingSensorStatus(
|
||||||
|
InitialEvent event, Emitter<WallSensorState> emit) async {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
try {
|
try {
|
||||||
var response = await DevicesAPI.getDeviceStatus(deviceId);
|
var response = await DevicesAPI.getDeviceStatus(deviceId);
|
||||||
@ -31,41 +34,62 @@ class WallSensorBloc extends Bloc<WallSensorEvent, WallSensorState> {
|
|||||||
}
|
}
|
||||||
deviceStatus = WallSensorModel.fromJson(statusModelList);
|
deviceStatus = WallSensorModel.fromJson(statusModelList);
|
||||||
emit(UpdateState(wallSensorModel: deviceStatus));
|
emit(UpdateState(wallSensorModel: deviceStatus));
|
||||||
// _listenToChanges();
|
_listenToChanges();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(FailedState(error: e.toString()));
|
emit(FailedState(error: e.toString()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_listenToChanges() {
|
Timer? _timer;
|
||||||
|
StreamSubscription<DatabaseEvent>? _streamSubscription;
|
||||||
|
|
||||||
|
void _listenToChanges() {
|
||||||
try {
|
try {
|
||||||
DatabaseReference ref = FirebaseDatabase.instance.ref('device-status/$deviceId');
|
_streamSubscription?.cancel();
|
||||||
|
DatabaseReference ref =
|
||||||
|
FirebaseDatabase.instance.ref('device-status/$deviceId');
|
||||||
Stream<DatabaseEvent> stream = ref.onValue;
|
Stream<DatabaseEvent> stream = ref.onValue;
|
||||||
|
|
||||||
stream.listen((DatabaseEvent event) {
|
_streamSubscription = stream.listen((DatabaseEvent event) async {
|
||||||
Map<dynamic, dynamic> usersMap = event.snapshot.value as Map<dynamic, dynamic>;
|
if (_timer != null) {
|
||||||
|
await Future.delayed(const Duration(seconds: 2));
|
||||||
|
}
|
||||||
|
Map<dynamic, dynamic> usersMap =
|
||||||
|
event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
List<StatusModel> statusList = [];
|
List<StatusModel> statusList = [];
|
||||||
|
|
||||||
usersMap['status'].forEach((element) {
|
usersMap['status'].forEach((element) {
|
||||||
statusList.add(StatusModel(code: element['code'], value: element['value']));
|
statusList
|
||||||
|
.add(StatusModel(code: element['code'], value: element['value']));
|
||||||
});
|
});
|
||||||
|
|
||||||
deviceStatus = WallSensorModel.fromJson(statusList);
|
deviceStatus = WallSensorModel.fromJson(statusList);
|
||||||
add(WallSensorUpdatedEvent());
|
if (!isClosed) {
|
||||||
|
add(WallSensorUpdatedEvent());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
_wallSensorUpdated(WallSensorUpdatedEvent event, Emitter<WallSensorState> emit) {
|
@override
|
||||||
|
Future<void> close() async {
|
||||||
|
_streamSubscription?.cancel();
|
||||||
|
_streamSubscription = null;
|
||||||
|
return super.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
_wallSensorUpdated(
|
||||||
|
WallSensorUpdatedEvent event, Emitter<WallSensorState> emit) {
|
||||||
emit(UpdateState(wallSensorModel: deviceStatus));
|
emit(UpdateState(wallSensorModel: deviceStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeIndicator(ChangeIndicatorEvent event, Emitter<WallSensorState> emit) async {
|
void _changeIndicator(
|
||||||
|
ChangeIndicatorEvent event, Emitter<WallSensorState> emit) async {
|
||||||
emit(LoadingNewSate(wallSensorModel: deviceStatus));
|
emit(LoadingNewSate(wallSensorModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
final response = await DevicesAPI.controlDevice(
|
final response = await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(deviceId: deviceId, code: 'indicator', value: !event.value), deviceId);
|
DeviceControlModel(
|
||||||
|
deviceId: deviceId, code: 'indicator', value: !event.value),
|
||||||
|
deviceId);
|
||||||
|
|
||||||
if (response['success'] ?? false) {
|
if (response['success'] ?? false) {
|
||||||
deviceStatus.indicator = !event.value;
|
deviceStatus.indicator = !event.value;
|
||||||
@ -74,11 +98,14 @@ class WallSensorBloc extends Bloc<WallSensorEvent, WallSensorState> {
|
|||||||
emit(UpdateState(wallSensorModel: deviceStatus));
|
emit(UpdateState(wallSensorModel: deviceStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeValue(ChangeValueEvent event, Emitter<WallSensorState> emit) async {
|
void _changeValue(
|
||||||
|
ChangeValueEvent event, Emitter<WallSensorState> emit) async {
|
||||||
emit(LoadingNewSate(wallSensorModel: deviceStatus));
|
emit(LoadingNewSate(wallSensorModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
final response = await DevicesAPI.controlDevice(
|
final response = await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(deviceId: deviceId, code: event.code, value: event.value), deviceId);
|
DeviceControlModel(
|
||||||
|
deviceId: deviceId, code: event.code, value: event.value),
|
||||||
|
deviceId);
|
||||||
|
|
||||||
if (response['success'] ?? false) {
|
if (response['success'] ?? false) {
|
||||||
if (event.code == 'far_detection') {
|
if (event.code == 'far_detection') {
|
||||||
@ -93,7 +120,8 @@ class WallSensorBloc extends Bloc<WallSensorEvent, WallSensorState> {
|
|||||||
emit(UpdateState(wallSensorModel: deviceStatus));
|
emit(UpdateState(wallSensorModel: deviceStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _getDeviceReports(GetDeviceReportsEvent event, Emitter<WallSensorState> emit) async {
|
void _getDeviceReports(
|
||||||
|
GetDeviceReportsEvent event, Emitter<WallSensorState> emit) async {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -35,7 +35,8 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
|||||||
List<ScheduleModel> listSchedule = [];
|
List<ScheduleModel> listSchedule = [];
|
||||||
DateTime? selectedTime = DateTime.now();
|
DateTime? selectedTime = DateTime.now();
|
||||||
|
|
||||||
WaterHeaterBloc({required this.whId, required this.switchCode}) : super(WHInitialState()) {
|
WaterHeaterBloc({required this.whId, required this.switchCode})
|
||||||
|
: super(WHInitialState()) {
|
||||||
on<WaterHeaterInitial>(_fetchWaterHeaterStatus);
|
on<WaterHeaterInitial>(_fetchWaterHeaterStatus);
|
||||||
on<WaterHeaterSwitch>(_changeFirstSwitch);
|
on<WaterHeaterSwitch>(_changeFirstSwitch);
|
||||||
on<SetCounterValue>(_setCounterValue);
|
on<SetCounterValue>(_setCounterValue);
|
||||||
@ -60,7 +61,8 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
|||||||
on<WaterHeaterUpdated>(_waterHeaterUpdated);
|
on<WaterHeaterUpdated>(_waterHeaterUpdated);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _fetchWaterHeaterStatus(WaterHeaterInitial event, Emitter<WaterHeaterState> emit) async {
|
void _fetchWaterHeaterStatus(
|
||||||
|
WaterHeaterInitial event, Emitter<WaterHeaterState> emit) async {
|
||||||
emit(WHLoadingState());
|
emit(WHLoadingState());
|
||||||
try {
|
try {
|
||||||
var response = await DevicesAPI.getDeviceStatus(whId);
|
var response = await DevicesAPI.getDeviceStatus(whId);
|
||||||
@ -72,29 +74,33 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
|||||||
statusModelList,
|
statusModelList,
|
||||||
);
|
);
|
||||||
emit(UpdateState(whModel: deviceStatus));
|
emit(UpdateState(whModel: deviceStatus));
|
||||||
// _listenToChanges();
|
_listenToChanges();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(WHFailedState(errorMessage: e.toString()));
|
emit(WHFailedState(errorMessage: e.toString()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_listenToChanges() {
|
//real-time db
|
||||||
|
StreamSubscription<DatabaseEvent>? _streamSubscription;
|
||||||
|
void _listenToChanges() {
|
||||||
try {
|
try {
|
||||||
DatabaseReference ref = FirebaseDatabase.instance.ref('device-status/$whId');
|
_streamSubscription?.cancel();
|
||||||
|
DatabaseReference ref =
|
||||||
|
FirebaseDatabase.instance.ref('device-status/$whId');
|
||||||
Stream<DatabaseEvent> stream = ref.onValue;
|
Stream<DatabaseEvent> stream = ref.onValue;
|
||||||
|
|
||||||
stream.listen((DatabaseEvent event) async {
|
_streamSubscription = stream.listen((DatabaseEvent event) async {
|
||||||
if (_timer != null) {
|
if (_timer != null) {
|
||||||
await Future.delayed(const Duration(seconds: 2));
|
await Future.delayed(const Duration(seconds: 2));
|
||||||
}
|
}
|
||||||
Map<dynamic, dynamic> usersMap = event.snapshot.value as Map<dynamic, dynamic>;
|
Map<dynamic, dynamic> usersMap =
|
||||||
|
event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
List<StatusModel> statusList = [];
|
List<StatusModel> statusList = [];
|
||||||
|
|
||||||
usersMap['status'].forEach((element) {
|
usersMap['status'].forEach((element) {
|
||||||
statusList.add(StatusModel(code: element['code'], value: element['value']));
|
statusList
|
||||||
|
.add(StatusModel(code: element['code'], value: element['value']));
|
||||||
});
|
});
|
||||||
|
|
||||||
deviceStatus = WHModel.fromJson(statusList);
|
deviceStatus = WHModel.fromJson(statusList);
|
||||||
if (!isClosed) {
|
if (!isClosed) {
|
||||||
add(WaterHeaterUpdated());
|
add(WaterHeaterUpdated());
|
||||||
@ -103,12 +109,21 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
|||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
_waterHeaterUpdated(WaterHeaterUpdated event, Emitter<WaterHeaterState> emit) async {
|
@override
|
||||||
|
Future<void> close() async {
|
||||||
|
_streamSubscription?.cancel();
|
||||||
|
_streamSubscription = null;
|
||||||
|
return super.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
_waterHeaterUpdated(
|
||||||
|
WaterHeaterUpdated event, Emitter<WaterHeaterState> emit) async {
|
||||||
emit(WHLoadingState());
|
emit(WHLoadingState());
|
||||||
emit(UpdateState(whModel: deviceStatus));
|
emit(UpdateState(whModel: deviceStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeFirstSwitch(WaterHeaterSwitch event, Emitter<WaterHeaterState> emit) async {
|
void _changeFirstSwitch(
|
||||||
|
WaterHeaterSwitch event, Emitter<WaterHeaterState> emit) async {
|
||||||
emit(LoadingNewSate(whModel: deviceStatus));
|
emit(LoadingNewSate(whModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
deviceStatus.firstSwitch = !event.whSwitch;
|
deviceStatus.firstSwitch = !event.whSwitch;
|
||||||
@ -118,7 +133,10 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
|||||||
}
|
}
|
||||||
_timer = Timer(const Duration(milliseconds: 500), () async {
|
_timer = Timer(const Duration(milliseconds: 500), () async {
|
||||||
final response = await DevicesAPI.controlDevice(
|
final response = await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(deviceId: whId, code: 'switch_1', value: deviceStatus.firstSwitch),
|
DeviceControlModel(
|
||||||
|
deviceId: whId,
|
||||||
|
code: 'switch_1',
|
||||||
|
value: deviceStatus.firstSwitch),
|
||||||
whId);
|
whId);
|
||||||
|
|
||||||
if (!response['success']) {
|
if (!response['success']) {
|
||||||
@ -132,13 +150,16 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
|||||||
|
|
||||||
//=====================---------- timer ----------------------------------------
|
//=====================---------- timer ----------------------------------------
|
||||||
|
|
||||||
void _setCounterValue(SetCounterValue event, Emitter<WaterHeaterState> emit) async {
|
void _setCounterValue(
|
||||||
|
SetCounterValue event, Emitter<WaterHeaterState> emit) async {
|
||||||
emit(LoadingNewSate(whModel: deviceStatus));
|
emit(LoadingNewSate(whModel: deviceStatus));
|
||||||
int seconds = 0;
|
int seconds = 0;
|
||||||
try {
|
try {
|
||||||
seconds = event.duration.inSeconds;
|
seconds = event.duration.inSeconds;
|
||||||
final response = await DevicesAPI.controlDevice(
|
final response = await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(deviceId: whId, code: event.deviceCode, value: seconds), whId);
|
DeviceControlModel(
|
||||||
|
deviceId: whId, code: event.deviceCode, value: seconds),
|
||||||
|
whId);
|
||||||
|
|
||||||
if (response['success'] ?? false) {
|
if (response['success'] ?? false) {
|
||||||
if (event.deviceCode == 'countdown_1') {
|
if (event.deviceCode == 'countdown_1') {
|
||||||
@ -160,7 +181,8 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _getCounterValue(GetCounterEvent event, Emitter<WaterHeaterState> emit) async {
|
void _getCounterValue(
|
||||||
|
GetCounterEvent event, Emitter<WaterHeaterState> emit) async {
|
||||||
emit(WHLoadingState());
|
emit(WHLoadingState());
|
||||||
try {
|
try {
|
||||||
var response = await DevicesAPI.getDeviceStatus(whId);
|
var response = await DevicesAPI.getDeviceStatus(whId);
|
||||||
@ -250,7 +272,8 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
|||||||
deviceId: whId,
|
deviceId: whId,
|
||||||
);
|
);
|
||||||
List<dynamic> jsonData = response;
|
List<dynamic> jsonData = response;
|
||||||
listSchedule = jsonData.map((item) => ScheduleModel.fromJson(item)).toList();
|
listSchedule =
|
||||||
|
jsonData.map((item) => ScheduleModel.fromJson(item)).toList();
|
||||||
emit(WHInitialState());
|
emit(WHInitialState());
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
final errorData = e.response!.data;
|
final errorData = e.response!.data;
|
||||||
@ -261,12 +284,13 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
|||||||
|
|
||||||
int? getTimeStampWithoutSeconds(DateTime? dateTime) {
|
int? getTimeStampWithoutSeconds(DateTime? dateTime) {
|
||||||
if (dateTime == null) return null;
|
if (dateTime == null) return null;
|
||||||
DateTime dateTimeWithoutSeconds =
|
DateTime dateTimeWithoutSeconds = DateTime(dateTime.year, dateTime.month,
|
||||||
DateTime(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute);
|
dateTime.day, dateTime.hour, dateTime.minute);
|
||||||
return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000;
|
return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future toggleChange(ToggleScheduleEvent event, Emitter<WaterHeaterState> emit) async {
|
Future toggleChange(
|
||||||
|
ToggleScheduleEvent event, Emitter<WaterHeaterState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(WHLoadingState());
|
emit(WHLoadingState());
|
||||||
final response = await DevicesAPI.changeSchedule(
|
final response = await DevicesAPI.changeSchedule(
|
||||||
@ -284,7 +308,8 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future deleteSchedule(DeleteScheduleEvent event, Emitter<WaterHeaterState> emit) async {
|
Future deleteSchedule(
|
||||||
|
DeleteScheduleEvent event, Emitter<WaterHeaterState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(WHLoadingState());
|
emit(WHLoadingState());
|
||||||
final response = await DevicesAPI.deleteSchedule(
|
final response = await DevicesAPI.deleteSchedule(
|
||||||
@ -303,7 +328,8 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _toggleCreateCirculate(ToggleCreateCirculate event, Emitter<WaterHeaterState> emit) {
|
void _toggleCreateCirculate(
|
||||||
|
ToggleCreateCirculate event, Emitter<WaterHeaterState> emit) {
|
||||||
emit(WHLoadingState());
|
emit(WHLoadingState());
|
||||||
createCirculate = !createCirculate;
|
createCirculate = !createCirculate;
|
||||||
selectedDays.clear();
|
selectedDays.clear();
|
||||||
@ -311,13 +337,15 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
|||||||
emit(UpdateCreateScheduleState(createCirculate));
|
emit(UpdateCreateScheduleState(createCirculate));
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggleSelectedIndex(ToggleSelectedEvent event, Emitter<WaterHeaterState> emit) {
|
void toggleSelectedIndex(
|
||||||
|
ToggleSelectedEvent event, Emitter<WaterHeaterState> emit) {
|
||||||
emit(WHLoadingState());
|
emit(WHLoadingState());
|
||||||
selectedTabIndex = event.index;
|
selectedTabIndex = event.index;
|
||||||
emit(ChangeSlidingSegmentState(value: selectedTabIndex));
|
emit(ChangeSlidingSegmentState(value: selectedTabIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggleCreateSchedule(ToggleCreateScheduleEvent event, Emitter<WaterHeaterState> emit) {
|
void toggleCreateSchedule(
|
||||||
|
ToggleCreateScheduleEvent event, Emitter<WaterHeaterState> emit) {
|
||||||
emit(WHLoadingState());
|
emit(WHLoadingState());
|
||||||
createSchedule = !createSchedule;
|
createSchedule = !createSchedule;
|
||||||
selectedDays.clear();
|
selectedDays.clear();
|
||||||
@ -366,8 +394,8 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
|||||||
List<GroupWHModel> groupWaterHeaterList = [];
|
List<GroupWHModel> groupWaterHeaterList = [];
|
||||||
bool allSwitchesOn = true;
|
bool allSwitchesOn = true;
|
||||||
|
|
||||||
void _changeFirstWizardSwitch(
|
void _changeFirstWizardSwitch(ChangeFirstWizardSwitchStatusEvent event,
|
||||||
ChangeFirstWizardSwitchStatusEvent event, Emitter<WaterHeaterState> emit) async {
|
Emitter<WaterHeaterState> emit) async {
|
||||||
emit(LoadingNewSate(whModel: deviceStatus));
|
emit(LoadingNewSate(whModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
bool allSwitchesValue = true;
|
bool allSwitchesValue = true;
|
||||||
@ -379,7 +407,8 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
|||||||
allSwitchesValue = false;
|
allSwitchesValue = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
emit(UpdateGroupState(twoGangList: groupWaterHeaterList, allSwitches: allSwitchesValue));
|
emit(UpdateGroupState(
|
||||||
|
twoGangList: groupWaterHeaterList, allSwitches: allSwitchesValue));
|
||||||
|
|
||||||
final response = await DevicesAPI.deviceBatchController(
|
final response = await DevicesAPI.deviceBatchController(
|
||||||
code: 'switch_1',
|
code: 'switch_1',
|
||||||
@ -394,7 +423,8 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _fetchWHWizardStatus(InitialWizardEvent event, Emitter<WaterHeaterState> emit) async {
|
void _fetchWHWizardStatus(
|
||||||
|
InitialWizardEvent event, Emitter<WaterHeaterState> emit) async {
|
||||||
emit(WHLoadingState());
|
emit(WHLoadingState());
|
||||||
try {
|
try {
|
||||||
devicesList = [];
|
devicesList = [];
|
||||||
@ -404,7 +434,8 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
|||||||
HomeCubit.getInstance().selectedSpace?.id ?? '', 'WH');
|
HomeCubit.getInstance().selectedSpace?.id ?? '', 'WH');
|
||||||
|
|
||||||
for (int i = 0; i < devicesList.length; i++) {
|
for (int i = 0; i < devicesList.length; i++) {
|
||||||
var response = await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
var response =
|
||||||
|
await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
||||||
List<StatusModel> statusModelList = [];
|
List<StatusModel> statusModelList = [];
|
||||||
for (var status in response['status']) {
|
for (var status in response['status']) {
|
||||||
statusModelList.add(StatusModel.fromJson(status));
|
statusModelList.add(StatusModel.fromJson(status));
|
||||||
@ -426,23 +457,27 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
emit(UpdateGroupState(twoGangList: groupWaterHeaterList, allSwitches: allSwitchesOn));
|
emit(UpdateGroupState(
|
||||||
|
twoGangList: groupWaterHeaterList, allSwitches: allSwitchesOn));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// emit(FailedState(error: e.toString()));
|
// emit(FailedState(error: e.toString()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _groupAllOn(GroupAllOnEvent event, Emitter<WaterHeaterState> emit) async {
|
void _groupAllOn(
|
||||||
|
GroupAllOnEvent event, Emitter<WaterHeaterState> emit) async {
|
||||||
emit(LoadingNewSate(whModel: deviceStatus));
|
emit(LoadingNewSate(whModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
for (int i = 0; i < groupWaterHeaterList.length; i++) {
|
for (int i = 0; i < groupWaterHeaterList.length; i++) {
|
||||||
groupWaterHeaterList[i].firstSwitch = true;
|
groupWaterHeaterList[i].firstSwitch = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit(UpdateGroupState(twoGangList: groupWaterHeaterList, allSwitches: true));
|
emit(UpdateGroupState(
|
||||||
|
twoGangList: groupWaterHeaterList, allSwitches: true));
|
||||||
|
|
||||||
List<String> allDeviceIds = groupWaterHeaterList.map((device) => device.deviceId).toList();
|
List<String> allDeviceIds =
|
||||||
|
groupWaterHeaterList.map((device) => device.deviceId).toList();
|
||||||
|
|
||||||
final response = await DevicesAPI.deviceBatchController(
|
final response = await DevicesAPI.deviceBatchController(
|
||||||
code: 'switch_1',
|
code: 'switch_1',
|
||||||
@ -460,15 +495,18 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _groupAllOff(GroupAllOffEvent event, Emitter<WaterHeaterState> emit) async {
|
void _groupAllOff(
|
||||||
|
GroupAllOffEvent event, Emitter<WaterHeaterState> emit) async {
|
||||||
emit(LoadingNewSate(whModel: deviceStatus));
|
emit(LoadingNewSate(whModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
for (int i = 0; i < groupWaterHeaterList.length; i++) {
|
for (int i = 0; i < groupWaterHeaterList.length; i++) {
|
||||||
groupWaterHeaterList[i].firstSwitch = false;
|
groupWaterHeaterList[i].firstSwitch = false;
|
||||||
}
|
}
|
||||||
emit(UpdateGroupState(twoGangList: groupWaterHeaterList, allSwitches: false));
|
emit(UpdateGroupState(
|
||||||
|
twoGangList: groupWaterHeaterList, allSwitches: false));
|
||||||
|
|
||||||
List<String> allDeviceIds = groupWaterHeaterList.map((device) => device.deviceId).toList();
|
List<String> allDeviceIds =
|
||||||
|
groupWaterHeaterList.map((device) => device.deviceId).toList();
|
||||||
|
|
||||||
final response = await DevicesAPI.deviceBatchController(
|
final response = await DevicesAPI.deviceBatchController(
|
||||||
code: 'switch_1',
|
code: 'switch_1',
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:firebase_database/firebase_database.dart';
|
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/water_leak_bloc/water_leak_event.dart';
|
import 'package:syncrow_app/features/devices/bloc/water_leak_bloc/water_leak_event.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/water_leak_bloc/water_leak_state.dart';
|
import 'package:syncrow_app/features/devices/bloc/water_leak_bloc/water_leak_state.dart';
|
||||||
@ -21,7 +20,6 @@ class WaterLeakBloc extends Bloc<WaterLeakEvent, WaterLeakState> {
|
|||||||
on<ToggleClosingReminderEvent>(_toggleClosingReminder);
|
on<ToggleClosingReminderEvent>(_toggleClosingReminder);
|
||||||
on<ToggleWaterLeakAlarmEvent>(_toggleWaterLeakAlarm);
|
on<ToggleWaterLeakAlarmEvent>(_toggleWaterLeakAlarm);
|
||||||
}
|
}
|
||||||
Timer? _timer;
|
|
||||||
bool lowBattery = false;
|
bool lowBattery = false;
|
||||||
bool closingReminder = false;
|
bool closingReminder = false;
|
||||||
bool waterAlarm = false;
|
bool waterAlarm = false;
|
||||||
@ -134,32 +132,42 @@ class WaterLeakBloc extends Bloc<WaterLeakEvent, WaterLeakState> {
|
|||||||
emit(WaterLeakFailedState(errorMessage: errorMessage));
|
emit(WaterLeakFailedState(errorMessage: errorMessage));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Timer? _timer;
|
||||||
|
// StreamSubscription<DatabaseEvent>? _streamSubscription;
|
||||||
|
// void _listenToChanges() {
|
||||||
|
// try {
|
||||||
|
// _streamSubscription?.cancel();
|
||||||
|
// DatabaseReference ref =
|
||||||
|
// FirebaseDatabase.instance.ref('device-status/$WLId');
|
||||||
|
// Stream<DatabaseEvent> stream = ref.onValue;
|
||||||
|
|
||||||
_listenToChanges() {
|
// _streamSubscription = stream.listen((DatabaseEvent event) async {
|
||||||
try {
|
// if (_timer != null) {
|
||||||
DatabaseReference ref =
|
// await Future.delayed(const Duration(seconds: 2));
|
||||||
FirebaseDatabase.instance.ref('device-status/$WLId');
|
// }
|
||||||
Stream<DatabaseEvent> stream = ref.onValue;
|
// Map<dynamic, dynamic> usersMap =
|
||||||
|
// event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
|
// List<StatusModel> statusList = [];
|
||||||
|
// usersMap['status'].forEach((element) {
|
||||||
|
// statusList
|
||||||
|
// .add(StatusModel(code: element['code'], value: element['value']));
|
||||||
|
// });
|
||||||
|
// deviceStatus = WaterLeakModel.fromJson(statusList);
|
||||||
|
// if (!isClosed) {
|
||||||
|
// add(
|
||||||
|
// WaterLeakSwitch(switchD: deviceStatus.waterContactState),
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// } catch (_) {}
|
||||||
|
// }
|
||||||
|
|
||||||
stream.listen((DatabaseEvent event) async {
|
// @override
|
||||||
if (_timer != null) {
|
// Future<void> close() async {
|
||||||
await Future.delayed(const Duration(seconds: 2));
|
// _streamSubscription?.cancel();
|
||||||
}
|
// _streamSubscription = null;
|
||||||
Map<dynamic, dynamic> usersMap =
|
// return super.close();
|
||||||
event.snapshot.value as Map<dynamic, dynamic>;
|
// }
|
||||||
List<StatusModel> statusList = [];
|
|
||||||
|
|
||||||
usersMap['status'].forEach((element) {
|
|
||||||
statusList.add(StatusModel(code: element['code'], value: true));
|
|
||||||
});
|
|
||||||
|
|
||||||
deviceStatus = WaterLeakModel.fromJson(statusList);
|
|
||||||
if (!isClosed) {
|
|
||||||
add(
|
|
||||||
WaterLeakSwitch(switchD: deviceStatus.waterContactState),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (_) {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -27,24 +27,24 @@ class AcStatusModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
factory AcStatusModel.fromJson(String id, List<StatusModel> jsonList) {
|
factory AcStatusModel.fromJson(String id, List<StatusModel> jsonList) {
|
||||||
late bool _acSwitch;
|
bool _acSwitch = false;
|
||||||
late String _mode;
|
String _mode = '';
|
||||||
late int _tempSet;
|
int _tempSet = 210;
|
||||||
late int _currentTemp;
|
int _currentTemp = 210;
|
||||||
late String _fanSpeeds;
|
String _fanSpeeds = '';
|
||||||
late int _countdown1;
|
int _countdown1 = 0;
|
||||||
late bool _childLock;
|
bool _childLock = false;
|
||||||
for (int i = 0; i < jsonList.length; i++) {
|
for (int i = 0; i < jsonList.length; i++) {
|
||||||
if (jsonList[i].code == 'switch') {
|
if (jsonList[i].code == 'switch') {
|
||||||
_acSwitch = jsonList[i].value ?? false;
|
_acSwitch = jsonList[i].value ?? false;
|
||||||
} else if (jsonList[i].code == 'mode') {
|
} else if (jsonList[i].code == 'mode') {
|
||||||
_mode = jsonList[i].value ?? TempModes.cold;
|
_mode = jsonList[i].value ?? '';
|
||||||
} else if (jsonList[i].code == 'temp_set') {
|
} else if (jsonList[i].code == 'temp_set') {
|
||||||
_tempSet = jsonList[i].value ?? 210;
|
_tempSet = jsonList[i].value ?? 210;
|
||||||
} else if (jsonList[i].code == 'temp_current') {
|
} else if (jsonList[i].code == 'temp_current') {
|
||||||
_currentTemp = jsonList[i].value ?? 210;
|
_currentTemp = jsonList[i].value ?? 210;
|
||||||
} else if (jsonList[i].code == 'level') {
|
} else if (jsonList[i].code == 'level') {
|
||||||
_fanSpeeds = jsonList[i].value ?? 210;
|
_fanSpeeds = jsonList[i].value ?? '';
|
||||||
} else if (jsonList[i].code == 'child_lock') {
|
} else if (jsonList[i].code == 'child_lock') {
|
||||||
_childLock = jsonList[i].value ?? false;
|
_childLock = jsonList[i].value ?? false;
|
||||||
} else if (jsonList[i].code == 'countdown_time') {
|
} else if (jsonList[i].code == 'countdown_time') {
|
||||||
|
@ -23,9 +23,9 @@ class CeilingSensorModel {
|
|||||||
required this.bodyMovement});
|
required this.bodyMovement});
|
||||||
|
|
||||||
factory CeilingSensorModel.fromJson(List<StatusModel> jsonList) {
|
factory CeilingSensorModel.fromJson(List<StatusModel> jsonList) {
|
||||||
late String _presenceState;
|
String _presenceState = 'none';
|
||||||
late int _sensitivity;
|
int _sensitivity = 1;
|
||||||
late String _checkingResult;
|
String _checkingResult = '';
|
||||||
int _presenceRange = 1;
|
int _presenceRange = 1;
|
||||||
int _sportsPara = 1;
|
int _sportsPara = 1;
|
||||||
int _moving_max_dis = 0;
|
int _moving_max_dis = 0;
|
||||||
|
@ -10,11 +10,11 @@ class CurtainModel {
|
|||||||
});
|
});
|
||||||
|
|
||||||
factory CurtainModel.fromJson(List<StatusModel> jsonList) {
|
factory CurtainModel.fromJson(List<StatusModel> jsonList) {
|
||||||
late String _control;
|
String _control = '';
|
||||||
late int _percent;
|
int _percent = 0;
|
||||||
for (int i = 0; i < jsonList.length; i++) {
|
for (int i = 0; i < jsonList.length; i++) {
|
||||||
if (jsonList[i].code == 'control') {
|
if (jsonList[i].code == 'control') {
|
||||||
_control = jsonList[i].value ?? false;
|
_control = jsonList[i].value ?? '';
|
||||||
}
|
}
|
||||||
if (jsonList[i].code == 'percent_control') {
|
if (jsonList[i].code == 'percent_control') {
|
||||||
_percent = jsonList[i].value ?? 0;
|
_percent = jsonList[i].value ?? 0;
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import 'dart:convert';
|
|
||||||
|
|
||||||
class DeviceInfoModel {
|
class DeviceInfoModel {
|
||||||
final int activeTime;
|
final int activeTime;
|
||||||
final String category;
|
final String category;
|
||||||
|
@ -1,27 +1,22 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import 'package:syncrow_app/features/devices/model/status_model.dart';
|
import 'package:syncrow_app/features/devices/model/status_model.dart';
|
||||||
|
|
||||||
class DoorSensorModel {
|
class DoorSensorModel {
|
||||||
bool doorContactState;
|
bool doorContactState;
|
||||||
int batteryPercentage;
|
int batteryPercentage;
|
||||||
|
|
||||||
DoorSensorModel(
|
DoorSensorModel({
|
||||||
{required this.doorContactState,
|
required this.doorContactState,
|
||||||
required this.batteryPercentage,
|
required this.batteryPercentage,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory DoorSensorModel.fromJson(List<StatusModel> jsonList) {
|
factory DoorSensorModel.fromJson(List<StatusModel> jsonList) {
|
||||||
late bool _doorContactState;
|
bool _doorContactState = false;
|
||||||
late int _batteryPercentage;
|
int _batteryPercentage = 0;
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < jsonList.length; i++) {
|
for (int i = 0; i < jsonList.length; i++) {
|
||||||
if (jsonList[i].code == 'doorcontact_state') {
|
if (jsonList[i].code == 'doorcontact_state') {
|
||||||
_doorContactState = jsonList[i].value ?? false;
|
_doorContactState = jsonList[i].value ?? false;
|
||||||
} else if (jsonList[i].code == 'battery_percentage') {
|
} else if (jsonList[i].code == 'battery_percentage') {
|
||||||
_batteryPercentage = jsonList[i].value ?? 0;
|
_batteryPercentage = jsonList[i].value ?? 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,15 +24,15 @@ class GarageDoorModel {
|
|||||||
});
|
});
|
||||||
|
|
||||||
factory GarageDoorModel.fromJson(List<StatusModel> jsonList) {
|
factory GarageDoorModel.fromJson(List<StatusModel> jsonList) {
|
||||||
late bool _switch1 = false;
|
bool _switch1 = false;
|
||||||
late bool _doorContactState = false;
|
bool _doorContactState = false;
|
||||||
late int _countdown1 = 0;
|
int _countdown1 = 0;
|
||||||
late int _countdownAlarm = 0;
|
int _countdownAlarm = 0;
|
||||||
late String _doorControl1 = "closed";
|
String _doorControl1 = "closed";
|
||||||
late bool _voiceControl1 = false;
|
bool _voiceControl1 = false;
|
||||||
late String _doorState1 = "closed";
|
String _doorState1 = "closed";
|
||||||
late int _batteryPercentage = 0;
|
int _batteryPercentage = 0;
|
||||||
late int _tr_timecon = 0;
|
int _tr_timecon = 0;
|
||||||
|
|
||||||
for (var status in jsonList) {
|
for (var status in jsonList) {
|
||||||
switch (status.code) {
|
switch (status.code) {
|
||||||
|
@ -1,29 +1,27 @@
|
|||||||
|
|
||||||
import 'package:syncrow_app/features/devices/model/status_model.dart';
|
import 'package:syncrow_app/features/devices/model/status_model.dart';
|
||||||
|
|
||||||
class OneGangModel {
|
class OneGangModel {
|
||||||
bool firstSwitch;
|
bool firstSwitch;
|
||||||
int firstCountDown;
|
int firstCountDown;
|
||||||
|
|
||||||
OneGangModel(
|
OneGangModel({
|
||||||
{required this.firstSwitch,
|
required this.firstSwitch,
|
||||||
required this.firstCountDown,
|
required this.firstCountDown,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory OneGangModel.fromJson(List<StatusModel> jsonList) {
|
factory OneGangModel.fromJson(List<StatusModel> jsonList) {
|
||||||
late bool _switch;
|
bool _switch = false;
|
||||||
late int _count;
|
int _count = 0;
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < jsonList.length; i++) {
|
for (int i = 0; i < jsonList.length; i++) {
|
||||||
if (jsonList[i].code == 'switch_1') {
|
if (jsonList[i].code == 'switch_1') {
|
||||||
_switch = jsonList[i].value ?? false;
|
_switch = jsonList[i].value ?? false;
|
||||||
} else if (jsonList[i].code == 'countdown_1') {
|
} else if (jsonList[i].code == 'countdown_1') {
|
||||||
_count = jsonList[i].value ?? 0;
|
_count = jsonList[i].value ?? 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return OneGangModel(
|
return OneGangModel(
|
||||||
firstSwitch: _switch,
|
firstSwitch: _switch,
|
||||||
firstCountDown: _count,
|
firstCountDown: _count,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
|
|
||||||
|
|
||||||
import 'package:syncrow_app/features/devices/model/status_model.dart';
|
import 'package:syncrow_app/features/devices/model/status_model.dart';
|
||||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||||
|
|
||||||
@ -15,15 +13,14 @@ class OneTouchModel {
|
|||||||
required this.firstCountDown,
|
required this.firstCountDown,
|
||||||
required this.light_mode,
|
required this.light_mode,
|
||||||
required this.relay,
|
required this.relay,
|
||||||
required this.relay_status_1
|
required this.relay_status_1});
|
||||||
});
|
|
||||||
|
|
||||||
factory OneTouchModel.fromJson(List<StatusModel> jsonList) {
|
factory OneTouchModel.fromJson(List<StatusModel> jsonList) {
|
||||||
late bool _switch;
|
bool _switch = false;
|
||||||
late int _count;
|
int _count = 0;
|
||||||
late String _relay;
|
String _relay = '';
|
||||||
late String _light_mode;
|
String _light_mode = '';
|
||||||
late String relay_status_1;
|
String relay_status_1 = '';
|
||||||
|
|
||||||
for (int i = 0; i < jsonList.length; i++) {
|
for (int i = 0; i < jsonList.length; i++) {
|
||||||
if (jsonList[i].code == 'switch_1') {
|
if (jsonList[i].code == 'switch_1') {
|
||||||
@ -41,10 +38,8 @@ class OneTouchModel {
|
|||||||
return OneTouchModel(
|
return OneTouchModel(
|
||||||
firstSwitch: _switch,
|
firstSwitch: _switch,
|
||||||
firstCountDown: _count,
|
firstCountDown: _count,
|
||||||
light_mode: lightStatusExtension.fromString(_light_mode) ,
|
light_mode: lightStatusExtension.fromString(_light_mode),
|
||||||
relay: StatusExtension.fromString(_relay ) ,
|
relay: StatusExtension.fromString(_relay),
|
||||||
relay_status_1: StatusExtension.fromString(relay_status_1 )
|
relay_status_1: StatusExtension.fromString(relay_status_1));
|
||||||
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,14 +22,14 @@ class SixSceneModel {
|
|||||||
});
|
});
|
||||||
|
|
||||||
factory SixSceneModel.fromJson(List<StatusModel> jsonList) {
|
factory SixSceneModel.fromJson(List<StatusModel> jsonList) {
|
||||||
late dynamic _scene_1;
|
dynamic _scene_1 = '';
|
||||||
late dynamic _scene_2;
|
dynamic _scene_2 = '';
|
||||||
late dynamic _scene_3;
|
dynamic _scene_3 = '';
|
||||||
late dynamic _scene_4;
|
dynamic _scene_4 = '';
|
||||||
late dynamic _scene_5;
|
dynamic _scene_5 = '';
|
||||||
late dynamic _scene_6;
|
dynamic _scene_6 = '';
|
||||||
late dynamic _scene_id_group_id;
|
dynamic _scene_id_group_id = 0;
|
||||||
late dynamic _switch_backlight;
|
dynamic _switch_backlight = false;
|
||||||
|
|
||||||
for (int i = 0; i < jsonList.length; i++) {
|
for (int i = 0; i < jsonList.length; i++) {
|
||||||
if (jsonList[i].code == 'scene_1') {
|
if (jsonList[i].code == 'scene_1') {
|
||||||
|
@ -39,23 +39,23 @@ class SmartDoorModel {
|
|||||||
required this.normalOpenSwitch});
|
required this.normalOpenSwitch});
|
||||||
|
|
||||||
factory SmartDoorModel.fromJson(List<StatusModel> jsonList) {
|
factory SmartDoorModel.fromJson(List<StatusModel> jsonList) {
|
||||||
late int _unlockFingerprint;
|
int _unlockFingerprint = 0;
|
||||||
late int _unlockPassword;
|
int _unlockPassword = 0;
|
||||||
late int _unlockTemporary;
|
int _unlockTemporary = 0;
|
||||||
late int _unlockCard;
|
int _unlockCard = 0;
|
||||||
late String _unlockAlarm;
|
String _unlockAlarm = '';
|
||||||
late int _unlockRequest;
|
int _unlockRequest = 0;
|
||||||
late int _residualElectricity;
|
int _residualElectricity = 0;
|
||||||
late bool _reverseLock;
|
bool _reverseLock = false;
|
||||||
late int _unlockApp;
|
int _unlockApp = 0;
|
||||||
late bool _hijack;
|
bool _hijack = false;
|
||||||
late bool _doorbell;
|
bool _doorbell = false;
|
||||||
late String _unlockOfflinePd;
|
String _unlockOfflinePd = '';
|
||||||
late String _unlockOfflineClear;
|
String _unlockOfflineClear = '';
|
||||||
late String _unlockDoubleKit;
|
String _unlockDoubleKit = '';
|
||||||
late String _remoteNoPdSetkey;
|
String _remoteNoPdSetkey = '';
|
||||||
late String _remoteNoDpKey;
|
String _remoteNoDpKey = '';
|
||||||
late bool _normalOpenSwitch;
|
bool _normalOpenSwitch = false;
|
||||||
|
|
||||||
for (int i = 0; i < jsonList.length; i++) {
|
for (int i = 0; i < jsonList.length; i++) {
|
||||||
if (jsonList[i].code == 'unlock_fingerprint') {
|
if (jsonList[i].code == 'unlock_fingerprint') {
|
||||||
|
@ -10,8 +10,8 @@ class SosModel {
|
|||||||
});
|
});
|
||||||
|
|
||||||
factory SosModel.fromJson(List<StatusModel> jsonList) {
|
factory SosModel.fromJson(List<StatusModel> jsonList) {
|
||||||
late String _sosContactState;
|
String _sosContactState = '';
|
||||||
late int _batteryPercentage;
|
int _batteryPercentage = 0;
|
||||||
|
|
||||||
for (int i = 0; i < jsonList.length; i++) {
|
for (int i = 0; i < jsonList.length; i++) {
|
||||||
if (jsonList[i].code == 'sos') {
|
if (jsonList[i].code == 'sos') {
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_svg/flutter_svg.dart';
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/6_scene_switch_bloc/6_scene_bloc.dart';
|
import 'package:syncrow_app/features/devices/bloc/6_scene_switch_bloc/6_scene_bloc.dart';
|
||||||
@ -31,7 +29,7 @@ class SixSceneScreen extends StatelessWidget {
|
|||||||
..add(const SexSceneSwitchInitial()),
|
..add(const SexSceneSwitchInitial()),
|
||||||
child: BlocBuilder<SixSceneBloc, SixSceneState>(
|
child: BlocBuilder<SixSceneBloc, SixSceneState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
final _bloc = BlocProvider.of<SixSceneBloc>(context);
|
final bloc = BlocProvider.of<SixSceneBloc>(context);
|
||||||
SixSceneModel model = SixSceneModel(
|
SixSceneModel model = SixSceneModel(
|
||||||
scene_1: '',
|
scene_1: '',
|
||||||
scene_2: '',
|
scene_2: '',
|
||||||
@ -48,7 +46,7 @@ class SixSceneScreen extends StatelessWidget {
|
|||||||
model = state.device;
|
model = state.device;
|
||||||
}
|
}
|
||||||
return DefaultScaffold(
|
return DefaultScaffold(
|
||||||
title: _bloc.deviceInfo.name,
|
title: device?.name ?? '6 Scene Switch',
|
||||||
actions: [
|
actions: [
|
||||||
InkWell(
|
InkWell(
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
@ -58,9 +56,9 @@ class SixSceneScreen extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
if (val == null) {
|
if (val == null) {
|
||||||
_bloc.add(const SixSceneInitialInfo());
|
bloc.add(const SixSceneInitialInfo());
|
||||||
_bloc.add(const SixSceneInitial());
|
bloc.add(const SixSceneInitial());
|
||||||
_bloc.add(const SexSceneSwitchInitial());
|
bloc.add(const SexSceneSwitchInitial());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: SvgPicture.asset(Assets.assetsIconsSettings),
|
child: SvgPicture.asset(Assets.assetsIconsSettings),
|
||||||
@ -77,7 +75,7 @@ class SixSceneScreen extends StatelessWidget {
|
|||||||
)
|
)
|
||||||
: RefreshIndicator(
|
: RefreshIndicator(
|
||||||
onRefresh: () async {
|
onRefresh: () async {
|
||||||
_bloc.add(const SixSceneInitial());
|
bloc.add(const SixSceneInitial());
|
||||||
},
|
},
|
||||||
child: ListView(
|
child: ListView(
|
||||||
children: [
|
children: [
|
||||||
@ -92,22 +90,22 @@ class SixSceneScreen extends StatelessWidget {
|
|||||||
switch4Title: model.scene_4,
|
switch4Title: model.scene_4,
|
||||||
switch5Title: model.scene_5,
|
switch5Title: model.scene_5,
|
||||||
switch6Title: model.scene_6,
|
switch6Title: model.scene_6,
|
||||||
switch1Down: _bloc.deviceStatus.switch_backlight
|
switch1Down: bloc.deviceStatus.switch_backlight
|
||||||
? Assets.switchOn
|
? Assets.switchOn
|
||||||
: Assets.switchOff,
|
: Assets.switchOff,
|
||||||
switch1Up: _bloc.deviceStatus.switch_backlight
|
switch1Up: bloc.deviceStatus.switch_backlight
|
||||||
? Assets.switchOn
|
? Assets.switchOn
|
||||||
: Assets.switchOff,
|
: Assets.switchOff,
|
||||||
switch2Down: _bloc.deviceStatus.switch_backlight
|
switch2Down: bloc.deviceStatus.switch_backlight
|
||||||
? Assets.switchOn
|
? Assets.switchOn
|
||||||
: Assets.switchOff,
|
: Assets.switchOff,
|
||||||
switch2Up: _bloc.deviceStatus.switch_backlight
|
switch2Up: bloc.deviceStatus.switch_backlight
|
||||||
? Assets.switchOn
|
? Assets.switchOn
|
||||||
: Assets.switchOff,
|
: Assets.switchOff,
|
||||||
switch3Up: _bloc.deviceStatus.switch_backlight
|
switch3Up: bloc.deviceStatus.switch_backlight
|
||||||
? Assets.switchOn
|
? Assets.switchOn
|
||||||
: Assets.switchOff,
|
: Assets.switchOff,
|
||||||
switch3Down: _bloc.deviceStatus.switch_backlight
|
switch3Down: bloc.deviceStatus.switch_backlight
|
||||||
? Assets.switchOn
|
? Assets.switchOn
|
||||||
: Assets.switchOff,
|
: Assets.switchOff,
|
||||||
onSwitch3DownTap: () {
|
onSwitch3DownTap: () {
|
||||||
@ -135,7 +133,7 @@ class SixSceneScreen extends StatelessWidget {
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: DefaultContainer(
|
child: DefaultContainer(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
_bloc.add(ChangeSwitchStatusEvent());
|
bloc.add(ChangeSwitchStatusEvent());
|
||||||
},
|
},
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment:
|
crossAxisAlignment:
|
||||||
@ -197,9 +195,9 @@ class SixSceneScreen extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
if (value == true) {
|
if (value == true) {
|
||||||
Future.delayed(
|
Future.delayed(
|
||||||
const Duration(
|
const Duration(milliseconds: 200),
|
||||||
milliseconds: 200), () {
|
() {
|
||||||
_bloc.add(
|
bloc.add(
|
||||||
const SexSceneSwitchInitial());
|
const SexSceneSwitchInitial());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ class ACsList extends StatelessWidget {
|
|||||||
List<DeviceModel> devicesList = [];
|
List<DeviceModel> devicesList = [];
|
||||||
bool allOn = false;
|
bool allOn = false;
|
||||||
bool allTempSame = false;
|
bool allTempSame = false;
|
||||||
int temperature = 20;
|
int temperature = 250;
|
||||||
if (state is GetAllAcsStatusState) {
|
if (state is GetAllAcsStatusState) {
|
||||||
devicesStatuesList = state.allAcsStatues;
|
devicesStatuesList = state.allAcsStatues;
|
||||||
devicesList = state.allAcs;
|
devicesList = state.allAcs;
|
||||||
|
@ -23,6 +23,7 @@ class ACsView extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
|
|
||||||
create: (context) => ACsBloc(acId: deviceModel?.uuid ?? '')
|
create: (context) => ACsBloc(acId: deviceModel?.uuid ?? '')
|
||||||
..add(AcsInitial(allAcs: deviceModel != null ? false : true)),
|
..add(AcsInitial(allAcs: deviceModel != null ? false : true)),
|
||||||
child: BlocBuilder<ACsBloc, AcsState>(
|
child: BlocBuilder<ACsBloc, AcsState>(
|
||||||
|
@ -332,7 +332,7 @@ class CeilingSensorInterface extends StatelessWidget {
|
|||||||
title: title.toString(),
|
title: title.toString(),
|
||||||
sensor: ceilingSensor,
|
sensor: ceilingSensor,
|
||||||
value: model.sensitivity,
|
value: model.sensitivity,
|
||||||
min: 0,
|
min: 1,
|
||||||
max: 10,
|
max: 10,
|
||||||
));
|
));
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:smooth_page_indicator/smooth_page_indicator.dart';
|
import 'package:smooth_page_indicator/smooth_page_indicator.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
|
||||||
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||||
|
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/all_devices.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/all_devices.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/room_page.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/room_page.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/rooms_slider.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/rooms_slider.dart';
|
||||||
@ -15,7 +15,7 @@ import 'package:syncrow_app/utils/context_extension.dart';
|
|||||||
import 'package:syncrow_app/utils/resource_manager/strings_manager.dart';
|
import 'package:syncrow_app/utils/resource_manager/strings_manager.dart';
|
||||||
|
|
||||||
class DevicesViewBody extends StatelessWidget {
|
class DevicesViewBody extends StatelessWidget {
|
||||||
const DevicesViewBody({Key? key}) : super(key: key);
|
const DevicesViewBody({super.key});
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocBuilder<HomeCubit, HomeState>(
|
return BlocBuilder<HomeCubit, HomeState>(
|
||||||
@ -80,10 +80,7 @@ class DevicesViewBody extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
SizedBox(
|
const SceneView(pageType: true),
|
||||||
height: MediaQuery.of(context).size.height * 0.1,
|
|
||||||
child: const SceneView(pageType: true),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
const RoomsSlider(),
|
const RoomsSlider(),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
|
@ -22,14 +22,15 @@ class DoorSensorScreen extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return DefaultScaffold(
|
return DefaultScaffold(
|
||||||
title: 'Door Sensor',
|
title: device?.name,
|
||||||
child: BlocProvider(
|
child: BlocProvider(
|
||||||
create: (context) =>
|
create: (context) =>
|
||||||
DoorSensorBloc(DSId: device?.uuid ?? '')..add(const DoorSensorInitial()),
|
DoorSensorBloc(DSId: device?.uuid ?? '')..add(const DoorSensorInitial()),
|
||||||
child: BlocBuilder<DoorSensorBloc, DoorSensorState>(
|
child: BlocBuilder<DoorSensorBloc, DoorSensorState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
final doorSensorBloc = BlocProvider.of<DoorSensorBloc>(context);
|
final doorSensorBloc = BlocProvider.of<DoorSensorBloc>(context);
|
||||||
DoorSensorModel model = DoorSensorModel(batteryPercentage: 0, doorContactState: false);
|
DoorSensorModel model =
|
||||||
|
DoorSensorModel(batteryPercentage: 0, doorContactState: false);
|
||||||
if (state is LoadingNewSate) {
|
if (state is LoadingNewSate) {
|
||||||
model = state.doorSensor;
|
model = state.doorSensor;
|
||||||
} else if (state is UpdateState) {
|
} else if (state is UpdateState) {
|
||||||
@ -37,8 +38,8 @@ class DoorSensorScreen extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
return state is DoorSensorLoadingState
|
return state is DoorSensorLoadingState
|
||||||
? const Center(
|
? const Center(
|
||||||
child:
|
child: DefaultContainer(
|
||||||
DefaultContainer(width: 50, height: 50, child: CircularProgressIndicator()),
|
width: 50, height: 50, child: CircularProgressIndicator()),
|
||||||
)
|
)
|
||||||
: RefreshIndicator(
|
: RefreshIndicator(
|
||||||
onRefresh: () async {
|
onRefresh: () async {
|
||||||
@ -56,7 +57,8 @@ class DoorSensorScreen extends StatelessWidget {
|
|||||||
Expanded(
|
Expanded(
|
||||||
flex: 4,
|
flex: 4,
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
overlayColor: WidgetStateProperty.all(Colors.transparent),
|
overlayColor:
|
||||||
|
WidgetStateProperty.all(Colors.transparent),
|
||||||
onTap: () {},
|
onTap: () {},
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
@ -107,17 +109,21 @@ class DoorSensorScreen extends StatelessWidget {
|
|||||||
Navigator.of(context).push(
|
Navigator.of(context).push(
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) =>
|
builder: (context) =>
|
||||||
DoorRecordsScreen(DSId: device!.uuid!)),
|
DoorRecordsScreen(
|
||||||
|
DSId: device!.uuid!)),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment:
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
CrossAxisAlignment.center,
|
||||||
|
mainAxisAlignment:
|
||||||
|
MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
ConstrainedBox(
|
ConstrainedBox(
|
||||||
constraints:
|
constraints: const BoxConstraints(
|
||||||
const BoxConstraints(maxHeight: 46, maxWidth: 50),
|
maxHeight: 46, maxWidth: 50),
|
||||||
child: SvgPicture.asset(Assets.doorRecordsIcon),
|
child: SvgPicture.asset(
|
||||||
|
Assets.doorRecordsIcon),
|
||||||
),
|
),
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
height: 15,
|
height: 15,
|
||||||
@ -143,18 +149,21 @@ class DoorSensorScreen extends StatelessWidget {
|
|||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.of(context).push(
|
Navigator.of(context).push(
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => NotificationSettingsPage()),
|
builder: (context) =>
|
||||||
|
NotificationSettingsPage()),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment:
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
CrossAxisAlignment.center,
|
||||||
|
mainAxisAlignment:
|
||||||
|
MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
ConstrainedBox(
|
ConstrainedBox(
|
||||||
constraints:
|
constraints: const BoxConstraints(
|
||||||
const BoxConstraints(maxHeight: 46, maxWidth: 50),
|
maxHeight: 46, maxWidth: 50),
|
||||||
child:
|
child: SvgPicture.asset(
|
||||||
SvgPicture.asset(Assets.doorNotificationSetting),
|
Assets.doorNotificationSetting),
|
||||||
),
|
),
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
height: 15,
|
height: 15,
|
||||||
|
@ -47,7 +47,7 @@ class FourSceneScreen extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return DefaultScaffold(
|
return DefaultScaffold(
|
||||||
title: _bloc.deviceInfo.name,
|
title: device?.name ?? '4 Scene',
|
||||||
actions: [
|
actions: [
|
||||||
InkWell(
|
InkWell(
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
@ -165,7 +165,7 @@ class FourSceneScreen extends StatelessWidget {
|
|||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
},
|
},
|
||||||
confirmTab:
|
confirmTab:
|
||||||
(switchSelected) async {
|
(switchSelected) {
|
||||||
Navigator.of(context).push(
|
Navigator.of(context).push(
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) =>
|
builder: (context) =>
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -8,8 +8,7 @@ import 'package:syncrow_app/features/shared_widgets/devices_default_switch.dart'
|
|||||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_small.dart';
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_small.dart';
|
||||||
|
|
||||||
class GarageList extends StatelessWidget {
|
class GarageList extends StatelessWidget {
|
||||||
const GarageList(
|
const GarageList({super.key, required this.garageList, required this.allSwitches});
|
||||||
{super.key, required this.garageList, required this.allSwitches});
|
|
||||||
|
|
||||||
final List<GroupGarageModel> garageList;
|
final List<GroupGarageModel> garageList;
|
||||||
final bool allSwitches;
|
final bool allSwitches;
|
||||||
@ -23,43 +22,42 @@ class GarageList extends StatelessWidget {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
const BodySmall(text: 'All Lights'),
|
const BodySmall(text: 'All Garages'),
|
||||||
const SizedBox(height: 5),
|
const SizedBox(height: 5),
|
||||||
DevicesDefaultSwitch(
|
DevicesDefaultSwitch(
|
||||||
off: 'OFF',
|
off: 'Close',
|
||||||
on: 'ON',
|
on: 'Open',
|
||||||
switchValue: allSwitches,
|
switchValue: allSwitches,
|
||||||
action: () {
|
action: () => BlocProvider.of<GarageDoorBloc>(context).add(
|
||||||
BlocProvider.of<GarageDoorBloc>(context)
|
GroupAllOnEvent(),
|
||||||
.add(GroupAllOnEvent());
|
),
|
||||||
},
|
secondAction: () => BlocProvider.of<GarageDoorBloc>(context).add(
|
||||||
secondAction: () {
|
GroupAllOffEvent(),
|
||||||
BlocProvider.of<GarageDoorBloc>(context)
|
),
|
||||||
.add(GroupAllOffEvent());
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
ListView.builder(
|
ListView.builder(
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
physics: const NeverScrollableScrollPhysics(),
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
padding: const EdgeInsets.all(0),
|
padding: EdgeInsetsDirectional.zero,
|
||||||
itemCount: garageList.length,
|
itemCount: garageList.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
|
final garageDoor = garageList[index];
|
||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
BodySmall(text: garageList[index].deviceName),
|
BodySmall(text: garageDoor.deviceName),
|
||||||
const SizedBox(height: 5),
|
const SizedBox(height: 5),
|
||||||
DevicesDefaultSwitch(
|
DevicesDefaultSwitch(
|
||||||
off: 'OFF',
|
off: 'Close',
|
||||||
on: 'ON',
|
on: 'Open',
|
||||||
switchValue: garageList[index].firstSwitch,
|
switchValue: garageDoor.firstSwitch,
|
||||||
action: () {
|
action: () => BlocProvider.of<GarageDoorBloc>(context).add(
|
||||||
BlocProvider.of<GarageDoorBloc>(context).add(
|
ChangeFirstWizardSwitchStatusEvent(
|
||||||
ChangeFirstWizardSwitchStatusEvent(
|
value: garageDoor.firstSwitch,
|
||||||
value: garageList[index].firstSwitch,
|
deviceId: garageDoor.deviceId,
|
||||||
deviceId: garageList[index].deviceId));
|
),
|
||||||
},
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
@ -21,7 +21,8 @@ class GateWayView extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
create: (context) => GatewayBloc()..add(GatewayInitial(gatewayId: gatewayObj.uuid ?? '')),
|
create: (context) =>
|
||||||
|
GatewayBloc()..add(GatewayInitial(gatewayId: gatewayObj.uuid ?? '')),
|
||||||
child: BlocBuilder<GatewayBloc, GatewayState>(builder: (context, state) {
|
child: BlocBuilder<GatewayBloc, GatewayState>(builder: (context, state) {
|
||||||
List<DeviceModel> devicesList = [];
|
List<DeviceModel> devicesList = [];
|
||||||
if (state is UpdateGatewayState) {
|
if (state is UpdateGatewayState) {
|
||||||
@ -37,7 +38,7 @@ class GateWayView extends StatelessWidget {
|
|||||||
extendBodyBehindAppBar: true,
|
extendBodyBehindAppBar: true,
|
||||||
extendBody: true,
|
extendBody: true,
|
||||||
appBar: DeviceAppbar(
|
appBar: DeviceAppbar(
|
||||||
deviceName: 'Gateway',
|
deviceName: gatewayObj.name ?? 'Gateway',
|
||||||
deviceUuid: gatewayObj.uuid!,
|
deviceUuid: gatewayObj.uuid!,
|
||||||
),
|
),
|
||||||
body: Container(
|
body: Container(
|
||||||
@ -60,7 +61,7 @@ class GateWayView extends StatelessWidget {
|
|||||||
},
|
},
|
||||||
child: ListView(
|
child: ListView(
|
||||||
children: [
|
children: [
|
||||||
Container(
|
SizedBox(
|
||||||
height: MediaQuery.of(context).size.height,
|
height: MediaQuery.of(context).size.height,
|
||||||
child: SafeArea(
|
child: SafeArea(
|
||||||
child: Column(
|
child: Column(
|
||||||
@ -90,7 +91,8 @@ class GateWayView extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
),
|
),
|
||||||
if (devicesList.isEmpty && state is UpdateGatewayState)
|
if (devicesList.isEmpty &&
|
||||||
|
state is UpdateGatewayState)
|
||||||
Container(
|
Container(
|
||||||
width: MediaQuery.sizeOf(context).width,
|
width: MediaQuery.sizeOf(context).width,
|
||||||
alignment: AlignmentDirectional.center,
|
alignment: AlignmentDirectional.center,
|
||||||
@ -115,7 +117,8 @@ class GateWayView extends StatelessWidget {
|
|||||||
margin: const EdgeInsets.only(top: 20),
|
margin: const EdgeInsets.only(top: 20),
|
||||||
height: 50,
|
height: 50,
|
||||||
width: 50,
|
width: 50,
|
||||||
child: const RefreshProgressIndicator()),
|
child:
|
||||||
|
const RefreshProgressIndicator()),
|
||||||
)
|
)
|
||||||
: Expanded(
|
: Expanded(
|
||||||
child: GridView.builder(
|
child: GridView.builder(
|
||||||
@ -130,7 +133,8 @@ class GateWayView extends StatelessWidget {
|
|||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
itemCount: devicesList.length,
|
itemCount: devicesList.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
return RoomPageSwitch(device: devicesList[index]);
|
return RoomPageSwitch(
|
||||||
|
device: devicesList[index]);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -20,8 +20,9 @@ class OneGangScreen extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
create: (context) => OneGangBloc(switchCode: 'switch_1', oneGangId: device?.uuid ?? '')
|
create: (context) =>
|
||||||
..add(const InitialEvent(groupScreen: false)),
|
OneGangBloc(switchCode: 'switch_1', oneGangId: device?.uuid ?? '')
|
||||||
|
..add(const InitialEvent(groupScreen: false)),
|
||||||
child: BlocBuilder<OneGangBloc, OneGangState>(
|
child: BlocBuilder<OneGangBloc, OneGangState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
OneGangModel oneGangModel = OneGangModel(
|
OneGangModel oneGangModel = OneGangModel(
|
||||||
@ -36,13 +37,15 @@ class OneGangScreen extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
return state is LoadingInitialState
|
return state is LoadingInitialState
|
||||||
? const Center(
|
? const Center(
|
||||||
child:
|
child: DefaultContainer(
|
||||||
DefaultContainer(width: 50, height: 50, child: CircularProgressIndicator()),
|
width: 50,
|
||||||
|
height: 50,
|
||||||
|
child: CircularProgressIndicator()),
|
||||||
)
|
)
|
||||||
: RefreshIndicator(
|
: RefreshIndicator(
|
||||||
onRefresh: () async {
|
onRefresh: () async {
|
||||||
BlocProvider.of<OneGangBloc>(context)
|
BlocProvider.of<OneGangBloc>(context).add(InitialEvent(
|
||||||
.add(InitialEvent(groupScreen: device != null ? false : true));
|
groupScreen: device != null ? false : true));
|
||||||
},
|
},
|
||||||
child: ListView(
|
child: ListView(
|
||||||
children: [
|
children: [
|
||||||
@ -55,7 +58,8 @@ class OneGangScreen extends StatelessWidget {
|
|||||||
const Expanded(child: SizedBox.shrink()),
|
const Expanded(child: SizedBox.shrink()),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
mainAxisAlignment:
|
||||||
|
MainAxisAlignment.spaceAround,
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Column(
|
Column(
|
||||||
@ -64,9 +68,10 @@ class OneGangScreen extends StatelessWidget {
|
|||||||
threeGangSwitch: device!,
|
threeGangSwitch: device!,
|
||||||
value: oneGangModel.firstSwitch,
|
value: oneGangModel.firstSwitch,
|
||||||
action: () {
|
action: () {
|
||||||
BlocProvider.of<OneGangBloc>(context).add(
|
BlocProvider.of<OneGangBloc>(context)
|
||||||
ChangeFirstSwitchStatusEvent(
|
.add(ChangeFirstSwitchStatusEvent(
|
||||||
value: oneGangModel.firstSwitch));
|
value: oneGangModel
|
||||||
|
.firstSwitch));
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
@ -74,7 +79,8 @@ class OneGangScreen extends StatelessWidget {
|
|||||||
width: 70,
|
width: 70,
|
||||||
child: BodySmall(
|
child: BodySmall(
|
||||||
text: " Entrance Light",
|
text: " Entrance Light",
|
||||||
fontColor: ColorsManager.textPrimaryColor,
|
fontColor:
|
||||||
|
ColorsManager.textPrimaryColor,
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -94,20 +100,24 @@ class OneGangScreen extends StatelessWidget {
|
|||||||
Card(
|
Card(
|
||||||
elevation: 3,
|
elevation: 3,
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(100),
|
borderRadius:
|
||||||
|
BorderRadius.circular(100),
|
||||||
),
|
),
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
PageRouteBuilder(
|
PageRouteBuilder(
|
||||||
pageBuilder:
|
pageBuilder: (context,
|
||||||
(context, animation1, animation2) =>
|
animation1,
|
||||||
TimerScheduleScreen(
|
animation2) =>
|
||||||
switchCode: 'switch_1',
|
TimerScheduleScreen(
|
||||||
device: device!,
|
switchCode:
|
||||||
deviceCode: 'countdown_1',
|
'switch_1',
|
||||||
)));
|
device: device!,
|
||||||
|
deviceCode:
|
||||||
|
'countdown_1',
|
||||||
|
)));
|
||||||
},
|
},
|
||||||
child: Stack(
|
child: Stack(
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
@ -117,7 +127,9 @@ class OneGangScreen extends StatelessWidget {
|
|||||||
height: 60,
|
height: 60,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.grey[300],
|
color: Colors.grey[300],
|
||||||
borderRadius: BorderRadius.circular(100),
|
borderRadius:
|
||||||
|
BorderRadius.circular(
|
||||||
|
100),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Container(
|
Container(
|
||||||
@ -125,12 +137,15 @@ class OneGangScreen extends StatelessWidget {
|
|||||||
height: 40,
|
height: 40,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
borderRadius: BorderRadius.circular(100),
|
borderRadius:
|
||||||
|
BorderRadius.circular(
|
||||||
|
100),
|
||||||
),
|
),
|
||||||
child: Center(
|
child: Center(
|
||||||
child: Icon(
|
child: Icon(
|
||||||
Icons.access_time,
|
Icons.access_time,
|
||||||
color: ColorsManager.primaryColorWithOpacity,
|
color: ColorsManager
|
||||||
|
.primaryColorWithOpacity,
|
||||||
size: 25,
|
size: 25,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -51,7 +51,7 @@ class _PowerClampPageState extends State<PowerClampPage> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return DefaultScaffold(
|
return DefaultScaffold(
|
||||||
title: 'Power Clamp',
|
title: widget.device?.name ?? 'Power Clamp',
|
||||||
child: BlocProvider(
|
child: BlocProvider(
|
||||||
create: (context) => PowerClampBloc(PCId: widget.device?.uuid ?? '')
|
create: (context) => PowerClampBloc(PCId: widget.device?.uuid ?? '')
|
||||||
..add(const PowerClampInitial()),
|
..add(const PowerClampInitial()),
|
||||||
@ -153,41 +153,6 @@ class _PowerClampPageState extends State<PowerClampPage> {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Widget> _buildPowerClampCards(PowerClampModel model,
|
|
||||||
List<EnergyData> chartData, PowerClampBloc blocProvider) {
|
|
||||||
return [
|
|
||||||
_buildPowerClampCard(
|
|
||||||
phaseType: '',
|
|
||||||
title: 'Total Energy \nConsumption',
|
|
||||||
phase: model.status.general,
|
|
||||||
isGeneral: true,
|
|
||||||
chartData: chartData,
|
|
||||||
blocProvider: blocProvider,
|
|
||||||
),
|
|
||||||
_buildPowerClampCard(
|
|
||||||
phaseType: 'Phase A consumption',
|
|
||||||
title: 'Phase A Energy \nConsumption',
|
|
||||||
phase: model.status.phaseA,
|
|
||||||
chartData: chartData,
|
|
||||||
blocProvider: blocProvider,
|
|
||||||
),
|
|
||||||
_buildPowerClampCard(
|
|
||||||
phaseType: 'Phase B consumption',
|
|
||||||
title: 'Phase B Energy \nConsumption',
|
|
||||||
phase: model.status.phaseB,
|
|
||||||
chartData: chartData,
|
|
||||||
blocProvider: blocProvider,
|
|
||||||
),
|
|
||||||
_buildPowerClampCard(
|
|
||||||
phaseType: 'Phase C consumption',
|
|
||||||
title: 'Phase C Energy \nConsumption',
|
|
||||||
phase: model.status.phaseC,
|
|
||||||
chartData: chartData,
|
|
||||||
blocProvider: blocProvider,
|
|
||||||
),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildPowerClampCard({
|
Widget _buildPowerClampCard({
|
||||||
required String title,
|
required String title,
|
||||||
required String phaseType,
|
required String phaseType,
|
||||||
@ -209,10 +174,8 @@ class _PowerClampPageState extends State<PowerClampPage> {
|
|||||||
blocProvider.add(SelectDateEvent(context: context));
|
blocProvider.add(SelectDateEvent(context: context));
|
||||||
},
|
},
|
||||||
totalActiveGeneral: isGeneral ? _getValueOrNA(phase.dataPoints, 2) : null,
|
totalActiveGeneral: isGeneral ? _getValueOrNA(phase.dataPoints, 2) : null,
|
||||||
totalCurrentGeneral:
|
totalCurrentGeneral: isGeneral ? _getValueOrNA(phase.dataPoints, 1) : null,
|
||||||
isGeneral ? _getValueOrNA(phase.dataPoints, 1) : null,
|
totalFrequencyGeneral: isGeneral ? _getValueOrNA(phase.dataPoints, 4) : null,
|
||||||
totalFrequencyGeneral:
|
|
||||||
isGeneral ? _getValueOrNA(phase.dataPoints, 4) : null,
|
|
||||||
totalFactor: !isGeneral ? _getValueOrNA(phase.dataPoints, 3) : null,
|
totalFactor: !isGeneral ? _getValueOrNA(phase.dataPoints, 3) : null,
|
||||||
totalActive: !isGeneral ? _getValueOrNA(phase.dataPoints, 2) : null,
|
totalActive: !isGeneral ? _getValueOrNA(phase.dataPoints, 2) : null,
|
||||||
totalCurrent: !isGeneral ? _getValueOrNA(phase.dataPoints, 1) : null,
|
totalCurrent: !isGeneral ? _getValueOrNA(phase.dataPoints, 1) : null,
|
||||||
@ -223,9 +186,7 @@ class _PowerClampPageState extends State<PowerClampPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String _getValueOrNA(List<DataPoint> dataPoints, int index) {
|
String _getValueOrNA(List<DataPoint> dataPoints, int index) {
|
||||||
return dataPoints.length > index
|
return dataPoints.length > index ? dataPoints[index].value.toString() : 'N/A';
|
||||||
? dataPoints[index].value.toString()
|
|
||||||
: 'N/A';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildPageIndicator() {
|
Widget _buildPageIndicator() {
|
||||||
@ -240,8 +201,7 @@ class _PowerClampPageState extends State<PowerClampPage> {
|
|||||||
height: 10.0,
|
height: 10.0,
|
||||||
width: _currentPage == index ? 10.0 : 10.0,
|
width: _currentPage == index ? 10.0 : 10.0,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color:
|
color: _currentPage == index ? Colors.grey : ColorsManager.greyColor,
|
||||||
_currentPage == index ? Colors.grey : ColorsManager.greyColor,
|
|
||||||
borderRadius: BorderRadius.circular(5.0),
|
borderRadius: BorderRadius.circular(5.0),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -10,6 +10,7 @@ import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
|||||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/6_scene_switch/six_scene_screen.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/6_scene_switch/six_scene_screen.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/ACs/acs_view.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/ACs/acs_view.dart';
|
||||||
|
import 'package:syncrow_app/features/devices/view/widgets/ceiling_sensor/ceiling_sensor_interface.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/curtains/curtain_view.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/curtains/curtain_view.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/door_sensor/door_sensor_screen.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/door_sensor/door_sensor_screen.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/four_scene_switch/four_scene_screen.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/four_scene_switch/four_scene_screen.dart';
|
||||||
@ -19,14 +20,13 @@ import 'package:syncrow_app/features/devices/view/widgets/lights/light_interface
|
|||||||
import 'package:syncrow_app/features/devices/view/widgets/one_gang/one_gang_Interface.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/one_gang/one_gang_Interface.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/one_touch/one_touch_screen.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/one_touch/one_touch_screen.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/power_clamp/power_clamp_page.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/power_clamp/power_clamp_page.dart';
|
||||||
|
import 'package:syncrow_app/features/devices/view/widgets/smart_door/door_interface.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/sos/sos_screen.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/sos/sos_screen.dart';
|
||||||
|
import 'package:syncrow_app/features/devices/view/widgets/three_gang/three_gang_interface.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/three_touch/three_touch_interface.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/three_touch/three_touch_interface.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/two_gang/two_gang_Interface.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/two_gang/two_gang_Interface.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/two_touch/two_touch_Interface.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/two_touch/two_touch_Interface.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/wall_sensor/wall_sensor_interface.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/wall_sensor/wall_sensor_interface.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/ceiling_sensor/ceiling_sensor_interface.dart';
|
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/smart_door/door_interface.dart';
|
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/three_gang/three_gang_interface.dart';
|
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/water_heater/water_heater_page.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/water_heater/water_heater_page.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/water_leak/water_leak_screen.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/water_leak/water_leak_screen.dart';
|
||||||
import 'package:syncrow_app/features/shared_widgets/custom_switch.dart';
|
import 'package:syncrow_app/features/shared_widgets/custom_switch.dart';
|
||||||
@ -73,34 +73,30 @@ class RoomPageSwitch extends StatelessWidget {
|
|||||||
? CustomSwitch(
|
? CustomSwitch(
|
||||||
device: device,
|
device: device,
|
||||||
)
|
)
|
||||||
: const SizedBox(),
|
: const SizedBox.shrink(),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Flexible(
|
Text(
|
||||||
child: FittedBox(
|
device.name ?? '',
|
||||||
child: Column(
|
textScaler: TextScaler.linear(1),
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
style: context.bodyLarge.copyWith(
|
||||||
children: [
|
fontWeight: FontWeight.bold,
|
||||||
Text(
|
color: Colors.grey,
|
||||||
device.name ?? "",
|
fontSize: 14,
|
||||||
overflow: TextOverflow.ellipsis,
|
),
|
||||||
maxLines: 2,
|
overflow: TextOverflow.ellipsis,
|
||||||
style: context.bodyLarge.copyWith(
|
maxLines: 1,
|
||||||
fontWeight: FontWeight.bold,
|
),
|
||||||
fontSize: 20,
|
FittedBox(
|
||||||
color: Colors.grey,
|
fit: BoxFit.scaleDown,
|
||||||
),
|
child: Text(
|
||||||
),
|
device.subspace!.subspaceName ?? '',
|
||||||
Text(
|
overflow: TextOverflow.ellipsis,
|
||||||
device.subspace!.subspaceName ?? '',
|
textScaler: TextScaler.linear(1),
|
||||||
overflow: TextOverflow.ellipsis,
|
style: context.bodySmall.copyWith(
|
||||||
style: context.bodySmall.copyWith(
|
fontWeight: FontWeight.w400,
|
||||||
fontWeight: FontWeight.w400,
|
fontSize: 9,
|
||||||
fontSize: 10,
|
color: Colors.grey,
|
||||||
color: Colors.grey,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -5,7 +5,6 @@ import 'package:syncrow_app/features/devices/bloc/sos_bloc/sos_bloc.dart';
|
|||||||
import 'package:syncrow_app/features/devices/bloc/sos_bloc/sos_event.dart';
|
import 'package:syncrow_app/features/devices/bloc/sos_bloc/sos_event.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/sos_bloc/sos_state.dart';
|
import 'package:syncrow_app/features/devices/bloc/sos_bloc/sos_state.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/sos_model.dart';
|
|
||||||
import 'package:syncrow_app/features/devices/view/device_settings/settings_page.dart';
|
import 'package:syncrow_app/features/devices/view/device_settings/settings_page.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/sos/sos_alarm_management_page.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/sos/sos_alarm_management_page.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/sos/sos_records_screen.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/sos/sos_records_screen.dart';
|
||||||
@ -29,17 +28,8 @@ class SosScreen extends StatelessWidget {
|
|||||||
child: BlocBuilder<SosBloc, SosState>(
|
child: BlocBuilder<SosBloc, SosState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
final sensor = BlocProvider.of<SosBloc>(context);
|
final sensor = BlocProvider.of<SosBloc>(context);
|
||||||
SosModel model = SosModel(
|
|
||||||
batteryPercentage: 0,
|
|
||||||
sosContactState: '',
|
|
||||||
);
|
|
||||||
if (state is LoadingNewSate) {
|
|
||||||
model = state.sosSensor;
|
|
||||||
} else if (state is UpdateState) {
|
|
||||||
model = state.sensor;
|
|
||||||
}
|
|
||||||
return DefaultScaffold(
|
return DefaultScaffold(
|
||||||
title: sensor.deviceInfo.name,
|
title: device?.name,
|
||||||
actions: [
|
actions: [
|
||||||
InkWell(
|
InkWell(
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
@ -82,38 +72,33 @@ class SosScreen extends StatelessWidget {
|
|||||||
Expanded(
|
Expanded(
|
||||||
flex: 4,
|
flex: 4,
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
overlayColor: MaterialStateProperty.all(
|
overlayColor:
|
||||||
Colors.transparent),
|
WidgetStateProperty.all(Colors.transparent),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
// Add functionality for the main SOS button here
|
// Add functionality for the main SOS button here
|
||||||
},
|
},
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
crossAxisAlignment:
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
CrossAxisAlignment.center,
|
|
||||||
children: [
|
children: [
|
||||||
Container(
|
Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
borderRadius:
|
borderRadius: BorderRadius.circular(890),
|
||||||
BorderRadius.circular(890),
|
|
||||||
boxShadow: [
|
boxShadow: [
|
||||||
BoxShadow(
|
BoxShadow(
|
||||||
color:
|
color: Colors.white.withOpacity(0.1),
|
||||||
Colors.white.withOpacity(0.1),
|
|
||||||
blurRadius: 24,
|
blurRadius: 24,
|
||||||
offset: const Offset(-5, -5),
|
offset: const Offset(-5, -5),
|
||||||
blurStyle: BlurStyle.outer,
|
blurStyle: BlurStyle.outer,
|
||||||
),
|
),
|
||||||
BoxShadow(
|
BoxShadow(
|
||||||
color: Colors.black
|
color: Colors.black.withOpacity(0.11),
|
||||||
.withOpacity(0.11),
|
|
||||||
blurRadius: 25,
|
blurRadius: 25,
|
||||||
offset: const Offset(5, 5),
|
offset: const Offset(5, 5),
|
||||||
blurStyle: BlurStyle.outer,
|
blurStyle: BlurStyle.outer,
|
||||||
),
|
),
|
||||||
BoxShadow(
|
BoxShadow(
|
||||||
color: Colors.black
|
color: Colors.black.withOpacity(0.13),
|
||||||
.withOpacity(0.13),
|
|
||||||
blurRadius: 30,
|
blurRadius: 30,
|
||||||
offset: const Offset(5, 5),
|
offset: const Offset(5, 5),
|
||||||
blurStyle: BlurStyle.inner,
|
blurStyle: BlurStyle.inner,
|
||||||
@ -140,9 +125,8 @@ class SosScreen extends StatelessWidget {
|
|||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.of(context).push(
|
Navigator.of(context).push(
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) =>
|
builder: (context) => SosRecordsScreen(
|
||||||
SosRecordsScreen(
|
sosId: device!.uuid!),
|
||||||
sosId: device!.uuid!),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -197,8 +181,8 @@ class SosScreen extends StatelessWidget {
|
|||||||
maxHeight: 46,
|
maxHeight: 46,
|
||||||
maxWidth: 50,
|
maxWidth: 50,
|
||||||
),
|
),
|
||||||
child: SvgPicture.asset(Assets
|
child: SvgPicture.asset(
|
||||||
.doorNotificationSetting),
|
Assets.doorNotificationSetting),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 15),
|
const SizedBox(height: 15),
|
||||||
const Flexible(
|
const Flexible(
|
||||||
|
@ -9,7 +9,10 @@ import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
|||||||
|
|
||||||
class GangSwitch extends StatelessWidget {
|
class GangSwitch extends StatelessWidget {
|
||||||
const GangSwitch(
|
const GangSwitch(
|
||||||
{super.key, required this.threeGangSwitch, required this.value, required this.action});
|
{super.key,
|
||||||
|
required this.threeGangSwitch,
|
||||||
|
required this.value,
|
||||||
|
required this.action});
|
||||||
|
|
||||||
final DeviceModel threeGangSwitch;
|
final DeviceModel threeGangSwitch;
|
||||||
final bool value;
|
final bool value;
|
||||||
|
@ -21,7 +21,7 @@ class WaterHeaterPage extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return DefaultScaffold(
|
return DefaultScaffold(
|
||||||
title: 'Water heater',
|
title: device?.name?? 'Water heater',
|
||||||
child: BlocProvider(
|
child: BlocProvider(
|
||||||
create: (context) => WaterHeaterBloc(switchCode: 'switch_1', whId: device?.uuid ?? '')
|
create: (context) => WaterHeaterBloc(switchCode: 'switch_1', whId: device?.uuid ?? '')
|
||||||
..add(const WaterHeaterInitial()),
|
..add(const WaterHeaterInitial()),
|
||||||
|
@ -8,7 +8,11 @@ import 'package:syncrow_app/features/shared_widgets/devices_default_switch.dart'
|
|||||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_small.dart';
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_small.dart';
|
||||||
|
|
||||||
class WHList extends StatelessWidget {
|
class WHList extends StatelessWidget {
|
||||||
const WHList({super.key, required this.whList, required this.allSwitches});
|
const WHList({
|
||||||
|
required this.whList,
|
||||||
|
required this.allSwitches,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
final List<GroupWHModel> whList;
|
final List<GroupWHModel> whList;
|
||||||
final bool allSwitches;
|
final bool allSwitches;
|
||||||
@ -22,43 +26,42 @@ class WHList extends StatelessWidget {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
const BodySmall(text: 'All Lights'),
|
const BodySmall(text: 'All Water Heaters'),
|
||||||
const SizedBox(height: 5),
|
const SizedBox(height: 5),
|
||||||
DevicesDefaultSwitch(
|
DevicesDefaultSwitch(
|
||||||
off: 'OFF',
|
off: 'OFF',
|
||||||
on: 'ON',
|
on: 'ON',
|
||||||
switchValue: allSwitches,
|
switchValue: allSwitches,
|
||||||
action: () {
|
action: () => context.read<WaterHeaterBloc>().add(
|
||||||
BlocProvider.of<WaterHeaterBloc>(context)
|
GroupAllOnEvent(),
|
||||||
.add(GroupAllOnEvent());
|
),
|
||||||
},
|
secondAction: () => context.read<WaterHeaterBloc>().add(
|
||||||
secondAction: () {
|
GroupAllOffEvent(),
|
||||||
BlocProvider.of<WaterHeaterBloc>(context)
|
),
|
||||||
.add(GroupAllOffEvent());
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
ListView.builder(
|
ListView.builder(
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
physics: const NeverScrollableScrollPhysics(),
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
padding: const EdgeInsets.all(0),
|
padding: EdgeInsetsDirectional.zero,
|
||||||
itemCount: whList.length,
|
itemCount: whList.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
|
final waterHeater = whList[index];
|
||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
BodySmall(text: whList[index].deviceName),
|
BodySmall(text: waterHeater.deviceName),
|
||||||
const SizedBox(height: 5),
|
const SizedBox(height: 5),
|
||||||
DevicesDefaultSwitch(
|
DevicesDefaultSwitch(
|
||||||
off: 'OFF',
|
off: 'OFF',
|
||||||
on: 'ON',
|
on: 'ON',
|
||||||
switchValue: whList[index].firstSwitch,
|
switchValue: waterHeater.firstSwitch,
|
||||||
action: () {
|
action: () => context.read<WaterHeaterBloc>().add(
|
||||||
BlocProvider.of<WaterHeaterBloc>(context).add(
|
|
||||||
ChangeFirstWizardSwitchStatusEvent(
|
ChangeFirstWizardSwitchStatusEvent(
|
||||||
value: whList[index].firstSwitch,
|
value: waterHeater.firstSwitch,
|
||||||
deviceId: whList[index].deviceId));
|
deviceId: waterHeater.deviceId,
|
||||||
},
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
@ -22,7 +22,7 @@ class WaterLeakScreen extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return DefaultScaffold(
|
return DefaultScaffold(
|
||||||
title: 'Water Leak Sensor',
|
title: device?.name ?? 'Water Leak',
|
||||||
child: BlocProvider(
|
child: BlocProvider(
|
||||||
create: (context) => WaterLeakBloc(WLId: device?.uuid ?? '')
|
create: (context) => WaterLeakBloc(WLId: device?.uuid ?? '')
|
||||||
..add(const WaterLeakInitial()),
|
..add(const WaterLeakInitial()),
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||||
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||||
|
import 'package:syncrow_app/features/auth/model/project_model.dart';
|
||||||
import 'package:syncrow_app/features/auth/model/user_model.dart';
|
import 'package:syncrow_app/features/auth/model/user_model.dart';
|
||||||
import 'package:syncrow_app/features/menu/bloc/create_unit_bloc/create_unit_event.dart';
|
import 'package:syncrow_app/features/menu/bloc/create_unit_bloc/create_unit_event.dart';
|
||||||
import 'package:syncrow_app/features/menu/bloc/create_unit_bloc/create_unit_state.dart';
|
import 'package:syncrow_app/features/menu/bloc/create_unit_bloc/create_unit_state.dart';
|
||||||
import 'package:syncrow_app/services/api/home_creation_api.dart';
|
import 'package:syncrow_app/services/api/home_creation_api.dart';
|
||||||
|
import 'package:syncrow_app/utils/constants/temp_const.dart';
|
||||||
import 'package:syncrow_app/utils/helpers/snack_bar.dart';
|
import 'package:syncrow_app/utils/helpers/snack_bar.dart';
|
||||||
|
|
||||||
class CreateUnitBloc extends Bloc<CreateUnitEvent, CreateUnitState> {
|
class CreateUnitBloc extends Bloc<CreateUnitEvent, CreateUnitState> {
|
||||||
@ -239,8 +241,13 @@ Future<String> _createNewRoom(
|
|||||||
required String communityId}) async {
|
required String communityId}) async {
|
||||||
try {
|
try {
|
||||||
Map<String, String> body = {'subspaceName': roomName};
|
Map<String, String> body = {'subspaceName': roomName};
|
||||||
|
Project? project = HomeCubit.getInstance().project;
|
||||||
|
|
||||||
final response = await HomeCreation.createRoom(
|
final response = await HomeCreation.createRoom(
|
||||||
communityId: communityId, spaceId: unitId, body: body);
|
communityId: communityId,
|
||||||
|
spaceId: unitId,
|
||||||
|
body: body,
|
||||||
|
projectId: project?.uuid ?? TempConst.projectIdDev);
|
||||||
// if (response['data']['uuid'] != '') {
|
// if (response['data']['uuid'] != '') {
|
||||||
// final result = await _assignToRoom(roomId: response['data']['uuid'], userId: userId);
|
// final result = await _assignToRoom(roomId: response['data']['uuid'], userId: userId);
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||||
|
import 'package:syncrow_app/features/auth/model/project_model.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||||
import 'package:syncrow_app/features/menu/bloc/manage_unit_bloc/manage_unit_event.dart';
|
import 'package:syncrow_app/features/menu/bloc/manage_unit_bloc/manage_unit_event.dart';
|
||||||
import 'package:syncrow_app/features/menu/bloc/manage_unit_bloc/manage_unit_state.dart';
|
import 'package:syncrow_app/features/menu/bloc/manage_unit_bloc/manage_unit_state.dart';
|
||||||
@ -7,6 +8,7 @@ import 'package:syncrow_app/services/api/devices_api.dart';
|
|||||||
import 'package:syncrow_app/services/api/home_creation_api.dart';
|
import 'package:syncrow_app/services/api/home_creation_api.dart';
|
||||||
import 'package:syncrow_app/services/api/home_management_api.dart';
|
import 'package:syncrow_app/services/api/home_management_api.dart';
|
||||||
import 'package:syncrow_app/services/api/spaces_api.dart';
|
import 'package:syncrow_app/services/api/spaces_api.dart';
|
||||||
|
import 'package:syncrow_app/utils/constants/temp_const.dart';
|
||||||
|
|
||||||
class ManageUnitBloc extends Bloc<ManageUnitEvent, ManageUnitState> {
|
class ManageUnitBloc extends Bloc<ManageUnitEvent, ManageUnitState> {
|
||||||
List<DeviceModel> allDevices = [];
|
List<DeviceModel> allDevices = [];
|
||||||
@ -24,8 +26,12 @@ class ManageUnitBloc extends Bloc<ManageUnitEvent, ManageUnitState> {
|
|||||||
FetchRoomsEvent event, Emitter<ManageUnitState> emit) async {
|
FetchRoomsEvent event, Emitter<ManageUnitState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingState());
|
emit(LoadingState());
|
||||||
|
Project? project = HomeCubit.getInstance().project;
|
||||||
|
|
||||||
final roomsList = await SpacesAPI.getSubSpaceBySpaceId(
|
final roomsList = await SpacesAPI.getSubSpaceBySpaceId(
|
||||||
event.unit.community.uuid, event.unit.id);
|
event.unit.community.uuid,
|
||||||
|
event.unit.id,
|
||||||
|
project?.uuid ?? TempConst.projectIdDev);
|
||||||
emit(FetchRoomsState(devicesList: allDevices, roomsList: roomsList));
|
emit(FetchRoomsState(devicesList: allDevices, roomsList: roomsList));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(const ErrorState(message: 'Something went wrong'));
|
emit(const ErrorState(message: 'Something went wrong'));
|
||||||
@ -37,12 +43,16 @@ class ManageUnitBloc extends Bloc<ManageUnitEvent, ManageUnitState> {
|
|||||||
FetchDevicesByRoomIdEvent event, Emitter<ManageUnitState> emit) async {
|
FetchDevicesByRoomIdEvent event, Emitter<ManageUnitState> emit) async {
|
||||||
try {
|
try {
|
||||||
Map<String, bool> roomDevicesId = {};
|
Map<String, bool> roomDevicesId = {};
|
||||||
|
Project? project = HomeCubit.getInstance().project;
|
||||||
|
|
||||||
emit(LoadingState());
|
emit(LoadingState());
|
||||||
final devicesList = await DevicesAPI.getDevicesByRoomId(
|
final devicesList = await DevicesAPI.getDevicesByRoomId(
|
||||||
communityUuid: event.unit.community.uuid,
|
communityUuid: event.unit.community.uuid,
|
||||||
spaceUuid: event.unit.id,
|
spaceUuid: event.unit.id,
|
||||||
roomId: event.roomId);
|
roomId: event.roomId,
|
||||||
allDevices = await HomeManagementAPI.fetchDevicesByUserId();
|
projectId: project?.uuid ?? TempConst.projectIdDev);
|
||||||
|
allDevices = await HomeManagementAPI.fetchDevices(
|
||||||
|
project?.uuid ?? TempConst.projectIdDev);
|
||||||
|
|
||||||
List<String> allDevicesIds = [];
|
List<String> allDevicesIds = [];
|
||||||
|
|
||||||
@ -72,14 +82,21 @@ class ManageUnitBloc extends Bloc<ManageUnitEvent, ManageUnitState> {
|
|||||||
AssignRoomEvent event, Emitter<ManageUnitState> emit) async {
|
AssignRoomEvent event, Emitter<ManageUnitState> emit) async {
|
||||||
try {
|
try {
|
||||||
Map<String, bool> roomDevicesId = {};
|
Map<String, bool> roomDevicesId = {};
|
||||||
|
Project? project = HomeCubit.getInstance().project;
|
||||||
|
|
||||||
emit(LoadingState());
|
emit(LoadingState());
|
||||||
|
|
||||||
await HomeManagementAPI.assignDeviceToRoom(
|
await HomeManagementAPI.assignDeviceToRoom(
|
||||||
event.unit.community.uuid, event.unit.id, event.roomId, event.deviceId);
|
event.unit.community.uuid,
|
||||||
|
event.unit.id,
|
||||||
|
event.roomId,
|
||||||
|
event.deviceId,
|
||||||
|
project?.uuid ?? TempConst.projectIdDev);
|
||||||
final devicesList = await DevicesAPI.getDevicesByRoomId(
|
final devicesList = await DevicesAPI.getDevicesByRoomId(
|
||||||
communityUuid: event.unit.community.uuid,
|
communityUuid: event.unit.community.uuid,
|
||||||
spaceUuid: event.unit.id,
|
spaceUuid: event.unit.id,
|
||||||
roomId: event.roomId);
|
roomId: event.roomId,
|
||||||
|
projectId: project?.uuid ?? TempConst.projectIdDev);
|
||||||
|
|
||||||
List<String> allDevicesIds = [];
|
List<String> allDevicesIds = [];
|
||||||
|
|
||||||
@ -105,19 +122,25 @@ class ManageUnitBloc extends Bloc<ManageUnitEvent, ManageUnitState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void _unassignDevice(
|
void _unassignDevice(
|
||||||
UnassignRoomEvent event, Emitter<ManageUnitState> emit) async {
|
UnassignRoomEvent event, Emitter<ManageUnitState> emit) async {
|
||||||
try {
|
try {
|
||||||
Map<String, bool> roomDevicesId = {};
|
Map<String, bool> roomDevicesId = {};
|
||||||
|
Project? project = HomeCubit.getInstance().project;
|
||||||
|
|
||||||
emit(LoadingState());
|
emit(LoadingState());
|
||||||
|
|
||||||
await HomeManagementAPI.unAssignDeviceToRoom(
|
await HomeManagementAPI.unAssignDeviceToRoom(
|
||||||
event.unit.community.uuid, event.unit.id, event.roomId, event.deviceId);
|
event.unit.community.uuid,
|
||||||
|
event.unit.id,
|
||||||
|
event.roomId,
|
||||||
|
event.deviceId,
|
||||||
|
project?.uuid ?? TempConst.projectIdDev);
|
||||||
final devicesList = await DevicesAPI.getDevicesByRoomId(
|
final devicesList = await DevicesAPI.getDevicesByRoomId(
|
||||||
communityUuid: event.unit.community.uuid,
|
communityUuid: event.unit.community.uuid,
|
||||||
spaceUuid: event.unit.id,
|
spaceUuid: event.unit.id,
|
||||||
roomId: event.roomId);
|
roomId: event.roomId,
|
||||||
|
projectId: project?.uuid ?? TempConst.projectIdDev);
|
||||||
|
|
||||||
List<String> allDevicesIds = [];
|
List<String> allDevicesIds = [];
|
||||||
|
|
||||||
@ -143,18 +166,22 @@ class ManageUnitBloc extends Bloc<ManageUnitEvent, ManageUnitState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
_addNewRoom(AddNewRoom event, Emitter<ManageUnitState> emit) async {
|
_addNewRoom(AddNewRoom event, Emitter<ManageUnitState> emit) async {
|
||||||
Map<String, String> body = {'subspaceName': event.roomName};
|
Map<String, String> body = {'subspaceName': event.roomName};
|
||||||
try {
|
try {
|
||||||
emit(LoadingState());
|
emit(LoadingState());
|
||||||
|
Project? project = HomeCubit.getInstance().project;
|
||||||
|
|
||||||
final response = await HomeCreation.createRoom(
|
final response = await HomeCreation.createRoom(
|
||||||
communityId: event.unit.community.uuid,
|
communityId: event.unit.community.uuid,
|
||||||
spaceId: event.unit.id,
|
spaceId: event.unit.id,
|
||||||
body: body);
|
body: body,
|
||||||
|
projectId: project?.uuid ?? TempConst.projectIdDev);
|
||||||
if (response['data']['uuid'] != '') {
|
if (response['data']['uuid'] != '') {
|
||||||
final roomsList = await SpacesAPI.getSubSpaceBySpaceId(
|
final roomsList = await SpacesAPI.getSubSpaceBySpaceId(
|
||||||
event.unit.community.uuid, event.unit.id);
|
event.unit.community.uuid,
|
||||||
|
event.unit.id,
|
||||||
|
project?.uuid ?? TempConst.projectIdDev);
|
||||||
allDevices = await HomeManagementAPI.fetchDevicesByUserId();
|
allDevices = await HomeManagementAPI.fetchDevicesByUserId();
|
||||||
emit(FetchRoomsState(devicesList: allDevices, roomsList: roomsList));
|
emit(FetchRoomsState(devicesList: allDevices, roomsList: roomsList));
|
||||||
await HomeCubit.getInstance().fetchUnitsByUserId();
|
await HomeCubit.getInstance().fetchUnitsByUserId();
|
||||||
|
@ -154,11 +154,11 @@ class MenuCubit extends Cubit<MenuState> {
|
|||||||
'title': 'Legal Information',
|
'title': 'Legal Information',
|
||||||
'color': const Color(0xFF001B72),
|
'color': const Color(0xFF001B72),
|
||||||
'buttons': [
|
'buttons': [
|
||||||
{
|
// {
|
||||||
'title': 'About',
|
// 'title': 'About',
|
||||||
'Icon': Assets.assetsIconsMenuIconsLeagalInfoIconsAbout,
|
// 'Icon': Assets.assetsIconsMenuIconsLeagalInfoIconsAbout,
|
||||||
'page': null
|
// 'page': null
|
||||||
},
|
// },
|
||||||
{
|
{
|
||||||
'title': 'Privacy Policy',
|
'title': 'Privacy Policy',
|
||||||
'Icon': Assets.assetsIconsMenuIconsLeagalInfoIconsPrivacyPolicy,
|
'Icon': Assets.assetsIconsMenuIconsLeagalInfoIconsPrivacyPolicy,
|
||||||
@ -176,7 +176,7 @@ class MenuCubit extends Cubit<MenuState> {
|
|||||||
Future<void> fetchMenuSections() async {
|
Future<void> fetchMenuSections() async {
|
||||||
emit(MenuLoading());
|
emit(MenuLoading());
|
||||||
try {
|
try {
|
||||||
emit(MenuItemsLoaded(menuSections));
|
emit(MenuItemsLoaded(menuSections));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(MenuError(e.toString()));
|
emit(MenuError(e.toString()));
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,8 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
|||||||
String timeZoneSelected = '';
|
String timeZoneSelected = '';
|
||||||
String regionSelected = '';
|
String regionSelected = '';
|
||||||
final TextEditingController searchController = TextEditingController();
|
final TextEditingController searchController = TextEditingController();
|
||||||
final TextEditingController nameController =
|
final TextEditingController nameController = TextEditingController(
|
||||||
TextEditingController(text: '${HomeCubit.user!.firstName} ${HomeCubit.user!.lastName}');
|
text: '${HomeCubit.user!.firstName} ${HomeCubit.user!.lastName}');
|
||||||
|
|
||||||
List<RegionModel> allRegions = [];
|
List<RegionModel> allRegions = [];
|
||||||
List<TimeZone> allTimeZone = [];
|
List<TimeZone> allTimeZone = [];
|
||||||
@ -77,10 +77,13 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
|||||||
emit(NameEditingState(editName: editName));
|
emit(NameEditingState(editName: editName));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _fetchUserInfo(InitialProfileEvent event, Emitter<ProfileState> emit) async {
|
void _fetchUserInfo(
|
||||||
|
InitialProfileEvent event, Emitter<ProfileState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
HomeCubit.user = await ProfileApi().fetchUserInfo(HomeCubit.user!.uuid);
|
HomeCubit.user = await ProfileApi().fetchUserInfo(HomeCubit.user!.uuid);
|
||||||
|
HomeCubit.getInstance().project = HomeCubit.user?.project;
|
||||||
|
|
||||||
emit(SaveState());
|
emit(SaveState());
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(FailedState(errorMessage: e.toString()));
|
emit(FailedState(errorMessage: e.toString()));
|
||||||
@ -88,7 +91,8 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future _fetchTimeZone(TimeZoneInitialEvent event, Emitter<ProfileState> emit) async {
|
Future _fetchTimeZone(
|
||||||
|
TimeZoneInitialEvent event, Emitter<ProfileState> emit) async {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
try {
|
try {
|
||||||
allTimeZone = await ProfileApi.fetchTimeZone();
|
allTimeZone = await ProfileApi.fetchTimeZone();
|
||||||
@ -100,7 +104,8 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future selectTimeZone(SelectTimeZoneEvent event, Emitter<ProfileState> emit) async {
|
Future selectTimeZone(
|
||||||
|
SelectTimeZoneEvent event, Emitter<ProfileState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
timeZoneSelected = event.val;
|
timeZoneSelected = event.val;
|
||||||
@ -112,7 +117,8 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future selectRegion(SelectRegionEvent event, Emitter<ProfileState> emit) async {
|
Future selectRegion(
|
||||||
|
SelectRegionEvent event, Emitter<ProfileState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
await ProfileApi.saveRegion(regionUuid: event.val);
|
await ProfileApi.saveRegion(regionUuid: event.val);
|
||||||
@ -124,7 +130,8 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> searchRegion(SearchRegionEvent event, Emitter<ProfileState> emit) async {
|
Future<void> searchRegion(
|
||||||
|
SearchRegionEvent event, Emitter<ProfileState> emit) async {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
final query = event.query.toLowerCase();
|
final query = event.query.toLowerCase();
|
||||||
if (allRegions.isEmpty) {
|
if (allRegions.isEmpty) {
|
||||||
@ -140,7 +147,8 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> searchTimeZone(SearchTimeZoneEvent event, Emitter<ProfileState> emit) async {
|
Future<void> searchTimeZone(
|
||||||
|
SearchTimeZoneEvent event, Emitter<ProfileState> emit) async {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
final query = event.query.toLowerCase();
|
final query = event.query.toLowerCase();
|
||||||
if (allTimeZone.isEmpty) {
|
if (allTimeZone.isEmpty) {
|
||||||
@ -156,7 +164,8 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _fetchRegion(RegionInitialEvent event, Emitter<ProfileState> emit) async {
|
void _fetchRegion(
|
||||||
|
RegionInitialEvent event, Emitter<ProfileState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
allRegions = await ProfileApi.fetchRegion();
|
allRegions = await ProfileApi.fetchRegion();
|
||||||
@ -166,7 +175,8 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _selectImage(SelectImageEvent event, Emitter<ProfileState> emit) async {
|
Future<void> _selectImage(
|
||||||
|
SelectImageEvent event, Emitter<ProfileState> emit) async {
|
||||||
try {
|
try {
|
||||||
if (await _requestPermission()) {
|
if (await _requestPermission()) {
|
||||||
emit(ChangeImageState());
|
emit(ChangeImageState());
|
||||||
@ -283,7 +293,8 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
|
SharedPreferences sharedPreferences =
|
||||||
|
await SharedPreferences.getInstance();
|
||||||
bool firstClick = sharedPreferences.getBool('firstPermission') ?? true;
|
bool firstClick = sharedPreferences.getBool('firstPermission') ?? true;
|
||||||
await sharedPreferences.setBool('firstPermission', false);
|
await sharedPreferences.setBool('firstPermission', false);
|
||||||
if (firstClick == false) {
|
if (firstClick == false) {
|
||||||
|
@ -28,8 +28,7 @@ class AssignDeviceView extends StatelessWidget {
|
|||||||
listener: (context, state) {
|
listener: (context, state) {
|
||||||
if (state is FetchDeviceByRoomIdState) {
|
if (state is FetchDeviceByRoomIdState) {
|
||||||
if (state.allDevices.isEmpty) {
|
if (state.allDevices.isEmpty) {
|
||||||
CustomSnackBar.displaySnackBar(
|
CustomSnackBar.displaySnackBar('You do not have the devices');
|
||||||
'You do not have the permission to assign devices');
|
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,85 +16,74 @@ class ManageHomeView extends StatelessWidget {
|
|||||||
var spaces = HomeCubit.getInstance().spaces;
|
var spaces = HomeCubit.getInstance().spaces;
|
||||||
return DefaultScaffold(
|
return DefaultScaffold(
|
||||||
title: 'Manage Your Home',
|
title: 'Manage Your Home',
|
||||||
child: spaces == null
|
height: MediaQuery.sizeOf(context).height,
|
||||||
|
child: spaces.isEmpty
|
||||||
? const Center(
|
? const Center(
|
||||||
child: BodyMedium(text: 'No spaces found'),
|
child: BodyMedium(text: 'No spaces found'),
|
||||||
)
|
)
|
||||||
: Column(
|
: DefaultContainer(
|
||||||
children: [
|
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 25),
|
||||||
DefaultContainer(
|
child: ListView.builder(
|
||||||
padding: const EdgeInsets.symmetric(
|
itemCount: spaces.length,
|
||||||
horizontal: 25,
|
itemBuilder: (context, index) {
|
||||||
vertical: 20,
|
if (index == spaces.length - 1) {
|
||||||
),
|
return InkWell(
|
||||||
child: Column(
|
onTap: () {
|
||||||
mainAxisSize: MainAxisSize.min,
|
Navigator.of(context).push(CustomPageRoute(
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
builder: (context) => HomeSettingsView(
|
||||||
children: List.generate(
|
space: spaces[index],
|
||||||
spaces.length,
|
)));
|
||||||
(index) {
|
},
|
||||||
if (index == spaces.length - 1) {
|
child: Row(
|
||||||
return InkWell(
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
onTap: () {
|
children: [
|
||||||
Navigator.of(context).push(CustomPageRoute(
|
BodyMedium(text: StringHelpers.toTitleCase(spaces[index].name)),
|
||||||
builder: (context) => HomeSettingsView(
|
const Icon(
|
||||||
space: spaces[index],
|
Icons.arrow_forward_ios,
|
||||||
)));
|
color: ColorsManager.greyColor,
|
||||||
},
|
size: 15,
|
||||||
child: Row(
|
)
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
],
|
||||||
children: [
|
),
|
||||||
BodyMedium(text: StringHelpers.toTitleCase(spaces[index].name)),
|
);
|
||||||
const Icon(
|
}
|
||||||
Icons.arrow_forward_ios,
|
return InkWell(
|
||||||
color: ColorsManager.greyColor,
|
onTap: () {
|
||||||
size: 15,
|
//TODO refactor the routing to use named routes
|
||||||
)
|
// Navigator.of(context).pushNamed(
|
||||||
],
|
// '/home_settings',
|
||||||
),
|
// arguments: spaces[index],
|
||||||
);
|
// );
|
||||||
}
|
|
||||||
return InkWell(
|
|
||||||
onTap: () {
|
|
||||||
//TODO refactor the routing to use named routes
|
|
||||||
// Navigator.of(context).pushNamed(
|
|
||||||
// '/home_settings',
|
|
||||||
// arguments: spaces[index],
|
|
||||||
// );
|
|
||||||
|
|
||||||
Navigator.of(context).push(CustomPageRoute(
|
Navigator.of(context).push(CustomPageRoute(
|
||||||
builder: (context) => HomeSettingsView(
|
builder: (context) => HomeSettingsView(
|
||||||
space: spaces[index],
|
space: spaces[index],
|
||||||
)));
|
)));
|
||||||
},
|
},
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
Row(
|
BodyMedium(text: HomeCubit.getInstance().spaces[index].name),
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
const Icon(
|
||||||
children: [
|
Icons.arrow_forward_ios,
|
||||||
BodyMedium(text: HomeCubit.getInstance().spaces![index].name),
|
|
||||||
const Icon(
|
|
||||||
Icons.arrow_forward_ios,
|
|
||||||
color: ColorsManager.greyColor,
|
|
||||||
size: 15,
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
Container(
|
|
||||||
margin: const EdgeInsets.symmetric(vertical: 15),
|
|
||||||
height: 1,
|
|
||||||
color: ColorsManager.greyColor,
|
color: ColorsManager.greyColor,
|
||||||
),
|
size: 15,
|
||||||
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
Container(
|
||||||
},
|
margin: const EdgeInsets.symmetric(vertical: 15),
|
||||||
),
|
height: 1,
|
||||||
),
|
color: ColorsManager.greyColor,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||||
|
import 'package:syncrow_app/features/auth/model/project_model.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
||||||
import 'package:syncrow_app/features/scene/bloc/effective_period/effect_period_bloc.dart';
|
import 'package:syncrow_app/features/scene/bloc/effective_period/effect_period_bloc.dart';
|
||||||
import 'package:syncrow_app/features/scene/bloc/effective_period/effect_period_event.dart';
|
import 'package:syncrow_app/features/scene/bloc/effective_period/effect_period_event.dart';
|
||||||
@ -348,15 +350,18 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
|||||||
emit(CreateSceneLoading());
|
emit(CreateSceneLoading());
|
||||||
try {
|
try {
|
||||||
dynamic response;
|
dynamic response;
|
||||||
|
Project? project = HomeCubit.getInstance().project;
|
||||||
|
|
||||||
if (event.createSceneModel != null) {
|
if (event.createSceneModel != null) {
|
||||||
response = event.updateScene
|
response = event.updateScene
|
||||||
? await SceneApi.updateScene(event.createSceneModel!, event.sceneId)
|
? await SceneApi.updateScene(event.createSceneModel!, event.sceneId)
|
||||||
: await SceneApi.createScene(event.createSceneModel!);
|
: await SceneApi.createScene(event.createSceneModel!);
|
||||||
} else if (event.createAutomationModel != null) {
|
} else if (event.createAutomationModel != null) {
|
||||||
response = event.updateScene
|
response = event.updateScene
|
||||||
? await SceneApi.updateAutomation(
|
? await SceneApi.updateAutomation(event.createAutomationModel!,
|
||||||
event.createAutomationModel!, event.sceneId)
|
event.sceneId, project?.uuid ?? '')
|
||||||
: await SceneApi.createAutomation(event.createAutomationModel!);
|
: await SceneApi.createAutomation(
|
||||||
|
event.createAutomationModel!, project?.uuid ?? '');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response['success'] == true) {
|
if (response['success'] == true) {
|
||||||
@ -421,6 +426,8 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
|||||||
emit(CreateSceneLoading());
|
emit(CreateSceneLoading());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
Project? project = HomeCubit.getInstance().project;
|
||||||
|
|
||||||
tasksList.clear();
|
tasksList.clear();
|
||||||
tempTasksList.clear();
|
tempTasksList.clear();
|
||||||
selectedValues.clear();
|
selectedValues.clear();
|
||||||
@ -436,7 +443,8 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
|||||||
conditionRule = 'or';
|
conditionRule = 'or';
|
||||||
|
|
||||||
final response = event.isAutomation
|
final response = event.isAutomation
|
||||||
? await SceneApi.getAutomationDetails(event.sceneId)
|
? await SceneApi.getAutomationDetails(
|
||||||
|
event.sceneId, project?.uuid ?? '')
|
||||||
: await SceneApi.getSceneDetails(event.sceneId);
|
: await SceneApi.getSceneDetails(event.sceneId);
|
||||||
if (response.id.isNotEmpty) {
|
if (response.id.isNotEmpty) {
|
||||||
if (event.isAutomation) {
|
if (event.isAutomation) {
|
||||||
@ -605,10 +613,14 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
|||||||
emit(DeleteSceneLoading());
|
emit(DeleteSceneLoading());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
Project? project = HomeCubit.getInstance().project;
|
||||||
|
|
||||||
final response =
|
final response =
|
||||||
sceneType.name == CreateSceneEnum.deviceStatusChanges.name
|
sceneType.name == CreateSceneEnum.deviceStatusChanges.name
|
||||||
? await SceneApi.deleteAutomation(
|
? await SceneApi.deleteAutomation(
|
||||||
automationId: event.sceneId, unitUuid: event.unitUuid)
|
automationId: event.sceneId,
|
||||||
|
unitUuid: event.unitUuid,
|
||||||
|
projectId: project?.uuid ?? '')
|
||||||
: await SceneApi.deleteScene(
|
: await SceneApi.deleteScene(
|
||||||
sceneId: event.sceneId,
|
sceneId: event.sceneId,
|
||||||
);
|
);
|
||||||
|
@ -2,9 +2,12 @@ import 'dart:async';
|
|||||||
|
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||||
|
import 'package:syncrow_app/features/auth/model/project_model.dart';
|
||||||
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_event.dart';
|
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_event.dart';
|
||||||
import 'package:syncrow_app/features/scene/model/scenes_model.dart';
|
import 'package:syncrow_app/features/scene/model/scenes_model.dart';
|
||||||
import 'package:syncrow_app/services/api/scene_api.dart';
|
import 'package:syncrow_app/services/api/scene_api.dart';
|
||||||
|
import 'package:syncrow_app/utils/constants/temp_const.dart';
|
||||||
|
|
||||||
part 'scene_state.dart';
|
part 'scene_state.dart';
|
||||||
|
|
||||||
@ -23,9 +26,11 @@ class SceneBloc extends Bloc<SceneEvent, SceneState> {
|
|||||||
emit(SceneLoading());
|
emit(SceneLoading());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
Project? project = HomeCubit.getInstance().project;
|
||||||
|
|
||||||
if (event.unitId.isNotEmpty) {
|
if (event.unitId.isNotEmpty) {
|
||||||
scenes = await SceneApi.getScenesByUnitId(
|
scenes = await SceneApi.getScenesByUnitId(event.unitId,
|
||||||
event.unitId, event.unit.community.uuid,
|
event.unit.community.uuid, project?.uuid ?? TempConst.projectIdDev,
|
||||||
showInDevice: event.showInDevice);
|
showInDevice: event.showInDevice);
|
||||||
emit(SceneLoaded(scenes, automationList));
|
emit(SceneLoaded(scenes, automationList));
|
||||||
} else {
|
} else {
|
||||||
@ -41,8 +46,11 @@ class SceneBloc extends Bloc<SceneEvent, SceneState> {
|
|||||||
emit(SceneLoading());
|
emit(SceneLoading());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
Project? project = HomeCubit.getInstance().project;
|
||||||
|
|
||||||
if (event.unitId.isNotEmpty) {
|
if (event.unitId.isNotEmpty) {
|
||||||
automationList = await SceneApi.getAutomationByUnitId(event.unitId);
|
automationList = await SceneApi.getAutomationByUnitId(
|
||||||
|
event.unitId, event.communityId, project?.uuid ?? '');
|
||||||
emit(SceneLoaded(scenes, automationList));
|
emit(SceneLoaded(scenes, automationList));
|
||||||
} else {
|
} else {
|
||||||
emit(const SceneError(message: 'Unit ID is empty'));
|
emit(const SceneError(message: 'Unit ID is empty'));
|
||||||
@ -91,11 +99,17 @@ class SceneBloc extends Bloc<SceneEvent, SceneState> {
|
|||||||
));
|
));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
Project? project = HomeCubit.getInstance().project;
|
||||||
|
|
||||||
final success = await SceneApi.updateAutomationStatus(
|
final success = await SceneApi.updateAutomationStatus(
|
||||||
event.automationId, event.automationStatusUpdate);
|
event.automationId,
|
||||||
|
event.automationStatusUpdate,
|
||||||
|
project?.uuid ?? '');
|
||||||
if (success) {
|
if (success) {
|
||||||
automationList = await SceneApi.getAutomationByUnitId(
|
automationList = await SceneApi.getAutomationByUnitId(
|
||||||
event.automationStatusUpdate.spaceUuid);
|
event.automationStatusUpdate.spaceUuid,
|
||||||
|
event.communityId,
|
||||||
|
project?.uuid ?? '');
|
||||||
newLoadingStates[event.automationId] = false;
|
newLoadingStates[event.automationId] = false;
|
||||||
emit(SceneLoaded(
|
emit(SceneLoaded(
|
||||||
currentState.scenes,
|
currentState.scenes,
|
||||||
|
@ -22,11 +22,13 @@ class LoadScenes extends SceneEvent {
|
|||||||
|
|
||||||
class LoadAutomation extends SceneEvent {
|
class LoadAutomation extends SceneEvent {
|
||||||
final String unitId;
|
final String unitId;
|
||||||
|
final String communityId;
|
||||||
|
|
||||||
const LoadAutomation(this.unitId);
|
|
||||||
|
const LoadAutomation(this.unitId, this.communityId);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [unitId];
|
List<Object> get props => [unitId, communityId];
|
||||||
}
|
}
|
||||||
|
|
||||||
class SceneTrigger extends SceneEvent {
|
class SceneTrigger extends SceneEvent {
|
||||||
@ -43,8 +45,9 @@ class SceneTrigger extends SceneEvent {
|
|||||||
class UpdateAutomationStatus extends SceneEvent {
|
class UpdateAutomationStatus extends SceneEvent {
|
||||||
final String automationId;
|
final String automationId;
|
||||||
final AutomationStatusUpdate automationStatusUpdate;
|
final AutomationStatusUpdate automationStatusUpdate;
|
||||||
|
final String communityId;
|
||||||
|
|
||||||
const UpdateAutomationStatus({required this.automationStatusUpdate, required this.automationId});
|
const UpdateAutomationStatus({required this.automationStatusUpdate, required this.automationId, required this.communityId});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [automationStatusUpdate];
|
List<Object> get props => [automationStatusUpdate];
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import 'dart:async';
|
|
||||||
|
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/device_manager_bloc/device_manager_bloc.dart';
|
import 'package:syncrow_app/features/devices/bloc/device_manager_bloc/device_manager_bloc.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/device_manager_bloc/device_manager_event.dart';
|
import 'package:syncrow_app/features/devices/bloc/device_manager_bloc/device_manager_event.dart';
|
||||||
@ -7,19 +5,31 @@ import 'package:syncrow_app/features/scene/bloc/tab_change/tab_change_event.dart
|
|||||||
import 'package:syncrow_app/features/scene/bloc/tab_change/tab_change_state.dart';
|
import 'package:syncrow_app/features/scene/bloc/tab_change/tab_change_state.dart';
|
||||||
|
|
||||||
class TabBarBloc extends Bloc<TabBarEvent, TabBarState> {
|
class TabBarBloc extends Bloc<TabBarEvent, TabBarState> {
|
||||||
final DeviceManagerBloc deviceManagerBloc;
|
TabBarBloc(this.deviceManagerBloc) : super(const TabBarInitialState()) {
|
||||||
TabBarBloc(this.deviceManagerBloc) : super(const Initial()) {
|
on<TabBarTabChangedEvent>(_onTabBarTabChangedEvent);
|
||||||
on<TabChanged>(_handleTabChanged);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<void> _handleTabChanged(
|
final DeviceManagerBloc deviceManagerBloc;
|
||||||
TabChanged event, Emitter<TabBarState> emit) {
|
|
||||||
|
void _onTabBarTabChangedEvent(
|
||||||
|
TabBarTabChangedEvent event,
|
||||||
|
Emitter<TabBarState> emit,
|
||||||
|
) {
|
||||||
|
_getDevices(event);
|
||||||
|
|
||||||
|
emit(
|
||||||
|
TabBarTabSelectedState(
|
||||||
|
roomId: event.roomId,
|
||||||
|
selectedTabIndex: event.selectedIndex,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _getDevices(TabBarTabChangedEvent event) {
|
||||||
if (event.roomId == "-1") {
|
if (event.roomId == "-1") {
|
||||||
deviceManagerBloc.add(FetchAllDevices());
|
deviceManagerBloc.add(FetchAllDevices());
|
||||||
} else {
|
} else {
|
||||||
deviceManagerBloc.add(FetchDevicesByRoomId(event.roomId,event.unit));
|
deviceManagerBloc.add(FetchDevicesByRoomId(event.roomId, event.unit));
|
||||||
}
|
}
|
||||||
emit(TabSelected(
|
|
||||||
roomId: event.roomId, selectedTabIndex: event.selectedIndex));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,14 @@ abstract class TabBarEvent {
|
|||||||
const TabBarEvent();
|
const TabBarEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
class TabChanged extends TabBarEvent {
|
class TabBarTabChangedEvent extends TabBarEvent {
|
||||||
|
const TabBarTabChangedEvent({
|
||||||
|
required this.selectedIndex,
|
||||||
|
required this.roomId,
|
||||||
|
required this.unit,
|
||||||
|
});
|
||||||
|
|
||||||
final int selectedIndex;
|
final int selectedIndex;
|
||||||
final String roomId;
|
final String roomId;
|
||||||
final SpaceModel unit;
|
final SpaceModel unit;
|
||||||
const TabChanged(
|
|
||||||
{required this.selectedIndex, required this.roomId, required this.unit});
|
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,16 @@ abstract class TabBarState {
|
|||||||
const TabBarState();
|
const TabBarState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class Initial extends TabBarState {
|
class TabBarInitialState extends TabBarState {
|
||||||
const Initial();
|
const TabBarInitialState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class TabSelected extends TabBarState {
|
class TabBarTabSelectedState extends TabBarState {
|
||||||
|
const TabBarTabSelectedState({
|
||||||
|
required this.roomId,
|
||||||
|
required this.selectedTabIndex,
|
||||||
|
});
|
||||||
|
|
||||||
final int selectedTabIndex;
|
final int selectedTabIndex;
|
||||||
final String roomId;
|
final String roomId;
|
||||||
const TabSelected({required this.roomId, required this.selectedTabIndex});
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,78 @@
|
|||||||
|
import 'package:syncrow_app/features/scene/enum/operation_dialog_type.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/model/scene_static_function.dart';
|
||||||
|
import 'package:syncrow_app/generated/assets.dart';
|
||||||
|
|
||||||
|
class OneGangHelperFunctions {
|
||||||
|
static List<SceneStaticFunction> oneGangHelperFunctions(
|
||||||
|
String deviceId, String deviceName, functionValue) {
|
||||||
|
return [
|
||||||
|
SceneStaticFunction(
|
||||||
|
deviceId: deviceId,
|
||||||
|
deviceName: deviceName,
|
||||||
|
icon: Assets.assetsAcPower,
|
||||||
|
operationName: 'Light Switch',
|
||||||
|
code: 'switch_1',
|
||||||
|
functionValue: functionValue,
|
||||||
|
operationDialogType: OperationDialogType.onOff,
|
||||||
|
operationalValues: [
|
||||||
|
SceneOperationalValue(
|
||||||
|
icon: Assets.assetsAcPower, description: "ON", value: true),
|
||||||
|
SceneOperationalValue(
|
||||||
|
icon: Assets.assetsAcPowerOFF, description: "OFF", value: false),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
SceneStaticFunction(
|
||||||
|
deviceId: deviceId,
|
||||||
|
deviceName: deviceName,
|
||||||
|
icon: Assets.assetsLightCountdown,
|
||||||
|
operationName: 'Light CountDown',
|
||||||
|
code: 'countdown_1',
|
||||||
|
functionValue: functionValue,
|
||||||
|
operationDialogType: OperationDialogType.countdown,
|
||||||
|
operationalValues: [
|
||||||
|
SceneOperationalValue(icon: '', value: 0),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
static List<SceneStaticFunction> oneGangAutomationFunctions(
|
||||||
|
String deviceId, String deviceName, functionValue) {
|
||||||
|
return [
|
||||||
|
SceneStaticFunction(
|
||||||
|
deviceId: deviceId,
|
||||||
|
deviceName: deviceName,
|
||||||
|
icon: Assets.assetsAcPower,
|
||||||
|
operationName: 'Light Switch',
|
||||||
|
code: 'switch_1',
|
||||||
|
functionValue: functionValue,
|
||||||
|
operationDialogType: OperationDialogType.onOff,
|
||||||
|
operationalValues: [
|
||||||
|
SceneOperationalValue(
|
||||||
|
icon: Assets.assetsAcPower, description: "ON", value: true),
|
||||||
|
SceneOperationalValue(
|
||||||
|
icon: Assets.assetsAcPowerOFF, description: "OFF", value: false),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
SceneStaticFunction(
|
||||||
|
deviceId: deviceId,
|
||||||
|
deviceName: deviceName,
|
||||||
|
icon: Assets.assetsLightCountdown,
|
||||||
|
operationName: 'Light CountDown',
|
||||||
|
code: 'countdown_1',
|
||||||
|
functionValue: functionValue,
|
||||||
|
operationDialogType: OperationDialogType.integerSteps,
|
||||||
|
operationalValues: [
|
||||||
|
SceneOperationalValue(
|
||||||
|
icon: '',
|
||||||
|
description: "sec",
|
||||||
|
value: 0.0,
|
||||||
|
minValue: 0,
|
||||||
|
maxValue: 43200,
|
||||||
|
stepValue: 1,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@ -10,7 +10,7 @@ class ThreeGangHelperFunctions {
|
|||||||
deviceId: deviceId,
|
deviceId: deviceId,
|
||||||
deviceName: deviceName,
|
deviceName: deviceName,
|
||||||
icon: Assets.assetsAcPower,
|
icon: Assets.assetsAcPower,
|
||||||
operationName: 'Light 1 Switch',
|
operationName: 'L - Light Switch',
|
||||||
code: 'switch_1',
|
code: 'switch_1',
|
||||||
functionValue: functionValue,
|
functionValue: functionValue,
|
||||||
operationDialogType: OperationDialogType.onOff,
|
operationDialogType: OperationDialogType.onOff,
|
||||||
@ -21,11 +21,23 @@ class ThreeGangHelperFunctions {
|
|||||||
icon: Assets.assetsAcPowerOFF, description: "OFF", value: false),
|
icon: Assets.assetsAcPowerOFF, description: "OFF", value: false),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
SceneStaticFunction(
|
||||||
|
deviceId: deviceId,
|
||||||
|
deviceName: deviceName,
|
||||||
|
icon: Assets.assetsLightCountdown,
|
||||||
|
operationName: 'L - Light Countdown',
|
||||||
|
code: 'countdown_1',
|
||||||
|
functionValue: functionValue,
|
||||||
|
operationDialogType: OperationDialogType.countdown,
|
||||||
|
operationalValues: [
|
||||||
|
SceneOperationalValue(icon: '', value: 0),
|
||||||
|
],
|
||||||
|
),
|
||||||
SceneStaticFunction(
|
SceneStaticFunction(
|
||||||
deviceId: deviceId,
|
deviceId: deviceId,
|
||||||
deviceName: deviceName,
|
deviceName: deviceName,
|
||||||
icon: Assets.assetsAcPower,
|
icon: Assets.assetsAcPower,
|
||||||
operationName: 'Light 2 Switch',
|
operationName: 'M - Light Switch',
|
||||||
code: 'switch_2',
|
code: 'switch_2',
|
||||||
functionValue: functionValue,
|
functionValue: functionValue,
|
||||||
operationDialogType: OperationDialogType.onOff,
|
operationDialogType: OperationDialogType.onOff,
|
||||||
@ -36,11 +48,23 @@ class ThreeGangHelperFunctions {
|
|||||||
icon: Assets.assetsAcPowerOFF, description: "OFF", value: false),
|
icon: Assets.assetsAcPowerOFF, description: "OFF", value: false),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
SceneStaticFunction(
|
||||||
|
deviceId: deviceId,
|
||||||
|
deviceName: deviceName,
|
||||||
|
icon: Assets.assetsLightCountdown,
|
||||||
|
operationName: 'M - Light Countdown',
|
||||||
|
code: 'countdown_2',
|
||||||
|
functionValue: functionValue,
|
||||||
|
operationDialogType: OperationDialogType.countdown,
|
||||||
|
operationalValues: [
|
||||||
|
SceneOperationalValue(icon: '', value: 0),
|
||||||
|
],
|
||||||
|
),
|
||||||
SceneStaticFunction(
|
SceneStaticFunction(
|
||||||
deviceId: deviceId,
|
deviceId: deviceId,
|
||||||
deviceName: deviceName,
|
deviceName: deviceName,
|
||||||
icon: Assets.assetsAcPower,
|
icon: Assets.assetsAcPower,
|
||||||
operationName: 'Light 3 Switch',
|
operationName: 'R - Light Switch',
|
||||||
code: 'switch_3',
|
code: 'switch_3',
|
||||||
functionValue: functionValue,
|
functionValue: functionValue,
|
||||||
operationDialogType: OperationDialogType.onOff,
|
operationDialogType: OperationDialogType.onOff,
|
||||||
@ -55,31 +79,7 @@ class ThreeGangHelperFunctions {
|
|||||||
deviceId: deviceId,
|
deviceId: deviceId,
|
||||||
deviceName: deviceName,
|
deviceName: deviceName,
|
||||||
icon: Assets.assetsLightCountdown,
|
icon: Assets.assetsLightCountdown,
|
||||||
operationName: 'Light 1 CountDown',
|
operationName: 'R - Light Countdown',
|
||||||
code: 'countdown_1',
|
|
||||||
functionValue: functionValue,
|
|
||||||
operationDialogType: OperationDialogType.countdown,
|
|
||||||
operationalValues: [
|
|
||||||
SceneOperationalValue(icon: '', value: 0),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
SceneStaticFunction(
|
|
||||||
deviceId: deviceId,
|
|
||||||
deviceName: deviceName,
|
|
||||||
icon: Assets.assetsLightCountdown,
|
|
||||||
operationName: 'Light 2 CountDown',
|
|
||||||
code: 'countdown_2',
|
|
||||||
functionValue: functionValue,
|
|
||||||
operationDialogType: OperationDialogType.countdown,
|
|
||||||
operationalValues: [
|
|
||||||
SceneOperationalValue(icon: '', value: 0),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
SceneStaticFunction(
|
|
||||||
deviceId: deviceId,
|
|
||||||
deviceName: deviceName,
|
|
||||||
icon: Assets.assetsLightCountdown,
|
|
||||||
operationName: 'Light 3 CountDown',
|
|
||||||
code: 'countdown_3',
|
code: 'countdown_3',
|
||||||
functionValue: functionValue,
|
functionValue: functionValue,
|
||||||
operationDialogType: OperationDialogType.countdown,
|
operationDialogType: OperationDialogType.countdown,
|
||||||
@ -97,7 +97,7 @@ class ThreeGangHelperFunctions {
|
|||||||
deviceId: deviceId,
|
deviceId: deviceId,
|
||||||
deviceName: deviceName,
|
deviceName: deviceName,
|
||||||
icon: Assets.assetsAcPower,
|
icon: Assets.assetsAcPower,
|
||||||
operationName: 'Light 1 Switch',
|
operationName: 'L - Light Switch',
|
||||||
code: 'switch_1',
|
code: 'switch_1',
|
||||||
functionValue: functionValue,
|
functionValue: functionValue,
|
||||||
operationDialogType: OperationDialogType.onOff,
|
operationDialogType: OperationDialogType.onOff,
|
||||||
@ -108,41 +108,11 @@ class ThreeGangHelperFunctions {
|
|||||||
icon: Assets.assetsAcPowerOFF, description: "OFF", value: false),
|
icon: Assets.assetsAcPowerOFF, description: "OFF", value: false),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
SceneStaticFunction(
|
|
||||||
deviceId: deviceId,
|
|
||||||
deviceName: deviceName,
|
|
||||||
icon: Assets.assetsAcPower,
|
|
||||||
operationName: 'Light 2 Switch',
|
|
||||||
code: 'switch_2',
|
|
||||||
functionValue: functionValue,
|
|
||||||
operationDialogType: OperationDialogType.onOff,
|
|
||||||
operationalValues: [
|
|
||||||
SceneOperationalValue(
|
|
||||||
icon: Assets.assetsAcPower, description: "ON", value: true),
|
|
||||||
SceneOperationalValue(
|
|
||||||
icon: Assets.assetsAcPowerOFF, description: "OFF", value: false),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
SceneStaticFunction(
|
|
||||||
deviceId: deviceId,
|
|
||||||
deviceName: deviceName,
|
|
||||||
icon: Assets.assetsAcPower,
|
|
||||||
operationName: 'Light 3 Switch',
|
|
||||||
code: 'switch_3',
|
|
||||||
functionValue: functionValue,
|
|
||||||
operationDialogType: OperationDialogType.onOff,
|
|
||||||
operationalValues: [
|
|
||||||
SceneOperationalValue(
|
|
||||||
icon: Assets.assetsAcPower, description: "ON", value: true),
|
|
||||||
SceneOperationalValue(
|
|
||||||
icon: Assets.assetsAcPowerOFF, description: "OFF", value: false),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
SceneStaticFunction(
|
SceneStaticFunction(
|
||||||
deviceId: deviceId,
|
deviceId: deviceId,
|
||||||
deviceName: deviceName,
|
deviceName: deviceName,
|
||||||
icon: Assets.assetsLightCountdown,
|
icon: Assets.assetsLightCountdown,
|
||||||
operationName: 'Light 1 CountDown',
|
operationName: 'L - Light Countdown',
|
||||||
code: 'countdown_1',
|
code: 'countdown_1',
|
||||||
functionValue: functionValue,
|
functionValue: functionValue,
|
||||||
operationDialogType: OperationDialogType.integerSteps,
|
operationDialogType: OperationDialogType.integerSteps,
|
||||||
@ -157,11 +127,26 @@ class ThreeGangHelperFunctions {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
SceneStaticFunction(
|
||||||
|
deviceId: deviceId,
|
||||||
|
deviceName: deviceName,
|
||||||
|
icon: Assets.assetsAcPower,
|
||||||
|
operationName: 'M - Light Switch',
|
||||||
|
code: 'switch_2',
|
||||||
|
functionValue: functionValue,
|
||||||
|
operationDialogType: OperationDialogType.onOff,
|
||||||
|
operationalValues: [
|
||||||
|
SceneOperationalValue(
|
||||||
|
icon: Assets.assetsAcPower, description: "ON", value: true),
|
||||||
|
SceneOperationalValue(
|
||||||
|
icon: Assets.assetsAcPowerOFF, description: "OFF", value: false),
|
||||||
|
],
|
||||||
|
),
|
||||||
SceneStaticFunction(
|
SceneStaticFunction(
|
||||||
deviceId: deviceId,
|
deviceId: deviceId,
|
||||||
deviceName: deviceName,
|
deviceName: deviceName,
|
||||||
icon: Assets.assetsLightCountdown,
|
icon: Assets.assetsLightCountdown,
|
||||||
operationName: 'Light 2 CountDown',
|
operationName: 'M - Light Countdown',
|
||||||
code: 'countdown_2',
|
code: 'countdown_2',
|
||||||
functionValue: functionValue,
|
functionValue: functionValue,
|
||||||
operationDialogType: OperationDialogType.integerSteps,
|
operationDialogType: OperationDialogType.integerSteps,
|
||||||
@ -176,11 +161,26 @@ class ThreeGangHelperFunctions {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
SceneStaticFunction(
|
||||||
|
deviceId: deviceId,
|
||||||
|
deviceName: deviceName,
|
||||||
|
icon: Assets.assetsAcPower,
|
||||||
|
operationName: 'R - Light Switch',
|
||||||
|
code: 'switch_3',
|
||||||
|
functionValue: functionValue,
|
||||||
|
operationDialogType: OperationDialogType.onOff,
|
||||||
|
operationalValues: [
|
||||||
|
SceneOperationalValue(
|
||||||
|
icon: Assets.assetsAcPower, description: "ON", value: true),
|
||||||
|
SceneOperationalValue(
|
||||||
|
icon: Assets.assetsAcPowerOFF, description: "OFF", value: false),
|
||||||
|
],
|
||||||
|
),
|
||||||
SceneStaticFunction(
|
SceneStaticFunction(
|
||||||
deviceId: deviceId,
|
deviceId: deviceId,
|
||||||
deviceName: deviceName,
|
deviceName: deviceName,
|
||||||
icon: Assets.assetsLightCountdown,
|
icon: Assets.assetsLightCountdown,
|
||||||
operationName: 'Light 3 CountDown',
|
operationName: 'R - Light Countdown',
|
||||||
code: 'countdown_3',
|
code: 'countdown_3',
|
||||||
functionValue: functionValue,
|
functionValue: functionValue,
|
||||||
operationDialogType: OperationDialogType.integerSteps,
|
operationDialogType: OperationDialogType.integerSteps,
|
||||||
|
@ -0,0 +1,139 @@
|
|||||||
|
import 'package:syncrow_app/features/scene/enum/operation_dialog_type.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/model/scene_static_function.dart';
|
||||||
|
import 'package:syncrow_app/generated/assets.dart';
|
||||||
|
|
||||||
|
class TowGangHelperFunctions {
|
||||||
|
static List<SceneStaticFunction> towGangHelperFunctions(
|
||||||
|
String deviceId, String deviceName, functionValue) {
|
||||||
|
return [
|
||||||
|
SceneStaticFunction(
|
||||||
|
deviceId: deviceId,
|
||||||
|
deviceName: deviceName,
|
||||||
|
icon: Assets.assetsAcPower,
|
||||||
|
operationName: 'L - Light Switch',
|
||||||
|
code: 'switch_1',
|
||||||
|
functionValue: functionValue,
|
||||||
|
operationDialogType: OperationDialogType.onOff,
|
||||||
|
operationalValues: [
|
||||||
|
SceneOperationalValue(
|
||||||
|
icon: Assets.assetsAcPower, description: "ON", value: true),
|
||||||
|
SceneOperationalValue(
|
||||||
|
icon: Assets.assetsAcPowerOFF, description: "OFF", value: false),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
SceneStaticFunction(
|
||||||
|
deviceId: deviceId,
|
||||||
|
deviceName: deviceName,
|
||||||
|
icon: Assets.assetsLightCountdown,
|
||||||
|
operationName: 'L - Light CountDown',
|
||||||
|
code: 'countdown_1',
|
||||||
|
functionValue: functionValue,
|
||||||
|
operationDialogType: OperationDialogType.countdown,
|
||||||
|
operationalValues: [
|
||||||
|
SceneOperationalValue(icon: '', value: 0),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
SceneStaticFunction(
|
||||||
|
deviceId: deviceId,
|
||||||
|
deviceName: deviceName,
|
||||||
|
icon: Assets.assetsAcPower,
|
||||||
|
operationName: 'R - Light Switch',
|
||||||
|
code: 'switch_2',
|
||||||
|
functionValue: functionValue,
|
||||||
|
operationDialogType: OperationDialogType.onOff,
|
||||||
|
operationalValues: [
|
||||||
|
SceneOperationalValue(
|
||||||
|
icon: Assets.assetsAcPower, description: "ON", value: true),
|
||||||
|
SceneOperationalValue(
|
||||||
|
icon: Assets.assetsAcPowerOFF, description: "OFF", value: false),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
SceneStaticFunction(
|
||||||
|
deviceId: deviceId,
|
||||||
|
deviceName: deviceName,
|
||||||
|
icon: Assets.assetsLightCountdown,
|
||||||
|
operationName: 'R - Light CountDown',
|
||||||
|
code: 'countdown_2',
|
||||||
|
functionValue: functionValue,
|
||||||
|
operationDialogType: OperationDialogType.countdown,
|
||||||
|
operationalValues: [
|
||||||
|
SceneOperationalValue(icon: '', value: 0),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
static List<SceneStaticFunction> towGangAutomationFunctions(
|
||||||
|
String deviceId, String deviceName, functionValue) {
|
||||||
|
return [
|
||||||
|
SceneStaticFunction(
|
||||||
|
deviceId: deviceId,
|
||||||
|
deviceName: deviceName,
|
||||||
|
icon: Assets.assetsAcPower,
|
||||||
|
operationName: 'L - Light Switch',
|
||||||
|
code: 'switch_1',
|
||||||
|
functionValue: functionValue,
|
||||||
|
operationDialogType: OperationDialogType.onOff,
|
||||||
|
operationalValues: [
|
||||||
|
SceneOperationalValue(
|
||||||
|
icon: Assets.assetsAcPower, description: "ON", value: true),
|
||||||
|
SceneOperationalValue(
|
||||||
|
icon: Assets.assetsAcPowerOFF, description: "OFF", value: false),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
SceneStaticFunction(
|
||||||
|
deviceId: deviceId,
|
||||||
|
deviceName: deviceName,
|
||||||
|
icon: Assets.assetsLightCountdown,
|
||||||
|
operationName: 'R - Light CountDown',
|
||||||
|
code: 'countdown_1',
|
||||||
|
functionValue: functionValue,
|
||||||
|
operationDialogType: OperationDialogType.integerSteps,
|
||||||
|
operationalValues: [
|
||||||
|
SceneOperationalValue(
|
||||||
|
icon: '',
|
||||||
|
description: "sec",
|
||||||
|
value: 0.0,
|
||||||
|
minValue: 0,
|
||||||
|
maxValue: 43200,
|
||||||
|
stepValue: 1,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
SceneStaticFunction(
|
||||||
|
deviceId: deviceId,
|
||||||
|
deviceName: deviceName,
|
||||||
|
icon: Assets.assetsAcPower,
|
||||||
|
operationName: 'R - Light Switch',
|
||||||
|
code: 'switch_2',
|
||||||
|
functionValue: functionValue,
|
||||||
|
operationDialogType: OperationDialogType.onOff,
|
||||||
|
operationalValues: [
|
||||||
|
SceneOperationalValue(
|
||||||
|
icon: Assets.assetsAcPower, description: "ON", value: true),
|
||||||
|
SceneOperationalValue(
|
||||||
|
icon: Assets.assetsAcPowerOFF, description: "OFF", value: false),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
SceneStaticFunction(
|
||||||
|
deviceId: deviceId,
|
||||||
|
deviceName: deviceName,
|
||||||
|
icon: Assets.assetsLightCountdown,
|
||||||
|
operationName: 'R - Light CountDown',
|
||||||
|
code: 'countdown_2',
|
||||||
|
functionValue: functionValue,
|
||||||
|
operationDialogType: OperationDialogType.integerSteps,
|
||||||
|
operationalValues: [
|
||||||
|
SceneOperationalValue(
|
||||||
|
icon: '',
|
||||||
|
description: "sec",
|
||||||
|
value: 0.0,
|
||||||
|
minValue: 0,
|
||||||
|
maxValue: 43200,
|
||||||
|
stepValue: 1,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
48
lib/features/scene/helper/scene_bloc_factory.dart
Normal file
48
lib/features/scene/helper/scene_bloc_factory.dart
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||||
|
import 'package:syncrow_app/features/app_layout/model/community_model.dart';
|
||||||
|
import 'package:syncrow_app/features/app_layout/model/space_model.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_bloc.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_event.dart';
|
||||||
|
|
||||||
|
abstract final class SceneBlocFactory {
|
||||||
|
static SceneBloc create({
|
||||||
|
required bool pageType,
|
||||||
|
required HomeCubit homeCubit,
|
||||||
|
}) {
|
||||||
|
final selectedSpace = homeCubit.selectedSpace;
|
||||||
|
final defaultSpace = SpaceModel(
|
||||||
|
id: '-1',
|
||||||
|
name: '',
|
||||||
|
community: Community(
|
||||||
|
uuid: '-1',
|
||||||
|
name: '',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
final spaceId = selectedSpace?.id ?? defaultSpace.id;
|
||||||
|
final space = selectedSpace ?? defaultSpace;
|
||||||
|
final communityUuid =
|
||||||
|
selectedSpace?.community.uuid ?? defaultSpace.community.uuid;
|
||||||
|
|
||||||
|
final sceneBloc = SceneBloc();
|
||||||
|
|
||||||
|
sceneBloc.add(
|
||||||
|
LoadScenes(
|
||||||
|
spaceId,
|
||||||
|
space,
|
||||||
|
showInDevice: pageType,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!pageType) {
|
||||||
|
sceneBloc.add(
|
||||||
|
LoadAutomation(
|
||||||
|
spaceId,
|
||||||
|
communityUuid,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sceneBloc;
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
@ -74,6 +74,9 @@ class Action {
|
|||||||
ExecutorProperty? executorProperty;
|
ExecutorProperty? executorProperty;
|
||||||
String? name;
|
String? name;
|
||||||
String? type;
|
String? type;
|
||||||
|
final String productType;
|
||||||
|
|
||||||
|
final String deviceName;
|
||||||
|
|
||||||
Action({
|
Action({
|
||||||
required this.actionExecutor,
|
required this.actionExecutor,
|
||||||
@ -81,6 +84,8 @@ class Action {
|
|||||||
this.executorProperty,
|
this.executorProperty,
|
||||||
this.name,
|
this.name,
|
||||||
this.type,
|
this.type,
|
||||||
|
required this.productType,
|
||||||
|
required this.deviceName,
|
||||||
});
|
});
|
||||||
|
|
||||||
String toRawJson() => json.encode(toJson());
|
String toRawJson() => json.encode(toJson());
|
||||||
@ -88,10 +93,12 @@ class Action {
|
|||||||
static Action? fromJson(Map<String, dynamic> json) {
|
static Action? fromJson(Map<String, dynamic> json) {
|
||||||
if (json['name'] != null && json['type'] != null) {
|
if (json['name'] != null && json['type'] != null) {
|
||||||
return Action(
|
return Action(
|
||||||
actionExecutor: json["actionExecutor"],
|
actionExecutor: json["actionExecutor"] as String,
|
||||||
entityId: json["entityId"],
|
entityId: json["entityId"] as String,
|
||||||
name: json['name'],
|
name: json['name'] as String?,
|
||||||
type: json['type'],
|
type: json['type'] as String?,
|
||||||
|
productType: json['productType'] as String,
|
||||||
|
deviceName: json['deviceName'] as String,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (json["executorProperty"] == null) {
|
if (json["executorProperty"] == null) {
|
||||||
@ -99,9 +106,11 @@ class Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return Action(
|
return Action(
|
||||||
actionExecutor: json["actionExecutor"],
|
actionExecutor: json["actionExecutor"] as String,
|
||||||
entityId: json["entityId"],
|
entityId: json["entityId"] as String,
|
||||||
executorProperty: ExecutorProperty.fromJson(json["executorProperty"]),
|
executorProperty: ExecutorProperty.fromJson(json["executorProperty"]),
|
||||||
|
productType: json['productType'] as String,
|
||||||
|
deviceName: json['deviceName'] as String,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,12 +151,16 @@ class Condition {
|
|||||||
final String entityId;
|
final String entityId;
|
||||||
final String entityType;
|
final String entityType;
|
||||||
final Expr expr;
|
final Expr expr;
|
||||||
|
final String productType;
|
||||||
|
final String deviceName;
|
||||||
|
|
||||||
Condition({
|
Condition({
|
||||||
required this.code,
|
required this.code,
|
||||||
required this.entityId,
|
required this.entityId,
|
||||||
required this.entityType,
|
required this.entityType,
|
||||||
required this.expr,
|
required this.expr,
|
||||||
|
required this.productType,
|
||||||
|
required this.deviceName,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory Condition.fromRawJson(String str) =>
|
factory Condition.fromRawJson(String str) =>
|
||||||
@ -160,6 +173,8 @@ class Condition {
|
|||||||
entityId: json["entityId"],
|
entityId: json["entityId"],
|
||||||
entityType: json["entityType"],
|
entityType: json["entityType"],
|
||||||
expr: Expr.fromJson(json["expr"]),
|
expr: Expr.fromJson(json["expr"]),
|
||||||
|
productType: json['productType'] as String,
|
||||||
|
deviceName: json['deviceName'] as String,
|
||||||
);
|
);
|
||||||
|
|
||||||
Map<String, dynamic> toJson() => {
|
Map<String, dynamic> toJson() => {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:flutter_svg/svg.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||||
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart';
|
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart';
|
||||||
@ -11,11 +12,10 @@ import 'package:syncrow_app/features/scene/widgets/scene_list_tile.dart';
|
|||||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||||
import 'package:syncrow_app/features/shared_widgets/default_scaffold.dart';
|
import 'package:syncrow_app/features/shared_widgets/default_scaffold.dart';
|
||||||
import 'package:syncrow_app/features/shared_widgets/light_divider.dart';
|
import 'package:syncrow_app/features/shared_widgets/light_divider.dart';
|
||||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
import 'package:syncrow_app/generated/assets.dart';
|
||||||
import 'package:syncrow_app/navigation/navigate_to_route.dart';
|
import 'package:syncrow_app/navigation/navigate_to_route.dart';
|
||||||
import 'package:syncrow_app/navigation/routing_constants.dart';
|
import 'package:syncrow_app/navigation/routing_constants.dart';
|
||||||
import 'package:syncrow_app/utils/context_extension.dart';
|
import 'package:syncrow_app/utils/context_extension.dart';
|
||||||
|
|
||||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||||
|
|
||||||
class DeviceFunctionsView extends StatelessWidget
|
class DeviceFunctionsView extends StatelessWidget
|
||||||
@ -51,22 +51,14 @@ class DeviceFunctionsView extends StatelessWidget
|
|||||||
.add(AddTaskEvent(isAutomation: isAutomation));
|
.add(AddTaskEvent(isAutomation: isAutomation));
|
||||||
navigateToRoute(context, Routes.sceneTasksRoute);
|
navigateToRoute(context, Routes.sceneTasksRoute);
|
||||||
},
|
},
|
||||||
child: BodyMedium(
|
child: SvgPicture.asset(Assets.saveRoutinesIcon),
|
||||||
text: 'Save',
|
|
||||||
fontWeight: FontWeight.normal,
|
|
||||||
fontColor: ColorsManager.secondaryColor.withOpacity(0.6),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
leading: TextButton(
|
leading: TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
_cancelOperation(context, device, isAutomation);
|
_cancelOperation(context, device, isAutomation);
|
||||||
},
|
},
|
||||||
child: BodyMedium(
|
child: SvgPicture.asset(Assets.cancelIcon),
|
||||||
text: 'Cancel',
|
|
||||||
fontWeight: FontWeight.normal,
|
|
||||||
fontColor: ColorsManager.textPrimaryColor.withOpacity(0.6),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
leadingWidth: 80,
|
leadingWidth: 80,
|
||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
@ -75,66 +67,127 @@ class DeviceFunctionsView extends StatelessWidget
|
|||||||
itemCount: functions.length,
|
itemCount: functions.length,
|
||||||
padding: const EdgeInsets.only(top: 24.0),
|
padding: const EdgeInsets.only(top: 24.0),
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
return DefaultContainer(
|
if (device.productType!.name.toString() == 'ThreeGang' ||
|
||||||
padding: index == 0
|
device.productType!.name.toString() == 'TwoGang') {
|
||||||
? const EdgeInsets.only(top: 8)
|
final bool isFirstInPair = index % 2 == 0;
|
||||||
: index == functions.length - 1
|
final bool isLastInPair =
|
||||||
? const EdgeInsets.only(bottom: 8)
|
index % 2 == 1 || index == functions.length - 1;
|
||||||
: EdgeInsets.zero,
|
final bool isLastItem = index == functions.length - 1;
|
||||||
margin: EdgeInsets.zero,
|
return Column(mainAxisSize: MainAxisSize.min, children: [
|
||||||
borderRadius: index == 0
|
if (isFirstInPair && index != 0) const SizedBox(height: 16),
|
||||||
? const BorderRadius.only(
|
DefaultContainer(
|
||||||
topLeft: Radius.circular(20), topRight: Radius.circular(20))
|
padding: EdgeInsets.only(
|
||||||
: index == functions.length - 1
|
top: isFirstInPair ? 8 : 0,
|
||||||
? const BorderRadius.only(
|
bottom: isLastInPair ? 8 : 0,
|
||||||
bottomLeft: Radius.circular(20),
|
),
|
||||||
bottomRight: Radius.circular(20))
|
margin: EdgeInsets.zero,
|
||||||
: BorderRadius.zero,
|
borderRadius: BorderRadius.only(
|
||||||
child: Column(
|
topLeft: Radius.circular(isFirstInPair ? 20 : 0),
|
||||||
mainAxisSize: MainAxisSize.min,
|
topRight: Radius.circular(isFirstInPair ? 20 : 0),
|
||||||
children: [
|
bottomLeft: Radius.circular(isLastInPair ? 20 : 0),
|
||||||
BlocBuilder<CreateSceneBloc, CreateSceneState>(
|
bottomRight: Radius.circular(isLastInPair ? 20 : 0),
|
||||||
builder: (context, state) {
|
),
|
||||||
return SceneListTile(
|
child: Column(
|
||||||
iconsSize: 22,
|
mainAxisSize: MainAxisSize.min,
|
||||||
minLeadingWidth: 20,
|
children: [
|
||||||
assetPath: functions[index].icon,
|
BlocBuilder<CreateSceneBloc, CreateSceneState>(
|
||||||
titleString: functions[index].operationName,
|
builder: (context, state) {
|
||||||
trailingWidget: const Row(
|
return SceneListTile(
|
||||||
mainAxisSize: MainAxisSize.min,
|
iconsSize: 22,
|
||||||
children: [
|
minLeadingWidth: 20,
|
||||||
Icon(
|
assetPath: functions[index].icon,
|
||||||
|
titleString: functions[index].operationName,
|
||||||
|
trailingWidget: const Icon(
|
||||||
Icons.arrow_forward_ios_rounded,
|
Icons.arrow_forward_ios_rounded,
|
||||||
color: ColorsManager.greyColor,
|
color: ColorsManager.greyColor,
|
||||||
size: 16,
|
size: 16,
|
||||||
),
|
),
|
||||||
],
|
onPressed: () {
|
||||||
),
|
if (isAutomation) {
|
||||||
onPressed: () {
|
_showAutomationDialog(
|
||||||
if (isAutomation) {
|
context, functions[index], device);
|
||||||
_showAutomationDialog(
|
} else {
|
||||||
context,
|
_showTabToRunDialog(
|
||||||
functions[index],
|
context, functions[index], device);
|
||||||
device,
|
}
|
||||||
);
|
},
|
||||||
} else {
|
);
|
||||||
_showTabToRunDialog(
|
|
||||||
context,
|
|
||||||
functions[index],
|
|
||||||
device,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
);
|
),
|
||||||
},
|
if (isFirstInPair && !isLastItem)
|
||||||
|
SizedBox(
|
||||||
|
width: context.width * 0.8,
|
||||||
|
child: const LightDivider(),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
index != functions.length - 1
|
)
|
||||||
? SizedBox(
|
]);
|
||||||
width: context.width * 0.8, child: const LightDivider())
|
} else {
|
||||||
: const SizedBox(),
|
return DefaultContainer(
|
||||||
],
|
padding: index == 0
|
||||||
),
|
? const EdgeInsets.only(top: 8)
|
||||||
);
|
: index == functions.length - 1
|
||||||
|
? const EdgeInsets.only(bottom: 8)
|
||||||
|
: EdgeInsets.zero,
|
||||||
|
margin: EdgeInsets.zero,
|
||||||
|
borderRadius: index == 0 && index == functions.length - 1
|
||||||
|
? const BorderRadius.only(
|
||||||
|
topLeft: Radius.circular(20),
|
||||||
|
topRight: Radius.circular(20),
|
||||||
|
bottomLeft: Radius.circular(20),
|
||||||
|
bottomRight: Radius.circular(20),
|
||||||
|
)
|
||||||
|
: index == 0
|
||||||
|
? const BorderRadius.only(
|
||||||
|
topLeft: Radius.circular(20),
|
||||||
|
topRight: Radius.circular(20),
|
||||||
|
)
|
||||||
|
: index == functions.length - 1
|
||||||
|
? const BorderRadius.only(
|
||||||
|
bottomLeft: Radius.circular(20),
|
||||||
|
bottomRight: Radius.circular(20),
|
||||||
|
)
|
||||||
|
: BorderRadius.zero,
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
BlocBuilder<CreateSceneBloc, CreateSceneState>(
|
||||||
|
builder: (context, state) {
|
||||||
|
return SceneListTile(
|
||||||
|
iconsSize: 22,
|
||||||
|
minLeadingWidth: 20,
|
||||||
|
assetPath: functions[index].icon,
|
||||||
|
titleString: functions[index].operationName,
|
||||||
|
trailingWidget: const Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
Icons.arrow_forward_ios_rounded,
|
||||||
|
color: ColorsManager.greyColor,
|
||||||
|
size: 16,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
if (isAutomation) {
|
||||||
|
_showAutomationDialog(
|
||||||
|
context, functions[index], device);
|
||||||
|
} else {
|
||||||
|
_showTabToRunDialog(
|
||||||
|
context, functions[index], device);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
index != functions.length - 1
|
||||||
|
? SizedBox(
|
||||||
|
width: context.width * 0.8,
|
||||||
|
child: const LightDivider())
|
||||||
|
: const SizedBox(),
|
||||||
|
],
|
||||||
|
));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
117
lib/features/scene/view/routines_view.dart
Normal file
117
lib/features/scene/view/routines_view.dart
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||||
|
import 'package:syncrow_app/features/app_layout/model/space_model.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_bloc.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_event.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/bloc/smart_scene/smart_scene_select_dart_bloc.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/helper/scene_bloc_factory.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/widgets/empty_routines_widget.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/widgets/routines_expansion_tile.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/widgets/scene_view_widget/scene_header.dart';
|
||||||
|
import 'package:syncrow_app/features/shared_widgets/app_loading_indicator.dart';
|
||||||
|
import 'package:syncrow_app/utils/context_extension.dart';
|
||||||
|
|
||||||
|
class RoutinesView extends StatelessWidget {
|
||||||
|
const RoutinesView({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return BlocProvider(
|
||||||
|
create: (context) => SceneBlocFactory.create(
|
||||||
|
pageType: false,
|
||||||
|
homeCubit: HomeCubit.getInstance(),
|
||||||
|
),
|
||||||
|
child: BlocBuilder<CreateSceneBloc, CreateSceneState>(
|
||||||
|
builder: (context, state) {
|
||||||
|
final selectedSpace = HomeCubit.getInstance().selectedSpace;
|
||||||
|
if (state is DeleteSceneSuccess) {
|
||||||
|
if (state.success) _loadScenesAndAutomations(context, selectedSpace);
|
||||||
|
}
|
||||||
|
if (state is CreateSceneWithTasks) {
|
||||||
|
if (state.success) {
|
||||||
|
_loadScenesAndAutomations(context, selectedSpace);
|
||||||
|
context.read<SmartSceneSelectBloc>().add(const SmartSceneClearEvent());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return BlocListener<SceneBloc, SceneState>(
|
||||||
|
listener: (context, state) {
|
||||||
|
if (state is SceneTriggerSuccess) {
|
||||||
|
context.showCustomSnackbar(
|
||||||
|
message: 'Scene ${state.sceneName} triggered successfully!',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
const SceneHeader(),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Expanded(
|
||||||
|
child: BlocBuilder<SceneBloc, SceneState>(
|
||||||
|
builder: (context, state) {
|
||||||
|
if (state is SceneLoading) {
|
||||||
|
return const AppLoadingIndicator();
|
||||||
|
}
|
||||||
|
if (state is SceneError) {
|
||||||
|
return Center(
|
||||||
|
child: Text(state.message),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (state is SceneLoaded) {
|
||||||
|
final scenes = state.scenes;
|
||||||
|
final automationList = state.automationList;
|
||||||
|
final routinesIsEmpty =
|
||||||
|
scenes.isEmpty && automationList.isEmpty;
|
||||||
|
|
||||||
|
if (routinesIsEmpty) return const EmptyRoutinesWidget();
|
||||||
|
|
||||||
|
return Theme(
|
||||||
|
data: Theme.of(context).copyWith(
|
||||||
|
dividerColor: Colors.transparent,
|
||||||
|
),
|
||||||
|
child: Expanded(
|
||||||
|
child: ListView(
|
||||||
|
children: [
|
||||||
|
RoutinesExpansionTile(
|
||||||
|
title: 'Tap to run routines',
|
||||||
|
emptyRoutinesMessage:
|
||||||
|
'No scenes have been added yet',
|
||||||
|
routines: state.scenes,
|
||||||
|
loadingStates: state.loadingStates,
|
||||||
|
loadingSceneId: state.loadingSceneId,
|
||||||
|
),
|
||||||
|
RoutinesExpansionTile(
|
||||||
|
title: 'Automation',
|
||||||
|
emptyRoutinesMessage:
|
||||||
|
'No automations have been added yet',
|
||||||
|
routines: state.automationList,
|
||||||
|
loadingStates: state.loadingStates,
|
||||||
|
loadingSceneId: state.loadingSceneId,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 15),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return const SizedBox.shrink();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _loadScenesAndAutomations(BuildContext context, SpaceModel? selectedSpace) {
|
||||||
|
context.read<SceneBloc>()
|
||||||
|
..add(LoadScenes(selectedSpace!.id, selectedSpace, showInDevice: false))
|
||||||
|
..add(LoadAutomation(selectedSpace.id, selectedSpace.community.uuid));
|
||||||
|
}
|
||||||
|
}
|
@ -20,69 +20,69 @@ class SceneRoomsTabBarDevicesView extends StatefulWidget {
|
|||||||
_SceneRoomsTabBarDevicesViewState();
|
_SceneRoomsTabBarDevicesViewState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _SceneRoomsTabBarDevicesViewState
|
class _SceneRoomsTabBarDevicesViewState extends State<SceneRoomsTabBarDevicesView>
|
||||||
extends State<SceneRoomsTabBarDevicesView>
|
|
||||||
with SingleTickerProviderStateMixin {
|
with SingleTickerProviderStateMixin {
|
||||||
late final TabController _tabController;
|
late final TabController _tabController;
|
||||||
List<SubSpaceModel>? rooms = [];
|
|
||||||
late final SpaceModel selectedSpace;
|
late final SpaceModel selectedSpace;
|
||||||
|
var rooms = <SubSpaceModel>[];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
selectedSpace = HomeCubit.getInstance().selectedSpace!;
|
|
||||||
rooms = List.from(HomeCubit.getInstance().selectedSpace?.subspaces ?? []);
|
|
||||||
if (rooms != null) {
|
|
||||||
if (rooms![0].id != '-1') {
|
|
||||||
rooms?.insert(
|
|
||||||
0,
|
|
||||||
SubSpaceModel(
|
|
||||||
name: 'All Devices',
|
|
||||||
devices: context.read<DevicesCubit>().allDevices,
|
|
||||||
id: '-1',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_tabController =
|
|
||||||
TabController(length: rooms!.length, vsync: this, initialIndex: 0);
|
|
||||||
_tabController.addListener(_handleTabSwitched);
|
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
|
||||||
|
|
||||||
void _handleTabSwitched() {
|
selectedSpace = HomeCubit.getInstance().selectedSpace!;
|
||||||
if (_tabController.indexIsChanging) {
|
|
||||||
final value = _tabController.index;
|
|
||||||
|
|
||||||
/// select tab
|
rooms = List.from(selectedSpace.subspaces);
|
||||||
context.read<TabBarBloc>().add(TabChanged(
|
final defaultSubSpaceModel = SubSpaceModel(
|
||||||
selectedIndex: value,
|
name: 'All Devices',
|
||||||
roomId: rooms?[value].id ?? '',
|
devices: context.read<DevicesCubit>().allDevices,
|
||||||
unit: selectedSpace));
|
id: '-1',
|
||||||
return;
|
);
|
||||||
|
|
||||||
|
if (rooms.isNotEmpty) {
|
||||||
|
final isFirstRoomIdValid = rooms[0].id != '-1';
|
||||||
|
if (isFirstRoomIdValid) {
|
||||||
|
rooms.insert(0, defaultSubSpaceModel);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
rooms = [defaultSubSpaceModel];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_tabController = TabController(length: rooms.length, vsync: this);
|
||||||
|
_tabController.addListener(_handleTabSwitched);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
super.dispose();
|
super.dispose();
|
||||||
_tabController.dispose();
|
|
||||||
_tabController.removeListener(() {});
|
_tabController.removeListener(() {});
|
||||||
|
_tabController.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _handleTabSwitched() {
|
||||||
|
if (_tabController.indexIsChanging) {
|
||||||
|
final index = _tabController.index;
|
||||||
|
|
||||||
|
context.read<TabBarBloc>().add(
|
||||||
|
TabBarTabChangedEvent(
|
||||||
|
selectedIndex: index,
|
||||||
|
roomId: rooms[index].id ?? '',
|
||||||
|
unit: selectedSpace,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return DefaultScaffold(
|
return DefaultScaffold(
|
||||||
title: StringsManager.createScene,
|
padding: EdgeInsetsDirectional.zero,
|
||||||
padding: EdgeInsets.zero,
|
|
||||||
leading: IconButton(
|
leading: IconButton(
|
||||||
onPressed: () {
|
onPressed: () => navigateToRoute(context, Routes.sceneTasksRoute),
|
||||||
navigateToRoute(context, Routes.sceneTasksRoute);
|
icon: const Icon(Icons.arrow_back_ios),
|
||||||
},
|
|
||||||
icon: const Icon(
|
|
||||||
Icons.arrow_back_ios,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
|
title: StringsManager.createScene,
|
||||||
child: SceneDevicesBody(tabController: _tabController, rooms: rooms),
|
child: SceneDevicesBody(tabController: _tabController, rooms: rooms),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,75 +1,45 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||||
import 'package:syncrow_app/features/app_layout/model/community_model.dart';
|
|
||||||
import 'package:syncrow_app/features/app_layout/model/space_model.dart';
|
import 'package:syncrow_app/features/app_layout/model/space_model.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/scene_listview.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/scene_listview.dart';
|
||||||
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart';
|
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart';
|
||||||
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_bloc.dart';
|
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_bloc.dart';
|
||||||
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_event.dart';
|
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_event.dart';
|
||||||
import 'package:syncrow_app/features/scene/bloc/smart_scene/smart_scene_select_dart_bloc.dart';
|
import 'package:syncrow_app/features/scene/bloc/smart_scene/smart_scene_select_dart_bloc.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/helper/scene_bloc_factory.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/widgets/empty_devices_widget.dart';
|
||||||
import 'package:syncrow_app/features/scene/widgets/scene_view_widget/scene_grid_view.dart';
|
import 'package:syncrow_app/features/scene/widgets/scene_view_widget/scene_grid_view.dart';
|
||||||
import 'package:syncrow_app/features/scene/widgets/scene_view_widget/scene_header.dart';
|
import 'package:syncrow_app/features/scene/widgets/scene_view_widget/scene_header.dart';
|
||||||
import 'package:syncrow_app/features/shared_widgets/create_unit.dart';
|
import 'package:syncrow_app/features/shared_widgets/app_loading_indicator.dart';
|
||||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
||||||
import 'package:syncrow_app/utils/context_extension.dart';
|
import 'package:syncrow_app/utils/context_extension.dart';
|
||||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||||
|
|
||||||
class SceneView extends StatelessWidget {
|
class SceneView extends StatelessWidget {
|
||||||
|
const SceneView({
|
||||||
|
this.pageType = false,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
final bool pageType;
|
final bool pageType;
|
||||||
const SceneView({super.key, this.pageType = false});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
create: (BuildContext context) {
|
create: (context) => SceneBlocFactory.create(
|
||||||
if (pageType) {
|
pageType: pageType,
|
||||||
return SceneBloc()
|
homeCubit: HomeCubit.getInstance(),
|
||||||
..add(LoadScenes(
|
),
|
||||||
HomeCubit.getInstance().selectedSpace?.id ?? '',
|
|
||||||
HomeCubit.getInstance().selectedSpace ??
|
|
||||||
SpaceModel(
|
|
||||||
id: '-1',
|
|
||||||
name: '',
|
|
||||||
community: Community(
|
|
||||||
uuid: '-1',
|
|
||||||
name: '',
|
|
||||||
)),
|
|
||||||
showInDevice: pageType));
|
|
||||||
} else {
|
|
||||||
return SceneBloc()
|
|
||||||
..add(LoadScenes(
|
|
||||||
HomeCubit.getInstance().selectedSpace?.id ?? '',
|
|
||||||
HomeCubit.getInstance().selectedSpace ??
|
|
||||||
SpaceModel(
|
|
||||||
id: '-1',
|
|
||||||
name: '',
|
|
||||||
community: Community(
|
|
||||||
uuid: '-1',
|
|
||||||
name: '',
|
|
||||||
)),
|
|
||||||
showInDevice: pageType))
|
|
||||||
..add(LoadAutomation(HomeCubit.getInstance().selectedSpace?.id ?? ''));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
child: BlocBuilder<CreateSceneBloc, CreateSceneState>(
|
child: BlocBuilder<CreateSceneBloc, CreateSceneState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
|
final selectedSpace = HomeCubit.getInstance().selectedSpace;
|
||||||
if (state is DeleteSceneSuccess) {
|
if (state is DeleteSceneSuccess) {
|
||||||
if (state.success) {
|
if (state.success) _loadScenesAndAutomations(context, selectedSpace);
|
||||||
BlocProvider.of<SceneBloc>(context).add(LoadScenes(
|
|
||||||
HomeCubit.getInstance().selectedSpace!.id, HomeCubit.getInstance().selectedSpace!,
|
|
||||||
showInDevice: pageType));
|
|
||||||
BlocProvider.of<SceneBloc>(context)
|
|
||||||
.add(LoadAutomation(HomeCubit.getInstance().selectedSpace!.id));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (state is CreateSceneWithTasks) {
|
if (state is CreateSceneWithTasks) {
|
||||||
if (state.success == true) {
|
if (state.success) {
|
||||||
BlocProvider.of<SceneBloc>(context).add(LoadScenes(
|
_loadScenesAndAutomations(context, selectedSpace);
|
||||||
HomeCubit.getInstance().selectedSpace!.id, HomeCubit.getInstance().selectedSpace!,
|
|
||||||
showInDevice: pageType));
|
|
||||||
BlocProvider.of<SceneBloc>(context)
|
|
||||||
.add(LoadAutomation(HomeCubit.getInstance().selectedSpace!.id));
|
|
||||||
context.read<SmartSceneSelectBloc>().add(const SmartSceneClearEvent());
|
context.read<SmartSceneSelectBloc>().add(const SmartSceneClearEvent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -77,23 +47,24 @@ class SceneView extends StatelessWidget {
|
|||||||
listener: (context, state) {
|
listener: (context, state) {
|
||||||
if (state is SceneTriggerSuccess) {
|
if (state is SceneTriggerSuccess) {
|
||||||
context.showCustomSnackbar(
|
context.showCustomSnackbar(
|
||||||
message: 'Scene ${state.sceneName} triggered successfully!');
|
message: 'Scene ${state.sceneName} triggered successfully!',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: HomeCubit.getInstance().spaces?.isEmpty ?? true
|
child: HomeCubit.getInstance().spaces.isEmpty
|
||||||
? const CreateUnitWidget()
|
? const EmptyDevicesWidget()
|
||||||
: Column(
|
: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: [
|
children: [
|
||||||
if (pageType == false) const SceneHeader(),
|
if (!pageType) ...[
|
||||||
if (pageType == false) const SizedBox(height: 8),
|
const SceneHeader(),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
],
|
||||||
BlocBuilder<SceneBloc, SceneState>(
|
BlocBuilder<SceneBloc, SceneState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
if (state is SceneLoading) {
|
if (state is SceneLoading) {
|
||||||
return const Center(
|
return const AppLoadingIndicator();
|
||||||
child: CircularProgressIndicator(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if (state is SceneError) {
|
if (state is SceneError) {
|
||||||
return Center(
|
return Center(
|
||||||
@ -103,80 +74,83 @@ class SceneView extends StatelessWidget {
|
|||||||
if (state is SceneLoaded) {
|
if (state is SceneLoaded) {
|
||||||
final scenes = state.scenes;
|
final scenes = state.scenes;
|
||||||
final automationList = state.automationList;
|
final automationList = state.automationList;
|
||||||
|
if (scenes.isEmpty) return const EmptyDevicesWidget();
|
||||||
|
|
||||||
return pageType
|
if (pageType) {
|
||||||
? Expanded(
|
return SizedBox(
|
||||||
child: SceneListview(
|
height: context.height * 0.1,
|
||||||
scenes: scenes,
|
child: SceneListview(
|
||||||
loadingSceneId: state.loadingSceneId,
|
scenes: scenes,
|
||||||
))
|
loadingSceneId: state.loadingSceneId,
|
||||||
: Expanded(
|
),
|
||||||
child: ListView(
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Theme(
|
||||||
|
data: Theme.of(context).copyWith(
|
||||||
|
dividerColor: Colors.transparent,
|
||||||
|
),
|
||||||
|
child: Expanded(
|
||||||
|
child: ListView(
|
||||||
|
children: [
|
||||||
|
ExpansionTile(
|
||||||
|
tilePadding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 6,
|
||||||
|
),
|
||||||
|
initiallyExpanded: true,
|
||||||
|
iconColor: ColorsManager.grayColor,
|
||||||
|
title: const BodyMedium(
|
||||||
|
text: 'Tap to run routines',
|
||||||
|
),
|
||||||
children: [
|
children: [
|
||||||
Theme(
|
if (scenes.isNotEmpty)
|
||||||
data: ThemeData()
|
SceneGrid(
|
||||||
.copyWith(dividerColor: Colors.transparent),
|
scenes: scenes,
|
||||||
child: ExpansionTile(
|
loadingSceneId: state.loadingSceneId,
|
||||||
tilePadding: const EdgeInsets.symmetric(horizontal: 6),
|
disablePlayButton: false,
|
||||||
initiallyExpanded: true,
|
loadingStates: state.loadingStates,
|
||||||
iconColor: ColorsManager.grayColor,
|
)
|
||||||
title: const BodyMedium(text: 'Tap to run routines'),
|
else
|
||||||
children: [
|
const Center(
|
||||||
scenes.isNotEmpty
|
child: BodyMedium(
|
||||||
? SceneGrid(
|
text: 'No scenes have been added yet',
|
||||||
scenes: scenes,
|
),
|
||||||
loadingSceneId: state.loadingSceneId,
|
|
||||||
disablePlayButton: false,
|
|
||||||
loadingStates:
|
|
||||||
state.loadingStates, // Add this line
|
|
||||||
)
|
|
||||||
: const Center(
|
|
||||||
child: BodyMedium(
|
|
||||||
text: 'No scenes have been added yet',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(
|
|
||||||
height: 10,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
const SizedBox(height: 10),
|
||||||
Theme(
|
|
||||||
data: ThemeData()
|
|
||||||
.copyWith(dividerColor: Colors.transparent),
|
|
||||||
child: ExpansionTile(
|
|
||||||
initiallyExpanded: true,
|
|
||||||
iconColor: ColorsManager.grayColor,
|
|
||||||
tilePadding: const EdgeInsets.symmetric(horizontal: 6),
|
|
||||||
title: const BodyMedium(text: 'Automation'),
|
|
||||||
children: [
|
|
||||||
automationList.isNotEmpty
|
|
||||||
? SceneGrid(
|
|
||||||
scenes: automationList,
|
|
||||||
loadingSceneId: state.loadingSceneId,
|
|
||||||
disablePlayButton: true,
|
|
||||||
loadingStates:
|
|
||||||
state.loadingStates, // Add this line
|
|
||||||
)
|
|
||||||
: const Center(
|
|
||||||
child: BodyMedium(
|
|
||||||
text: 'No automations have been added yet',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(
|
|
||||||
height: 10,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(
|
|
||||||
height: 15,
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
ExpansionTile(
|
||||||
|
initiallyExpanded: true,
|
||||||
|
iconColor: ColorsManager.grayColor,
|
||||||
|
tilePadding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 6,
|
||||||
|
),
|
||||||
|
title: const BodyMedium(text: 'Automation'),
|
||||||
|
children: [
|
||||||
|
if (automationList.isNotEmpty)
|
||||||
|
SceneGrid(
|
||||||
|
scenes: automationList,
|
||||||
|
loadingSceneId: state.loadingSceneId,
|
||||||
|
disablePlayButton: true,
|
||||||
|
loadingStates: state.loadingStates,
|
||||||
|
)
|
||||||
|
else
|
||||||
|
const Center(
|
||||||
|
child: BodyMedium(
|
||||||
|
text:
|
||||||
|
'No automations have been added yet',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 15),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return const SizedBox();
|
return const SizedBox.shrink();
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -186,4 +160,21 @@ class SceneView extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _loadScenesAndAutomations(BuildContext context, SpaceModel? selectedSpace) {
|
||||||
|
BlocProvider.of<SceneBloc>(context)
|
||||||
|
..add(
|
||||||
|
LoadScenes(
|
||||||
|
selectedSpace!.id,
|
||||||
|
selectedSpace,
|
||||||
|
showInDevice: pageType,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
..add(
|
||||||
|
LoadAutomation(
|
||||||
|
selectedSpace.id,
|
||||||
|
selectedSpace.community.uuid,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ class DeleteRoutineButton extends StatelessWidget {
|
|||||||
BlocProvider.of<SceneBloc>(context).add(LoadScenes(
|
BlocProvider.of<SceneBloc>(context).add(LoadScenes(
|
||||||
HomeCubit.getInstance().selectedSpace!.id, HomeCubit.getInstance().selectedSpace!));
|
HomeCubit.getInstance().selectedSpace!.id, HomeCubit.getInstance().selectedSpace!));
|
||||||
BlocProvider.of<SceneBloc>(context)
|
BlocProvider.of<SceneBloc>(context)
|
||||||
.add(LoadAutomation(HomeCubit.getInstance().selectedSpace!.id));
|
.add(LoadAutomation(HomeCubit.getInstance().selectedSpace!.id,HomeCubit.getInstance().selectedSpace!.community.uuid));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
22
lib/features/scene/widgets/empty_devices_widget.dart
Normal file
22
lib/features/scene/widgets/empty_devices_widget.dart
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||||
|
|
||||||
|
class EmptyDevicesWidget extends StatelessWidget {
|
||||||
|
const EmptyDevicesWidget({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 48),
|
||||||
|
child: Text(
|
||||||
|
"No routines.\nEnable 'Show on Home Screen' to add routines",
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: TextStyle(
|
||||||
|
color: ColorsManager.grayColor,
|
||||||
|
fontWeight: FontWeight.w400,
|
||||||
|
fontSize: 12,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
34
lib/features/scene/widgets/empty_routines_widget.dart
Normal file
34
lib/features/scene/widgets/empty_routines_widget.dart
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
||||||
|
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||||
|
|
||||||
|
class EmptyRoutinesWidget extends StatelessWidget {
|
||||||
|
const EmptyRoutinesWidget({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Expanded(
|
||||||
|
child: Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
mainAxisSize: MainAxisSize.max,
|
||||||
|
spacing: 16,
|
||||||
|
children: [
|
||||||
|
SvgPicture.asset(
|
||||||
|
'assets/icons/empty_routines.svg',
|
||||||
|
colorFilter: ColorFilter.mode(
|
||||||
|
ColorsManager.textGray,
|
||||||
|
BlendMode.srcIn,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
BodyMedium(
|
||||||
|
text: 'No Routines yet',
|
||||||
|
fontColor: ColorsManager.textGray,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
53
lib/features/scene/widgets/routines_expansion_tile.dart
Normal file
53
lib/features/scene/widgets/routines_expansion_tile.dart
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/model/scenes_model.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/widgets/scene_view_widget/scene_grid_view.dart';
|
||||||
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
||||||
|
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||||
|
|
||||||
|
class RoutinesExpansionTile extends StatelessWidget {
|
||||||
|
const RoutinesExpansionTile({
|
||||||
|
super.key,
|
||||||
|
required this.title,
|
||||||
|
required this.emptyRoutinesMessage,
|
||||||
|
required this.routines,
|
||||||
|
required this.loadingStates,
|
||||||
|
this.loadingSceneId,
|
||||||
|
});
|
||||||
|
final String title;
|
||||||
|
final String emptyRoutinesMessage;
|
||||||
|
final List<ScenesModel> routines;
|
||||||
|
final Map<String, bool> loadingStates;
|
||||||
|
final String? loadingSceneId;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return ExpansionTile(
|
||||||
|
tilePadding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 6,
|
||||||
|
),
|
||||||
|
initiallyExpanded: true,
|
||||||
|
iconColor: ColorsManager.grayColor,
|
||||||
|
title: BodyMedium(
|
||||||
|
text: title,
|
||||||
|
),
|
||||||
|
childrenPadding: EdgeInsetsDirectional.only(bottom: 10),
|
||||||
|
children: [
|
||||||
|
Visibility(
|
||||||
|
visible: routines.isNotEmpty,
|
||||||
|
replacement: Center(
|
||||||
|
child: BodyMedium(
|
||||||
|
text: emptyRoutinesMessage,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: SceneGrid(
|
||||||
|
scenes: routines,
|
||||||
|
loadingSceneId: loadingSceneId,
|
||||||
|
disablePlayButton: false,
|
||||||
|
loadingStates: loadingStates,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_svg/flutter_svg.dart';
|
|
||||||
import 'package:syncrow_app/features/devices/bloc/device_manager_bloc/device_manager_bloc.dart';
|
import 'package:syncrow_app/features/devices/bloc/device_manager_bloc/device_manager_bloc.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/device_manager_bloc/device_manager_state.dart';
|
import 'package:syncrow_app/features/devices/bloc/device_manager_bloc/device_manager_state.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/subspace_model.dart';
|
import 'package:syncrow_app/features/devices/model/subspace_model.dart';
|
||||||
@ -8,60 +7,44 @@ import 'package:syncrow_app/features/scene/bloc/tab_change/tab_change_bloc.dart'
|
|||||||
import 'package:syncrow_app/features/scene/bloc/tab_change/tab_change_state.dart';
|
import 'package:syncrow_app/features/scene/bloc/tab_change/tab_change_state.dart';
|
||||||
import 'package:syncrow_app/features/scene/enum/create_scene_enum.dart';
|
import 'package:syncrow_app/features/scene/enum/create_scene_enum.dart';
|
||||||
import 'package:syncrow_app/features/scene/model/scene_settings_route_arguments.dart';
|
import 'package:syncrow_app/features/scene/model/scene_settings_route_arguments.dart';
|
||||||
import 'package:syncrow_app/features/scene/widgets/scene_list_tile.dart';
|
import 'package:syncrow_app/features/scene/widgets/scene_devices/scene_devices_body_tab_bar.dart';
|
||||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
import 'package:syncrow_app/features/scene/widgets/scene_devices/scene_devices_list.dart';
|
||||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
import 'package:syncrow_app/features/shared_widgets/app_loading_indicator.dart';
|
||||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
|
||||||
import 'package:syncrow_app/navigation/routing_constants.dart';
|
|
||||||
import 'package:syncrow_app/utils/context_extension.dart';
|
|
||||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
|
||||||
|
|
||||||
class SceneDevicesBody extends StatelessWidget {
|
class SceneDevicesBody extends StatelessWidget {
|
||||||
const SceneDevicesBody({
|
const SceneDevicesBody({
|
||||||
super.key,
|
required this.tabController,
|
||||||
required TabController tabController,
|
|
||||||
required this.rooms,
|
required this.rooms,
|
||||||
}) : _tabController = tabController;
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
final TabController _tabController;
|
final TabController tabController;
|
||||||
final List<SubSpaceModel>? rooms;
|
final List<SubSpaceModel> rooms;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final isAutomationDeviceStatus =
|
|
||||||
((ModalRoute.of(context)?.settings.arguments as SceneSettingsRouteArguments?)?.sceneType ==
|
|
||||||
CreateSceneEnum.deviceStatusChanges.name);
|
|
||||||
return BlocBuilder<TabBarBloc, TabBarState>(
|
return BlocBuilder<TabBarBloc, TabBarState>(
|
||||||
builder: (context, tabState) {
|
builder: (context, state) {
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
TabBar(
|
SceneDevicesBodyTabBar(
|
||||||
controller: _tabController,
|
tabController: tabController,
|
||||||
dividerColor: Colors.transparent,
|
rooms: rooms,
|
||||||
indicatorColor: Colors.transparent,
|
selectedRoomId: state is TabBarTabSelectedState ? state.roomId : '-1',
|
||||||
tabs: [
|
|
||||||
...rooms!.map((e) => Tab(
|
|
||||||
child: BodyLarge(
|
|
||||||
text: e.name ?? '',
|
|
||||||
textAlign: TextAlign.start,
|
|
||||||
style: context.bodyLarge.copyWith(
|
|
||||||
color: (tabState is TabSelected) && tabState.roomId == e.id
|
|
||||||
? ColorsManager.textPrimaryColor
|
|
||||||
: ColorsManager.textPrimaryColor.withOpacity(0.2),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)),
|
|
||||||
],
|
|
||||||
isScrollable: true,
|
|
||||||
tabAlignment: TabAlignment.start,
|
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: TabBarView(
|
child: TabBarView(
|
||||||
controller: _tabController,
|
|
||||||
physics: const NeverScrollableScrollPhysics(),
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
children:
|
controller: tabController,
|
||||||
rooms!.map((e) => _buildRoomTab(e, context, isAutomationDeviceStatus)).toList(),
|
children: rooms
|
||||||
|
.map(
|
||||||
|
(room) => _buildRoomTab(
|
||||||
|
room,
|
||||||
|
_isAutomationDeviceStatus(context),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.toList(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -70,52 +53,46 @@ class SceneDevicesBody extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildRoomTab(SubSpaceModel room, BuildContext context, bool isAutomationDeviceStatus) {
|
bool _isAutomationDeviceStatus(BuildContext context) {
|
||||||
|
final routeArguments =
|
||||||
|
ModalRoute.of(context)?.settings.arguments as SceneSettingsRouteArguments?;
|
||||||
|
final deviceStatusChangesScene = CreateSceneEnum.deviceStatusChanges.name;
|
||||||
|
final sceneType = routeArguments?.sceneType;
|
||||||
|
|
||||||
|
return sceneType == deviceStatusChangesScene;
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildRoomTab(
|
||||||
|
SubSpaceModel room,
|
||||||
|
bool isAutomationDeviceStatus,
|
||||||
|
) {
|
||||||
return BlocBuilder<DeviceManagerBloc, DeviceManagerState>(
|
return BlocBuilder<DeviceManagerBloc, DeviceManagerState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
if (state.loading && state.devices == null) {
|
final isLoading = state.loading && state.devices == null;
|
||||||
return const Center(child: CircularProgressIndicator());
|
final hasData =
|
||||||
} else if (state.devices != null && state.devices!.isNotEmpty) {
|
state.devices != null && (state.devices?.isNotEmpty ?? false);
|
||||||
return ListView.builder(
|
final hasError = state.error != null;
|
||||||
itemCount: state.devices!.length,
|
|
||||||
itemBuilder: (context, index) {
|
final widgets = <bool, Widget>{
|
||||||
final device = state.devices![index];
|
isLoading: const AppLoadingIndicator(),
|
||||||
return DefaultContainer(
|
hasError: Center(child: Text('${state.error}')),
|
||||||
child: SceneListTile(
|
hasData: SceneDevicesList(
|
||||||
minLeadingWidth: 40,
|
devices: state.devices ?? [],
|
||||||
leadingWidget: SvgPicture.asset(device.icon ?? ''),
|
isAutomationDeviceStatus: isAutomationDeviceStatus,
|
||||||
titleWidget: BodyMedium(
|
),
|
||||||
text: device.name ?? '',
|
};
|
||||||
style: context.titleSmall.copyWith(
|
|
||||||
color: ColorsManager.secondaryTextColor,
|
final invalidWidgetEntry = MapEntry(
|
||||||
fontWeight: FontWeight.w400,
|
true,
|
||||||
fontSize: 20,
|
Center(child: Text('This subspace has no devices')),
|
||||||
),
|
);
|
||||||
),
|
|
||||||
trailingWidget: const Icon(
|
final validWidgetEntry = widgets.entries.firstWhere(
|
||||||
Icons.arrow_forward_ios_rounded,
|
(entry) => entry.key == true,
|
||||||
color: ColorsManager.greyColor,
|
orElse: () => invalidWidgetEntry,
|
||||||
size: 16,
|
);
|
||||||
),
|
|
||||||
onPressed: () {
|
return validWidgetEntry.value;
|
||||||
Navigator.pushNamed(
|
|
||||||
context,
|
|
||||||
Routes.deviceFunctionsRoute,
|
|
||||||
arguments: {
|
|
||||||
"device": device,
|
|
||||||
"isAutomationDeviceStatus": isAutomationDeviceStatus
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
} else if (state.error != null) {
|
|
||||||
return const Center(child: Text('Something went wrong'));
|
|
||||||
} else {
|
|
||||||
return const SizedBox();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,46 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:syncrow_app/features/devices/model/subspace_model.dart';
|
||||||
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
||||||
|
import 'package:syncrow_app/utils/context_extension.dart';
|
||||||
|
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||||
|
|
||||||
|
class SceneDevicesBodyTabBar extends StatelessWidget {
|
||||||
|
const SceneDevicesBodyTabBar({
|
||||||
|
required this.tabController,
|
||||||
|
required this.rooms,
|
||||||
|
required this.selectedRoomId,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
final String selectedRoomId;
|
||||||
|
|
||||||
|
final TabController tabController;
|
||||||
|
final List<SubSpaceModel> rooms;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return TabBar(
|
||||||
|
controller: tabController,
|
||||||
|
dividerColor: Colors.transparent,
|
||||||
|
indicatorColor: Colors.transparent,
|
||||||
|
isScrollable: true,
|
||||||
|
tabAlignment: TabAlignment.start,
|
||||||
|
tabs: rooms.map((e) {
|
||||||
|
final isSelected = selectedRoomId == e.id;
|
||||||
|
return Tab(
|
||||||
|
child: BodyLarge(
|
||||||
|
text: e.name ?? '',
|
||||||
|
textAlign: TextAlign.start,
|
||||||
|
style: context.bodyLarge.copyWith(
|
||||||
|
color: isSelected
|
||||||
|
? ColorsManager.textPrimaryColor
|
||||||
|
: ColorsManager.textPrimaryColor.withValues(
|
||||||
|
alpha: 0.2,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,66 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
|
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/widgets/scene_list_tile.dart';
|
||||||
|
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||||
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
||||||
|
import 'package:syncrow_app/navigation/routing_constants.dart';
|
||||||
|
import 'package:syncrow_app/utils/context_extension.dart';
|
||||||
|
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||||
|
|
||||||
|
class SceneDevicesList extends StatelessWidget {
|
||||||
|
const SceneDevicesList({
|
||||||
|
required this.isAutomationDeviceStatus,
|
||||||
|
required this.devices,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
final List<DeviceModel> devices;
|
||||||
|
final bool isAutomationDeviceStatus;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return ListView.builder(
|
||||||
|
itemCount: devices.length,
|
||||||
|
itemBuilder: (context, index) => _buildDeviceTile(context, devices[index]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildDeviceTile(
|
||||||
|
BuildContext context,
|
||||||
|
DeviceModel device,
|
||||||
|
) {
|
||||||
|
return DefaultContainer(
|
||||||
|
child: SceneListTile(
|
||||||
|
minLeadingWidth: 40,
|
||||||
|
leadingWidget: SvgPicture.asset(device.icon ?? ''),
|
||||||
|
titleWidget: BodyMedium(
|
||||||
|
text: device.name ?? '',
|
||||||
|
style: context.titleSmall.copyWith(
|
||||||
|
color: ColorsManager.secondaryTextColor,
|
||||||
|
fontWeight: FontWeight.w400,
|
||||||
|
fontSize: 20,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
trailingWidget: const Icon(
|
||||||
|
Icons.arrow_forward_ios_rounded,
|
||||||
|
color: ColorsManager.greyColor,
|
||||||
|
size: 16,
|
||||||
|
),
|
||||||
|
onPressed: () => _navigateToDeviceFunctions(context, device),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _navigateToDeviceFunctions(
|
||||||
|
BuildContext context,
|
||||||
|
DeviceModel device,
|
||||||
|
) {
|
||||||
|
Navigator.of(context).pushNamed(
|
||||||
|
Routes.deviceFunctionsRoute,
|
||||||
|
arguments: {
|
||||||
|
"device": device,
|
||||||
|
"isAutomationDeviceStatus": isAutomationDeviceStatus,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/title_medium.dart';
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/title_medium.dart';
|
||||||
|
|
||||||
import 'package:syncrow_app/utils/resource_manager/strings_manager.dart';
|
import 'package:syncrow_app/utils/resource_manager/strings_manager.dart';
|
||||||
|
|
||||||
class SceneHeader extends StatelessWidget {
|
class SceneHeader extends StatelessWidget {
|
||||||
@ -19,10 +17,6 @@ class SceneHeader extends StatelessWidget {
|
|||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
// SizedBox(height: 20),
|
|
||||||
// BodySmall(
|
|
||||||
// text: StringsManager.tapToRunRoutine,
|
|
||||||
// ),
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -132,6 +132,10 @@ class SceneItem extends StatelessWidget {
|
|||||||
spaceUuid: HomeCubit.getInstance()
|
spaceUuid: HomeCubit.getInstance()
|
||||||
.selectedSpace!
|
.selectedSpace!
|
||||||
.id),
|
.id),
|
||||||
|
communityId: HomeCubit.getInstance()
|
||||||
|
.selectedSpace!
|
||||||
|
.community
|
||||||
|
.uuid,
|
||||||
automationId: scene.id));
|
automationId: scene.id));
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
@ -22,7 +22,7 @@ class SmartEnableAutomation extends StatelessWidget {
|
|||||||
child: BlocBuilder<SceneBloc, SceneState>(
|
child: BlocBuilder<SceneBloc, SceneState>(
|
||||||
bloc: context.read<SceneBloc>()
|
bloc: context.read<SceneBloc>()
|
||||||
..add(
|
..add(
|
||||||
LoadAutomation(HomeCubit.getInstance().selectedSpace?.id ?? '')),
|
LoadAutomation(HomeCubit.getInstance().selectedSpace?.id ?? '',HomeCubit.getInstance().selectedSpace?.community.uuid ?? '')),
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
if (state is SceneLoading) {
|
if (state is SceneLoading) {
|
||||||
return const Align(
|
return const Align(
|
||||||
|
12
lib/features/shared_widgets/app_loading_indicator.dart
Normal file
12
lib/features/shared_widgets/app_loading_indicator.dart
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class AppLoadingIndicator extends StatelessWidget {
|
||||||
|
const AppLoadingIndicator({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Center(
|
||||||
|
child: CircularProgressIndicator.adaptive(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -59,13 +59,16 @@ class DefaultScaffold extends StatelessWidget {
|
|||||||
height: height ?? MediaQuery.sizeOf(context).height,
|
height: height ?? MediaQuery.sizeOf(context).height,
|
||||||
padding: padding ??
|
padding: padding ??
|
||||||
const EdgeInsets.symmetric(horizontal: Constants.defaultPadding),
|
const EdgeInsets.symmetric(horizontal: Constants.defaultPadding),
|
||||||
decoration: const BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
image: DecorationImage(
|
image: const DecorationImage(
|
||||||
|
colorFilter: ColorFilter.mode(
|
||||||
|
ColorsManager.backgroundGrey,
|
||||||
|
BlendMode.srcIn,
|
||||||
|
),
|
||||||
image: AssetImage(
|
image: AssetImage(
|
||||||
Assets.assetsImagesBackground,
|
Assets.assetsImagesBackground,
|
||||||
),
|
),
|
||||||
fit: BoxFit.cover,
|
fit: BoxFit.cover,
|
||||||
opacity: 0.4,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: SafeArea(child: child),
|
child: SafeArea(child: child),
|
||||||
|
@ -1142,5 +1142,9 @@ class Assets {
|
|||||||
|
|
||||||
static const String toggleSwitchSmall = 'assets/icons/toggleSwitchSmall.svg';
|
static const String toggleSwitchSmall = 'assets/icons/toggleSwitchSmall.svg';
|
||||||
static const String offToggleSwitchSmall = 'assets/icons/offToggleSwitchSmall.svg';
|
static const String offToggleSwitchSmall = 'assets/icons/offToggleSwitchSmall.svg';
|
||||||
|
static const String saveRoutinesIcon = 'assets/icons/save_routines_icon.svg';
|
||||||
|
static const String cancelIcon = 'assets/icons/cancel_icon.svg';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,8 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
|||||||
import 'package:syncrow_app/features/app_layout/model/community_model.dart';
|
import 'package:syncrow_app/features/app_layout/model/community_model.dart';
|
||||||
import 'package:syncrow_app/features/app_layout/model/space_model.dart';
|
import 'package:syncrow_app/features/app_layout/model/space_model.dart';
|
||||||
import 'package:syncrow_app/features/app_layout/view/app_layout.dart';
|
import 'package:syncrow_app/features/app_layout/view/app_layout.dart';
|
||||||
import 'package:syncrow_app/features/auth/view/otp_view.dart';
|
|
||||||
import 'package:syncrow_app/features/auth/view/login_view.dart';
|
import 'package:syncrow_app/features/auth/view/login_view.dart';
|
||||||
|
import 'package:syncrow_app/features/auth/view/otp_view.dart';
|
||||||
import 'package:syncrow_app/features/auth/view/sign_up_view.dart';
|
import 'package:syncrow_app/features/auth/view/sign_up_view.dart';
|
||||||
import 'package:syncrow_app/features/dashboard/view/dashboard_view.dart';
|
import 'package:syncrow_app/features/dashboard/view/dashboard_view.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/device_manager_bloc/device_manager_bloc.dart';
|
import 'package:syncrow_app/features/devices/bloc/device_manager_bloc/device_manager_bloc.dart';
|
||||||
@ -17,11 +17,12 @@ import 'package:syncrow_app/features/scene/bloc/tab_change/tab_change_bloc.dart'
|
|||||||
import 'package:syncrow_app/features/scene/bloc/tab_change/tab_change_event.dart';
|
import 'package:syncrow_app/features/scene/bloc/tab_change/tab_change_event.dart';
|
||||||
import 'package:syncrow_app/features/scene/view/device_functions_view.dart';
|
import 'package:syncrow_app/features/scene/view/device_functions_view.dart';
|
||||||
import 'package:syncrow_app/features/scene/view/scene_auto_settings.dart';
|
import 'package:syncrow_app/features/scene/view/scene_auto_settings.dart';
|
||||||
import 'package:syncrow_app/features/scene/view/scene_tasks_view.dart';
|
|
||||||
import 'package:syncrow_app/features/scene/view/scene_rooms_tabbar.dart';
|
import 'package:syncrow_app/features/scene/view/scene_rooms_tabbar.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/view/scene_tasks_view.dart';
|
||||||
import 'package:syncrow_app/features/scene/view/scene_view.dart';
|
import 'package:syncrow_app/features/scene/view/scene_view.dart';
|
||||||
import 'package:syncrow_app/features/scene/view/smart_automation_select_route.dart';
|
import 'package:syncrow_app/features/scene/view/smart_automation_select_route.dart';
|
||||||
import 'package:syncrow_app/features/splash/view/splash_view.dart';
|
import 'package:syncrow_app/features/splash/view/splash_view.dart';
|
||||||
|
|
||||||
import 'routing_constants.dart';
|
import 'routing_constants.dart';
|
||||||
|
|
||||||
class Router {
|
class Router {
|
||||||
@ -88,7 +89,7 @@ class Router {
|
|||||||
BlocProvider(
|
BlocProvider(
|
||||||
create: (BuildContext context) =>
|
create: (BuildContext context) =>
|
||||||
TabBarBloc(context.read<DeviceManagerBloc>())
|
TabBarBloc(context.read<DeviceManagerBloc>())
|
||||||
..add(TabChanged(
|
..add(TabBarTabChangedEvent(
|
||||||
selectedIndex: 0,
|
selectedIndex: 0,
|
||||||
roomId: '-1',
|
roomId: '-1',
|
||||||
unit: SpaceModel(
|
unit: SpaceModel(
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user