harmonoid/libwinmedia

flutter build web - error occurs even not using this plugin(just import)

sleepreading opened this issue · 5 comments

Error:

/.../libwinmedia-0.0.7/lib/src/player.dart:2:8: Error: Not found: 'dart:ffi'
import 'dart:ffi';
       ^

/.../libwinmedia-0.0.7/lib/src/internal.dart:2:8: Error: Not found: 'dart:ffi'
import 'dart:ffi';

Environment:

Flutter 2.8.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 77d935af4d (6 weeks ago) • 2021-12-16 08:37:33 -0800
Engine • revision 890a5fca2e
Tools • Dart 2.15.1
mytja commented

ffi doesn't support web and so doesn't this. It supports only Linux and Windows.

Please notice that: I JUST IMPORT this package and not using it!
Here is my code:

import 'package:libwinmedia/libwinmedia.dart';
if (isWindows || isLinux) {
      try {
        LWM.initialize();
        deskPlayer = Player(id: 0);
      } catch (e) {
        print('desk media init error: $e');
        return false;
      }
}

Please notice that: I JUST IMPORT this package and not using it! Here is my code:

import 'package:libwinmedia/libwinmedia.dart';
if (isWindows || isLinux) {
      try {
        LWM.initialize();
        deskPlayer = Player(id: 0);
      } catch (e) {
        print('desk media init error: $e');
        return false;
      }
}

What can I do then? Join Google & change behaviour of dart:ffi to be available on web?

Learn about conditional imports in Dart here and here.
It's like a kIsWeb scenario & there's nothing I can do unfortunately.

I already searched the 'conditional imports', but it can't distinct desktop and mobile.
I understand you now: the dart:ffi can't be compiled when you build for web.
Package like https://github.com/leanflutter/launch_at_startup can only works on desktop, but it will be ok when compile for web(leanflutter/launch_at_startup#2 (comment)). Now I figure it out: launch_at_startup doesn't depend on dart:ffi.