Flutter 中所有可用货币

问题描述 投票:0回答:1

我想获得所有可用货币的列表。

那么在Flutter中如何获取呢?

我想显示所有可用货币的列表(名称、代码、符号)。此外,该货币名称必须采用所需的语言:

flutter currency
1个回答
0
投票

不知何故,我获得了国家货币详细信息的 JSON 文件。它包含 115 种货币的信息。我相信我们几乎拥有所有国家的货币。因此,我为您提供两个文件:一个是主文件,您可以在其中看到它的 UI,另一个有一张地图,您可以在其中看到所有货币。

main.dart

import "package:flutter/material.dart";
import "package:myapp/currencies.dart";

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: "My App",
      home: HomePage(),
      debugShowCheckedModeBanner: false,
    );
  }
}

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  int? selectedIndex;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: ListView.separated(
          itemCount: currencies.length,
          itemBuilder: (BuildContext context, int index) {
            final Map<String, dynamic> currency = currencies[index];
            return ListTile(
              dense: true,
              leading: CircleAvatar(child: Text("${currency["symbol"]}")),
              title: Text("Name: ${currency["name"]}"),
              subtitle: Text("Code: ${currency["code"]}"),
              trailing: selectedIndex == index ? const Icon(Icons.check) : null,
              onTap: () {
                selectedIndex = selectedIndex != index ? index : null;
                setState(() {});
              },
            );
          },
          separatorBuilder: (BuildContext context, int index) {
            return const Divider(height: 1, thickness: 1);
          },
        ),
      ),
    );
  }
}

currency.dart 查看

该文件有 1500 行。我无法在这里复制粘贴,所以我提供了一个 Git Gist。

© www.soinside.com 2019 - 2024. All rights reserved.