Finish KeyToken operations
This commit is contained in:
112
flutter/lib/pages/keytoken_view/keytoken_channel_modal.dart
Normal file
112
flutter/lib/pages/keytoken_view/keytoken_channel_modal.dart
Normal file
@@ -0,0 +1,112 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:simplecloudnotifier/models/channel.dart';
|
||||
import 'package:simplecloudnotifier/models/keytoken.dart';
|
||||
|
||||
class EditKeyTokenChannelsDialog extends StatefulWidget {
|
||||
final List<Channel> ownedChannels;
|
||||
final KeyTokenPreview keytoken;
|
||||
|
||||
final void Function(Set<String>) onUpdateChannels;
|
||||
final void Function() onUpdateSetAllChannels;
|
||||
|
||||
const EditKeyTokenChannelsDialog({
|
||||
required this.ownedChannels,
|
||||
required this.keytoken,
|
||||
required this.onUpdateChannels,
|
||||
required this.onUpdateSetAllChannels,
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
_EditKeyTokenChannelsDialogState createState() => _EditKeyTokenChannelsDialogState();
|
||||
}
|
||||
|
||||
class _EditKeyTokenChannelsDialogState extends State<EditKeyTokenChannelsDialog> {
|
||||
late bool allChannels;
|
||||
late Set<String> selectedEntries;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
allChannels = widget.keytoken.allChannels;
|
||||
selectedEntries = (widget.keytoken.channels).toSet();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var ownChannels = widget.ownedChannels.toList();
|
||||
ownChannels.sort((a, b) => a.displayName.toLowerCase().compareTo(b.displayName.toLowerCase()));
|
||||
|
||||
return AlertDialog(
|
||||
title: const Text('Channels'),
|
||||
content: Container(
|
||||
width: 0,
|
||||
height: 400,
|
||||
child: Column(
|
||||
children: [
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.fromLTRB(8, 0, 8, 0),
|
||||
visualDensity: VisualDensity(horizontal: 0, vertical: -4),
|
||||
title: Text('All Channels'),
|
||||
leading: Icon(
|
||||
allChannels ? Icons.check_box : Icons.check_box_outline_blank,
|
||||
color: Theme.of(context).primaryColor,
|
||||
),
|
||||
onTap: () {
|
||||
setState(() {
|
||||
allChannels = !allChannels;
|
||||
});
|
||||
},
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
if (!allChannels)
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemBuilder: (builder, index) {
|
||||
return ListTile(
|
||||
contentPadding: EdgeInsets.fromLTRB(8, 0, 8, 0),
|
||||
visualDensity: VisualDensity(horizontal: 0, vertical: -4),
|
||||
title: Text(ownChannels[index].displayName),
|
||||
leading: Icon(
|
||||
selectedEntries.contains(ownChannels[index].channelID) ? Icons.check_box : Icons.check_box_outline_blank,
|
||||
color: Theme.of(context).primaryColor,
|
||||
),
|
||||
onTap: () {
|
||||
setState(() {
|
||||
if (selectedEntries.contains(ownChannels[index].channelID)) {
|
||||
selectedEntries.remove(ownChannels[index].channelID);
|
||||
} else {
|
||||
selectedEntries.add(ownChannels[index].channelID);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
itemCount: ownChannels.length,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: Text('Cancel'),
|
||||
),
|
||||
TextButton(
|
||||
style: TextButton.styleFrom(textStyle: Theme.of(context).textTheme.labelLarge),
|
||||
child: const Text('Update'),
|
||||
onPressed: () {
|
||||
if (allChannels) {
|
||||
widget.onUpdateSetAllChannels();
|
||||
} else {
|
||||
widget.onUpdateChannels(selectedEntries);
|
||||
}
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user