Skip to content

Commit

Permalink
new_group_page: add custom policy hints
Browse files Browse the repository at this point in the history
  • Loading branch information
jjanku committed May 4, 2024
1 parent 0038237 commit 3a96881
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions lib/ui/new_group_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,19 @@ class _NewGroupPageState extends State<NewGroupPage> {
_addMembers(devices);
}

Map<String, dynamic> _buildPolicy({bool includeAll = false}) {
String pad(num n) => n.toString().padLeft(2, '0');
return {
if (_policyTime || includeAll) ...{
'after':
'${pad(_policyAfterTime.hour)}:${pad(_policyAfterTime.minute)}',
'before':
'${pad(_policyBeforeTime.hour)}:${pad(_policyBeforeTime.minute)}',
},
if (_policyDecline || includeAll) 'decline': _policyDecline,
};
}

void _tryCreate() {
if (_nameController.text.isEmpty) {
setState(() {
Expand All @@ -260,18 +273,7 @@ class _NewGroupPageState extends State<NewGroupPage> {
});
}

var policy = <String, dynamic>{};

String pad(num n) => n.toString().padLeft(2, '0');
if (_policyTime) {
policy['after'] =
'${pad(_policyAfterTime.hour)}:${pad(_policyAfterTime.minute)}';
policy['before'] =
'${pad(_policyBeforeTime.hour)}:${pad(_policyBeforeTime.minute)}';
}
if (_policyDecline) {
policy['decline'] = true;
}
Map<String, dynamic> policy = _buildPolicy();

if (_policyController.text.trim().isNotEmpty) {
try {
Expand Down Expand Up @@ -640,6 +642,8 @@ class _NewGroupPageState extends State<NewGroupPage> {
decoration: InputDecoration(
border: const OutlineInputBorder(),
errorText: _policyErr,
hintText: const JsonEncoder.withIndent(' ')
.convert(_buildPolicy(includeAll: true)),
),
maxLines: null,
),
Expand Down

0 comments on commit 3a96881

Please sign in to comment.