vm75 / sweph.dart

GNU Affero General Public License v3.0
16 stars 6 forks source link

MissingPluginException getApplicationSupportDirectory #15

Closed acmpo6ou closed 7 months ago

acmpo6ou commented 7 months ago

Hello! Thanks for making this plugin!

I am a complete newbie in Flutter, this is my first project. I wanted to try out your package. So I opened up the test/widget_test.dart, and changed its contents to this:

import 'package:flutter_test/flutter_test.dart';
import 'package:sweph/sweph.dart';

void main() {
  TestWidgetsFlutterBinding.ensureInitialized();

  test("test", () async {
    await Sweph.init(epheAssets: [
      "packages/sweph/assets/ephe/sepl_18.se1",
    ]);
    print('sweph.swe_version = ${Sweph.swe_version()}');
    print('Moon longitude on 2022-06-29 02:52:00 UTC = ${Sweph.swe_calc_ut(Sweph.swe_julday(2022, 6, 29, (2 + 52 / 60), CalendarType.SE_GREG_CAL), HeavenlyBody.SE_MOON, SwephFlag.SEFLG_SWIEPH).longitude}');
  });
}

but it fails for me with this error:

  MissingPluginException(No implementation found for method getApplicationSupportDirectory on channel plugins.flutter.io/path_provider)
  package:flutter/src/services/platform_channel.dart 320:7  MethodChannel._invokeMethod

Do you know why this happens? It looks like to load the ephemeris file it needs getApplicationSupportDirectory function, but it can't find it?

Thank you!

acmpo6ou commented 7 months ago

I have this in my pubspec.yaml:

dependencies:
  flutter:
    sdk: flutter
  sweph: ^2.10.3
  plugin_platform_interface: ^2.0.2
vm75 commented 7 months ago

pls share the whole project

acmpo6ou commented 7 months ago

The project is just freshly created Flutter project with support for all platforms except the Web. The only files I modified are the pubspec.yaml and that test file.

But actually, your library does work for me, it just doesn't work in tests. Because if I change the dummy Flutter example, you know the one with the button that increments a counter, then it does work:

// ...
      floatingActionButton: FloatingActionButton(
        onPressed: () async {
          await Sweph.init();
          print('sweph.swe_version = ${Sweph.swe_version()}');
          print('Moon longitude on 2022-06-29 02:52:00 UTC = ${Sweph.swe_calc_ut(Sweph.swe_julday(2022, 6, 29, (2 + 52 / 60), CalendarType.SE_GREG_CAL), HeavenlyBody.SE_MOON, SwephFlag.SEFLG_SWIEPH).longitude}');
        },
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
// ...

So if I modify the main.dart like this, when I click on the button the print statements work. But in tests it doesn't work.

I even tried using testWidgets function instead of test, but it gets stuck on Sweph.init(), and the test runs forever.

  testWidgets('test', (WidgetTester tester) async {
    await Sweph.init(epheAssets: [
      "packages/sweph/assets/ephe/sepl_18.se1",
    ]);
    print('sweph.swe_version = ${Sweph.swe_version()}');
    print('Moon longitude on 2022-06-29 02:52:00 UTC = ${Sweph.swe_calc_ut(Sweph.swe_julday(2022, 6, 29, (2 + 52 / 60), CalendarType.SE_GREG_CAL), HeavenlyBody.SE_MOON, SwephFlag.SEFLG_SWIEPH).longitude}');
  });