@@ -24,7 +24,10 @@ class _ServerSettingsState extends State<ServerSettings> {
2424 final _settingsBox = Hive .box ('settings' );
2525
2626 final _serverAddressController = TextEditingController ();
27+ final _apiKeyController = TextEditingController ();
28+ final _apiKeyFocusNode = FocusNode ();
2729
30+ bool _apiKeyObscured = true ;
2831 OllamaRequestState _requestState = OllamaRequestState .uninitialized;
2932 get _isLoading => _requestState == OllamaRequestState .loading;
3033
@@ -34,21 +37,36 @@ class _ServerSettingsState extends State<ServerSettings> {
3437 void initState () {
3538 super .initState ();
3639
40+ _apiKeyFocusNode.addListener (() {
41+ if (_apiKeyFocusNode.hasFocus) {
42+ setState (() => _apiKeyObscured = false );
43+ } else {
44+ setState (() => _apiKeyObscured = true );
45+ }
46+ });
47+
3748 _initialize ();
3849 }
3950
4051 _initialize () {
4152 final serverAddress = _settingsBox.get ('serverAddress' );
53+ final apiKey = _settingsBox.get ('apiKey' );
4254
4355 if (serverAddress != null ) {
4456 _serverAddressController.text = serverAddress;
4557 _handleConnectButton ();
4658 }
59+
60+ if (apiKey != null ) {
61+ _apiKeyController.text = apiKey;
62+ }
4763 }
4864
4965 @override
5066 void dispose () {
5167 _serverAddressController.dispose ();
68+ _apiKeyController.dispose ();
69+ _apiKeyFocusNode.dispose ();
5270
5371 super .dispose ();
5472 }
@@ -89,6 +107,23 @@ class _ServerSettingsState extends State<ServerSettings> {
89107 },
90108 ),
91109 const SizedBox (height: 16 ),
110+ TextField (
111+ controller: _apiKeyController,
112+ focusNode: _apiKeyFocusNode,
113+ keyboardType: TextInputType .text,
114+ obscureText: _apiKeyObscured,
115+ onChanged: (value) {
116+ _settingsBox.put ('apiKey' , value);
117+ },
118+ decoration: InputDecoration (
119+ labelText: 'API key' ,
120+ border: OutlineInputBorder (),
121+ ),
122+ onTapOutside: (PointerDownEvent event) {
123+ FocusManager .instance.primaryFocus? .unfocus ();
124+ },
125+ ),
126+ const SizedBox (height: 16 ),
92127 SizedBox (
93128 width: double .infinity,
94129 child: Wrap (
0 commit comments