Added settings screen (Vibration toggle might not work)

This commit is contained in:
Matic Ivešić 2026-02-05 21:37:35 +01:00
parent 78f2dfa742
commit ba2dc23c6c
11 changed files with 617 additions and 460 deletions

View File

@ -1,4 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> <manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application <application
android:label="QuickSSH" android:label="QuickSSH"
android:name="${applicationName}" android:name="${applicationName}"

View File

@ -1,6 +1,12 @@
import 'package:QuickSSH/services/settings_controller.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'screens/home_screen.dart'; import 'screens/home_screen.dart';
import 'package:QuickSSH/classes/theme_provider.dart'; import 'package:QuickSSH/classes/theme_provider.dart';
import 'package:QuickSSH/services/theme_controller.dart';
import 'package:QuickSSH/services/settings_controller.dart';
final themeController = ThemeController();
final settingsController = SettingsController();
void main() { void main() {
runApp(MyApp()); runApp(MyApp());
@ -11,15 +17,19 @@ class MyApp extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return ListenableBuilder(
title: 'Quick SSH', listenable: themeController,
builder: (context, child) {
return MaterialApp(
title: 'Quick SSH',
theme: MyThemes.lightTheme, theme: MyThemes.lightTheme,
darkTheme: MyThemes.darkTheme, darkTheme: MyThemes.darkTheme,
themeMode: themeController.themeMode,
themeMode: ThemeMode.system, home: const HomeScreen(),
);
home: HomeScreen(), },
); );
} }
} }

View File

@ -46,178 +46,180 @@ class _AddClientState extends State<AddClient> {
}, },
), ),
), ),
body: Column( body: Padding(
children: [ padding: const EdgeInsets.symmetric(horizontal: 8.0),
const SizedBox(height: 20), child: Column(
TextField( children: [
style: TextStyle(color: theme.onSurface), const SizedBox(height: 20),
controller: nameController, TextField(
decoration: InputDecoration( style: TextStyle(color: theme.onSurface),
filled: true, controller: nameController,
fillColor: theme.primaryContainer, decoration: InputDecoration(
labelText: 'Command name', filled: true,
labelStyle: TextStyle( fillColor: theme.primaryContainer,
color: theme.onSurfaceVariant, labelText: 'Command name',
fontSize: 20, labelStyle: TextStyle(
fontWeight: FontWeight.bold, color: theme.onSurfaceVariant,
), fontSize: 20,
border: OutlineInputBorder( fontWeight: FontWeight.bold,
borderRadius: BorderRadius.circular(10), ),
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)), border: OutlineInputBorder(
), borderRadius: BorderRadius.circular(10),
focusedBorder: OutlineInputBorder( borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
borderRadius: BorderRadius.circular(10), ),
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)), focusedBorder: OutlineInputBorder(
), borderRadius: BorderRadius.circular(10),
enabledBorder: OutlineInputBorder( borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
borderRadius: BorderRadius.circular(20), ),
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),
const SizedBox(height: 20), TextField(
TextField( style: TextStyle(color: theme.onSurface),
style: TextStyle(color: theme.onSurface), controller: ipController,
controller: ipController, decoration: InputDecoration(
decoration: InputDecoration( filled: true,
filled: true, fillColor: theme.primaryContainer,
fillColor: theme.primaryContainer, labelText: 'Host (IP address)',
labelText: 'Host (IP address)', labelStyle: TextStyle(
labelStyle: TextStyle( color: theme.onSurfaceVariant,
color: theme.onSurfaceVariant, fontSize: 20,
fontSize: 20, fontWeight: FontWeight.bold,
fontWeight: FontWeight.bold, ),
), border: OutlineInputBorder(
border: OutlineInputBorder( borderRadius: BorderRadius.circular(10),
borderRadius: BorderRadius.circular(10), borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)), ),
), focusedBorder: OutlineInputBorder(
focusedBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(10),
borderRadius: BorderRadius.circular(10), borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)), ),
), enabledBorder: OutlineInputBorder(
enabledBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(20),
borderRadius: BorderRadius.circular(20), borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)), ),
), ),
), ),
), const SizedBox(height: 20),
const SizedBox(height: 20), TextField(
TextField( style: TextStyle(color: theme.onSurface),
style: TextStyle(color: theme.onSurface), controller: userController,
controller: userController, decoration: InputDecoration(
decoration: InputDecoration( filled: true,
filled: true, fillColor: theme.primaryContainer,
fillColor: theme.primaryContainer, labelText: 'Login as (user)',
labelText: 'Login as (user)', labelStyle: TextStyle(
labelStyle: TextStyle( color: theme.onSurfaceVariant,
color: theme.onSurfaceVariant, fontSize: 20,
fontSize: 20, fontWeight: FontWeight.bold,
fontWeight: FontWeight.bold, ),
), border: OutlineInputBorder(
border: OutlineInputBorder( borderRadius: BorderRadius.circular(10),
borderRadius: BorderRadius.circular(10), borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)), ),
), focusedBorder: OutlineInputBorder(
focusedBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(10),
borderRadius: BorderRadius.circular(10), borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)), ),
), enabledBorder: OutlineInputBorder(
enabledBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(20),
borderRadius: BorderRadius.circular(20), borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)), ),
), ),
), ),
), const SizedBox(height: 20),
const SizedBox(height: 20), TextField(
TextField( style: TextStyle(color: theme.onSurface),
style: TextStyle(color: theme.onSurface), controller: passController,
controller: passController, obscureText: true,
obscureText: true, decoration: InputDecoration(
decoration: InputDecoration( filled: true,
filled: true, fillColor: theme.primaryContainer,
fillColor: theme.primaryContainer, labelText: 'Password',
labelText: 'Password', labelStyle: TextStyle(
labelStyle: TextStyle( color: theme.onSurfaceVariant,
color: theme.onSurfaceVariant, fontSize: 20,
fontSize: 20, fontWeight: FontWeight.bold,
fontWeight: FontWeight.bold, ),
), border: OutlineInputBorder(
border: OutlineInputBorder( borderRadius: BorderRadius.circular(10),
borderRadius: BorderRadius.circular(10), borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)), ),
), focusedBorder: OutlineInputBorder(
focusedBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(10),
borderRadius: BorderRadius.circular(10), borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)), ),
), enabledBorder: OutlineInputBorder(
enabledBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(20),
borderRadius: BorderRadius.circular(20), borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)), ),
), ),
), ),
), const SizedBox(height: 20),
const SizedBox(height: 20), TextField(
TextField( style: TextStyle(color: theme.onSurface),
style: TextStyle(color: theme.onSurface), controller: cmdController,
controller: cmdController, minLines: 3,
minLines: 3, maxLines: 100,
maxLines: 100, decoration: InputDecoration(
decoration: InputDecoration( filled: true,
filled: true, fillColor: theme.primaryContainer,
fillColor: theme.primaryContainer, labelText: 'Command',
labelText: 'Command', labelStyle: TextStyle(
labelStyle: TextStyle( color: theme.onSurfaceVariant,
color: theme.onSurfaceVariant, fontSize: 20,
fontSize: 20, fontWeight: FontWeight.bold,
fontWeight: FontWeight.bold, ),
), border: OutlineInputBorder(
border: OutlineInputBorder( borderRadius: BorderRadius.circular(10),
borderRadius: BorderRadius.circular(10), borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)), ),
), focusedBorder: OutlineInputBorder(
focusedBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(10),
borderRadius: BorderRadius.circular(10), borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)), ),
), enabledBorder: OutlineInputBorder(
enabledBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(20),
borderRadius: BorderRadius.circular(20), borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)), ),
), ),
), ),
), Spacer(),
Spacer(), Padding(
Padding( padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 20),
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 20), child: Row(
child: Row( mainAxisAlignment: MainAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.end, children: [
children: [ ElevatedButton(
ElevatedButton( onPressed: () {
onPressed: () { _onSaved();
_onSaved(); },
}, style: ElevatedButton.styleFrom(
style: ElevatedButton.styleFrom( backgroundColor: theme.primary,
backgroundColor: theme.primary, fixedSize: const Size(140, 40),
fixedSize: const Size(140, 40), ),
), child: Text(
child: Text( 'Add',
'Add', style: TextStyle(
style: TextStyle( color: theme.onPrimary,
color: theme.onPrimary, fontWeight: FontWeight.bold,
fontWeight: FontWeight.bold, ),
), ),
), ),
), ],
], ),
), ),
), ],
], ),
), ),
); );
} }
void _onSaved() { void _onSaved() {
// Create the object using the controller text
final newCmd = ServerCommand( final newCmd = ServerCommand(
name: nameController.text, name: nameController.text,
ip: ipController.text, ip: ipController.text,
@ -226,9 +228,6 @@ class _AddClientState extends State<AddClient> {
password: passController.text, password: passController.text,
); );
print("Saving: ${newCmd.name}");
// Send the object BACK to the previous screen (Home)
Navigator.pop(context, newCmd); Navigator.pop(context, newCmd);
} }
} }

