Resolves #126 Connection settings save button
This commit is contained in:
parent
c2b88c8a12
commit
17a3bd8d35
@ -62,7 +62,9 @@ class _TextEntityWidgetState extends _EntityWidgetState {
|
|||||||
new TextEditingValue(
|
new TextEditingValue(
|
||||||
text: _tmpValue,
|
text: _tmpValue,
|
||||||
selection:
|
selection:
|
||||||
new TextSelection.collapsed(offset: _tmpValue.length))),
|
new TextSelection.collapsed(offset: _tmpValue.length)
|
||||||
|
)
|
||||||
|
),
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
_tmpValue = value;
|
_tmpValue = value;
|
||||||
}),
|
}),
|
||||||
|
@ -11,15 +11,29 @@ class ConnectionSettingsPage extends StatefulWidget {
|
|||||||
|
|
||||||
class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> {
|
class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> {
|
||||||
String _hassioDomain = "";
|
String _hassioDomain = "";
|
||||||
|
String _newHassioDomain = "";
|
||||||
String _hassioPort = "";
|
String _hassioPort = "";
|
||||||
|
String _newHassioPort = "";
|
||||||
String _hassioPassword = "";
|
String _hassioPassword = "";
|
||||||
|
String _newHassioPassword = "";
|
||||||
String _socketProtocol = "wss";
|
String _socketProtocol = "wss";
|
||||||
|
String _newSocketProtocol = "wss";
|
||||||
String _authType = "access_token";
|
String _authType = "access_token";
|
||||||
|
String _newAuthType = "access_token";
|
||||||
bool _edited = false;
|
bool _edited = false;
|
||||||
|
FocusNode _domainFocusNode;
|
||||||
|
FocusNode _portFocusNode;
|
||||||
|
FocusNode _passwordFocusNode;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
_domainFocusNode = FocusNode();
|
||||||
|
_portFocusNode = FocusNode();
|
||||||
|
_passwordFocusNode = FocusNode();
|
||||||
|
_domainFocusNode.addListener(_checkConfigChanged);
|
||||||
|
_portFocusNode.addListener(_checkConfigChanged);
|
||||||
|
_passwordFocusNode.addListener(_checkConfigChanged);
|
||||||
_loadSettings();
|
_loadSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,11 +41,21 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> {
|
|||||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_hassioDomain = prefs.getString("hassio-domain")?? "";
|
_hassioDomain = _newHassioDomain = prefs.getString("hassio-domain")?? "";
|
||||||
_hassioPort = prefs.getString("hassio-port") ?? "";
|
_hassioPort = _newHassioPort = prefs.getString("hassio-port") ?? "";
|
||||||
_hassioPassword = prefs.getString("hassio-password") ?? "";
|
_hassioPassword = _newHassioPassword = prefs.getString("hassio-password") ?? "";
|
||||||
_socketProtocol = prefs.getString("hassio-protocol") ?? 'wss';
|
_socketProtocol = _newSocketProtocol = prefs.getString("hassio-protocol") ?? 'wss';
|
||||||
_authType = prefs.getString("hassio-auth-type") ?? 'access_token';
|
_authType = _newAuthType = prefs.getString("hassio-auth-type") ?? 'access_token';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void _checkConfigChanged() {
|
||||||
|
setState(() {
|
||||||
|
_edited = ((_newHassioPassword != _hassioPassword) ||
|
||||||
|
(_newHassioPort != _hassioPort) ||
|
||||||
|
(_newHassioDomain != _hassioDomain) ||
|
||||||
|
(_newSocketProtocol != _socketProtocol) ||
|
||||||
|
(_newAuthType != _authType));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,12 +99,10 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> {
|
|||||||
children: [
|
children: [
|
||||||
Text("Use ssl (HTTPS)"),
|
Text("Use ssl (HTTPS)"),
|
||||||
Switch(
|
Switch(
|
||||||
value: (_socketProtocol == "wss"),
|
value: (_newSocketProtocol == "wss"),
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
setState(() {
|
_newSocketProtocol = value ? "wss" : "ws";
|
||||||
_socketProtocol = value ? "wss" : "ws";
|
_checkConfigChanged();
|
||||||
_edited = true;
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
@ -89,35 +111,45 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> {
|
|||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: "Home Assistant domain or ip address"
|
labelText: "Home Assistant domain or ip address"
|
||||||
),
|
),
|
||||||
controller: TextEditingController(
|
controller: new TextEditingController.fromValue(
|
||||||
text: _hassioDomain
|
new TextEditingValue(
|
||||||
|
text: _newHassioDomain,
|
||||||
|
selection:
|
||||||
|
new TextSelection.collapsed(offset: _newHassioDomain.length)
|
||||||
|
)
|
||||||
),
|
),
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
_hassioDomain = value;
|
_newHassioDomain = value;
|
||||||
},
|
},
|
||||||
|
focusNode: _domainFocusNode,
|
||||||
|
onEditingComplete: _checkConfigChanged,
|
||||||
),
|
),
|
||||||
new TextField(
|
new TextField(
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: "Home Assistant port (default is 8123)"
|
labelText: "Home Assistant port (default is 8123)"
|
||||||
),
|
),
|
||||||
controller: TextEditingController(
|
controller: new TextEditingController.fromValue(
|
||||||
text: _hassioPort
|
new TextEditingValue(
|
||||||
|
text: _newHassioPort,
|
||||||
|
selection:
|
||||||
|
new TextSelection.collapsed(offset: _newHassioPort.length)
|
||||||
|
)
|
||||||
),
|
),
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
_hassioPort = value;
|
_newHassioPort = value;
|
||||||
//_saveSettings();
|
//_saveSettings();
|
||||||
},
|
},
|
||||||
|
focusNode: _portFocusNode,
|
||||||
|
onEditingComplete: _checkConfigChanged,
|
||||||
),
|
),
|
||||||
new Row(
|
new Row(
|
||||||
children: [
|
children: [
|
||||||
Text("Login with access token (HA >= 0.78.0)"),
|
Text("Login with access token (HA >= 0.78.0)"),
|
||||||
Switch(
|
Switch(
|
||||||
value: (_authType == "access_token"),
|
value: (_newAuthType == "access_token"),
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
setState(() {
|
_newAuthType = value ? "access_token" : "api_password";
|
||||||
_authType = value ? "access_token" : "api_password";
|
_checkConfigChanged();
|
||||||
_edited = true;
|
|
||||||
});
|
|
||||||
//_saveSettings();
|
//_saveSettings();
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@ -127,16 +159,33 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> {
|
|||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: _authType == "access_token" ? "Access token" : "API password"
|
labelText: _authType == "access_token" ? "Access token" : "API password"
|
||||||
),
|
),
|
||||||
controller: TextEditingController(
|
controller: new TextEditingController.fromValue(
|
||||||
text: _hassioPassword
|
new TextEditingValue(
|
||||||
|
text: _newHassioPassword,
|
||||||
|
selection:
|
||||||
|
new TextSelection.collapsed(offset: _newHassioPassword.length)
|
||||||
|
)
|
||||||
),
|
),
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
_hassioPassword = value;
|
_newHassioPassword = value;
|
||||||
//_saveSettings();
|
//_saveSettings();
|
||||||
},
|
},
|
||||||
|
focusNode: _passwordFocusNode,
|
||||||
|
onEditingComplete: _checkConfigChanged,
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_domainFocusNode.removeListener(_checkConfigChanged);
|
||||||
|
_portFocusNode.removeListener(_checkConfigChanged);
|
||||||
|
_passwordFocusNode.removeListener(_checkConfigChanged);
|
||||||
|
_domainFocusNode.dispose();
|
||||||
|
_portFocusNode.dispose();
|
||||||
|
_passwordFocusNode.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user