diff --git a/lib/model/user_setting.dart b/lib/model/user_setting.dart index d3daf38..a8c9390 100644 --- a/lib/model/user_setting.dart +++ b/lib/model/user_setting.dart @@ -9,6 +9,7 @@ class Setting { String? host; String? path; String? nodeId; + bool? customLambdaServer; String? lambdaServer; String? rune; @@ -17,7 +18,8 @@ class Setting { this.host, this.path, this.nodeId, - this.lambdaServer = "https://lnlambda.lnmetrics.info", + this.customLambdaServer, + this.lambdaServer, this.rune}) { clientMode = ClientProvider.getClientByDefPlatform().first; } @@ -56,6 +58,7 @@ class Setting { 'nodeId': nodeId, 'host': host, 'rune': rune, + 'customLambdaServer': customLambdaServer, 'lambdaServer': lambdaServer, }; } @@ -73,6 +76,7 @@ class Setting { return path != null; case ClientMode.lnlambda: return nodeId != null && + customLambdaServer != null && lambdaServer != null && rune != null && host != null; diff --git a/lib/model/user_setting.g.dart b/lib/model/user_setting.g.dart index e690490..f036dd8 100644 --- a/lib/model/user_setting.g.dart +++ b/lib/model/user_setting.g.dart @@ -11,6 +11,7 @@ Setting _$SettingFromJson(Map json) => Setting( host: json['host'] as String?, path: json['path'] as String?, nodeId: json['nodeId'] as String?, + customLambdaServer: json['customLambdaServer'] as bool?, lambdaServer: json['lambdaServer'] as String?, rune: json['rune'] as String?, ); @@ -28,6 +29,7 @@ Map _$SettingToJson(Setting instance) { writeNotNull('host', instance.host); writeNotNull('path', instance.path); writeNotNull('nodeId', instance.nodeId); + writeNotNull('customLambdaServer', instance.customLambdaServer); writeNotNull('lambdaServer', instance.lambdaServer); writeNotNull('rune', instance.rune); return val; diff --git a/lib/views/setting/lnlambda_setting_view.dart b/lib/views/setting/lnlambda_setting_view.dart index 8b63c39..a3d2591 100644 --- a/lib/views/setting/lnlambda_setting_view.dart +++ b/lib/views/setting/lnlambda_setting_view.dart @@ -40,16 +40,48 @@ class _LnlambdaSettingViewState extends State { ), ), const Text("Lambda Server"), - TextFormField( - controller: TextEditingController(text: setting.lambdaServer), - onChanged: (text) { - setting.lambdaServer = text; + DropdownButtonFormField( + value: setting.customLambdaServer == null + ? null + : setting.customLambdaServer == true + ? 'custom' + : setting.lambdaServer, + items: const [ + DropdownMenuItem( + value: 'https://lnlambda.lnmetrics.info', + child: Text("https://lnlambda.lnmetrics.info"), + ), + DropdownMenuItem( + value: 'custom', + child: Text("Enter lambda server url manually"), + ), + ], + onChanged: (value) { + setState(() { + if (value == 'custom') { + setting.customLambdaServer = true; + } else { + setting.customLambdaServer = false; + setting.lambdaServer = value as String; + } + }); }, - decoration: const InputDecoration( - label: Text("lnlambda server url"), - border: OutlineInputBorder(), - ), ), + () { + if (setting.customLambdaServer == true) { + return TextFormField( + controller: TextEditingController(text: setting.lambdaServer), + onChanged: (text) { + setting.lambdaServer = text; + }, + decoration: const InputDecoration( + label: Text("lnlambda server url"), + border: OutlineInputBorder(), + ), + ); + } + return const SizedBox(); + }(), const Text("Rune"), TextFormField( controller: TextEditingController(text: setting.rune ?? ''),