gpt4 book ai didi

flutter - 如何在没有错误的情况下将Future main转换为dart flutter 中的Future

转载 作者:行者123 更新时间:2023-12-03 04:23:33 25 4
gpt4 key购买 nike

我想将下面的代码变成:

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;
}

关于flutter - 如何在没有错误的情况下将Future <void> main转换为dart flutter 中的Future <List>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61174862/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com