Flutter功能未知插件getworld的介绍与使用
Flutter功能未知插件getworld的介绍与使用
getworld 1.1.0
简单包,用于获取国家、货币和语言信息。
目录
安装
运行以下命令:
使用Dart
$ dart pub add getworld
使用Flutter
$ flutter pub add getworld
这将在你的包的pubspec.yaml文件中添加如下行(并隐式地运行dart pub get
):
dependencies:
getworld: ^1.1.0
或者,你的编辑器可能支持dart pub get
或flutter pub get
。请查阅编辑器文档以了解更多信息。
现在可以在你的Dart代码中使用:
import 'package:getworld/getworld.dart';
国家对象
基于ISO_3166国家代码的国家数据。
对象 | 类型 | 描述 |
---|---|---|
Country.name | Name | 确定国家的官方和常见名称 |
Country.natives | Map<Language, Name> | 所有可用的本地名称集合 |
Country.translations | Map<Language, Name> | 所有可用的翻译名称集合 |
Country.demonym | String | 居民名称 |
Country.capital | String | 首都城市名称 |
Country.iso_3166_1_alpha2 | String | ISO 3166-1 alpha-2 代码 |
Country.iso_3166_1_alpha3 | String | ISO 3166-1 alpha-3 代码 |
Country.iso_3166_1_numeric | String | ISO 3166-1 数字代码 |
Country.languages | Language | 官方语言列表 |
Country.currencies | Currency | 官方货币列表 |
Country.tld | List<String> | 国家顶级域名 |
Country.alt_spellings | List<String> | 国家名称的替代拼写 |
Country.provinces | List<Province> | 省份及其城市的列表 |
Country.geographical | Geographical | 描述所有地理信息 |
Country.dialling | Dialling | 拨号信息 |
Country.extra | Extra | 国家的一些额外数据 |
Country.population | Population | 人口数量及国家人口占世界人口百分比 |
Country.wikiLink | String | 相对链接到国家维基百科页面 |
语言对象
基于ISO 639-3语言代码的语言数据。
对象 | 类型 | 描述 |
---|---|---|
Language.iso_639_1_alpha2 | String | ISO 639-1 alpha-2 代码 |
Language.iso_639_2_alpha3 | String | ISO 639-2 alpha-3 代码 |
Language.name | String | 语言名称 |
Language.family | String | 语言家族 |
Language.native | String | 可用的本地名称集合 |
Language.wikiUrl | String | 相对链接到语言维基百科页面 |
Language.name_in | Map<Language, List<String>> | 可用的翻译名称集合 |
货币对象
基于ISO 4217货币代码的货币数据。
对象 | 类型 | 描述 |
---|---|---|
Currency.iso_4217_code | String | ISO 4217 alpha3 代码 |
Currency.iso_4217_numeric | String | ISO 4217 数字代码 |
Currency.iso_4217_name | String | ISO 4217 数字代码 |
Currency.iso_4217_minor_unit | String | 货币的最小单位,取决于小数位数 |
Currency.full_name | String | 英语全名 |
Currency.symbol | String | 货币符号 |
Currency.symbol_native | String | 货币本地符号 |
Currency.decimal_digits | String | 小数位数 |
Currency.rounding | String | 货币四舍五入 |
Currency.name_plural | String | 货币复数名称 |
Currency.withdrawal_date | String | 退出日期 |
名称对象
对象 | 类型 | 描述 |
---|---|---|
Name.common | String | 英语中的常用名称 |
Name.official | String | 英语中的正式名称 |
拨号对象
对象 | 类型 | 描述 |
---|---|---|
Dialing.calling_code | String | 拨号代码 |
Dialing.national_number_lengths | int | 国内号码长度 |
经纬度对象
对象 | 类型 | 描述 |
---|---|---|
LatLng.latitude | String | 纬度坐标点 |
LatLng.longitude | String | 经度坐标点 |
省份对象
对象 | 类型 | 描述 |
---|---|---|
Province.id | int | 省份ID |
Province.name | String | 省份名称 |
Province.state_code | String | 州/省代码 |
Province.latLng | LatLng | 坐标点(十进制度形式) |
Province.type | String | 州/省类型 |
Province.cities | List<City> | 州/省内的城市列表 |
城市对象
对象 | 类型 | 描述 |
---|---|---|
City.id | int | 城市ID |
City.name | String | 城市名称 |
City.latLng | LatLng | 坐标点(十进制度形式) |
地理对象
对象 | 类型 | 描述 |
---|---|---|
Geographical.Continents | Continents | 国家所在的大陆 |
Geographical.postal_code | String | 区域邮政编码 |
Geographical.latLng_dms | LatLng | 坐标点(度分秒形式) |
Geographical.latLng_dec | LatLng | 坐标点(十进制度形式) |
Geographical.latLng_min | LatLng | 最小坐标点(十进制度形式) |
Geographical.latLng_max | LatLng | 最大坐标点(十进制度形式) |
Geographical.area | double | 土地面积(平方公里) |
Geographical.region | String | 地理区域 |
Geographical.subregion | String | 地理子区域 |
Geographical.world_region | int | 地理世界区域 |
Geographical.region_code | String | 地理子区域数字代码 |
Geographical.subregion_code | LatLng | 地理子区域数字代码 |
Geographical.landlocked | bool | 是否内陆 |
Geographical.borders | Country | 陆地边界 |
Geographical.independent | String | 独立状态 |
额外数据对象
对象 | 类型 | 描述 |
---|---|---|
Extra.geonameid | String | Geoname ID |
Extra.edgar | String | 电子数据收集、分析和检索系统 |
Extra.itu | String | 国际电信联盟分配的代码 |
Extra.marc | String | 来自国会图书馆的机器可读目录代码 |
Extra.wmo | String | 世界气象组织的国家缩写 |
Extra.ds | String | 国际交通车辆识别标志 |
Extra.fifa | String | 国际足球联合会分配的代码 |
Extra.fips | String | 美国联邦信息处理标准代码 |
Extra.gaul | String | 食品和农业组织的全球行政单位层 |
Extra.ioc | String | 国际奥委会分配的代码 |
Extra.cowc | String | 战争相关性特征 |
Extra.cown | String | 战争相关性数值 |
Extra.fao | String | 食品和农业组织 |
Extra.imf | String | 国际货币基金组织 |
Extra.ar5 | String | 第五次评估报告(AR5) |
Extra.address_format | String | 地址格式 |
Extra.eu_member | String | 欧盟成员 |
人口对象
对象 | 类型 | 描述 |
---|---|---|
Population.count | int | 人口数量 |
Population.worldPercentage | double | 国家人口占世界人口的百分比 |
居民对象
对象 | 类型 | 描述 |
---|---|---|
Demonym.male | Map<Language, String> | 男性居民名称 |
Demonym.female | Map<Language, String> | 女性居民名称 |
时区对象
对象 | 类型 | 描述 |
---|---|---|
TimeZone.zoneName | Map<Language, String> | 时区名称 |
TimeZone.gmtOffset | Map<Language, String> | 与格林尼治标准时间的时间差 |
TimeZone.gmtOffsetName | Map<Language, String> | 格林尼治标准时间名称 |
TimeZone.abbreviation | Map<Language, String> | 时区缩写 |
TimeZone.tzName | Map<Language, String> | 时区名称 |
增值税率对象
对象 | 类型 | 描述 |
---|---|---|
VATRate.standard | double | 标准增值税 |
VATRate.reduced | List<double> | 减少的税率 |
VATRate.super_reduced | double | 超低税率 |
VATRate.parking | double | 停车增值税 |
使用
getworld
必须通过initialize
函数初始化,并在整个项目中只调用一次。initialize
函数会从三个列表Countries
、Currencies
和Languages
中检索数据。你可以像使用map
、forEach
等方法一样使用它们。
import 'package:getworld/getworld.dart';
void main() async {
Stopwatch stopwatch = Stopwatch()..start();
GetWorld().initialize();
print(Countries.length);
print(Languages.length);
print(Currencies.length);
print('GetWorld.initialize executed in ${stopwatch.elapsed.inMilliseconds} Milliseconds\n');
//按常用/官方名称查找
stopwatch.reset();
print(Countries.where((country) => country.name.official.toLowerCase().contains("Egypt".toLowerCase()) || country.name.common.toLowerCase().contains("Egypt".toLowerCase())).map((e) => e.name.common));
print('Countries.where executed in ${stopwatch.elapsed.inMilliseconds} Milliseconds\n');
//按拨号代码查找
stopwatch.reset();
print(Countries.where((country) => country.dialling!.calling_code.contains("+1")).map((e) => e.name.common));
print('Countries.where executed in ${stopwatch.elapsed.inMilliseconds} Milliseconds\n');
//按货币对象查找
stopwatch.reset();
print(Countries.where(
(country) => country.currencies!.contains(Currencies.firstWhere((cur) => cur.iso_4217_code == "USD")))
.map((e) => e.name.common));
print('Countries.where executed in ${stopwatch.elapsed.inMilliseconds} Milliseconds\n');
//按货币代码查找
stopwatch.reset();
print(Countries.where((country) => country.currencies!.any((currency) => currency.iso_4217_code == "USD"))
.map((e) => e.name.common));
print('Countries.where executed in ${stopwatch.elapsed.inMilliseconds} Milliseconds\n');
}
更多关于Flutter功能未知插件getworld的介绍与使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
更多关于Flutter功能未知插件getworld的介绍与使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
Flutter 功能未知插件 getworld
的介绍与使用
getworld
是一个在 Flutter 社区中可能不太常见但功能丰富的插件,用于处理一些特定的业务需求或集成第三方服务。尽管其具体功能和用途可能因版本和文档更新而有所变化,但以下将提供一个基本的介绍和使用示例。
介绍
getworld
插件通常用于提供以下功能之一或多个:
- 地理位置服务:集成地图服务,获取用户位置,显示地图等。
- 第三方API集成:与特定的第三方服务进行集成,如支付、社交登录将等基于。假设
的3地理位置.服务 功能UI提供一个组件示例。:
提供
自定义####的 使用UI
组件
,1如.特殊 **的添加按钮依赖、**动画
等
。首先
,
在由于
具体pub功能和用法需要参考官方文档和源码,以下spec.yaml
文件中添加getworld
插件的依赖:
dependencies:
flutter:
sdk: flutter
getworld: ^x.y.z # 替换为实际版本号
然后运行 flutter pub get
来获取依赖。
- 导入插件
在你的 Dart 文件中导入插件:
import 'package:getworld/getworld.dart';
- 使用插件功能
以下是一个假设的示例,展示如何使用 getworld
插件获取用户当前位置并在地图上显示:
import 'package:flutter/material.dart';
import 'package:getworld/getworld.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
double? latitude;
double? longitude;
@override
void initState() {
super.initState();
_getCurrentLocation();
}
Future<void> _getCurrentLocation() async {
try {
// 假设 getworld 插件有一个 getCurrentLocation 方法
LocationResult locationResult = await GetWorldPlugin.getCurrentLocation();
if (locationResult.success) {
setState(() {
latitude = locationResult.latitude;
longitude = locationResult.longitude;
});
} else {
print("Failed to get location: ${locationResult.error}");
}
} catch (e) {
print("Error getting location: $e");
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('GetWorld Plugin Example'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
if (latitude != null && longitude != null)
Text("Latitude: $latitude, Longitude: $longitude"),
else
Text("Loading location..."),
],
),
),
);
}
}
注意:
- 上面的代码是一个假设性的示例,因为
getworld
插件的实际 API 和方法名可能不同。 - 请务必参考
getworld
插件的官方文档和源码来了解其实际功能和用法。 - 插件可能包含多个类和方法,需要根据具体需求选择使用。
结论
getworld
插件可能提供多种功能,具体取决于其版本和文档。上述示例仅展示了如何假设性地使用其获取地理位置的功能。为了准确使用插件,请查阅其官方文档和源码。