Flutter - Is there anything similar to sync adapter in flutter - android

I wanted to sync my local DB with my server. In Android we have sync Adapter that does the work and make life easier. I would wonder if we have something similar in Flutter or how can I do that in flutter.

Sync-adapters are core Android components. Flutter cannot directly provide a replacement for them. However, flutter does provide a mechanism to use platform specific APIs called flutter plugin. And although their are a lot of plugins already present, their is still a bit lack of plugins providing such core platform support.
Ideally, in an android application, the sync adapters are background services which can be triggered by the OS itself in a separate process, so the simplest way would be to do the following :
Create a separate sync-adapter inside the android directory of your flutter app. Make sure you correctly follow all the requirements for the sync-adapter to work. The documentation is in here.
Create a simple plugin-mechanism using this to invoke android APIs corresponding to the sync-adapter.
Also note that all this code - Android sync-adapter, flutter-plugin and your flutter-app, can simply reside in current code base. You are NOT REQUIRED to create a separate "plugin" to actually use the plugin.

Related

How to log from platform specific module (Android) in Flutter

I am starting development of my first Flutter app and I would like to know if there is a way how to use breakpoints and logging in classes that are not written in Dart (either iOS or Android specific classes).
I didnt find any mention of platform specific logging in official docs
There are many plugin which can help you to put logs in flutter or if you want to make some custom logerUtils than you can also create your plugin and use in for you project it it very simple and you can find lots of refrence on the internet
also you can use this which provided by flutter as well
https://api.flutter.dev/flutter/foundation/debugPrint.html

How to keep my flutter app running in the background when close?

I am building an app and I want it to show up in the user's notification bar and run in the background even when it's closed. Similar to "KWGT Kustom Widget Maker".
I've tried looking for libraries that allow this, but I can only find those related to java. Are there any available for Dart/Flutter or any other workaround? I am only targeting android devices.
I used a package called flutter_background , which worked for me perfectly.
The mechanism for this feature involves setting up an isolate. Isolates are Dart’s model for multithreading, though an isolate differs from a conventional thread in that it doesn’t share memory with the main program. You’ll set up your isolate for background execution using callbacks and a callback dispatcher.
For more information and a geofencing example that uses background execution of Dart code, see Executing Dart in the Background with Flutter Plugins and Geofencing, an article in the Flutter Publication on Medium. At the end of this article, you’ll find links to example code, and relevant documentation for Dart, iOS, and Android
After searching, I guess you have two solution:
You can use flutter wrapper for both android and IOS platform, but you won't be able to run jobs often than every 15 minutes. If you want to schedule jobs more often, you'll need to write platform dependent code, using the android_alarm_manager flutter package and background_fetch for IOS.
You can trigger the correct one using the Platform function in dart.
You should use Isolates for this, also you can use android_alarm_manager or background_fetch libraries
You can use the flutter_workmanager plugin.
It's better than the android_alarm_manager plugin since it uses newer API's on Android and also works with iOS.

NativeScript : Use platform specific native library without a multi-platform plugin?

We're trying to use ArcGIS's Android Runtime SDK in NativeScript (it has no nativescript plugin) but we have accessed that rewriting the whole library as a multi-platform plugin would take too much time.
My question is, how can we utilize the native library directly but only the android version of it?
This is the library: https://developers.arcgis.com/android/latest/api-reference/reference/packages.html
Also, is it possible to use it without a custom UI plugin? I don't understand how to add the mapView to the app .xml
For example, in their AndroidStudio tutorial they mention the following steps and I'm not sure how to translate them to NativeScript
Source : https://developers.arcgis.com/android/latest/guide/develop-your-first-map-app.htm
I'm not quite sure what you mean by re-writing the whole library, you never have to do that.
Plugins are being written to wrap the native library with simple user friendly JS api / methods, it necessarily need not to be cross (or multi) platform either.
You may even directly access any third party library within your project as soon you mark them as dependency in your app gradle file.
Here is how you access native apis.
For instance if you want to create an instance of LocatorTask, this should work once you add the library as dependency in your NativeScript project.
const locatorTask = com.esri.arcgisruntime.tasks.geocode.LocatorTask("URI_HERE");
locatorTask.loadAsync();

How are your experiences with NativeScript?