View File

@ -61,246 +61,252 @@ class _EditClientState extends State<EditClient> {
}, },
), ),
), ),
body: Column( body: Padding(
children: [ padding: const EdgeInsets.symmetric(horizontal: 8.0),
const SizedBox(height: 20), child: Column(
TextField( children: [
style: TextStyle(color: theme.onSurface), const SizedBox(height: 20),
controller: nameController, TextField(
decoration: InputDecoration( style: TextStyle(color: theme.onSurface),
filled: true, controller: nameController,
fillColor: theme.primaryContainer, decoration: InputDecoration(
labelText: 'Command name', filled: true,
labelStyle: TextStyle( fillColor: theme.primaryContainer,
color: theme.onSurfaceVariant, labelText: 'Command name',
fontSize: 20, labelStyle: TextStyle(
fontWeight: FontWeight.bold, color: theme.onSurfaceVariant,
), fontSize: 20,
border: OutlineInputBorder( fontWeight: FontWeight.bold,
borderRadius: BorderRadius.circular(10), ),
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)), border: OutlineInputBorder(
), borderRadius: BorderRadius.circular(10),
focusedBorder: OutlineInputBorder( borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
borderRadius: BorderRadius.circular(10), ),
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)), focusedBorder: OutlineInputBorder(
), borderRadius: BorderRadius.circular(10),
enabledBorder: OutlineInputBorder( borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
borderRadius: BorderRadius.circular(20), ),
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),
const SizedBox(height: 20), TextField(
TextField( style: TextStyle(color: theme.onSurface),
style: TextStyle(color: theme.onSurface), controller: ipController,
controller: ipController, decoration: InputDecoration(
decoration: InputDecoration( filled: true,
filled: true, fillColor: theme.primaryContainer,
fillColor: theme.primaryContainer, labelText: 'Host (IP address)',
labelText: 'Host (IP address)', labelStyle: TextStyle(
labelStyle: TextStyle( color: theme.onSurfaceVariant,
color: theme.onSurfaceVariant, fontSize: 20,
fontSize: 20, fontWeight: FontWeight.bold,
fontWeight: FontWeight.bold, ),
), border: OutlineInputBorder(
border: OutlineInputBorder( borderRadius: BorderRadius.circular(10),
borderRadius: BorderRadius.circular(10), borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)), ),
), focusedBorder: OutlineInputBorder(
focusedBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(10),
borderRadius: BorderRadius.circular(10), borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)), ),
), enabledBorder: OutlineInputBorder(
enabledBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(20),
borderRadius: BorderRadius.circular(20), borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)), ),
), ),
), ),
), const SizedBox(height: 20),
const SizedBox(height: 20), TextField(
TextField( style: TextStyle(color: theme.onSurface),
style: TextStyle(color: theme.onSurface), controller: userController,
controller: userController, decoration: InputDecoration(
decoration: InputDecoration( filled: true,
filled: true, fillColor: theme.primaryContainer,
fillColor: theme.primaryContainer, labelText: 'Login as (user)',
labelText: 'Login as (user)', labelStyle: TextStyle(
labelStyle: TextStyle( color: theme.onSurfaceVariant,
color: theme.onSurfaceVariant, fontSize: 20,
fontSize: 20, fontWeight: FontWeight.bold,
fontWeight: FontWeight.bold, ),
), border: OutlineInputBorder(
border: OutlineInputBorder( borderRadius: BorderRadius.circular(10),
borderRadius: BorderRadius.circular(10), borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)), ),
), focusedBorder: OutlineInputBorder(
focusedBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(10),
borderRadius: BorderRadius.circular(10), borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)), ),
), enabledBorder: OutlineInputBorder(
enabledBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(20),
borderRadius: BorderRadius.circular(20), borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)), ),
), ),
), ),
), const SizedBox(height: 20),
const SizedBox(height: 20), TextField(
TextField( style: TextStyle(color: theme.onSurface),
style: TextStyle(color: theme.onSurface), controller: passController,
controller: passController, obscureText: true,
obscureText: true, decoration: InputDecoration(
decoration: InputDecoration( filled: true,
filled: true, fillColor: theme.primaryContainer,
fillColor: theme.primaryContainer, labelText: 'Password',
labelText: 'Password', labelStyle: TextStyle(
labelStyle: TextStyle( color: theme.onSurfaceVariant,
color: theme.onSurfaceVariant, fontSize: 20,
fontSize: 20, fontWeight: FontWeight.bold,
fontWeight: FontWeight.bold, ),
), border: OutlineInputBorder(
border: OutlineInputBorder( borderRadius: BorderRadius.circular(10),
borderRadius: BorderRadius.circular(10), borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)), ),
), focusedBorder: OutlineInputBorder(
focusedBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(10),
borderRadius: BorderRadius.circular(10), borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)), ),
), enabledBorder: OutlineInputBorder(
enabledBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(20),
borderRadius: BorderRadius.circular(20), borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)), ),
), ),
), ),
), const SizedBox(height: 20),
const SizedBox(height: 20), TextField(
TextField( style: TextStyle(color: theme.onSurface),
style: TextStyle(color: theme.onSurface), controller: cmdController,
controller: cmdController, minLines: 3,
minLines: 3, maxLines: 100,
maxLines: 100, decoration: InputDecoration(
decoration: InputDecoration( filled: true,
filled: true, fillColor: theme.primaryContainer,
fillColor: theme.primaryContainer, labelText: 'Command',
labelText: 'Command', labelStyle: TextStyle(
labelStyle: TextStyle( color: theme.onSurfaceVariant,
color: theme.onSurfaceVariant, fontSize: 20,
fontSize: 20, fontWeight: FontWeight.bold,
fontWeight: FontWeight.bold, ),
), border: OutlineInputBorder(
border: OutlineInputBorder( borderRadius: BorderRadius.circular(10),
borderRadius: BorderRadius.circular(10), borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)), ),
), focusedBorder: OutlineInputBorder(
focusedBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(10),
borderRadius: BorderRadius.circular(10), borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)), ),
), enabledBorder: OutlineInputBorder(
enabledBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(20),
borderRadius: BorderRadius.circular(20), borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)), ),
), ),
), ),
), Spacer(),
Spacer(), Padding(
Padding( padding: const EdgeInsets.symmetric(
padding: const EdgeInsets.symmetric(horizontal: 20.0, vertical: 20), horizontal: 20.0,
child: Row( vertical: 20,
mainAxisAlignment: MainAxisAlignment.spaceBetween, ),
children: [ child: Row(
ElevatedButton( mainAxisAlignment: MainAxisAlignment.spaceBetween,
onPressed: () { children: [
showModalBottomSheet( ElevatedButton(
context: context, onPressed: () {
shape: const RoundedRectangleBorder( showModalBottomSheet(
borderRadius: BorderRadius.vertical( context: context,
top: Radius.circular(25.0), 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,
),
),
),
],
),
],
),
), ),
); ),
}, builder: (BuildContext context) {
); return SizedBox(
}, height: 400,
style: ElevatedButton.styleFrom( child: Center(
backgroundColor: theme.error, child: Column(
fixedSize: const Size(140, 40), mainAxisAlignment: MainAxisAlignment.center,
), children: [
child: Text( const Text(
'Remove', 'Remove this command?',
style: TextStyle( style: TextStyle(fontSize: 20),
color: const Color.fromARGB(255, 0, 0, 0), ),
fontWeight: FontWeight.bold, 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(
ElevatedButton( onPressed: _save,
onPressed: _save, style: ElevatedButton.styleFrom(
style: ElevatedButton.styleFrom( backgroundColor: theme.onSurface,
backgroundColor: theme.onSurface, fixedSize: const Size(140, 40),
fixedSize: const Size(140, 40), ),
), child: Text(
child: Text( 'Save',
'Save', style: TextStyle(
style: TextStyle( color: theme.surface,
color: theme.surface, fontWeight: FontWeight.bold,
fontWeight: FontWeight.bold, ),
), ),
), ),
), ],
], ),
), ),
), ],
], ),
), ),
); );
} }

View File

@ -4,6 +4,7 @@ import '../widgets/server_status_tile.dart';
import 'add_client.dart'; import 'add_client.dart';
import 'package:QuickSSH/classes/ServerCommand.dart'; import 'package:QuickSSH/classes/ServerCommand.dart';
import 'package:QuickSSH/services/storage_service.dart'; import 'package:QuickSSH/services/storage_service.dart';
import 'package:QuickSSH/screens/settings.dart';
class HomeScreen extends StatefulWidget { class HomeScreen extends StatefulWidget {
const HomeScreen({super.key}); const HomeScreen({super.key});
@ -45,29 +46,37 @@ class _HomeScreenState extends State<HomeScreen> {
), ),
drawer: Drawer( drawer: Drawer(
backgroundColor: theme.primaryContainer, backgroundColor: theme.primaryContainer,
child: ListView( child: Padding(
children: [ padding: const EdgeInsets.all(16.0),
ListTile( child: ListView(
title: Text( children: [
"Settings", InkWell(
style: TextStyle( borderRadius: BorderRadius.circular(16),
color: theme.onSurface, onTap: _openSettings,
fontWeight: FontWeight.bold, child: Padding(
fontSize: 20, padding: const EdgeInsets.all(8.0),
child: Text(
"Settings",
style: TextStyle(
color: theme.onSurface,
fontWeight: FontWeight.bold,
fontSize: 20,
),
),
), ),
), ),
), ListTile(
ListTile( title: Text(
title: Text( "Help",
"Help", style: TextStyle(
style: TextStyle( color: theme.onSurface,
color: theme.onSurface, fontWeight: FontWeight.bold,
fontWeight: FontWeight.bold, fontSize: 20,
fontSize: 20, ),
), ),
), ),
), ],
], ),
), ),
), ),
body: ListView.builder( body: ListView.builder(
@ -102,24 +111,16 @@ class _HomeScreenState extends State<HomeScreen> {
} }
void _addCommand() async { void _addCommand() async {
// 1. Must be async
print("Opening Add Screen...");
final result = await Navigator.push( final result = await Navigator.push(
// 2. Must have await
context, context,
MaterialPageRoute(builder: (context) => const AddClient()), MaterialPageRoute(builder: (context) => const AddClient()),
); );
// This part only runs AFTER you come back from AddClient
if (result != null) { if (result != null) {
print("Received data: ${result.name}");
setState(() { setState(() {
allCommands.add(result); allCommands.add(result);
}); });
SecureStorageService.saveCommands(allCommands); SecureStorageService.saveCommands(allCommands);
} else {
print("Result was null - user might have just hit 'Back'");
} }
} }
@ -140,13 +141,17 @@ class _HomeScreenState extends State<HomeScreen> {
return; return;
} }
print("Received edited data: ${result.name}");
setState(() { setState(() {
allCommands[index] = result; allCommands[index] = result;
}); });
SecureStorageService.saveCommands(allCommands); SecureStorageService.saveCommands(allCommands);
} else {
print("Edit result was null - user might have just hit 'Back'");
} }
} }
_openSettings() {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const Settings()),
);
}
} }

