From 8a18e7a4c9ddd4788915ae365350813e6d6cc909 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Wed, 5 Mar 2025 10:31:18 -0600 Subject: [PATCH] Create management portal in Flutter #39 --- .../lib/widgets/add_mount_widget.dart | 116 ++++-------------- 1 file changed, 25 insertions(+), 91 deletions(-) diff --git a/web/repertory/lib/widgets/add_mount_widget.dart b/web/repertory/lib/widgets/add_mount_widget.dart index c8d4df7f..500906ef 100644 --- a/web/repertory/lib/widgets/add_mount_widget.dart +++ b/web/repertory/lib/widgets/add_mount_widget.dart @@ -30,6 +30,7 @@ class AddMountWidget extends StatefulWidget { class _AddMountWidgetState extends State { static const _items = ['Encrypt', 'Remote', 'S3', 'Sia']; + static const _padding = 10.0; String? _mountType; @@ -39,6 +40,21 @@ class _AddMountWidgetState extends State { super.initState(); } + List _createTextField(String name, onChanged) { + return [ + const SizedBox(height: _padding), + Text( + name, + textAlign: TextAlign.left, + style: TextStyle( + color: Theme.of(context).colorScheme.onSurface, + fontWeight: FontWeight.bold, + ), + ), + TextField(decoration: InputDecoration(), onChanged: onChanged), + ]; + } + @override Widget build(BuildContext context) { final mountTypeLower = _mountType?.toLowerCase(); @@ -59,7 +75,7 @@ class _AddMountWidgetState extends State { fontWeight: FontWeight.bold, ), ), - const SizedBox(width: 10), + const SizedBox(width: _padding), DropdownButton( value: _mountType, onChanged: (value) { @@ -78,103 +94,21 @@ class _AddMountWidgetState extends State { ), ], ), - const SizedBox(height: 10), - Text( - 'Configuration Name', - textAlign: TextAlign.left, - style: TextStyle( - color: Theme.of(context).colorScheme.onSurface, - fontWeight: FontWeight.bold, - ), - ), - TextField( - autofocus: true, - decoration: InputDecoration(), - onChanged: widget.onNameChanged, - ), + ..._createTextField('Configuration Name', widget.onNameChanged), if (mountTypeLower == 'encrypt') - Text( - 'Path', - textAlign: TextAlign.left, - style: TextStyle( - color: Theme.of(context).colorScheme.onSurface, - fontWeight: FontWeight.bold, - ), - ), - if (mountTypeLower == 'encrypt') - TextField( - decoration: InputDecoration(), - onChanged: widget.onPathChanged, - ), + ..._createTextField('Path', widget.onPathChanged), if (mountTypeLower == 'sia') - Text( - 'ApiAuth', - textAlign: TextAlign.left, - style: TextStyle( - color: Theme.of(context).colorScheme.onSurface, - fontWeight: FontWeight.bold, - ), - ), - if (mountTypeLower == 'sia') - TextField( - decoration: InputDecoration(), - onChanged: widget.onApiAuthChanged, - ), + ..._createTextField('ApiAuth', widget.onApiAuthChanged), if (mountTypeLower == 's3' || mountTypeLower == 'sia') - Text( - 'Bucket', - textAlign: TextAlign.left, - style: TextStyle( - color: Theme.of(context).colorScheme.onSurface, - fontWeight: FontWeight.bold, - ), - ), - if (mountTypeLower == 's3' || mountTypeLower == 'sia') - TextField( - decoration: InputDecoration(), - onChanged: widget.onBucketChanged, - ), + ..._createTextField('Bucket', widget.onBucketChanged), if (mountTypeLower == 'remote') - Text( - 'HostNameOrIp', - textAlign: TextAlign.left, - style: TextStyle( - color: Theme.of(context).colorScheme.onSurface, - fontWeight: FontWeight.bold, - ), - ), + ..._createTextField('HostNameOrIp', widget.onHostNameOrIpChanged), if (mountTypeLower == 'remote') - TextField( - decoration: InputDecoration(), - onChanged: widget.onHostNameOrIpChanged, - ), + ..._createTextField('ApiPort', widget.onApiPortChanged), if (mountTypeLower == 'remote') - Text( - 'ApiPort', - textAlign: TextAlign.left, - style: TextStyle( - color: Theme.of(context).colorScheme.onSurface, - fontWeight: FontWeight.bold, - ), - ), - if (mountTypeLower == 'remote') - TextField( - decoration: InputDecoration(), - onChanged: widget.onApiPortChanged, - ), - if (mountTypeLower == 'remote') - Text( + ..._createTextField( 'EncryptionToken', - textAlign: TextAlign.left, - style: TextStyle( - color: Theme.of(context).colorScheme.onSurface, - fontWeight: FontWeight.bold, - ), - ), - if (mountTypeLower == 'remote') - TextField( - decoration: InputDecoration(), - onChanged: widget.onEncryptionTokenChanged, + widget.onEncryptionTokenChanged, ), ], );