Restructure Action Button Logic
This commit is contained in:
parent
df687a52a8
commit
bae5cc903c
@ -68,8 +68,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
String _output = '';
|
||||
String key = '';
|
||||
|
||||
Future<void> _incrementCounter() async {
|
||||
if (navIndex == 0) {
|
||||
Future<void> doSSH() async {
|
||||
SSHSocket? socket;
|
||||
|
||||
try {
|
||||
@ -103,7 +102,9 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
});
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
|
||||
Future<void> generateKey() async {
|
||||
// Generate a key pair
|
||||
|
||||
final generatedKeyPair =
|
||||
@ -119,7 +120,6 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
<String, dynamic>{'text': key},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -144,14 +144,29 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
),
|
||||
);
|
||||
|
||||
final actionButtonMain = FloatingActionButton(
|
||||
onPressed: doSSH,
|
||||
tooltip: 'Do SSH',
|
||||
child: const Icon(Icons.computer),
|
||||
);
|
||||
|
||||
final actionButtonInfo = FloatingActionButton(
|
||||
onPressed: generateKey,
|
||||
tooltip: 'Regenerate Key',
|
||||
child: const Icon(Icons.refresh),
|
||||
);
|
||||
|
||||
var bodyComponent = bodyComponentMain;
|
||||
var actionButton = actionButtonMain;
|
||||
|
||||
if (navIndex == 0) {
|
||||
// Main page
|
||||
bodyComponent = bodyComponentMain;
|
||||
actionButton = actionButtonMain;
|
||||
} else if (navIndex == 1) {
|
||||
// Info page
|
||||
bodyComponent = bodyComponentInfo;
|
||||
actionButton = actionButtonInfo;
|
||||
} else {
|
||||
throw Exception('Unknown navIndex: $navIndex');
|
||||
}
|
||||
@ -159,11 +174,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
return Scaffold(
|
||||
appBar: AppBar(backgroundColor: Colors.amber, title: Text(widget.title)),
|
||||
body: bodyComponent,
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: _incrementCounter,
|
||||
tooltip: 'Increment',
|
||||
child: const Icon(Icons.add),
|
||||
),
|
||||
floatingActionButton: actionButton,
|
||||
drawer: Drawer(
|
||||
child: ListView(
|
||||
padding: EdgeInsets.zero,
|
||||
|
Loading…
x
Reference in New Issue
Block a user