Completed basic functionality

This commit is contained in:
MaticIvesic committed 2026-02-02 20:52:17 +01:00
1 parent 922f26310a
commit 78f2dfa742
55 files changed
+1399 -101

No files matched your search

+234
View File
@@ -0,0 +1,234 @@
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);
}
}
+319
View File
@@ -0,0 +1,319 @@
import 'package:flutter/material.dart';
import 'package:QuickSSH/classes/ServerCommand.dart';
class EditClient extends StatefulWidget {
final ServerCommand? existingCommand; // Null if adding, not null if editing
final int? index;
const EditClient({super.key, this.existingCommand, this.index});
@override
State<EditClient> createState() => _EditClientState();
}
class _EditClientState extends State<EditClient> {
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
void initState() {
super.initState();
if (widget.existingCommand != null) {
nameController.text = widget.existingCommand!.name;
ipController.text = widget.existingCommand!.ip;
userController.text = widget.existingCommand!.username;
passController.text = widget.existingCommand!.password;
cmdController.text = widget.existingCommand!.command;
}
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context).colorScheme;
return Scaffold(
backgroundColor: theme.surface,
resizeToAvoidBottomInset: false,
appBar: AppBar(
backgroundColor: theme.surface,
title: Text("Edit", 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.0, vertical: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
ElevatedButton(
onPressed: () {
showModalBottomSheet(
context: context,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
top: Radius.circular(25.0),
),
),
builder: (BuildContext context) {
return SizedBox(
height: 400,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'Remove this command?',
style: TextStyle(fontSize: 20),
),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: [
ElevatedButton(
onPressed: () {
Navigator.pop(context);
Navigator.pop(context, "DELETE");
},
style: ElevatedButton.styleFrom(
backgroundColor: theme.error,
fixedSize: const Size(140, 40),
),
child: Text(
'Yes, remove',
style: TextStyle(
color: theme.surface,
fontWeight: FontWeight.bold,
),
),
),
ElevatedButton(
onPressed: () => Navigator.pop(context),
style: ElevatedButton.styleFrom(
backgroundColor: theme.onSurface,
fixedSize: const Size(140, 40),
),
child: Text(
'No',
style: TextStyle(
color: theme.surface,
fontWeight: FontWeight.bold,
),
),
),
],
),
],
),
),
);
},
);
},
style: ElevatedButton.styleFrom(
backgroundColor: theme.error,
fixedSize: const Size(140, 40),
),
child: Text(
'Remove',
style: TextStyle(
color: const Color.fromARGB(255, 0, 0, 0),
fontWeight: FontWeight.bold,
),
),
),
ElevatedButton(
onPressed: _save,
style: ElevatedButton.styleFrom(
backgroundColor: theme.onSurface,
fixedSize: const Size(140, 40),
),
child: Text(
'Save',
style: TextStyle(
color: theme.surface,
fontWeight: FontWeight.bold,
),
),
),
],
),
),
],
),
);
}
void _save() {
final updatedCommand = ServerCommand(
name: nameController.text,
ip: ipController.text,
username: userController.text,
command: cmdController.text,
password: passController.text,
);
Navigator.pop(context, updatedCommand);
}
}
+152
View File
@@ -0,0 +1,152 @@
import 'package:flutter/material.dart';
import 'package:QuickSSH/screens/edit_client.dart';
import '../widgets/server_status_tile.dart';
import 'add_client.dart';
import 'package:QuickSSH/classes/ServerCommand.dart';
import 'package:QuickSSH/services/storage_service.dart';
class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});
@override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
List<ServerCommand> allCommands = [];
@override
void initState() {
super.initState();
_loadData();
}
void _loadData() async {
allCommands = await SecureStorageService.loadCommands();
setState(() {});
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context).colorScheme;
return Scaffold(
appBar: AppBar(
backgroundColor: theme.surface,
leading: Builder(
builder: (context) {
return IconButton(
icon: Icon(Icons.menu, color: theme.onSurface),
onPressed: () {
Scaffold.of(context).openDrawer();
},
);
},
),
),
drawer: Drawer(
backgroundColor: theme.primaryContainer,
child: ListView(
children: [
ListTile(
title: Text(
"Settings",
style: TextStyle(
color: theme.onSurface,
fontWeight: FontWeight.bold,
fontSize: 20,
),
),
),
ListTile(
title: Text(
"Help",
style: TextStyle(
color: theme.onSurface,
fontWeight: FontWeight.bold,
fontSize: 20,
),
),
),
],
),
),
body: ListView.builder(
itemCount: allCommands.length,
itemBuilder: (context, index) {
// You can keep this as 'context' or rename it
return ServerStatusTile(
command: allCommands[index],
onEdit: () => _editCommand(allCommands[index], index),
);
},
),
floatingActionButton: Builder(
builder: (context) {
return FloatingActionButton(
backgroundColor: theme.primary,
shape: const CircleBorder(),
child: const Icon(
Icons.add,
color: Color.fromARGB(255, 0, 0, 0),
size: 32,
weight: 50,
),
onPressed: () {
_addCommand();
},
);
},
),
backgroundColor: theme.surface,
);
}
void _addCommand() async {
// 1. Must be async
print("Opening Add Screen...");
final result = await Navigator.push(
// 2. Must have await
context,
MaterialPageRoute(builder: (context) => const AddClient()),
);
// This part only runs AFTER you come back from AddClient
if (result != null) {
print("Received data: ${result.name}");
setState(() {
allCommands.add(result);
});
SecureStorageService.saveCommands(allCommands);
} else {
print("Result was null - user might have just hit 'Back'");
}
}
_editCommand(ServerCommand cmdToEdit, int index) async {
final result = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => EditClient(existingCommand: cmdToEdit),
),
);
if (result != null) {
if (result == "DELETE") {
setState(() {
allCommands.removeAt(index);
});
SecureStorageService.saveCommands(allCommands);
return;
}
print("Received edited data: ${result.name}");
setState(() {
allCommands[index] = result;
});
SecureStorageService.saveCommands(allCommands);
} else {
print("Edit result was null - user might have just hit 'Back'");
}
}
}