Skip to content

Instantly share code, notes, and snippets.

@abbath0767
Created December 5, 2018 12:47
Show Gist options
  • Save abbath0767/f7b39e5f583754660b88b0dc5bee6058 to your computer and use it in GitHub Desktop.
Save abbath0767/f7b39e5f583754660b88b0dc5bee6058 to your computer and use it in GitHub Desktop.
class MyScaffold extends StatelessWidget {
var restClient = RestClient();
var dropDownCurrencies = DropDownCurrency();
@override
Widget build(BuildContext context) {
// Material is a conceptual piece of paper on which the UI appears.
restClient.loadConfig().then((value) {
print("load finish. result: ${value.status}");
if (value.status == Status.failure) {
print("error: ${value.message}");
} else {
print(
"data: currencies size: ${(value.data as Config).currencyList
.length}, merchant size: ${(value.data as Config).merchantList
.length}");
setUpViewForConfig((value.data as Config).currencies);
}
});
return Scaffold(
// Column is a vertical, linear layout.
body: Column(
children: <Widget>[
AppBar(
title: Text('Oats Dumb Terminal'),
),
//....
dropDownCurrencies,
//...
],
),
);
}
void setUpViewForConfig(List<Currency> currencies) {
dropDownCurrencies.setCurrencyItems(currencies); //how it make?
}
}
class DropCurrency extends StatefulWidget {
@override
State<StatefulWidget> createState() => DropDownState()
}
class DropDownState extends State<DropCurrency> {
List<String> currencyList = List();
void setCurrencyItems(List<Currency> currencyList) {
setState(() {
this.currencyList = currencyList.map((curr) {
return curr.currencyName;
}).toList();
});
}
@override
Widget build(BuildContext context) {
return SizedBox(
width: double.infinity,
child: Container(
alignment: Alignment.centerLeft,
padding: EdgeInsets.only(left: 8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Select Currency',
textAlign: TextAlign.left,
),
currencyList.isEmpty
? Text('loading...')
: DropdownButton<String>(
items: currencyList.map((String curr) {
return DropdownMenuItem<String>(
value: curr,
child: Text(curr),
);
}).toList(),
hint: Text('Currencies...'),
onChanged: (_) {},
)
],
)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment