sweph 2.10.3+1 copy "sweph: ^2.10.3+1" to clipboard
sweph: ^2.10.3+1 copied to clipboard

outdated

Cross-platform bindings of Swiss Ephemeris APIs for Flutter/Dart.

example/lib/main.dart

import 'package:flutter/material.dart';

import 'package:sweph/sweph.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final sweph = Sweph();
  late String swephVersion;
  late double moonLongitude;
  late Future<double> starDistance;
  late Future<String> heavenlyBodyName;
  late Future<double> houseAscmc;

  @override
  void initState() {
    super.initState();
    swephVersion = sweph.swe_version();
    final jd =
        sweph.swe_julday(2022, 6, 29, (2 + 52 / 60), CalendarType.SE_GREG_CAL);
    moonLongitude = sweph
        .swe_calc_ut(jd, HeavenlyBody.SE_MOON, SwephFlag.SEFLG_SWIEPH)
        .longitude;
    starDistance = getStarName();
    heavenlyBodyName = getAstroidName();
    houseAscmc = getHouseAscmc();
  }

  Future<double> getStarName() async {
    await sweph.ensureInit;
    final jd =
        sweph.swe_julday(2022, 6, 29, (2 + 52 / 60), CalendarType.SE_GREG_CAL);
    return sweph
        .swe_fixstar2_ut('Rohini', jd, SwephFlag.SEFLG_SWIEPH)
        .coordinates
        .distance;
  }

  Future<String> getAstroidName() async {
    await sweph.ensureInit;
    return sweph.swe_get_planet_name(HeavenlyBody.SE_AST_OFFSET + 5);
  }

  Future<double> getHouseAscmc() async {
    await sweph.ensureInit;
    const year = 1947;
    const month = 8;
    const day = 15;
    const hour = 16 + (0.0 / 60.0) - 5.5;

    const longitude = 81 + 50 / 60.0;
    const latitude = 25 + 57 / 60.0;
    final julday =
        sweph.swe_julday(year, month, day, hour, CalendarType.SE_GREG_CAL);

    await sweph.swe_set_ephe_path('assets/ephe');
    sweph.swe_set_sid_mode(SiderealMode.SE_SIDM_LAHIRI,
        SiderealModeFlag.SE_SIDBIT_NONE, 0.0 /* t0 */, 0.0 /* ayan_t0 */);
    final result = sweph.swe_houses(julday, latitude, longitude, 80);
    return result.ascmc[0];
  }

  @override
  Widget build(BuildContext context) {
    const textStyle = TextStyle(fontSize: 25);
    const spacerSmall = SizedBox(height: 10);

    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Native Packages'),
        ),
        body: SingleChildScrollView(
          child: Center(
            child: Container(
              padding: const EdgeInsets.all(10),
              child: Column(
                children: [
                  const Text(
                    'Dart binding for Swiss Ephemeris',
                    style: textStyle,
                    textAlign: TextAlign.center,
                  ),
                  spacerSmall,
                  Text(
                    'sweph.swe_version = $swephVersion',
                    style: textStyle,
                    textAlign: TextAlign.center,
                  ),
                  spacerSmall,
                  Text(
                    'Moon longitude on 2022-06-29 02:52:00 UTC = $moonLongitude',
                    style: textStyle,
                    textAlign: TextAlign.center,
                  ),
                  spacerSmall,
                  FutureBuilder<double>(
                    future: starDistance,
                    builder:
                        (BuildContext context, AsyncSnapshot<double> value) {
                      final displayValue =
                          (value.hasData) ? value.data : 'loading';
                      return Text(
                        'Distance of star Rohini = $displayValue AU',
                        style: textStyle,
                        textAlign: TextAlign.center,
                      );
                    },
                  ),
                  spacerSmall,
                  FutureBuilder<String>(
                    future: heavenlyBodyName,
                    builder:
                        (BuildContext context, AsyncSnapshot<String> value) {
                      final displayValue =
                          (value.hasData) ? value.data : 'loading';
                      return Text(
                        'Name of 5th asteroid = $displayValue',
                        style: textStyle,
                        textAlign: TextAlign.center,
                      );
                    },
                  ),
                  spacerSmall,
                  FutureBuilder<double>(
                    future: houseAscmc,
                    builder:
                        (BuildContext context, AsyncSnapshot<double> value) {
                      final displayValue =
                          (value.hasData) ? value.data : 'loading';
                      return Text(
                        'Distance of star Rohini = $displayValue AU',
                        style: textStyle,
                        textAlign: TextAlign.center,
                      );
                    },
                  ),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}
23
likes
0
points
2
downloads

Publisher

verified publishervm75.duckdns.org

Weekly Downloads

Cross-platform bindings of Swiss Ephemeris APIs for Flutter/Dart.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

ffi, flutter, path_provider, plugin_platform_interface

More

Packages that depend on sweph