Does anyone have experience with NativeScript and can compare it to developing native apps, especially for Android?
I have read all these articles:
FIRST THOUGHTS ON NATIVESCRIPT
SECOND THOUGHTS ON NATIVESCRIPT
Introduction to Native Script – Is It Worth Your Time?
My Experience Developing with Telerik NativeScript
I know especially three of them may be outdated. But I want to ask all of you developers:
How is your experience with NativeScript?
Are there any Android-Components you cannot use? Which are these ones?
Is styling really so limited?
Do apps really look so different at runtime as in the mockup as in the pictures of the first article referenced above?
Does loading of native Android objects into JavaScript Code always work correctly?
Does NativeScript generate Java-Code for Android-Platform out of the NativeScript code I write?
Is it possible to modifiy this code if I want to use some native-only features? What if I want to make UI changes then? Do I have to regenerate the code and do I miss my native extensions then?
Very glad to see that you are evaluating NativeScript to eventually use it in present and future projects.
I'll try to condense answers to a few of the questions into one, as they really are mostly related.
Skipped.*
That depends on what has already been exposed through a custom view/plugin or module. The core-modules that every NativeScript app comes with contains the most basic of wrappers for both Android and iOS under a common API. There are plugins (nativescript npm modules) that provide additional wrappers on native android views (nativescript-telerik-ui for one, nativescript-carousel), most of which are created by the NS community.
As RexSplode mentioned before me - it's mostly the platform that imposes certain limitations. NS uses CSS to declare style, but you can also access the native components and manage their style and appearance programatically if what you need isn't readily available out of the box.
First I'd like to note that the first 3 articles you've linked are over a year old now, and trust me, NativeScript has evolved a lot since then. With all the available components (remember the npm modules I mentioned earlier?) there's a good chance that you will get a close to 1:1 similarity to a well-styled native Android mockup.
At build time metadata is generated for the Android/Java public API used in the project. When the JavaScript Engine (V8) fires up, that metadata is loaded into memory, prototype chains are constructed, and callbacks are attached, so that when you call new android.widget.Button(); in your JavaScript code, the proper virtual machine instructions will be called, and a native button will be created. Static methods are accessed similarly, check out the official docs to get a better understanding of how it all works.https://docs.nativescript.org/runtimes/android/advanced-topics/execution-flow
and 7., and a cont. of 2. Java code, or rather compiled Java code is generated whenever you wish to extend a native Android class that isn't available already in a module or in the native Framework. Extending classes is very similar to how you would do it in Java - you extend a class, and create new implementations of interfaces. That means that you won't have to open Android Studio to create a new class, build it into a native plugin and then add it to your project, since you can do it all in your NativeScript code using JavaScript/TypeScript. https://docs.nativescript.org/runtimes/android/generator/extend-class-interface
Disclaimer: I am on the NativeScript Engineering team
I investigated the Native Script a little and my colleague at work writes an app with it, so I can offer you a bit of information that I have.
1. skipped
There are limited amount of components you can use with native script out of the box. However, if you have a native-java developer who can write a wrapper for you - you can use everything.
It is limited to the platform you are using. Android itself has a lot of style limitations which cannot be easily overwhelmed.
don't know
It works a little different. Your JS object, or rather widgets are translated to java code. So with the items from the box - yes, they are okey. If you write a wrapper for your custom component, then all is up to you.
Yes it does.
No, the code is generated, how are you going to modify it? Changes will be undone on the next build. However, you can write a native module for your application and use any features you want. It is like defining an interface, which you can use in JS code afterwards.

NativeScript - Native UI access

I dont get it yet.
In NativeScript/Android can I use all the UI components even if there is nota bundle (nativescript plugin). ?
I ask this question because Telerik offers a special UI package, with elements that already exists in native Android UI.
Thanks.
Short and simple: Yes, you can access the native UI even if there is not a plugin.
Those plugins are to provide some helpers so yo don't need to type everything for both platforms on your own.
For example, if you want to create a label on an Android platform, without using the plugin, is as easy as:
new android.widget.TextView(this._context);
You can take a look at all the UI components in their GitHub to see how the plugins work in both platforms:
https://github.com/NativeScript/NativeScript/tree/master/tns-core-modules/ui

Categories

Resources