extra form validation and connection list done
This commit is contained in:
parent
bd8884787d
commit
789cea13a1
5 changed files with 281 additions and 74 deletions
147
lib/sftp_connection_list.dart
Normal file
147
lib/sftp_connection_list.dart
Normal file
|
@ -0,0 +1,147 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:fluxcloud/add_server_modal.dart';
|
||||
import 'package:fluxcloud/connection.dart';
|
||||
|
||||
class SftpConnectionList extends StatefulWidget {
|
||||
const SftpConnectionList({
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
State<SftpConnectionList> createState() => _SftpConnectionListState();
|
||||
}
|
||||
|
||||
class _SftpConnectionListState extends State<SftpConnectionList> {
|
||||
|
||||
late List<Connection> _connections;
|
||||
bool _isConnectionsInit = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_getConnections();
|
||||
}
|
||||
|
||||
Future<void> _getConnections() async {
|
||||
final storage = FlutterSecureStorage();
|
||||
final secureMap = await storage.readAll();
|
||||
setState(() {
|
||||
_connections = secureMap.values.map((json) => Connection.fromJson(jsonDecode(json))).toList();
|
||||
_isConnectionsInit = true;
|
||||
});
|
||||
}
|
||||
|
||||
String _getAuthString(int index) {
|
||||
String result = 'Auth: ';
|
||||
final hasKey = _connections[index].privateKey?.isNotEmpty ?? false;
|
||||
final hasPass = _connections[index].password?.isNotEmpty ?? false;
|
||||
|
||||
if (hasKey) result += 'Private Key';
|
||||
if (hasKey && hasPass) result += ', ';
|
||||
if (hasPass) result += 'Password';
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void _showBottomSheet(BuildContext context, Connection? initialState) {
|
||||
showModalBottomSheet(
|
||||
isScrollControlled: true,
|
||||
context: context,
|
||||
showDragHandle: true,
|
||||
builder: (context) => AddServerModal(updateConnectionList: _getConnections, initialState: initialState,)
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
floatingActionButton: FloatingActionButton(
|
||||
child: Icon(Icons.add),
|
||||
onPressed: () => _showBottomSheet(context, null)
|
||||
),
|
||||
body: _isConnectionsInit ? RefreshIndicator(
|
||||
onRefresh: () => _getConnections(),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: ListView.builder(
|
||||
itemCount: _connections.length,
|
||||
itemBuilder: (context, index) {
|
||||
return Column(
|
||||
children: [
|
||||
Material(
|
||||
color: Theme.of(context).colorScheme.onSecondary,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
// TODO: connect to connection here
|
||||
},
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Row(
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
_connections[index].host!,
|
||||
style: TextStyle(fontSize: 20),
|
||||
),
|
||||
Text('Port: ${_connections[index].port}'),
|
||||
Text('Username: ${_connections[index].username}'),
|
||||
Text(_getAuthString(index)),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text('Encryption: '),
|
||||
Icon(
|
||||
_connections[index].isEncryptionEnabled! ? Icons.check : Icons.close,
|
||||
size: 18
|
||||
)
|
||||
],
|
||||
),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text('Default: '),
|
||||
Icon(
|
||||
_connections[index].isDefault! ? Icons.check : Icons.close,
|
||||
size: 18
|
||||
)
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
Expanded(child: SizedBox()),
|
||||
IconButton(
|
||||
onPressed: () => _showBottomSheet(context, _connections[index]),
|
||||
icon: Icon(Icons.edit)
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
final storage = FlutterSecureStorage();
|
||||
storage.delete(key: _connections[index].host!);
|
||||
_getConnections();
|
||||
},
|
||||
icon: Icon(Icons.delete)
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 10,)
|
||||
],
|
||||
);
|
||||
}
|
||||
),
|
||||
),
|
||||
) : Center(child: CircularProgressIndicator())
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue