Resolves #170 Saving settings button issue fix

This commit is contained in:
Yegor Vialov 2018-11-05 20:34:56 +02:00
parent 644f5e7fc6
commit a87aff67ac

View File

@ -57,14 +57,13 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> {
} }
void _checkConfigChanged() { void _checkConfigChanged() {
setState(() {
_edited = ((_newHassioPassword != _hassioPassword) || _edited = ((_newHassioPassword != _hassioPassword) ||
(_newHassioPort != _hassioPort) || (_newHassioPort != _hassioPort) ||
(_newHassioDomain != _hassioDomain) || (_newHassioDomain != _hassioDomain) ||
(_newSocketProtocol != _socketProtocol) || (_newSocketProtocol != _socketProtocol) ||
(_newAuthType != _authType) || (_newAuthType != _authType) ||
(_newUseLovelace != _useLovelace)); (_newUseLovelace != _useLovelace));
});
} }
_saveSettings() async { _saveSettings() async {
@ -92,12 +91,18 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> {
actions: <Widget>[ actions: <Widget>[
IconButton( IconButton(
icon: Icon(Icons.check), icon: Icon(Icons.check),
onPressed: _edited ? (){ onPressed: (){
_saveSettings().then((r){ if (_edited) {
TheLogger.debug("Settings changed. Saving...");
_saveSettings().then((r) {
Navigator.pop(context); Navigator.pop(context);
eventBus.fire(SettingsChangedEvent(true)); eventBus.fire(SettingsChangedEvent(true));
}); });
} : null } else {
TheLogger.debug("Settings was not changed");
Navigator.pop(context);
}
}
) )
], ],
), ),
@ -117,8 +122,10 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> {
Switch( Switch(
value: (_newSocketProtocol == "wss"), value: (_newSocketProtocol == "wss"),
onChanged: (value) { onChanged: (value) {
_newSocketProtocol = value ? "wss" : "ws";
_checkConfigChanged(); _checkConfigChanged();
setState(() {
_newSocketProtocol = value ? "wss" : "ws";
});
}, },
) )
], ],
@ -136,9 +143,9 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> {
), ),
onChanged: (value) { onChanged: (value) {
_newHassioDomain = value; _newHassioDomain = value;
_checkConfigChanged();
}, },
focusNode: _domainFocusNode, focusNode: _domainFocusNode,
onEditingComplete: _checkConfigChanged,
), ),
new TextField( new TextField(
decoration: InputDecoration( decoration: InputDecoration(
@ -153,10 +160,10 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> {
), ),
onChanged: (value) { onChanged: (value) {
_newHassioPort = value; _newHassioPort = value;
_checkConfigChanged();
//_saveSettings(); //_saveSettings();
}, },
focusNode: _portFocusNode, focusNode: _portFocusNode
onEditingComplete: _checkConfigChanged,
), ),
new Row( new Row(
children: [ children: [
@ -164,8 +171,10 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> {
Switch( Switch(
value: (_newAuthType == "access_token"), value: (_newAuthType == "access_token"),
onChanged: (value) { onChanged: (value) {
_newAuthType = value ? "access_token" : "api_password";
_checkConfigChanged(); _checkConfigChanged();
setState(() {
_newAuthType = value ? "access_token" : "api_password";
});
//_saveSettings(); //_saveSettings();
}, },
) )
@ -173,7 +182,7 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> {
), ),
new TextField( new TextField(
decoration: InputDecoration( decoration: InputDecoration(
labelText: _authType == "access_token" ? "Access token" : "API password" labelText: _newAuthType == "access_token" ? "Access token" : "API password"
), ),
controller: new TextEditingController.fromValue( controller: new TextEditingController.fromValue(
new TextEditingValue( new TextEditingValue(
@ -184,10 +193,10 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> {
), ),
onChanged: (value) { onChanged: (value) {
_newHassioPassword = value; _newHassioPassword = value;
_checkConfigChanged();
//_saveSettings(); //_saveSettings();
}, },
focusNode: _passwordFocusNode, focusNode: _passwordFocusNode
onEditingComplete: _checkConfigChanged,
), ),
Padding( Padding(
padding: EdgeInsets.only(top: 20.0), padding: EdgeInsets.only(top: 20.0),
@ -205,8 +214,10 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> {
Switch( Switch(
value: _newUseLovelace, value: _newUseLovelace,
onChanged: (value) { onChanged: (value) {
_newUseLovelace = value;
_checkConfigChanged(); _checkConfigChanged();
setState(() {
_newUseLovelace = value;
});
}, },
) )
], ],