https://github.com/lunagao/leancloud_flutter_plugin
LeanCloud flutter plugin by Luna Gao
https://github.com/lunagao/leancloud_flutter_plugin
flutter flutter-plugin leancloud
Last synced: about 1 month ago
JSON representation
LeanCloud flutter plugin by Luna Gao
- Host: GitHub
- URL: https://github.com/lunagao/leancloud_flutter_plugin
- Owner: LunaGao
- License: mit
- Created: 2018-12-29T17:32:52.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-09-11T08:32:09.000Z (over 5 years ago)
- Last Synced: 2025-04-11T23:53:23.442Z (about 1 month ago)
- Topics: flutter, flutter-plugin, leancloud
- Language: Java
- Size: 158 KB
- Stars: 33
- Watchers: 5
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# LeanCloud flutter plugin
[](http://lunagao.github.io/BlessYourCodeTag/)
[](https://shields.io/)
[](https://travis-ci.org/LunaGao/leancloud_flutter_plugin)[Leancloud](https://leancloud.cn/) flutter plugin by Luna Gao
[Dark packages](https://pub.dartlang.org/packages/leancloud_flutter_plugin)
## Description
This plugin depends on Leancloud Native(iOS / Android) SDK. It's just convert the code from dart to those native language(Objective-C / Java).## Getting Started
### Install
* Add this to your package's pubspec.yaml file:
```
dependencies:
leancloud_flutter_plugin: ^0.0.5
```
* Install packages from the command line:
```
flutter packages get
```
* Import it
```
import 'package:leancloud_flutter_plugin/leancloud_flutter_plugin.dart';
```### How to use
Before your `runApp` function, initialize the leancloud. Such as the `example` app does.**Steps:**
* initialize plugin
* setup log level *(Optional, default value is `OFF`)*
* setup region *(Optional, default value is `NorthChina`)*
* initialize leancloud
* save object or you can do whet ever you want :)#### Initialize plugin
Plugin is *Singleton mode*. Please **NOT** initialize it by yourself.Import: `import 'package:leancloud_flutter_plugin/leancloud_flutter_plugin.dart';`
```
LeancloudFlutterPlugin leancloudFlutterPlugin = LeancloudFlutterPlugin.getInstance();
```
#### Log Level *(Optional)*
Setup log level must be earlier than **initialize leancloud** function.
```
leancloudFlutterPlugin.setLogLevel(LeancloudLoggerLevel.DEBUG);
```
#### Region *(Optional)*
Setup region must be earlier than **initialize leancloud** function.
```
leancloudFlutterPlugin.setRegion(LeancloudCloudRegion.NorthChina);
```
#### Initialize Leancloud
```
leancloudFlutterPlugin.initialize(appId, appKey);
```
#### Create and update an Object
Import: `import 'package:leancloud_flutter_plugin/leancloud_object.dart';````
// Create
AVObject object = new AVObject("YOUR_OBJECT");
object.put("FIELD_NAME", "VALUE"); // String
object.put("OR_INT", 10); // int
object.put("OR_BOOLEAN", true); // boolean
object.put("OR_FLOAT", 10.01); // float
object.save().then((object) {
// Saved
print(object);
// and Update
object.put("description", "updated!");
object.save().then((object) {
// Updated
print(object);
});
});```
If your update your object, `{"code":403,"error":"Forbidden writing by object's ACL."}` happened,
then please check leancloud data's ACL field.#### Delete an Object
```
// object is an AVObject
object.delete().then((isDeleted) {
// Deleted
if (isDeleted) {
object = null; // you should set ref to null manually if you don't using this object
print("Deleted!");
}
});```
#### Query an Object
Import: `import 'package:leancloud_flutter_plugin/leancloud_query.dart';`
```
// query by object_id
AVQuery avQuery = new AVQuery("DemoObject");
avQuery.get("OBJECT_ID").then((object) {
print("Queryed!");
});// query objects
AVQuery avQuery = new AVQuery("DemoObject");
avQuery.whereEqualTo("KEY", "VALUE"); // string value
avQuery.whereNotEqualTo("KEY", 10); // int value
avQuery.whereGreaterThan("KEY", true); // bool value
avQuery.whereGreaterThanOrEqualTo("KEY", "VALUE");
avQuery.whereLessThan("KEY", "VALUE");
avQuery.whereLessThanOrEqualTo("KEY", "VALUE");
avQuery.find().then((objects) {
print("All Objects Queryed!");
});
```## Example App
[Example App README.md](https://github.com/LunaGao/leancloud_flutter_plugin/blob/master/example/README.md)
## Publish Plugin
```
cd PROJECT_PATH
flutter format .
flutter pub pub publish --dry-run
flutter pub pub publish```