Fix settings saving issue

This commit is contained in:
Yegor Vialov 2018-11-06 14:01:00 +02:00 committed by GitHub
parent 4a49372410
commit 69fd37d4fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -22,20 +22,10 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> {
String _newAuthType = "access_token"; String _newAuthType = "access_token";
bool _useLovelace = false; bool _useLovelace = false;
bool _newUseLovelace = false; bool _newUseLovelace = 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();
} }
@ -56,8 +46,8 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> {
}); });
} }
void _checkConfigChanged() { bool _checkConfigChanged() {
_edited = ((_newHassioPassword != _hassioPassword) || return ((_newHassioPassword != _hassioPassword) ||
(_newHassioPort != _hassioPort) || (_newHassioPort != _hassioPort) ||
(_newHassioDomain != _hassioDomain) || (_newHassioDomain != _hassioDomain) ||
(_newSocketProtocol != _socketProtocol) || (_newSocketProtocol != _socketProtocol) ||
@ -92,7 +82,7 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> {
IconButton( IconButton(
icon: Icon(Icons.check), icon: Icon(Icons.check),
onPressed: (){ onPressed: (){
if (_edited) { if (_checkConfigChanged()) {
TheLogger.debug("Settings changed. Saving..."); TheLogger.debug("Settings changed. Saving...");
_saveSettings().then((r) { _saveSettings().then((r) {
Navigator.pop(context); Navigator.pop(context);
@ -122,7 +112,6 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> {
Switch( Switch(
value: (_newSocketProtocol == "wss"), value: (_newSocketProtocol == "wss"),
onChanged: (value) { onChanged: (value) {
_checkConfigChanged();
setState(() { setState(() {
_newSocketProtocol = value ? "wss" : "ws"; _newSocketProtocol = value ? "wss" : "ws";
}); });
@ -143,9 +132,7 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> {
), ),
onChanged: (value) { onChanged: (value) {
_newHassioDomain = value; _newHassioDomain = value;
_checkConfigChanged(); }
},
focusNode: _domainFocusNode,
), ),
new TextField( new TextField(
decoration: InputDecoration( decoration: InputDecoration(
@ -160,10 +147,7 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> {
), ),
onChanged: (value) { onChanged: (value) {
_newHassioPort = value; _newHassioPort = value;
_checkConfigChanged(); }
//_saveSettings();
},
focusNode: _portFocusNode
), ),
new Row( new Row(
children: [ children: [
@ -171,11 +155,9 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> {
Switch( Switch(
value: (_newAuthType == "access_token"), value: (_newAuthType == "access_token"),
onChanged: (value) { onChanged: (value) {
_checkConfigChanged();
setState(() { setState(() {
_newAuthType = value ? "access_token" : "api_password"; _newAuthType = value ? "access_token" : "api_password";
}); });
//_saveSettings();
}, },
) )
], ],
@ -193,10 +175,7 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> {
), ),
onChanged: (value) { onChanged: (value) {
_newHassioPassword = value; _newHassioPassword = value;
_checkConfigChanged(); }
//_saveSettings();
},
focusNode: _passwordFocusNode
), ),
Padding( Padding(
padding: EdgeInsets.only(top: 20.0), padding: EdgeInsets.only(top: 20.0),
@ -214,7 +193,6 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> {
Switch( Switch(
value: _newUseLovelace, value: _newUseLovelace,
onChanged: (value) { onChanged: (value) {
_checkConfigChanged();
setState(() { setState(() {
_newUseLovelace = value; _newUseLovelace = value;
}); });
@ -229,12 +207,6 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> {
@override @override
void dispose() { void dispose() {
_domainFocusNode.removeListener(_checkConfigChanged);
_portFocusNode.removeListener(_checkConfigChanged);
_passwordFocusNode.removeListener(_checkConfigChanged);
_domainFocusNode.dispose();
_portFocusNode.dispose();
_passwordFocusNode.dispose();
super.dispose(); super.dispose();
} }
} }