我想将下面的代码变成:
Future<List> fetchPrices() async {details in code below}
没有错误。
要更改的代码在这里:
Future<void> main(List<String> arguments) async {
Map<String, num> quotes = await Forex.fx(
quoteProvider: QuoteProvider.yahoo,
base: 'USD',
quotes: <String>['EUR', 'JPY']
);
print('Number of quotes retrieved: ${quotes.keys.length}.');
print('Exchange rate USDEUR: ${quotes['USDEUR']}.');
print('Exchange rate USDJPY: ${quotes['USDJPY']}.');
quotes = await Forex.fx(
quoteProvider: QuoteProvider.ecb,
base: 'JPY',
quotes: <String>['EUR', 'USD']
);
print('Number of quotes retrieved: ${quotes.keys.length}.');
print('Exchange rate JPYEUR: ${quotes['JPYEUR']}.');
print('Exchange rate JPYUSD: ${quotes['JPYUSD']}.');
}
最佳答案
根据您的代码示例Forex.fx()
返回Map<String, num>
。因此,您在这里有两个选择。
Future<List<String>> fooFunction(List<String> arguments) async {
Map<String, num> quotes = await Forex.fx(
quoteProvider: QuoteProvider.yahoo,
base: 'USD',
quotes: <String>['EUR', 'JPY']
);
return quotes.keys;
}
Future<List<num>> fooFunction(List<String> arguments) async {
Map<String, num> quotes = await Forex.fx(
quoteProvider: QuoteProvider.yahoo,
base: 'USD',
quotes: <String>['EUR', 'JPY']
);
return quotes.values;
}