dart_iztro 0.0.3
dart_iztro: ^0.0.3 copied to clipboard
一个支持多平台的紫微斗数和八字计算 Flutter 插件,支持农历阳历转换。
dart_iztro #
一个支持多平台的紫微斗数和八字计算Flutter插件。提供紫微斗数星盘和八字计算功能,支持农历阳历转换,可用于命理、占卜和星盘分析应用。
声明:本项目代码源自 @SylarLong/iztro,感谢原作者的开源贡献。
功能特点 #
- 根据阳历日期计算农历日期
- 计算八字信息
- 计算紫微斗数星盘信息
- 提供星盘各宫位的详细信息
- 支持多平台:Android、iOS、macOS、Windows和Web
安装 #
将以下内容添加到您的 pubspec.yaml 文件中:
dependencies:
dart_iztro: ^0.0.1
然后运行:
flutter pub get
备选安装方式 #
如果从pub.dev安装遇到问题,可以使用Git依赖方式安装:
dependencies:
dart_iztro:
git:
url: https://github.com/yourusername/dart_iztro.git
ref: v0.0.2
使用方法 #
import 'package:dart_iztro/dart_iztro.dart';
// 创建实例
final iztro = DartIztro();
// 获取八字信息
final birthData = await iztro.calculateBaZi(
year: 1990,
month: 1,
day: 1,
hour: 12,
minute: 0,
isLunar: false, // 是否农历
gender: Gender.male,
);
// 获取紫微斗数星盘
final chart = await iztro.calculateChart(
year: 1990,
month: 1,
day: 1,
hour: 12,
minute: 0,
isLunar: false, // 是否农历
gender: Gender.male,
);
// 打印宫位信息
print(chart.palaces);
更多示例 #
更多使用示例请查看 example 文件夹中的示例应用。
许可证 #
本项目采用 MIT 许可证 - 详见 LICENSE 文件
本项目遵循与原项目 @SylarLong/iztro 相同的开源许可证。如有任何版权问题,请联系我们立即处理。
Getting Started #
This project is a starting point for a Flutter plug-in package, a specialized package that includes platform-specific implementation code for Android and/or iOS.
For help getting started with Flutter development, view the online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.
多语言支持 #
本库使用GetX框架管理多语言翻译。以下是使用多语言功能的步骤:
1. 初始化翻译服务 #
在应用启动时初始化翻译服务:
void main() {
// 初始化翻译服务,设置初始语言为中文
IztroTranslationService.init(initialLocale: 'zh_CN');
runApp(MyApp());
}
2. 使用GetMaterialApp #
确保在应用中使用GetMaterialApp而不是MaterialApp:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GetMaterialApp(
// 应用配置
);
}
}
3. 切换语言 #
可以随时切换应用的语言:
// 切换到英文
IztroTranslationService.changeLocale('en_US');
// 切换到中文
IztroTranslationService.changeLocale('zh_CN');
4. 获取当前语言信息 #
// 获取当前语言的Locale对象
Locale? locale = IztroTranslationService.currentLocale;
// 获取当前语言代码
String languageCode = IztroTranslationService.currentLanguageCode;
// 获取当前国家代码
String countryCode = IztroTranslationService.currentCountryCode;
5. 支持的语言 #
目前支持的语言列表:
List<Map<String, dynamic>> supportedLocales = IztroTranslationService.supportedLocales;
6. 集成应用层的多语言支持 #
如果您的应用也需要多语言支持,可以将应用的翻译与库的翻译集成在一起:
void main() {
// 初始化翻译服务
IztroTranslationService.init(initialLocale: 'zh_CN');
// 添加应用层的翻译
IztroTranslationService.addAppTranslations({
'zh_CN': {
'app_name': '我的紫微应用',
'welcome': '欢迎使用',
// 其他应用翻译...
},
'en_US': {
'app_name': 'My Zi Wei App',
'welcome': 'Welcome',
// 其他应用翻译...
},
});
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GetMaterialApp(
// 使用合并了应用翻译的翻译服务
translations: IztroTranslationService.withAppTranslations(),
locale: IztroTranslationService.currentLocale,
fallbackLocale: const Locale('zh', 'CN'),
title: 'app_name'.tr, // 应用层翻译
home: HomePage(),
);
}
}
这样您就可以在应用中同时使用库的翻译和自己的翻译。