Replaced math based approach with bitwise operations
This commit is contained in:
parent
916ea41159
commit
b73362c101
1 changed files with 30 additions and 26 deletions
|
@ -31,10 +31,10 @@ class _EditRoomPermissionSetPageState extends State<EditRoomPermissionSetPage> {
|
||||||
doNetworkRequest(
|
doNetworkRequest(
|
||||||
sm,
|
sm,
|
||||||
req: () => postWithCreadentials(
|
req: () => postWithCreadentials(
|
||||||
path: 'getRoomInfo',
|
path: 'getRoomInfo',
|
||||||
credentials: user,
|
credentials: user,
|
||||||
target: user.server,
|
target: user.server,
|
||||||
body: {'room': widget.tag, 'server': widget.server}),
|
body: {'room': widget.tag, 'server': widget.server}),
|
||||||
onAnyErr: () {
|
onAnyErr: () {
|
||||||
// user should not be here
|
// user should not be here
|
||||||
// close screen
|
// close screen
|
||||||
|
@ -44,7 +44,7 @@ class _EditRoomPermissionSetPageState extends State<EditRoomPermissionSetPage> {
|
||||||
onOK: (body) async {
|
onOK: (body) async {
|
||||||
final info = RoomInfo.fromJSON(body['data']);
|
final info = RoomInfo.fromJSON(body['data']);
|
||||||
setState(() {
|
setState(() {
|
||||||
permissions = info.permissions;
|
permissions = info.permissions;
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
@ -69,17 +69,21 @@ class _EditRoomPermissionSetPageState extends State<EditRoomPermissionSetPage> {
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final item = items[index];
|
final item = items[index];
|
||||||
|
|
||||||
final int col = pow(2, index + 1) as int;
|
final int col = pow(2, index) as int;
|
||||||
|
|
||||||
return SwitchListTile(
|
return SwitchListTile(
|
||||||
title: Text(RoomPermission.name(item, context)),
|
title: Text(RoomPermission.name(item, context)),
|
||||||
subtitle: Text(RoomPermission.describe(item, context)),
|
subtitle: Text(RoomPermission.describe(item, context)),
|
||||||
onChanged: (state) {
|
onChanged: (state) {
|
||||||
setState(() {
|
setState(() {
|
||||||
permissions += (state ? 1 : -1) * col;
|
if (state) {
|
||||||
});
|
permissions |= col;
|
||||||
},
|
} else {
|
||||||
value: permissions & col != 0);
|
permissions &= ~col;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
value: permissions & col != 0);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
floatingActionButton: FloatingActionButton.extended(
|
floatingActionButton: FloatingActionButton.extended(
|
||||||
|
@ -93,18 +97,18 @@ class _EditRoomPermissionSetPageState extends State<EditRoomPermissionSetPage> {
|
||||||
|
|
||||||
// update permissions
|
// update permissions
|
||||||
doNetworkRequest(sm,
|
doNetworkRequest(sm,
|
||||||
req: () => postWithCreadentials(
|
req: () => postWithCreadentials(
|
||||||
path: 'setRoomRight',
|
path: 'setRoomRight',
|
||||||
credentials: user,
|
credentials: user,
|
||||||
target: user.server,
|
target: user.server,
|
||||||
body: {
|
body: {
|
||||||
'room': widget.tag,
|
'room': widget.tag,
|
||||||
'server': widget.server,
|
'server': widget.server,
|
||||||
'rights': permissions
|
'rights': permissions
|
||||||
}),
|
}),
|
||||||
onOK: (_) {
|
onOK: (_) {
|
||||||
router.pop();
|
router.pop();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue