Skip to content

Commit

Permalink
Fix default value
Browse files Browse the repository at this point in the history
  • Loading branch information
EwuUwe committed Dec 26, 2024
1 parent c2b5cea commit e7c8a78
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 33 deletions.
52 changes: 20 additions & 32 deletions lib/pages/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ class _SettingsPageState extends State<SettingsPage> {
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(
Expand All @@ -43,8 +42,7 @@ class _SettingsPageState extends State<SettingsPage> {
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),
),
Expand All @@ -60,21 +58,16 @@ class _SettingsPageState extends State<SettingsPage> {
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,
Expand Down Expand Up @@ -108,8 +101,7 @@ class _SettingsPageState extends State<SettingsPage> {
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),
),
Expand All @@ -127,8 +119,7 @@ class _SettingsPageState extends State<SettingsPage> {
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) {
Expand All @@ -155,8 +146,7 @@ class _SettingsPageState extends State<SettingsPage> {
child: const Text('Save'),
onPressed: () {
this.setState(() {
Settings.setThemeMode(theme)
.then((_) => Restart.restartApp());
Settings.setThemeMode(theme).then((_) => Restart.restartApp());
});
Navigator.of(context).pop();
},
Expand All @@ -175,15 +165,11 @@ class _SettingsPageState extends State<SettingsPage> {
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),
)
]))),
);
Expand All @@ -195,16 +181,17 @@ class _SettingsPageState extends State<SettingsPage> {
}),
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);
}),
);
}
Expand All @@ -214,16 +201,17 @@ class _SettingsPageState extends State<SettingsPage> {
);
}),
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);
}),
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/settings_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class _SettingFieldState extends State<SettingField> {
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),
)
]))),
Expand Down

0 comments on commit e7c8a78

Please sign in to comment.