Skip to content

Commit

Permalink
Add reset button to settings dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
EwuUwe committed Dec 6, 2024
1 parent 70d79d7 commit 72fa11b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
14 changes: 10 additions & 4 deletions lib/pages/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import 'package:iyox_wormhole/widgets/settings_field.dart';
import 'package:iyox_wormhole/widgets/settings_header.dart';
import 'package:restart_app/restart_app.dart';

import '../gen/ffi.dart';

class SettingsPage extends StatefulWidget {
const SettingsPage({Key? key}) : super(key: key);

Expand Down Expand Up @@ -193,12 +195,14 @@ class _SettingsPageState extends State<SettingsPage> {
}),
const SettingsHeader("Connection"),
FutureBuilder(
future: Settings.getRendezvousUrl(),
future: Future.wait([Settings.getRendezvousUrl()
, api.defaultRendezvousUrl()]),
builder: (context, snapshot) {
if (snapshot.hasData) {
return SettingField(
title: "Rendezvous URL",
initialValue: snapshot.data.toString(),
defaultValue: snapshot.data![1].toString(),
initialValue: snapshot.data![0].toString(),
onSubmit: (value) => setState(() {
Settings.setRendezvousUrl(value);
}),
Expand All @@ -210,12 +214,14 @@ class _SettingsPageState extends State<SettingsPage> {
);
}),
FutureBuilder(
future: Settings.getTransitUrl(),
future: Future.wait([Settings.getTransitUrl()
, api.defaultTransitUrl()]),
builder: (context, snapshot) {
if (snapshot.hasData) {
return SettingField(
title: "Transit URL",
initialValue: snapshot.data.toString(),
defaultValue: snapshot.data![1].toString(),
initialValue: snapshot.data![0].toString(),
onSubmit: (value) => setState(() {
Settings.setTransitUrl(value);
}),
Expand Down
22 changes: 17 additions & 5 deletions lib/widgets/settings_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ class SettingField extends StatefulWidget {
required this.title,
required this.initialValue,
required this.onSubmit,
this.defaultValue = '',
this.editWidget});

final String title;
final String initialValue;
final String defaultValue;
final void Function(String) onSubmit;
final Widget? editWidget;

Expand All @@ -33,7 +35,8 @@ class _SettingFieldState extends State<SettingField> {
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 @@ -49,13 +52,15 @@ class _SettingFieldState extends State<SettingField> {
children: [
Text(
widget.title,
style:
TextStyle(fontSize: 20, color: Theme.of(context).colorScheme.onSurface),
style: TextStyle(
fontSize: 20,
color: Theme.of(context).colorScheme.onSurface),
),
Text(
widget.initialValue,
style:
TextStyle(fontSize: 15, color: Theme.of(context).colorScheme.onSurface),
style: TextStyle(
fontSize: 15,
color: Theme.of(context).colorScheme.onSurface),
)
]))),
);
Expand All @@ -70,6 +75,13 @@ class _SettingFieldState extends State<SettingField> {
TextField(
controller: _textController,
onSubmitted: widget.onSubmit,
decoration: InputDecoration(
hintText: widget.defaultValue,
suffixIcon: IconButton(
onPressed: _textController.clear,
icon: Icon(Icons.clear),
),
),
),
actions: [
TextButton(
Expand Down

0 comments on commit 72fa11b

Please sign in to comment.