dart_iztro
English | 简体中文 | 繁體中文 | 日本語 | 한국어 | ภาษาไทย | Tiếng Việt
A cross-platform Flutter plugin for Purple Star Astrology (Zi Wei Dou Shu) and BaZi calculations. It provides functionality for calculating Purple Star astrology charts and BaZi, supports lunar and solar calendar conversion, and can be used for destiny analysis, divination, and astrological applications.
Disclaimer: This project code is derived from @SylarLong/iztro. Thanks to the original author for the open-source contribution.
Features
- Calculate lunar date from solar date
- Calculate BaZi information
- Calculate Purple Star Astrology chart information
- Provide detailed information for each palace in the chart
- Accurately calculate true solar time (based on astronomical algorithms)
- Geographic location query with latitude and longitude information
- Support multiple platforms: Android, iOS, macOS, Windows, and Web
- Multi-language support: Simplified Chinese, Traditional Chinese, English, Japanese, Korean, Thai, Vietnamese
Installation
dependencies:
dart_iztro: ^0.1.0
Alternative Installation
If you encounter issues installing from pub.dev, you can install via Git dependency:
dependencies:
dart_iztro:
git:
url: https://github.com/EdwinXiang/dart_iztro.git
ref: v0.1.0
Usage
import 'package:dart_iztro/dart_iztro.dart';
// Create an instance
final iztro = DartIztro();
// Get BaZi information
final birthData = await iztro.calculateBaZi(
year: 1990,
month: 1,
day: 1,
hour: 12,
minute: 0,
isLunar: false, // Whether it's lunar calendar
isLeap: true, // If lunar, whether to adjust for leap month (default is true)
gender: Gender.male,
);
// Get Purple Star Astrology chart
final chart = await iztro.calculateChart(
year: 1990,
month: 1,
day: 1,
hour: 12,
minute: 0,
isLunar: false, // Whether it's lunar calendar
isLeap: true, // If lunar, whether to adjust for leap month (default is true)
gender: Gender.male,
);
// Set language
// Supports multiple languages, default is Simplified Chinese (zh_CN)
await iztro.setLanguage('en_US'); // English
await iztro.setLanguage('zh_TW'); // Traditional Chinese
await iztro.setLanguage('ja_JP'); // Japanese
await iztro.setLanguage('ko_KR'); // Korean
await iztro.setLanguage('th_TH'); // Thai
await iztro.setLanguage('vi_VN'); // Vietnamese
// Print palace information
print(chart.palaces);
Calculate True Solar Time
This library provides accurate true solar time calculation functionality, based on astronomical algorithms, considering factors such as the elliptical shape of Earth's orbit and the tilt of Earth's axis:
import 'package:dart_iztro/utils/solar_time_util.dart';
// Create a date-time object
final solarTime = SolarTime(
2023, // Year
6, // Month
15, // Day
12, // Hour
30, // Minute
0 // Second
);
// Create a solar time calculation utility, specifying the longitude and latitude of the location (Beijing)
final solarTimeUtil = SolarTimeUtil(
longitude: 116.4074, // Longitude, positive for east, negative for west
latitude: 39.9042 // Latitude, positive for north, negative for south
);
// Calculate mean solar time
final meanSolarTime = solarTimeUtil.getMeanSolarTime(solarTime);
// Calculate true solar time
final realSolarTime = solarTimeUtil.getRealSolarTime(solarTime);
// Output results
print('Mean Solar Time: ${meanSolarTime.toString()}');
print('True Solar Time: ${realSolarTime.toString()}');
Geographic Location Query
This library provides geographic location query functionality, supporting latitude and longitude lookup by address:
import 'package:dart_iztro/services/geo_lookup_service.dart';
// Create a geographic location query service
final geoService = GeoLookupService();
// Query address
final location = await geoService.lookupAddress('Haidian District, Beijing');
if (location != null) {
print('Address: ${location.displayName}');
print('Longitude: ${location.longitude}');
print('Latitude: ${location.latitude}');
}
Parameter Description
year
,month
,day
,hour
,minute
: Year, month, day, hour, and minute of birthisLunar
: Whether it's a lunar calendar date, default is solar calendar (false
)isLeap
: Effective whenisLunar
istrue
, used to handle leap month situations- When set to
true
(default), the first half of a leap month is considered as the previous month, the second half as the next month - When set to
false
, leap months are not adjusted
- When set to
gender
: Gender, using enum type, possible values areGender.male
orGender.female
More Examples
For more usage examples, please check the sample application in the example folder.
License
This project is licensed under the MIT License - see the LICENSE file for details
This project follows the same open-source license as the original project @SylarLong/iztro. If there are any copyright issues, please contact us for immediate handling.
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.
Multi-language Support
This library uses the GetX framework to manage multilingual translations. Here are the steps to use the multilingual functionality:
1. Initialize Translation Service
Initialize the translation service when starting the application:
void main() {
// Initialize translation service, set initial language to Chinese
IztroTranslationService.init(initialLocale: 'zh_CN');
runApp(MyApp());
}
2. Use GetMaterialApp
Ensure you use GetMaterialApp instead of MaterialApp in your application:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GetMaterialApp(
// Application configuration
);
}
}
3. Switch Language
You can switch the application's language at any time:
// Switch to English
IztroTranslationService.changeLocale('en_US');
// Switch to Chinese
IztroTranslationService.changeLocale('zh_CN');
4. Get Current Language Information
// Get the Locale object of the current language
Locale? locale = IztroTranslationService.currentLocale;
// Get the current language code
String languageCode = IztroTranslationService.currentLanguageCode;
// Get the current country code
String countryCode = IztroTranslationService.currentCountryCode;
5. Supported Languages
List of currently supported languages:
List<Map<String, dynamic>> supportedLocales = IztroTranslationService.supportedLocales;
6. Integrate Application-level Multi-language Support
If your application also needs multi-language support, you can integrate your application's translations with the library's translations:
void main() {
// Initialize translation service
IztroTranslationService.init(initialLocale: 'zh_CN');
// Add application-level translations
IztroTranslationService.addAppTranslations({
'zh_CN': {
'app_name': 'My Purple Star App',
'welcome': 'Welcome',
// Other application translations...
},
'en_US': {
'app_name': 'My Zi Wei App',
'welcome': 'Welcome',
// Other application translations...
},
});
runApp(MyApp());
}
In this way, you can use both the library's translations and your own translations in your application.
Contribution Guidelines
If you are interested in dart_iztro
and want to join the contributor team, we greatly welcome your contribution in the following ways:
- If you have suggestions about the functionality of the program, please create a
Feature Request
on GitHub - If you find bugs in the program, please create a
Bug Report
on GitHub - You can also
fork
this repository to your own repository for modification, then send a PR to this repository - If you have expertise in foreign languages, we welcome your contribution in translating the language translation files
Important note: If you find the code useful, please hit ⭐ to support! Your ⭐ is my motivation to continue updating!
Note: Please use this open-source code appropriately. Do not use it for illegal purposes.
Support Through Donations
If you find this project helpful, you might consider supporting me with a cup of coffee ☕️

Alipay

WeChat Pay
Libraries
- crape_myrtle/astro/analyzer
- crape_myrtle/astro/astro
- crape_myrtle/astro/funcation_astrolabe
- crape_myrtle/astro/funcation_horoscope
- crape_myrtle/astro/funcation_palace
- crape_myrtle/astro/funcation_surpalaces
- crape_myrtle/astro/palace
- crape_myrtle/astro/yearly_stems_branches
- crape_myrtle/data/constants
- crape_myrtle/data/earth_branches
- crape_myrtle/data/heavenly_stems
- crape_myrtle/data/stars
- crape_myrtle/data/types/astro
- crape_myrtle/data/types/general
- crape_myrtle/data/types/palace
- crape_myrtle/data/types/star
- crape_myrtle/star/adjective_star
- crape_myrtle/star/decorative_star
- crape_myrtle/star/funcational_star
- crape_myrtle/star/horoscope_star
- crape_myrtle/star/location
- crape_myrtle/star/major_star
- crape_myrtle/star/minor_star
- crape_myrtle/tools/crape_util
- crape_myrtle/tools/strings
- crape_myrtle/translations/en_US/brightness_en
- crape_myrtle/translations/en_US/common_en
- crape_myrtle/translations/en_US/earthly_branch_en
- crape_myrtle/translations/en_US/five_element_class_en
- crape_myrtle/translations/en_US/gender_en
- crape_myrtle/translations/en_US/heavenly_stem_en
- crape_myrtle/translations/en_US/index
- crape_myrtle/translations/en_US/mutagen_en
- crape_myrtle/translations/en_US/palace_en
- crape_myrtle/translations/en_US/stars_en
- crape_myrtle/translations/ja_JP/brightness_ja
- crape_myrtle/translations/ja_JP/common_ja
- crape_myrtle/translations/ja_JP/earthly_branch_ja
- crape_myrtle/translations/ja_JP/five_element_class_ja
- crape_myrtle/translations/ja_JP/gender_ja
- crape_myrtle/translations/ja_JP/heavenly_stem_ja
- crape_myrtle/translations/ja_JP/index
- crape_myrtle/translations/ja_JP/mutagen_ja
- crape_myrtle/translations/ja_JP/palace_ja
- crape_myrtle/translations/ja_JP/stars_ja
- crape_myrtle/translations/ko_KR/brightness_ko
- crape_myrtle/translations/ko_KR/common_ko
- crape_myrtle/translations/ko_KR/earthly_branch_ko
- crape_myrtle/translations/ko_KR/five_element_class_ko
- crape_myrtle/translations/ko_KR/gender_ko
- crape_myrtle/translations/ko_KR/heavenly_stem_ko
- crape_myrtle/translations/ko_KR/index
- crape_myrtle/translations/ko_KR/mutagen_ko
- crape_myrtle/translations/ko_KR/palace_ko
- crape_myrtle/translations/ko_KR/stars_ko
- crape_myrtle/translations/th_TH/brightness_th
- crape_myrtle/translations/th_TH/common_th
- crape_myrtle/translations/th_TH/earthly_branch_th
- crape_myrtle/translations/th_TH/five_element_class_th
- crape_myrtle/translations/th_TH/gender_th
- crape_myrtle/translations/th_TH/heavenly_stem_th
- crape_myrtle/translations/th_TH/index
- crape_myrtle/translations/th_TH/mutagen_th
- crape_myrtle/translations/th_TH/palace_th
- crape_myrtle/translations/th_TH/stars_th
- crape_myrtle/translations/translation_service
- crape_myrtle/translations/types/brightness
- crape_myrtle/translations/types/earthly_branch
- crape_myrtle/translations/types/five_element_class
- crape_myrtle/translations/types/gender
- crape_myrtle/translations/types/heavenly_stem
- crape_myrtle/translations/types/mutagen
- crape_myrtle/translations/types/palace
- crape_myrtle/translations/types/star_name
- crape_myrtle/translations/vi_VN/brightness_vi
- crape_myrtle/translations/vi_VN/common_vi
- crape_myrtle/translations/vi_VN/earthly_branch_vi
- crape_myrtle/translations/vi_VN/five_element_class_vi
- crape_myrtle/translations/vi_VN/gender_vi
- crape_myrtle/translations/vi_VN/heavenly_stem_vi
- crape_myrtle/translations/vi_VN/index
- crape_myrtle/translations/vi_VN/mutagen_vi
- crape_myrtle/translations/vi_VN/palace_vi
- crape_myrtle/translations/vi_VN/stars_vi
- crape_myrtle/translations/zh_CN/brightness_cn
- crape_myrtle/translations/zh_CN/common_cn
- crape_myrtle/translations/zh_CN/earthly_branch_cn
- crape_myrtle/translations/zh_CN/five_element_class_cn
- crape_myrtle/translations/zh_CN/gender_cn
- crape_myrtle/translations/zh_CN/heavenly_stem_cn
- crape_myrtle/translations/zh_CN/mutagen_cn
- crape_myrtle/translations/zh_CN/palace_cn
- crape_myrtle/translations/zh_CN/stars_cn
- crape_myrtle/translations/zh_TW/brightness_tw
- crape_myrtle/translations/zh_TW/common_tw
- crape_myrtle/translations/zh_TW/earthly_branch_tw
- crape_myrtle/translations/zh_TW/five_element_class_tw
- crape_myrtle/translations/zh_TW/gender_tw
- crape_myrtle/translations/zh_TW/heavenly_stem_tw
- crape_myrtle/translations/zh_TW/index
- crape_myrtle/translations/zh_TW/mutagen_tw
- crape_myrtle/translations/zh_TW/palace_tw
- crape_myrtle/translations/zh_TW/stars_tw
- dart_iztro
- dart_iztro_method_channel
- dart_iztro_platform_interface
- dart_iztro_web
- lunar_lite/utils/convertor
- lunar_lite/utils/ganzhi
- lunar_lite/utils/misc
- lunar_lite/utils/types
- lunar_lite/utils/utils
- models/city_model
- services/geo_lookup_service
- solar_time_calculator
- utils/solar_time_util