[ui] Implement provider test button #49
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good

This commit is contained in:
Scott E. Graves 2025-04-24 10:48:13 -05:00
parent 3c8e1d5986
commit 45a46650a2
2 changed files with 70 additions and 53 deletions

View File

@ -21,6 +21,8 @@ class _AddMountScreenState extends State<AddMountScreen> {
Mount? _mount;
final _mountNameController = TextEditingController();
String _mountType = "";
bool _allowAdd = false;
final Map<String, Map<String, dynamic>> _settings = {
"": {},
"Encrypt": createDefaultSettings("Encrypt"),
@ -123,6 +125,7 @@ class _AddMountScreenState extends State<AddMountScreen> {
child: MountSettingsWidget(
isAdd: true,
mount: _mount!,
onChanged: () => setState(() => _allowAdd = false),
settings: _settings[_mountType]!,
showAdvanced: false,
),
@ -132,6 +135,7 @@ class _AddMountScreenState extends State<AddMountScreen> {
const SizedBox(height: constants.padding),
Row(
children: [
if (_allowAdd) ...[
ElevatedButton.icon(
label: const Text('Add'),
icon: const Icon(Icons.add),
@ -188,7 +192,8 @@ class _AddMountScreenState extends State<AddMountScreen> {
Navigator.pop(context);
},
),
const SizedBox(width: constants.padding),
],
if (!_allowAdd)
ElevatedButton.icon(
label: const Text('Test'),
icon: const Icon(Icons.check),
@ -237,14 +242,20 @@ class _AddMountScreenState extends State<AddMountScreen> {
return;
}
if (_allowAdd) {
return;
}
final success = await _mount!.test();
if (!mounted) {
return;
}
setState(() => _allowAdd = success);
displayErrorMessage(
context,
success ? "Success!" : "Provider settings are invalid!",
success ? "Success" : "Provider settings are invalid!",
);
}

View File

@ -18,9 +18,11 @@ class MountSettingsWidget extends StatefulWidget {
final bool showAdvanced;
final Mount mount;
final Map<String, dynamic> settings;
final Function? onChanged;
const MountSettingsWidget({
super.key,
this.isAdd = false,
this.onChanged,
required this.mount,
required this.settings,
required this.showAdvanced,
@ -1020,6 +1022,10 @@ class _MountSettingsWidgetState extends State<MountSettingsWidget> {
return;
}
if (widget.onChanged != null) {
widget.onChanged!();
}
super.setState(fn);
}
}