Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
961 views
in Technique[技术] by (71.8m points)

mysql - Flutter connecting to a database in server

I'm new to flutter and i really want to know, is there a way to connect to a database server (for instance mysql) in flutter rather using firebase. I'm working on a smart parking system project where i need to insert the latitude and longitude of the parking area which is free into the database which is created in server and retrieve it whenever user requests for it. It would be great if anyone gives solution for above mentioned problem (Flutter with database).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Since Flutter is just a UI Framework, topics such as persistence and databases may be out of scope or may depend on the use case.

Flutter UI's can persist data (application state) for short periods of time in a manner that is really only useful for the purposes of creating a good User Experience (is this button click? is it green? etc.)

For persisting more useful data outside of the application and on the actual device, you may want to consider the Shared Preferences Plugin for Flutter.

Wraps NSUserDefaults (on iOS) and SharedPreferences (on Android), providing a persistent store for simple data. Data is persisted to disk automatically and asynchronously.

Now, if you require persisting data in any centralized manner (e.g. RDMS, Firebase, or any data persistence service) your options are:

  • Persistence options that have a Flutter plugin (e.g. Firestore, Firebase)
  • Build your own service layer using HTTP, gRPC that talks to some backend service that provides access to a data store. You can do this with Express, Rails, CloudFunctions, etc.
  • As for connecting directly to a database such as MySQL, I don't see why you couldn't do that (maybe there is some technical limitation), but this would be a very bad idea in any practical situations as (unlike Firebase/Firestore) you won't be able to protect your data store once any client application has write access.

It sounds like you need a central read/write data store, so your best bet may be to host a server that provides access to a database while exposing an API to Flutter for which you can use dart:io to make requests.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...