From 6ed64b7349c6345da600945d3a12089b377bca50 Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Fri, 17 Jan 2025 12:30:34 -0500 Subject: [PATCH] Do not allow starting site if there are errors (#220) --- lib/screens/SiteDetailScreen.dart | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) 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(