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