0

I was looking for a way to possibly use a java library of my own inside of my Flutter App. I did some research but was only able to find information about how to integrate flutter with native Java libraries on Android exclusively.

Is there a way to call on java code also from Flutter Web and/or Flutter Desktop?

I am sorry I can't provide further information to this question as I was not able to find any "lead" if not starflut (https://pub.dev/packages/starflut) - which to the 'beginner' programmer I am in Flutter might seem an overkill approach to this problem - and I'm not even sure it supports Flutter Web/Desktop as of yet.

Any help, comments or ideas would be highly appreciated

EDIT 1

As implementing Java on Flutter Web seems close to impossible (or not worth the hassle), would calling C++ libraries from Flutter Web be a possibility?

EDIT 2

To better describe my problem/situation, I'll add some context.

I need to write a library that can be accessed by multiple flutter apps (both Web and possibly Mobile, but PWA would also be ok), but also by multiple programs which don't use the flutter framework.

I considered a couple of options, but I am still quite inexperienced and I am not sure which way to go forward with:

  • C++ as the core of the library, and making language bindings to Dart
    • It seems C++ code can work on mobile, but I haven't found a way it can be run on Web as well as within Flutter
  • JavaScript as the core of the library, and
  • Using Dart itself as the core of the library
    • this would be the quickest option when rolling out the Flutter App(s), but it would also have the drawback that I'll need to rewrite the library in another language later on
David Wicker
  • 73
  • 1
  • 1
  • 13
  • 2
    You're going to have a right awful time getting a java library to run on the web and to integrate with flutter. It's not worth the hassle. If starflut does what it says, that's the closest thing I've seen to mobile java support on IOS. – TheChubbyPanda Mar 23 '21 at 21:43
  • @TheChubbyPanda thank you for your comment! Do you have any idea if implementing C++ would be any easier? (For Flutter Web) – David Wicker Mar 23 '21 at 23:26
  • 1
    Like I said, starflut looks like your best bet. I have no idea otherwise, I've never had the need to use languages other than dart. – TheChubbyPanda Mar 23 '21 at 23:31
  • 1
    Why not implementing your library in Dart - and then compile it for non-Flutter separately into a platform-specific library (windows, linux etc)? – Andrija Mar 24 '21 at 10:38
  • @Andrija thank you for your comment; I wouldn't know how to go about that, may I ask if you have an article you could share on that? – David Wicker Mar 24 '21 at 10:39
  • 1
    Here's an article describing how to compile native code: https://medium.com/dartlang/dart2native-a76c815e6baf You cloud also try this: https://medium.com/flutter-community/integrating-c-library-in-a-flutter-app-using-dart-ffi-38a15e16bc14 But again - calling C from web doesn't seem possible. – Andrija Mar 24 '21 at 10:44

1 Answers1

3

Calling c++ from flutter web is not possible. You can, however implement whatever functionality you want in the server-side using whatever language you want and expose the functionality to flutter using whatever web API you desire. You can follow the same approach with Java, and it doesn't have to be just web. The requirement though is that whatever you're implementing has to reside on the "server" which the system can run freely. Your flutter app just "connects" to it and sends and receives messages

Adebayo
  • 175
  • 8