Skip to content

Commit a3b9c49

Browse files
committed
Currency settings options
1 parent 3b6e37d commit a3b9c49

File tree

2 files changed

+163
-0
lines changed

2 files changed

+163
-0
lines changed
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
import 'package:flutter/cupertino.dart';
2+
import 'package:flutter/material.dart';
3+
import 'package:provider/provider.dart';
4+
import 'package:sentinelx/models/db/prefs_store.dart';
5+
import 'package:sentinelx/models/exchange/currencies.dart';
6+
import 'package:sentinelx/shared_state/rate_state.dart';
7+
8+
class CurrencySettings extends StatefulWidget {
9+
@override
10+
_CurrencySettingsState createState() => _CurrencySettingsState();
11+
}
12+
13+
class _CurrencySettingsState extends State<CurrencySettings> {
14+
bool loading = false;
15+
String selectedCurrency;
16+
17+
@override
18+
Widget build(BuildContext context) {
19+
selectedCurrency = RateState().provider.currency;
20+
21+
return Scaffold(
22+
appBar: AppBar(
23+
title: Text("Currency settings"),
24+
bottom: UnderProgress(loading),
25+
),
26+
backgroundColor: Theme.of(context).backgroundColor,
27+
body: ListView(
28+
children: <Widget>[
29+
Divider(),
30+
ListTile(
31+
title: Text("Rate provider"),
32+
subtitle: Text("Select exchange for fiat price"),
33+
onTap: showProvider,
34+
),
35+
Divider(),
36+
ListTile(
37+
title: Text("Select currency"),
38+
subtitle: Text("$selectedCurrency"),
39+
onTap: showCurrencyChooser,
40+
),
41+
Divider(),
42+
],
43+
),
44+
);
45+
}
46+
47+
void showCurrencyChooser() {
48+
showModalBottomSheet(
49+
context: context,
50+
builder: (context) {
51+
return Card(
52+
margin: const EdgeInsets.all(8.0),
53+
child: Consumer<RateState>(
54+
builder: (context, rateState, _) {
55+
return Container(
56+
height: double.infinity,
57+
child: ListView.separated(
58+
separatorBuilder: (b, c) => Divider(height: 1,),
59+
itemBuilder: (BuildContext context, int i) {
60+
String curr = rateState.provider.availableCurrencies[i];
61+
return ListTile(
62+
title: Text(curr),
63+
trailing: selectedCurrency == curr ? Icon(Icons.check,color: Colors.greenAccent,): SizedBox.shrink(),
64+
onTap: () {
65+
this.setCurrency(rateState.provider.availableCurrencies[i]);
66+
},
67+
);
68+
},
69+
itemCount: rateState.provider.availableCurrencies.length,
70+
),
71+
);
72+
},
73+
),
74+
);
75+
});
76+
}
77+
78+
void setCurrency(String currency) async {
79+
PrefsStore().put(PrefsStore.CURRENCY, currency);
80+
setState(() {
81+
loading = true;
82+
selectedCurrency = currency;
83+
});
84+
Navigator.pop(context);
85+
await RateState().setCurrency(currency);
86+
setState(() {
87+
loading = false;
88+
});
89+
}
90+
91+
showProvider () {
92+
List<String> providers = ["LocalBitcoins"];
93+
String radioGroup = "LocalBitcoins";
94+
showModalBottomSheet(
95+
context: context,
96+
builder: (context){
97+
return Padding(
98+
padding: const EdgeInsets.all(8.0),
99+
child: Card(
100+
child: Wrap(
101+
direction: Axis.horizontal,
102+
children: providers.map((provider) {
103+
return ListTile(
104+
dense: true,
105+
onTap: () {
106+
// onSelect(timeout);
107+
},
108+
title: Text('$provider'),
109+
trailing: Radio(
110+
value: provider,
111+
groupValue: radioGroup,
112+
onChanged: (va){},
113+
),
114+
);
115+
}).toList(),
116+
),
117+
),
118+
);
119+
});
120+
}
121+
}
122+
123+
class UnderProgress extends StatelessWidget implements PreferredSizeWidget {
124+
final bool loading;
125+
126+
UnderProgress(this.loading);
127+
128+
@override
129+
Widget build(BuildContext context) {
130+
return AnimatedOpacity(
131+
opacity: loading ? 1 : 0,
132+
duration: Duration(milliseconds: 600),
133+
child: Container(
134+
height: 1,
135+
child: LinearProgressIndicator(),
136+
),
137+
);
138+
}
139+
140+
@override
141+
// TODO: implement preferredSize
142+
Size get preferredSize => Size(double.infinity, 1);
143+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:sentinelx/models/db/prefs_store.dart';
55
import 'package:sentinelx/models/db/sentinelx_db.dart';
66
import 'package:sentinelx/screens/Lock/lock_screen.dart';
77
import 'package:sentinelx/screens/dojo_configure.dart';
8+
import 'package:sentinelx/screens/settings/currency_settings.dart';
89
import 'package:sentinelx/shared_state/app_state.dart';
910
import 'package:sentinelx/widgets/confirm_modal.dart';
1011
import 'package:sentinelx/widgets/port_selector.dart';
@@ -97,6 +98,25 @@ class _SettingsState extends State<Settings> {
9798
},
9899
),
99100
Divider(),
101+
ListTile(
102+
leading: Padding(
103+
padding: const EdgeInsets.symmetric(vertical: 12),
104+
child: Icon(Icons.attach_money),
105+
),
106+
title: Text(
107+
"Currency Settings",
108+
style: Theme.of(context).textTheme.subtitle,
109+
),
110+
subtitle: Text("Choose street price"),
111+
onTap: () {
112+
Navigator.push(context, new MaterialPageRoute(
113+
builder: (c) {
114+
return CurrencySettings();
115+
},
116+
));
117+
},
118+
),
119+
Divider(),
100120
Container(
101121
padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 18),
102122
child: Text(

0 commit comments

Comments
 (0)