235 lines
8.1 KiB
Dart
235 lines
8.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:QuickSSH/classes/ServerCommand.dart';
|
|
|
|
class AddClient extends StatefulWidget {
|
|
const AddClient({super.key});
|
|
|
|
@override
|
|
State<AddClient> createState() => _AddClientState();
|
|
}
|
|
|
|
class _AddClientState extends State<AddClient> {
|
|
final nameController = TextEditingController();
|
|
final ipController = TextEditingController();
|
|
final userController = TextEditingController();
|
|
final cmdController = TextEditingController();
|
|
final passController = TextEditingController();
|
|
|
|
@override
|
|
void dispose() {
|
|
nameController.dispose();
|
|
ipController.dispose();
|
|
userController.dispose();
|
|
cmdController.dispose();
|
|
passController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context).colorScheme;
|
|
|
|
return Scaffold(
|
|
resizeToAvoidBottomInset: false,
|
|
backgroundColor: theme.surface,
|
|
appBar: AppBar(
|
|
backgroundColor: theme.surface,
|
|
title: Text("Add command", style: TextStyle(color: theme.onSurface)),
|
|
leading: Builder(
|
|
builder: (context) {
|
|
return IconButton(
|
|
icon: Icon(Icons.arrow_back_ios_rounded, color: theme.onSurface),
|
|
onPressed: () {
|
|
Navigator.pop(context);
|
|
},
|
|
);
|
|
},
|
|
),
|
|
),
|
|
body: Column(
|
|
children: [
|
|
const SizedBox(height: 20),
|
|
TextField(
|
|
style: TextStyle(color: theme.onSurface),
|
|
controller: nameController,
|
|
decoration: InputDecoration(
|
|
filled: true,
|
|
fillColor: theme.primaryContainer,
|
|
labelText: 'Command name',
|
|
labelStyle: TextStyle(
|
|
color: theme.onSurfaceVariant,
|
|
fontSize: 20,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(10),
|
|
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
|
),
|
|
focusedBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(10),
|
|
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
|
),
|
|
enabledBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(20),
|
|
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 20),
|
|
TextField(
|
|
style: TextStyle(color: theme.onSurface),
|
|
controller: ipController,
|
|
decoration: InputDecoration(
|
|
filled: true,
|
|
fillColor: theme.primaryContainer,
|
|
labelText: 'Host (IP address)',
|
|
labelStyle: TextStyle(
|
|
color: theme.onSurfaceVariant,
|
|
fontSize: 20,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(10),
|
|
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
|
),
|
|
focusedBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(10),
|
|
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
|
),
|
|
enabledBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(20),
|
|
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 20),
|
|
TextField(
|
|
style: TextStyle(color: theme.onSurface),
|
|
controller: userController,
|
|
decoration: InputDecoration(
|
|
filled: true,
|
|
fillColor: theme.primaryContainer,
|
|
labelText: 'Login as (user)',
|
|
labelStyle: TextStyle(
|
|
color: theme.onSurfaceVariant,
|
|
fontSize: 20,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(10),
|
|
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
|
),
|
|
focusedBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(10),
|
|
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
|
),
|
|
enabledBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(20),
|
|
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 20),
|
|
TextField(
|
|
style: TextStyle(color: theme.onSurface),
|
|
controller: passController,
|
|
obscureText: true,
|
|
decoration: InputDecoration(
|
|
filled: true,
|
|
fillColor: theme.primaryContainer,
|
|
labelText: 'Password',
|
|
labelStyle: TextStyle(
|
|
color: theme.onSurfaceVariant,
|
|
fontSize: 20,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(10),
|
|
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
|
),
|
|
focusedBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(10),
|
|
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
|
),
|
|
enabledBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(20),
|
|
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 20),
|
|
TextField(
|
|
style: TextStyle(color: theme.onSurface),
|
|
controller: cmdController,
|
|
minLines: 3,
|
|
maxLines: 100,
|
|
decoration: InputDecoration(
|
|
filled: true,
|
|
fillColor: theme.primaryContainer,
|
|
labelText: 'Command',
|
|
labelStyle: TextStyle(
|
|
color: theme.onSurfaceVariant,
|
|
fontSize: 20,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(10),
|
|
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
|
),
|
|
focusedBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(10),
|
|
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
|
),
|
|
enabledBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(20),
|
|
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
|
),
|
|
),
|
|
),
|
|
Spacer(),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 20),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: [
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
_onSaved();
|
|
},
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: theme.primary,
|
|
fixedSize: const Size(140, 40),
|
|
),
|
|
child: Text(
|
|
'Add',
|
|
style: TextStyle(
|
|
color: theme.onPrimary,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
void _onSaved() {
|
|
// Create the object using the controller text
|
|
final newCmd = ServerCommand(
|
|
name: nameController.text,
|
|
ip: ipController.text,
|
|
username: userController.text,
|
|
command: cmdController.text,
|
|
password: passController.text,
|
|
);
|
|
|
|
print("Saving: ${newCmd.name}");
|
|
|
|
// Send the object BACK to the previous screen (Home)
|
|
Navigator.pop(context, newCmd);
|
|
}
|
|
}
|