disable editing of default node fields

This commit is contained in:
julian 2023-01-09 09:15:53 -06:00
parent db2c7bb5ab
commit 1d057a7f22

View file

@ -671,7 +671,6 @@ class _NodeFormState extends ConsumerState<NodeForm> {
bool _trusted = false; bool _trusted = false;
int? port; int? port;
late bool enableSSLCheckbox; late bool enableSSLCheckbox;
late bool trustedCheckbox;
late final bool enableAuthFields; late final bool enableAuthFields;
@ -722,6 +721,9 @@ class _NodeFormState extends ConsumerState<NodeForm> {
return enable; return enable;
} }
bool get shouldBeReadOnly =>
widget.readOnly || widget.node?.isDefault == true;
void _updateState() { void _updateState() {
port = int.tryParse(_portController.text); port = int.tryParse(_portController.text);
onChanged?.call(canSave, canTestConnection); onChanged?.call(canSave, canTestConnection);
@ -775,11 +777,6 @@ class _NodeFormState extends ConsumerState<NodeForm> {
} else { } else {
enableSSLCheckbox = true; enableSSLCheckbox = true;
} }
if (widget.coin == Coin.monero || widget.coin == Coin.wownero) {
trustedCheckbox = node.trusted ?? false;
} else {
trustedCheckbox = false;
}
WidgetsBinding.instance.addPostFrameCallback((_) { WidgetsBinding.instance.addPostFrameCallback((_) {
// update provider state object so test connection works without having to modify a field in the ui first // update provider state object so test connection works without having to modify a field in the ui first
@ -822,7 +819,7 @@ class _NodeFormState extends ConsumerState<NodeForm> {
autocorrect: Util.isDesktop ? false : true, autocorrect: Util.isDesktop ? false : true,
enableSuggestions: Util.isDesktop ? false : true, enableSuggestions: Util.isDesktop ? false : true,
key: const Key("addCustomNodeNodeNameFieldKey"), key: const Key("addCustomNodeNodeNameFieldKey"),
readOnly: widget.readOnly, readOnly: shouldBeReadOnly,
enabled: enableField(_nameController), enabled: enableField(_nameController),
controller: _nameController, controller: _nameController,
focusNode: _nameFocusNode, focusNode: _nameFocusNode,
@ -832,7 +829,7 @@ class _NodeFormState extends ConsumerState<NodeForm> {
_nameFocusNode, _nameFocusNode,
context, context,
).copyWith( ).copyWith(
suffixIcon: !widget.readOnly && _nameController.text.isNotEmpty suffixIcon: !shouldBeReadOnly && _nameController.text.isNotEmpty
? Padding( ? Padding(
padding: const EdgeInsets.only(right: 0), padding: const EdgeInsets.only(right: 0),
child: UnconstrainedBox( child: UnconstrainedBox(
@ -868,7 +865,7 @@ class _NodeFormState extends ConsumerState<NodeForm> {
autocorrect: Util.isDesktop ? false : true, autocorrect: Util.isDesktop ? false : true,
enableSuggestions: Util.isDesktop ? false : true, enableSuggestions: Util.isDesktop ? false : true,
key: const Key("addCustomNodeNodeAddressFieldKey"), key: const Key("addCustomNodeNodeAddressFieldKey"),
readOnly: widget.readOnly, readOnly: shouldBeReadOnly,
enabled: enableField(_hostController), enabled: enableField(_hostController),
controller: _hostController, controller: _hostController,
focusNode: _hostFocusNode, focusNode: _hostFocusNode,
@ -880,7 +877,7 @@ class _NodeFormState extends ConsumerState<NodeForm> {
_hostFocusNode, _hostFocusNode,
context, context,
).copyWith( ).copyWith(
suffixIcon: !widget.readOnly && _hostController.text.isNotEmpty suffixIcon: !shouldBeReadOnly && _hostController.text.isNotEmpty
? Padding( ? Padding(
padding: const EdgeInsets.only(right: 0), padding: const EdgeInsets.only(right: 0),
child: UnconstrainedBox( child: UnconstrainedBox(
@ -927,7 +924,7 @@ class _NodeFormState extends ConsumerState<NodeForm> {
autocorrect: Util.isDesktop ? false : true, autocorrect: Util.isDesktop ? false : true,
enableSuggestions: Util.isDesktop ? false : true, enableSuggestions: Util.isDesktop ? false : true,
key: const Key("addCustomNodeNodePortFieldKey"), key: const Key("addCustomNodeNodePortFieldKey"),
readOnly: widget.readOnly, readOnly: shouldBeReadOnly,
enabled: enableField(_portController), enabled: enableField(_portController),
controller: _portController, controller: _portController,
focusNode: _portFocusNode, focusNode: _portFocusNode,
@ -939,7 +936,7 @@ class _NodeFormState extends ConsumerState<NodeForm> {
_portFocusNode, _portFocusNode,
context, context,
).copyWith( ).copyWith(
suffixIcon: !widget.readOnly && _portController.text.isNotEmpty suffixIcon: !shouldBeReadOnly && _portController.text.isNotEmpty
? Padding( ? Padding(
padding: const EdgeInsets.only(right: 0), padding: const EdgeInsets.only(right: 0),
child: UnconstrainedBox( child: UnconstrainedBox(
@ -976,7 +973,7 @@ class _NodeFormState extends ConsumerState<NodeForm> {
autocorrect: Util.isDesktop ? false : true, autocorrect: Util.isDesktop ? false : true,
enableSuggestions: Util.isDesktop ? false : true, enableSuggestions: Util.isDesktop ? false : true,
controller: _usernameController, controller: _usernameController,
readOnly: widget.readOnly, readOnly: shouldBeReadOnly,
enabled: enableField(_usernameController), enabled: enableField(_usernameController),
keyboardType: TextInputType.number, keyboardType: TextInputType.number,
focusNode: _usernameFocusNode, focusNode: _usernameFocusNode,
@ -987,7 +984,7 @@ class _NodeFormState extends ConsumerState<NodeForm> {
context, context,
).copyWith( ).copyWith(
suffixIcon: suffixIcon:
!widget.readOnly && _usernameController.text.isNotEmpty !shouldBeReadOnly && _usernameController.text.isNotEmpty
? Padding( ? Padding(
padding: const EdgeInsets.only(right: 0), padding: const EdgeInsets.only(right: 0),
child: UnconstrainedBox( child: UnconstrainedBox(
@ -1025,7 +1022,7 @@ class _NodeFormState extends ConsumerState<NodeForm> {
autocorrect: Util.isDesktop ? false : true, autocorrect: Util.isDesktop ? false : true,
enableSuggestions: Util.isDesktop ? false : true, enableSuggestions: Util.isDesktop ? false : true,
controller: _passwordController, controller: _passwordController,
readOnly: widget.readOnly, readOnly: shouldBeReadOnly,
enabled: enableField(_passwordController), enabled: enableField(_passwordController),
keyboardType: TextInputType.number, keyboardType: TextInputType.number,
focusNode: _passwordFocusNode, focusNode: _passwordFocusNode,
@ -1036,7 +1033,7 @@ class _NodeFormState extends ConsumerState<NodeForm> {
context, context,
).copyWith( ).copyWith(
suffixIcon: suffixIcon:
!widget.readOnly && _passwordController.text.isNotEmpty !shouldBeReadOnly && _passwordController.text.isNotEmpty
? Padding( ? Padding(
padding: const EdgeInsets.only(right: 0), padding: const EdgeInsets.only(right: 0),
child: UnconstrainedBox( child: UnconstrainedBox(
@ -1069,7 +1066,7 @@ class _NodeFormState extends ConsumerState<NodeForm> {
Row( Row(
children: [ children: [
GestureDetector( GestureDetector(
onTap: !widget.readOnly && enableSSLCheckbox onTap: !shouldBeReadOnly && enableSSLCheckbox
? () { ? () {
setState(() { setState(() {
_useSSL = !_useSSL; _useSSL = !_useSSL;
@ -1085,7 +1082,7 @@ class _NodeFormState extends ConsumerState<NodeForm> {
width: 20, width: 20,
height: 20, height: 20,
child: Checkbox( child: Checkbox(
fillColor: !widget.readOnly && enableSSLCheckbox fillColor: !shouldBeReadOnly && enableSSLCheckbox
? null ? null
: MaterialStateProperty.all(Theme.of(context) : MaterialStateProperty.all(Theme.of(context)
.extension<StackColors>()! .extension<StackColors>()!
@ -1093,7 +1090,7 @@ class _NodeFormState extends ConsumerState<NodeForm> {
materialTapTargetSize: materialTapTargetSize:
MaterialTapTargetSize.shrinkWrap, MaterialTapTargetSize.shrinkWrap,
value: _useSSL, value: _useSSL,
onChanged: !widget.readOnly && enableSSLCheckbox onChanged: !shouldBeReadOnly && enableSSLCheckbox
? (newValue) { ? (newValue) {
setState(() { setState(() {
_useSSL = newValue!; _useSSL = newValue!;
@ -1136,7 +1133,7 @@ class _NodeFormState extends ConsumerState<NodeForm> {
width: 20, width: 20,
height: 20, height: 20,
child: Checkbox( child: Checkbox(
fillColor: !widget.readOnly /*&& trustedCheckbox*/ fillColor: !widget.readOnly
? null ? null
: MaterialStateProperty.all(Theme.of(context) : MaterialStateProperty.all(Theme.of(context)
.extension<StackColors>()! .extension<StackColors>()!
@ -1144,7 +1141,7 @@ class _NodeFormState extends ConsumerState<NodeForm> {
materialTapTargetSize: materialTapTargetSize:
MaterialTapTargetSize.shrinkWrap, MaterialTapTargetSize.shrinkWrap,
value: _trusted, value: _trusted,
onChanged: !widget.readOnly /*&& trustedCheckbox*/ onChanged: !widget.readOnly
? (newValue) { ? (newValue) {
setState(() { setState(() {
_trusted = newValue!; _trusted = newValue!;