diff --git a/lib/screens/SiteDetailScreen.dart b/lib/screens/SiteDetailScreen.dart index 07b1ba0..e1a937a 100644 --- a/lib/screens/SiteDetailScreen.dart +++ b/lib/screens/SiteDetailScreen.dart @@ -134,6 +134,19 @@ class _SiteDetailScreenState extends State { } Widget _buildConfig() { + void handleChange(v) async { + try { + if (v) { + await widget.site.start(); + } else { + await widget.site.stop(); + } + } catch (error) { + var action = v ? 'start' : 'stop'; + Utils.popError(context, 'Failed to $action the site', error.toString()); + } + } + return ConfigSection(children: [ ConfigItem( label: Text('Status'), @@ -145,18 +158,7 @@ class _SiteDetailScreenState extends State { Switch.adaptive( value: widget.site.connected, materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, - onChanged: (v) async { - try { - if (v) { - await widget.site.start(); - } else { - await widget.site.stop(); - } - } catch (error) { - var action = v ? 'start' : 'stop'; - Utils.popError(context, 'Failed to $action the site', error.toString()); - } - }, + onChanged: widget.site.errors.length > 0 && !widget.site.connected ? null : handleChange, ) ])), ConfigPageItem(