the app is work with android but not work with desktop
[ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: MissingPluginException(No implementation fou
nd for method getDatabasesPath on channel com.tekartik.sqflite)
As pointed in a comment sqflite_common_ffi allows using sqflite API on Desktop. It is not implemented as a flutter plugin as it also works in a regular dart VM.
You might read this to see how to use your existing sqflite code on desktop. But since it is always better to explain a little bit more than adding a link, here are the basic steps:
Setup
First add the dependency:
dependencies:
sqflite_common_ffi:
Initialization
Then initialize ffi before running your app:
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
import 'package:sqflite/sqflite.dart';
Future main() async {
if (Platform.isWindows || Platform.isLinux) {
// Initialize FFI
sqfliteFfiInit();
// Change the default factory
databaseFactory = databaseFactoryFfi;
}
runApp(MyApp());
}
Currently the sqflite only supports Android Ios and Mac.
Alternatively, you can either use Hive or sembast.
If you want to perform queries on the database I suggest you use sembast.
both the packages currently supports all the platform however if you are using sembast you have to include the package sembast_web for web support.
Packages:
Hive: https://pub.dev/packages/hive
Sembast: https://pub.dev/packages/sembast
Sembast_web: https://pub.dev/packages/sembast_web
As #alextk noted, you can use sqflite_common_ffi, to get the Windows support you desire. Depending on your requirements, a pure Dart option may be a better alternative though.
If you just want to store key/value pairs, Hive is probably the way to go, but if you want to store objects, ObjectBox is probably your best bet.
Here is a good article which contains a comparison of existing storage technologies for Flutter:
https://objectbox.io/flutter-databases-sqflite-hive-objectbox-and-moor/
Related
The Firebase docs provide several ways to import SDK in service worker, which confused me. Here are the methods I discovered in the documentation:
https://firebase.google.com/docs/cloud-messaging/js/receive#web-version-9
import { initializeApp } from 'firebase/app';
import { getFirestore, collection, getDocs } from 'firebase/firestore/lite';
I can't utilize the method since I can't process my service worker because my project still uses webpack version 1. So I'm going to concentrate on the 'importScripts' techniques I discovered.
https://firebase.google.com/docs/cloud-messaging/js/receive#web-version-8
importScripts('https://www.gstatic.com/firebasejs/8.10.0/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/8.10.0/firebase-messaging.js');
This is a working approach that I've tested; nevertheless, I have some questions about it:
Is it okay to use this gstatic domain in production?
This official SDK differs from the quickstart-js that they gave.
https://github.com/firebase/quickstart-js/blob/master/messaging/firebase-messaging-sw.js
importScripts('/__/firebase/9.2.0/firebase-app-compat.js');
importScripts('/__/firebase/9.2.0/firebase-messaging-compat.js');
importScripts('/__/firebase/init.js');
This is from the official example quickstart-js, however I still have a lot of questions about it:
It appears that they automatically updated the sample SDK, but the current version of Firebase is 9.6.1, not 9.2.0; should I remain with 9.2.0?
This approach only works in projects hosted by Firebase, and I can't find the init.js file matching to gstatic at the third line; is there a way to directly access that file?
Which approach should I utilize?
And I'm currently using Firebase 9.6.1 outside of my service worker; would utilizing Version 8 within my service worker cause any issues?
I think I'll stick to this:
importScripts('https://www.gstatic.com/firebasejs/9.6.1/firebase-app-compat.js')
importScripts(
'https://www.gstatic.com/firebasejs/9.6.1/firebase-messaging-compat.js'
)
I have this database.
database
How can i get firstName in React-Native ?
It's simple in your case : use react-native-firebase
import firebase from 'react-native-firebase'
const ref = firebase.database().ref('users/fwDRY...G3');
const name = ref.get({ firstname: 'firstname' });
console.log(name.firstname)
Find yourself helpful from the docs: https://rnfirebase.io/docs/v5.x.x/database/reference/database
As React Native runs in Java Script thread on mobile platforms there are 2 ways to use it.
Using Web SDK, but it might be slower and is not as well integrated to the mobile operating system as native.
Using Native SDK for each platform. Using them manually on 2 platforms would require you to write React Native bindings for both platforms. Fortunately, the job has already been done. I highly recommend you to use this library https://github.com/invertase/react-native-firebase. It uses native APIs internally but exposes them into nice JavaScript API. It requires some setup but you won't work it around anyway regardless of the method chosen.
For example, to set it up for Android, you need to follow
https://rnfirebase.io/docs/v5.x.x/installation/initial-setup
https://rnfirebase.io/docs/v5.x.x/installation/android
https://rnfirebase.io/docs/v5.x.x/database/android
After you set it up, follow the link provided by frank-van-puffelen, https://firebase.google.com/docs/database/web/read-and-write#listen_for_value_events. The API on react-native-firebase is almost the same.
i made an app with Electron, react, realm.
my OS is windows 10(x64)
and now i meet a problem when i try to use 'encryptionKey ' option.
var realm = new Realm({schema: [CarSchema, PersonSchema], encryptionKey: new Int8Array(64)});
as you can see, i followed Docs.
and my electron app say "Error: Encryption not enabled at Object."
i try to find the reason for 2 days...but still i can't understand.
i use latest electron(ver.1.6.2) and realm(ver.1.2.0)
and i used 'electron-rebuild' to use realm db in Electron.
so, when i check node_modules
node_modules
------|--relam
------------|-- compiled
------------------|-- electron-v1.6_win32_x64_ <--- this is newly added after i use
electron-rebuild.
------------------|-- node-v48_win32_x64
if i don't use encryptionKey option, my app is working well with no problems to use relam DB.
please give me an answer how to fix it.
Encryption and Sync aren't supported on Windows.
This isn't mentioned in the Realm React Native docs, but it's in the Realm Xamarin Docs under Limitations: https://realm.io/docs/xamarin/latest/#limitations-on-windows-desktop-or-uwp
When using Firebase on ReactNative, it will show such error message:
can't find variable process
However, if I require firebase/lib/firebase-web.js manually, it will show:
can't find variable document
How can I resolve this?
I just went through the same issue while trying to use sockets.io in my react native app so hopefully I can help.
The reason that you cannot use firebase's node module is because there hasn't been a polyfill created yet for websockets support (which firebase is dependent on) in react native.
If you take a look at issue #619 in react native's repo you'll find the current discussion on creating a websockets api polyfill.
The way that we solved it is by using Jason's modified version of the sockets library and creating our own repo around just that file. Then we added the line below to our package.json dependencies.
"react-sockets": "crewapp/react-native-sockets-io"
The reason that Jason's version of the sockets.io client file works is because react-native is added as a user agent. You can find the code that makes this change at the top of the file:
window.navigator = {
userAgent: "react-native"
}
Once you've gone through these steps you should be able to require sockets.io / firebase as normal.
Just figuring it our. Pavan's answer is helpful, but it is not quite true when using with Firebase.
For firebase, please follow the steps:
Download the firebase-debug.js from wsExample. Or you can just install wsExample by npm and require the firebase-debug.js inside it.
Use badfortrains's forked React-Native:
"react-native": "git://github.com/badfortrains/react-native#WebSocket"
New the Firebase like this:
var firebase = require("../../firebase-debug.js");
var rootRef = new Firebase(Const.FB_ROOT);
Things should just work now!
I had issues with socket.io on React Native too, solution was to get notifications about new data and if data is big enough - get it by simple RESTfull request. in my case data was small enough to be sent all within notifications API.
I was using GCM service to send notification to phone from nodejs server. BTW, it uses less battery then socket connection and works great :)
Dart recently added a support for async/await keywords:
https://www.dartlang.org/articles/await-async/
I tried to run a simple code but Chrome Dev Editor does not recognise async keyword
import 'dart:async';
void main() async {
}
Am I doing something wrong (something to modify in the pubspec.yaml ?) or is it just that this feature is not supported yet on Chrome Dev Editor ?
Edit:
Ok, so for know it seem that async/await seems to be more an experimental feature:
https://www.dartlang.org/docs/dart-up-and-running/ch02.html#async-opt-in
To opt into asynchrony support in Dart Editor, go to Preferences, click Experimental, and select Enable Async Support.
In dart and dartanalyzer, use the --enable-async command-line flag:
dart --enable-async async_await.dart
dartanalyzer --enable-async async_await.dart
Unfortunatly, it seems only to work for Dart Editor, not CDE.
Also, dart does not currently support the conversion into javascript without adding a package:
dependencies:
async_await:
git: https://github.com/dart-lang/async_await.git
transformers:
- async_await
So currently it's not supported.
Now there is an issue on this problem: https://github.com/dart-lang/chromedeveditor/issues/3822
Thank you for all your answer
Wait & see...
Did you import the async module?
From the page you linked:
The features described in this article are still under development. Not all the parts of the system necessarily comply with the spec. Early adopters may need to import dart:async for these features to work. Ultimately, Future should move to dart:core and be universally available.
I'm on my Chromebook right now (and can't verify), but I believe you have to enable it under experimental features in the settings.
I don't know whether this helps with CDE, but the Asynchrony part of the Dart language tour has some information on opting in to asynchrony support for other tools.