2021-07-09 06:33:39 -07:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_form_builder/flutter_form_builder.dart';
|
|
|
|
import 'package:flutter_masked_text/flutter_masked_text.dart';
|
|
|
|
import 'package:flutter_mobx/flutter_mobx.dart';
|
|
|
|
|
|
|
|
import 'main.dart';
|
2021-08-15 09:18:09 -07:00
|
|
|
import 'generated/l10n.dart';
|
2021-07-09 06:33:39 -07:00
|
|
|
|
|
|
|
class SettingsPage extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() => SettingsState();
|
|
|
|
}
|
|
|
|
|
|
|
|
final _settingsFormKey = GlobalKey<FormBuilderState>();
|
|
|
|
|
|
|
|
class SettingsState extends State<SettingsPage> {
|
2021-07-09 22:44:34 -07:00
|
|
|
var _anchorController =
|
|
|
|
MaskedTextController(mask: "00", text: "${settings.anchorOffset}");
|
2021-07-09 06:33:39 -07:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2021-08-16 06:07:16 -07:00
|
|
|
List<FormBuilderFieldOption> options = coin.lwd
|
|
|
|
.map((lwd) => FormBuilderFieldOption<dynamic>(
|
|
|
|
child: Text(lwd.name), value: lwd.name))
|
|
|
|
.toList();
|
2021-08-13 20:44:53 -07:00
|
|
|
options.add(
|
|
|
|
FormBuilderFieldOption(
|
|
|
|
value: 'custom',
|
|
|
|
child: FormBuilderTextField(
|
2021-08-16 06:07:16 -07:00
|
|
|
decoration: InputDecoration(labelText: S.of(context).custom),
|
2021-08-13 20:44:53 -07:00
|
|
|
initialValue: settings.ldUrl,
|
|
|
|
onSaved: _onURL,
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
|
2021-07-09 06:33:39 -07:00
|
|
|
return Scaffold(
|
2021-08-15 09:18:09 -07:00
|
|
|
appBar: AppBar(title: Text(S.of(context).settings)),
|
2021-07-09 06:33:39 -07:00
|
|
|
body: Padding(
|
2021-07-09 22:44:34 -07:00
|
|
|
padding: EdgeInsets.all(16),
|
2021-07-09 06:33:39 -07:00
|
|
|
child: FormBuilder(
|
|
|
|
key: _settingsFormKey,
|
2021-07-09 22:44:34 -07:00
|
|
|
child: Observer(
|
2021-08-16 06:07:16 -07:00
|
|
|
builder: (context) => SingleChildScrollView(
|
|
|
|
child: Column(children: [
|
2021-07-09 22:44:34 -07:00
|
|
|
FormBuilderRadioGroup(
|
|
|
|
orientation: OptionsOrientation.vertical,
|
|
|
|
name: 'servers',
|
2021-08-16 06:07:16 -07:00
|
|
|
decoration: InputDecoration(
|
|
|
|
labelText: S.of(context).server),
|
2021-07-09 22:44:34 -07:00
|
|
|
initialValue: settings.ldUrlChoice,
|
|
|
|
onSaved: _onChoice,
|
2021-08-13 20:44:53 -07:00
|
|
|
options: options),
|
2021-08-07 00:32:10 -07:00
|
|
|
FormBuilderRadioGroup(
|
|
|
|
orientation: OptionsOrientation.horizontal,
|
|
|
|
name: 'themes',
|
2021-08-16 06:07:16 -07:00
|
|
|
decoration: InputDecoration(
|
|
|
|
labelText: S.of(context).theme),
|
2021-08-07 00:32:10 -07:00
|
|
|
initialValue: settings.theme,
|
|
|
|
onChanged: _onTheme,
|
|
|
|
options: [
|
|
|
|
FormBuilderFieldOption(
|
|
|
|
child: Text('Zcash'), value: 'zcash'),
|
|
|
|
FormBuilderFieldOption(
|
2021-08-16 06:07:16 -07:00
|
|
|
child: Text(S.of(context).blue),
|
|
|
|
value: 'blue'),
|
2021-08-07 00:32:10 -07:00
|
|
|
FormBuilderFieldOption(
|
2021-08-16 06:07:16 -07:00
|
|
|
child: Text(S.of(context).pink),
|
|
|
|
value: 'pink'),
|
2021-08-07 00:32:10 -07:00
|
|
|
FormBuilderFieldOption(
|
2021-08-16 06:07:16 -07:00
|
|
|
child: Text(S.of(context).coffee),
|
|
|
|
value: 'coffee'),
|
2021-08-07 00:32:10 -07:00
|
|
|
]),
|
|
|
|
FormBuilderRadioGroup(
|
|
|
|
orientation: OptionsOrientation.horizontal,
|
|
|
|
name: 'brightness',
|
|
|
|
initialValue: settings.themeBrightness,
|
|
|
|
onChanged: _onThemeBrightness,
|
|
|
|
options: [
|
|
|
|
FormBuilderFieldOption(
|
2021-08-16 06:07:16 -07:00
|
|
|
child: Text(S.of(context).light),
|
|
|
|
value: 'light'),
|
2021-08-07 00:32:10 -07:00
|
|
|
FormBuilderFieldOption(
|
2021-08-16 06:07:16 -07:00
|
|
|
child: Text(S.of(context).dark),
|
|
|
|
value: 'dark'),
|
2021-08-07 00:32:10 -07:00
|
|
|
]),
|
|
|
|
Row(children: [
|
2021-08-16 06:07:16 -07:00
|
|
|
SizedBox(
|
|
|
|
width: 100,
|
|
|
|
child: DropdownButtonFormField<String>(
|
|
|
|
decoration: InputDecoration(
|
|
|
|
labelText: S.of(context).currency),
|
|
|
|
value: settings.currency,
|
|
|
|
items: settings.currencies
|
|
|
|
.map((c) => DropdownMenuItem(
|
|
|
|
child: Text(c), value: c))
|
|
|
|
.toList(),
|
|
|
|
onChanged: (v) {
|
|
|
|
settings.setCurrency(v);
|
|
|
|
})),
|
2021-08-07 00:32:10 -07:00
|
|
|
]),
|
2021-07-09 22:44:34 -07:00
|
|
|
FormBuilderTextField(
|
2021-08-07 00:32:10 -07:00
|
|
|
decoration: InputDecoration(
|
2021-08-16 06:07:16 -07:00
|
|
|
labelText: S
|
|
|
|
.of(context)
|
|
|
|
.numberOfConfirmationsNeededBeforeSpending),
|
2021-07-09 22:44:34 -07:00
|
|
|
name: 'anchor',
|
|
|
|
keyboardType: TextInputType.number,
|
|
|
|
controller: _anchorController,
|
|
|
|
onSaved: _onAnchorOffset),
|
2021-08-16 06:07:16 -07:00
|
|
|
FormBuilderRadioGroup(
|
|
|
|
orientation: OptionsOrientation.horizontal,
|
|
|
|
name: 'pnl',
|
|
|
|
decoration: InputDecoration(
|
|
|
|
labelText: S.of(context).tradingChartRange),
|
|
|
|
initialValue: settings.chartRange,
|
|
|
|
onChanged: _onChartRange,
|
|
|
|
options: [
|
|
|
|
FormBuilderFieldOption(
|
|
|
|
child: Text('1 M'), value: '1M'),
|
|
|
|
FormBuilderFieldOption(
|
|
|
|
child: Text('3 M'), value: '3M'),
|
|
|
|
FormBuilderFieldOption(
|
|
|
|
child: Text('6 M'), value: '6M'),
|
|
|
|
FormBuilderFieldOption(
|
|
|
|
child: Text('1 Y'), value: '1Y'),
|
|
|
|
]),
|
|
|
|
FormBuilderCheckbox(
|
|
|
|
name: 'get_tx',
|
|
|
|
title: Text(
|
|
|
|
S.of(context).retrieveTransactionDetails),
|
|
|
|
initialValue: settings.getTx,
|
|
|
|
onSaved: _onGetTx),
|
|
|
|
ButtonBar(children: confirmButtons(context, _onSave))
|
2021-08-07 00:32:10 -07:00
|
|
|
]))))));
|
2021-07-09 06:33:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
_onChoice(v) {
|
|
|
|
settings.setURLChoice(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
_onURL(v) {
|
|
|
|
settings.setURL(v);
|
|
|
|
}
|
|
|
|
|
2021-07-10 22:20:53 -07:00
|
|
|
_onTheme(v) {
|
|
|
|
settings.setTheme(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
_onThemeBrightness(v) {
|
|
|
|
settings.setThemeBrightness(v);
|
|
|
|
}
|
|
|
|
|
2021-08-16 06:07:16 -07:00
|
|
|
_onChartRange(v) {
|
|
|
|
settings.setChartRange(v);
|
|
|
|
}
|
|
|
|
|
2021-07-09 06:33:39 -07:00
|
|
|
_onSave() {
|
2021-08-07 00:32:10 -07:00
|
|
|
final form = _settingsFormKey.currentState;
|
|
|
|
if (form.validate()) {
|
|
|
|
form.save();
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
}
|
2021-07-09 06:33:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
_onAnchorOffset(v) {
|
|
|
|
settings.anchorOffset = int.parse(v);
|
|
|
|
}
|
2021-07-09 22:44:34 -07:00
|
|
|
|
|
|
|
_onGetTx(v) {
|
|
|
|
settings.updateGetTx(v);
|
|
|
|
}
|
2021-08-07 00:32:10 -07:00
|
|
|
|
|
|
|
String _checkFx(String vs) {
|
|
|
|
final v = double.tryParse(vs);
|
|
|
|
if (v == null) return 'FX rate must be a number';
|
|
|
|
if (v <= 0.0) return 'FX rate must be positive';
|
|
|
|
return null;
|
|
|
|
}
|
2021-07-09 06:33:39 -07:00
|
|
|
}
|