diff --git a/lib/pages/settings_page.dart b/lib/pages/settings_page.dart index 74a721a..596a3ff 100644 --- a/lib/pages/settings_page.dart +++ b/lib/pages/settings_page.dart @@ -29,8 +29,7 @@ class _SettingsPageState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ const Padding( - padding: EdgeInsets.fromLTRB(20, 55, 0, 0), - child: Text("Settings", style: TextStyle(fontSize: 37))), + padding: EdgeInsets.fromLTRB(20, 55, 0, 0), child: Text("Settings", style: TextStyle(fontSize: 37))), const Gap(5), const SettingsHeader("Security"), FutureBuilder( @@ -43,8 +42,7 @@ class _SettingsPageState extends State { style: ButtonStyle( padding: WidgetStateProperty.all(EdgeInsets.zero), shape: WidgetStateProperty.all(LinearBorder.none), - backgroundColor: - WidgetStateProperty.all(Theme.of(context).colorScheme.surface), + backgroundColor: WidgetStateProperty.all(Theme.of(context).colorScheme.surface), textStyle: WidgetStateProperty.all( TextStyle(color: Theme.of(context).colorScheme.primary), ), @@ -60,21 +58,16 @@ class _SettingsPageState extends State { children: [ Text( "Word Count", - style: TextStyle( - fontSize: 20, - color: Theme.of(context).colorScheme.onSurface), + style: TextStyle(fontSize: 20, color: Theme.of(context).colorScheme.onSurface), ), Row(children: [ Text( _wordCount.toString(), - style: TextStyle( - fontSize: 15, - color: Theme.of(context).colorScheme.onSurface), + style: TextStyle(fontSize: 15, color: Theme.of(context).colorScheme.onSurface), ), Expanded( child: Slider( - value: _wordCountSlider.clamp( - minWordCount.toDouble(), maxWordCount.toDouble()), + value: _wordCountSlider.clamp(minWordCount.toDouble(), maxWordCount.toDouble()), min: minWordCount.toDouble(), max: maxWordCount.toDouble(), divisions: maxWordCount - minWordCount, @@ -108,8 +101,7 @@ class _SettingsPageState extends State { style: ButtonStyle( padding: WidgetStateProperty.all(EdgeInsets.zero), shape: WidgetStateProperty.all(LinearBorder.none), - backgroundColor: - WidgetStateProperty.all(Theme.of(context).colorScheme.surface), + backgroundColor: WidgetStateProperty.all(Theme.of(context).colorScheme.surface), textStyle: WidgetStateProperty.all( TextStyle(color: Theme.of(context).colorScheme.primary), ), @@ -127,8 +119,7 @@ class _SettingsPageState extends State { children: [ for (var value in ThemeMode.values) RadioListTile( - title: - Text(value.toString().split('.').last.capitalize()), + title: Text(value.toString().split('.').last.capitalize()), value: value, groupValue: theme, onChanged: (value) { @@ -155,8 +146,7 @@ class _SettingsPageState extends State { child: const Text('Save'), onPressed: () { this.setState(() { - Settings.setThemeMode(theme) - .then((_) => Restart.restartApp()); + Settings.setThemeMode(theme).then((_) => Restart.restartApp()); }); Navigator.of(context).pop(); }, @@ -175,15 +165,11 @@ class _SettingsPageState extends State { children: [ Text( "Theme", - style: TextStyle( - fontSize: 20, - color: Theme.of(context).colorScheme.onSurface), + style: TextStyle(fontSize: 20, color: Theme.of(context).colorScheme.onSurface), ), Text( snapshot.data!.toString().split('.').last.capitalize(), - style: TextStyle( - fontSize: 15, - color: Theme.of(context).colorScheme.onSurface), + style: TextStyle(fontSize: 15, color: Theme.of(context).colorScheme.onSurface), ) ]))), ); @@ -195,16 +181,17 @@ class _SettingsPageState extends State { }), const SettingsHeader("Connection"), FutureBuilder( - future: Future.wait([Settings.getRendezvousUrl() - , api.defaultRendezvousUrl()]), + future: Future.wait([Settings.getRendezvousUrl(), api.defaultRendezvousUrl()]), builder: (context, snapshot) { if (snapshot.hasData) { return SettingField( title: "Rendezvous URL", defaultValue: snapshot.data![1].toString(), - initialValue: snapshot.data![0].toString(), + initialValue: snapshot.data![0].toString() == snapshot.data![1].toString() + ? '' + : snapshot.data![0].toString(), onSubmit: (value) => setState(() { - Settings.setRendezvousUrl(value); + Settings.setRendezvousUrl(value == '' ? snapshot.data![1].toString() : value); }), ); } @@ -214,16 +201,17 @@ class _SettingsPageState extends State { ); }), FutureBuilder( - future: Future.wait([Settings.getTransitUrl() - , api.defaultTransitUrl()]), + future: Future.wait([Settings.getTransitUrl(), api.defaultTransitUrl()]), builder: (context, snapshot) { if (snapshot.hasData) { return SettingField( title: "Transit URL", defaultValue: snapshot.data![1].toString(), - initialValue: snapshot.data![0].toString(), + initialValue: snapshot.data![0].toString() == snapshot.data![1].toString() + ? '' + : snapshot.data![0].toString(), onSubmit: (value) => setState(() { - Settings.setTransitUrl(value); + Settings.setTransitUrl(value == '' ? snapshot.data![1].toString() : value); }), ); } diff --git a/lib/widgets/settings_field.dart b/lib/widgets/settings_field.dart index 8e73fbb..d5605b4 100644 --- a/lib/widgets/settings_field.dart +++ b/lib/widgets/settings_field.dart @@ -54,7 +54,7 @@ class _SettingFieldState extends State { style: TextStyle(fontSize: 20, color: Theme.of(context).colorScheme.onSurface), ), Text( - widget.initialValue, + widget.initialValue == '' ? widget.defaultValue : widget.initialValue, style: TextStyle(fontSize: 15, color: Theme.of(context).colorScheme.onSurface), ) ]))),