I am using flutter web and I want to use some packages that are available for the mobile in the web version of flutter. The pubspec of flutter web look a bit different from that of flutter mobile but this is not the real problem. What I am concerned about is that is it possible to add the packages availble for mobile into that of the web. If yes, what is the proper way to do so?
This is not currently possible (as of June 2019) for any package which is dependent on the mobile OS. The reason for this is that the plugins on mobile use platform channels to communicate with platform-dependent code implementations for Android and iOS written in java/kotlin for android or objc/swift for iOS.
The only way those packages would ever work on the web is if a web-specific implementation were written for them which I assume would either use an emscripten-compiled library or more likely some sort of javascript bridge to call the relevant browser APIs.
From the flutter for web readme:
flutter_web does not have a plugin system yet. Temporarily, we provide access to dart:html, dart:js, dart:svg, dart:indexed_db and other web libraries that give you access to the vast majority of browser APIs. However, expect that these libraries will be replaced by a different plugin API.
For any plugin that is 100% dart code, you should be able to just include it in your pubspec.yaml the same way you would in flutter - under dependencies.
yes you can by take source code packages from github and take codes inside lib file inside package and put it in your project and fix errors may happen inside files by change path import to:
import 'package:flutter_web/material.dart';
and some more changes may need to do it.
it will work 100% and so easy :)
Related
I have a Flutter web project, started with flutter_web and migrated to 1.9, all works great but no way to make a external link work.
There're some solutions in stack overflow but any of the solutions don't seems to works as expected, tried all from this link and similar other ones, I supouse the accepted questions would work before 1.9.
With flutter 1.10, we can use universal_html package to open external link:
import 'package:universal_html/prefer_universal/html.dart' as html;
// ...
html.window.location.assign('https://stackoverflow.com');
As of today, you can use url_launcher to open urls for flutter web app. It supports both relative and absolute urls.
https://github.com/flutter/plugins/tree/master/packages/url_launcher/url_launcher_web
Now you can alternatively add url_launcher_web dependency along with url_launcher and then use launch and canLaunch functions from url_launcher package for your web project as if it was mobile.
# pubspec
url_launcher: 5.2.7 # the newest version rather than ^5.1.4
url_launcher_web: ^0.1.0
Seems like it's a temporary solution though, to be merged with the main url_launcher plugin. For now it only works on web but ruins the mobile build (Flutter v1.12.16-pre.35).
I have read a question/answer which states Flutter Web is a fork of Flutter and so one Android Studio (or VScode) project can't be built to handle both.
I'm not an expert on either (obviously) but I don't understand why the fact the libraries are forked implicitly precludes one from using the same source code for the different destinations.
Has anyone done so? And, if so, is there a skeletal project anyone would care to share?
I come from an Android native background and have recently started using Flutter more frequently, but I have no ReactNative experience whatsoever.
Is it at all possible to port an existing RN (npm-package) for use with a Flutter application? My understanding is that a RN compliant package exposes a JS API. Is there any way to implement a form of JS interop to achieve this, or is it not possible, and it would be better to ask the package vendor for Android and iOS specific native library / SDK releases (which were probably used to create the npm-package initially)?
My initial outlook was that it was not possible, but then I saw this article;
https://www.thesmythgroup.com/in-development/how-to-use-npm-packages-in-native-ios-apps/
I would say it is better to use only dart packages, you don't have support for dart in npm, in some months you would have very big problems with that because of the lack of support, take that in mind...
(this is probably a stupid question, but here goes..)
I've been trying for some days now at having a go at creating a integrated cast that works with react-native, but can't get it working.
Is there any easy way of integrating the cast library with react-native, any go-to examples like the CastHelloText-Android for example?
You may check this react-native-google-cast library that unifies both android and iOS chromecast sdk.
For iOS
This library requires Cocoapods to manage Chromecast SDK.
Add pod google-cast-sdk to your Podfile. This is the easier way to have the SDK up to date.
For Android
This library requires Google Play Services, Media Router and Google Cast dependencies to manage Chromecast SDK.
You need to add compile 'com.google.android.gms:play-services-cast:9.4.0' and compile 'com.android.support:mediarouter-v7:23.0.1' into your your app's build.gradle dependencies. mediarouterversion must match with your appcompat version.
Refer to the example folder to find an implementation of this project. Use pod install and react-native link react-native-google-cast to try it.
I am trying to build a project using NDK media sdk, but I need it to run on older phones too (to support 90% of the market...). Now, I am able to include the libmediasdk.so & libOpenMAXAL.so manually, and it seem to link properly, but I am not sure this is a correct practice.
Moreover, the libraries (libmediasdk.so & libOpenMAXAL.so) are expected to be available on the target device, so unless I do copy them manually to the project/libs/arch-arm the application complains libraries are not found.
Have I gone too far ? :) hope not..
You can write code that optionally uses the new native media functions (libmediandk.so), but you can only use it on Android 21+. So if you want to support older android versions, you must make this codepath optional, allowing it to fail cleanly on other devices where libmediandk.so doesn't exist.
If the MediaCodec APIs are optional within your app and you are ok with them only being available on Android 21+, you can just make sure you build this into a separate lib (like libyourapp-media.so), and be ready to handle the case when System.loadLibrary() for this library fails.
However, if you want to use other native code components in your app, there's a few gotchas you need to know. If you build your app targeting android-21 and your native code uses certain functions (such as atof), it will only run on android-21 or newer (even if code using the function atof would build just fine for the older platforms). The reason for this is that the atof function didn't exist before, and calls to it were redirected to strtod. If you build your library targeting android-21, it will actually do the calls to atof instead, which doesn't exist in the older platform versions. This also goes for quite a number of other functions, not only atof. See http://b.android.com/73725 for details on this.
Therefore, if you want to use the new native media APIs in a library that should be loadable on older versions (except for the native media APIs that obviously won't work on older versions), you need to build your native components targeting an older android version. You'd need to duplicate the media/* headers from android-21, but instead of linking to libmediandk.so (-lmediandk in LOCAL_LDLIBS), you'd need to load this library at runtime using dlopen.
If you need to do the same on older platforms as well, you should use the MediaCodec API in java (which you can call via JNI). Then, there's little point in doing all of this extra work just to use the native version of the API on Android 21+, when you can use the java API on all versions (it works from Android 16, and more reliably since Android 18).