117
lib/screens/settings.dart Normal file
View File

@ -0,0 +1,117 @@
import 'package:QuickSSH/main.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class Settings extends StatefulWidget {
const Settings({super.key});
@override
State<Settings> createState() => _SettingsState();
}
class _SettingsState extends State<Settings> {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context).colorScheme;
return Scaffold(
appBar: AppBar(
backgroundColor: theme.surface,
title: Text("Settings", 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: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: Column(
children: [
Row(
children: [
Expanded(
child: Text(
"Appearance",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20,
color: theme.onSurface,
),
),
),
Expanded(
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 4,
),
decoration: BoxDecoration(
color: theme.primaryContainer,
borderRadius: BorderRadius.circular(16),
),
child: DropdownButton<ThemeMode>(
value: themeController.themeMode,
underline: Container(),
items: const [
DropdownMenuItem(
value: ThemeMode.system,
child: Text("System Default"),
),
DropdownMenuItem(
value: ThemeMode.dark,
child: Text("Dark"),
),
DropdownMenuItem(
value: ThemeMode.light,
child: Text("Light"),
),
],
onChanged: (ThemeMode? newMode) {
themeController.updateTheme(newMode);
setState(() {});
},
),
),
),
],
),
SizedBox(height: 20),
Row(
children: [
Expanded(
child: Text(
"Vibrations",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20,
color: theme.onSurface,
),
),
),
Expanded(
child: Switch(
activeTrackColor: theme.primary,
activeThumbColor: theme.onPrimary,
inactiveThumbColor: theme.onSurface,
inactiveTrackColor: theme.surface,
value: settingsController.vibrationEnabled,
onChanged: (bool value) {
settingsController.toggleVibration(value);
if (value) HapticFeedback.mediumImpact();
setState(() {});
},
),
),
],
),
],
),
),
);
}
}

