Make KeepOrDeleteKey Widget stateless
This commit is contained in:
parent
b099cab718
commit
b104cd584e
@ -464,23 +464,14 @@ class SSHKeyList extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class KeepOrDeleteKey extends StatefulWidget {
|
class KeepOrDeleteKey extends StatelessWidget {
|
||||||
final String sshKey;
|
final String sshKey;
|
||||||
|
|
||||||
const KeepOrDeleteKey({super.key, required this.sshKey});
|
const KeepOrDeleteKey({super.key, required this.sshKey});
|
||||||
|
|
||||||
@override
|
|
||||||
State<KeepOrDeleteKey> createState() => _KeepOrDeleteKeyState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _KeepOrDeleteKeyState extends State<KeepOrDeleteKey> {
|
|
||||||
bool _selectedForDeletion = false;
|
|
||||||
|
|
||||||
bool get selectedForDeletion => _selectedForDeletion;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final key = widget.sshKey;
|
final key = sshKey;
|
||||||
final isKeySelectedToKeep = context.select<SSHKeyList, bool>(
|
final isKeySelectedToKeep = context.select<SSHKeyList, bool>(
|
||||||
(keylist) => keylist.isKeySelectedToKeep(key),
|
(keylist) => keylist.isKeySelectedToKeep(key),
|
||||||
);
|
);
|
||||||
@ -504,7 +495,7 @@ class _KeepOrDeleteKeyState extends State<KeepOrDeleteKey> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var title = "Unnamed Key";
|
var title = "Unnamed Key";
|
||||||
final sshKeySplit = widget.sshKey.split(' ');
|
final sshKeySplit = sshKey.split(' ');
|
||||||
if (sshKeySplit.length >= 3) {
|
if (sshKeySplit.length >= 3) {
|
||||||
final potentialTitle = sshKeySplit.sublist(2).join(' ');
|
final potentialTitle = sshKeySplit.sublist(2).join(' ');
|
||||||
if (potentialTitle != "") {
|
if (potentialTitle != "") {
|
||||||
@ -522,7 +513,7 @@ class _KeepOrDeleteKeyState extends State<KeepOrDeleteKey> {
|
|||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: EdgeInsets.fromLTRB(20, 0, 20, 20),
|
padding: EdgeInsets.fromLTRB(20, 0, 20, 20),
|
||||||
child: Text(widget.sshKey, style: TextStyle(fontSize: 15)),
|
child: Text(sshKey, style: TextStyle(fontSize: 15)),
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: EdgeInsets.fromLTRB(20, 0, 20, 20),
|
padding: EdgeInsets.fromLTRB(20, 0, 20, 20),
|
||||||
@ -531,26 +522,20 @@ class _KeepOrDeleteKeyState extends State<KeepOrDeleteKey> {
|
|||||||
children: [
|
children: [
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
setState(() {
|
|
||||||
_selectedForDeletion = true;
|
|
||||||
Provider.of<SSHKeyList>(
|
Provider.of<SSHKeyList>(
|
||||||
context,
|
context,
|
||||||
listen: false,
|
listen: false,
|
||||||
).selectKeyForDeletion(widget.sshKey);
|
).selectKeyForDeletion(sshKey);
|
||||||
});
|
|
||||||
},
|
},
|
||||||
style: buttonStyleDelete,
|
style: buttonStyleDelete,
|
||||||
child: Text('Select for Deletion'),
|
child: Text('Select for Deletion'),
|
||||||
),
|
),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
setState(() {
|
|
||||||
_selectedForDeletion = false;
|
|
||||||
Provider.of<SSHKeyList>(
|
Provider.of<SSHKeyList>(
|
||||||
context,
|
context,
|
||||||
listen: false,
|
listen: false,
|
||||||
).keepKey(widget.sshKey);
|
).keepKey(sshKey);
|
||||||
});
|
|
||||||
},
|
},
|
||||||
style: buttonStyleKeep,
|
style: buttonStyleKeep,
|
||||||
child: Text('Keep Key'),
|
child: Text('Keep Key'),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user