View File

@ -5,27 +5,23 @@ import 'package:QuickSSH/classes/ServerCommand.dart';
class SSHService { class SSHService {
static Future<String> execute(ServerCommand server) async { static Future<String> execute(ServerCommand server) async {
try { try {
// 1. Connect to the IP and Port
final socket = await SSHSocket.connect( final socket = await SSHSocket.connect(
server.ip, server.ip,
22, 22,
timeout: const Duration(seconds: 10), timeout: const Duration(seconds: 10),
); );
// 2. Authenticate
final client = SSHClient( final client = SSHClient(
socket, socket,
username: server.username, username: server.username,
onPasswordRequest: () => server.password, onPasswordRequest: () => server.password,
); );
// 3. Run the specific command
final result = await client.run(server.command); final result = await client.run(server.command);
client.close(); client.close();
await client.done; await client.done;
// 4. Return the server's response
return utf8.decode(result); return utf8.decode(result);
} catch (e) { } catch (e) {
return "Error: $e"; return "Error: $e";

View File

@ -0,0 +1,24 @@
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
class SettingsController extends ChangeNotifier {
bool _vibrationEnabled = true;
bool get vibrationEnabled => _vibrationEnabled;
SettingsController() {
_loadSettings();
}
Future<void> _loadSettings() async {
final prefs = await SharedPreferences.getInstance();
_vibrationEnabled = prefs.getBool('vibration_enabled') ?? true;
notifyListeners();
}
Future<void> toggleVibration(bool value) async {
_vibrationEnabled = value;
final prefs = await SharedPreferences.getInstance();
await prefs.setBool('vibration_enabled', value);
notifyListeners();
}
}

View File

@ -0,0 +1,31 @@
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
class ThemeController extends ChangeNotifier {
ThemeMode _themeMode = ThemeMode.system;
ThemeMode get themeMode => _themeMode;
ThemeController() {
_loadTheme();
}
// Load saved theme from disk
Future<void> _loadTheme() async {
final prefs = await SharedPreferences.getInstance();
final themeIndex = prefs.getInt('theme_mode') ?? 0;
_themeMode = ThemeMode.values[themeIndex];
notifyListeners();
}
// Update and save theme
Future<void> updateTheme(ThemeMode? newThemeMode) async {
if (newThemeMode == null || newThemeMode == _themeMode) return;
_themeMode = newThemeMode;
notifyListeners();
final prefs = await SharedPreferences.getInstance();
await prefs.setInt('theme_mode', newThemeMode.index);
}
}

View File

@ -1,3 +1,4 @@
import 'package:QuickSSH/main.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:QuickSSH/classes/ServerCommand.dart'; import 'package:QuickSSH/classes/ServerCommand.dart';
import 'package:QuickSSH/services/SSHService.dart'; import 'package:QuickSSH/services/SSHService.dart';
@ -21,21 +22,16 @@ class ServerStatusTile extends StatelessWidget {
clipBehavior: Clip.antiAlias, clipBehavior: Clip.antiAlias,
color: theme.primaryContainer, color: theme.primaryContainer,
child: InkWell( child: InkWell(
splashColor: const Color.fromARGB( splashColor: const Color.fromARGB(47, 255, 255, 255),
47,
255,
255,
255,
), // Custom ripple color!
highlightColor: Colors.transparent, highlightColor: Colors.transparent,
onDoubleTap: () { onDoubleTap: () {
HapticFeedback.heavyImpact(); if (settingsController.vibrationEnabled) HapticFeedback.heavyImpact();
_handleCommandTap(context, command); _handleCommandTap(context, command);
}, },
onLongPress: () { onLongPress: () {
HapticFeedback.heavyImpact(); if (settingsController.vibrationEnabled) HapticFeedback.heavyImpact();
onEdit(); onEdit();
}, },

View File

@ -1,30 +0,0 @@
// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility in the flutter_test package. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:quick_ssh/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const MyApp());
// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
await tester.pump();
// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
});
}