bmob / bmob-flutter-sdk Goto Github PK
View Code? Open in Web Editor NEWBmob Flutter SDK
Bmob Flutter SDK
比如:分页查询、统计对象数量,已经在用SDK,感觉还不错,希望官方尽快完善,O(∩_∩)O
我的环境如下
• Flutter version 1.7.8+hotfix.4 at C:\some_explore\flutter
• Framework revision 20e59316b8 (5 weeks ago), 2019-07-18 20:04:33 -0700
• Engine revision fee001c93f
• Dart version 2.4.0
T.toString() 的结果是 BmobUser
T.runtimeType.toString() 的结果是 _Type
T is BmobUser 与 T.runtimeType is BmobUser 的结果均为 false
导致无法得到正确的表名 _User
建议修改表名传递
才接入就发现bug
加密初始化 Bmob.initEncryption
调用发送验证码接口 会报验证失败
https://github.com/bmob/bmob-flutter-sdk/blob/master/data_plugin/lib/bmob/bmob_sms.dart
sendSms() 方法
忘记在发送之前转string 了
String params = json.encode(getParams());
没有使用Export,导致引入一个文件不能获取所有功能,参考flutter其他库,均在入口文件export重要文件。减少学习成本,避免使用时去源码目录看目录名。
I/flutter ( 5231): Post请求启动! url:https://api2.bmob.cn/1/users ,body: {"smsCode":"594739","username":"FG ","mobilePhoneNumber":"13073636078"} ,headers:{content-type: null, X-Bmob-Application-Id: 28009b3f686439f09b5f81da404177fb, X-Bmob-REST-API-Key: e9f5e4b15c5b57631d280d0bcd49330d, Content-Type: application/json}
I/flutter ( 5231): Post请求结果:{"createdAt":"2021-08-10 20:04:35","mobilePhoneNumber":"13073636078","mobilePhoneNumberVerified":true,"objectId":"a425c6c147","sessionToken":"a390930140b625898085592bc36fa88d","updatedAt":"2021-08-10 20:04:35","username":"NBA"}
I/flutter ( 5231): type 'String' is not a subtype of type 'Map<dynamic, dynamic>'
I/flutter ( 5231): error
验证码登录接口,返回值为String?
//Map转String
//发送请求
///返回值类型为String,这里用Map接收
Map result = await BmobDio.getInstance()
.post(Bmob.BMOB_API_USERS, data: getParamsJsonFromParamsMap(data));
print(result);
data_plugin ^0.0.13 which doesn't match any versions
///查询单条数据
Future queryObject(objectId) async {
String tableName = T.toString();
if (T.runtimeType is BmobUser) {
tableName = "_User";
} else if (T.runtimeType is BmobInstallation) {
tableName = "_Installation";
}
return BmobDio.getInstance().get(
Bmob.BMOB_API_CLASSES + tableName + Bmob.BMOB_API_SLASH + objectId,
data: getParams());
}
上述通过T.runtimeType 去判断是用“_User”表还是“_Installation”表,操作是无效的,导致无法查询用户表数据
release 不要打印网络请求日志
访问的表名可以自定义而不是使用当前 dart 名称(需要考虑一些特殊情况,比如 Dart 混淆)
别的无关的地方用,就关键的用的最多的数据操作没有future封装,更过分的是,你们的内部方法是async的然后就返回了一个void?这个封装你们真的是认真写的吗
官方案例, 就没成功过, 哎....
// 环境
[√] Flutter is fully installed. (Channel stable, v1.2.1, on Microsoft Windows [Version
10.0.17134.706], locale zh-CN)
[√] Android toolchain - develop for Android devices is fully installed. (Android SDK version 28.0.3)
[√] Android Studio is fully installed. (version 3.4)
[√] VS Code is fully installed. (version 1.33.1)
[√] Connected device is fully installed. (1 available)
//报错
Launching lib\main.dart on Android SDK built for x86 in debug mode...
Initializing gradle...
Resolving dependencies...
Configure project :app
WARNING: API 'variant.getMergeAssets()' is obsolete and has been replaced with 'variant.getMergeAssetsProvider()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance.
To determine what is calling variant.getMergeAssets(), use -Pandroid.debug.obsoleteApi=true on the command line to display more information.
WARNING: API 'variantOutput.getProcessResources()' is obsolete and has been replaced with 'variantOutput.getProcessResourcesProvider()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance.
To determine what is calling variantOutput.getProcessResources(), use -Pandroid.debug.obsoleteApi=true on the command line to display more information.
Command: D:\temp2\data_demo\android\gradlew.bat app:properties
Finished with error: Please review your Gradle project setup in the android/ folder.
快点做呀,等着呢.
///查询关联数据
_queryPointer() {
BmobQuery<Diary> query = BmobQuery();
query.setInclude("author");
query.setOrder("-createdAt");
query.queryObjects().then((data) {
List<Diary> blogs = data.map((i) => Diary.fromJson(i)).toList();
print(blogs);
for (Diary blog in blogs) {
if (blog != null) {
print(blog.objectId);
print(blog.title);
print(blog.content);
if (blog.author != null) {
print("rrrr"+blog.author.objectId + " yyyyyy "+ userId + blog.author.objectId.compareTo(userId).toString());
if(blog.author.objectId.compareTo(userId) == 0){
restaurants.add(blog);
print(blog.author.objectId + "rrrr");
}
}
}
}
setState(() {
});
}).catchError((e) {
DataPlugin.toast(BmobError.convert(e).error);
});
}
Future<List> process(String method, List<BmobObject> bmobObjects) async {
List list = List();
Map params = Map();
SharedPreferences prefs = await SharedPreferences.getInstance();
String userJson = prefs.get("user");
print(userJson);
BmobUser bmobUser;
if (userJson != null) {
// 这里解析出来的是map类型,不能直接赋值给BmobUser
bmobUser = json.decode(userJson);
}
..........
}
上述问题,我已经本地修复了:
if (userJson != null) {
var jsonSp = json.decode(userJson);
bmobUser = BmobUser.fromJson(jsonSp);
}
但是我看你们这边的接口貌似有问题,如下:
Launching lib/main.dart on MuMu in debug mode...
Running Gradle task 'assembleDebug'...
../../../.pub-cache/hosted/pub.dev/data_plugin-0.0.18/lib/utils/dialog_util.dart:23:15: Error: Couldn't find constructor 'FlatButton'.
new FlatButton(
^^^^^^^^^^
Target kernel_snapshot failed: Exception
FAILURE: Build failed with an exception.
这个 cupertino_icons 库版本差得有点多。
Because data_plugin >=0.0.18 depends on cupertino_icons ^0.1.3 and flutter_combat depends on cupertino_icons ^1.0.1, data_plugin >=0.0.18 is forbidden.
So, because flutter_combat depends on data_plugin ^0.0.18, version solving failed.
pub get failed (1; So, because flutter_combat depends on data_plugin ^0.0.18, version solving failed.)
dio plugin版本较低,建议升一下。
ecause data_plugin >=0.0.2 depends on dio ^1.0.12 and wanandroid_ngu depends on dio ^2.1.0, data_plugin >=0.0.2 is forbidden.
怎样判断当前是否有用户登录
怎样获取当前用户以及用户属性
Unhandled Exception: MissingPluginException(No implementation found for method showToast on channel data_plugin)
#0 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:300:7)
#1 DataPlugin.toast (package:data_plugin/data_plugin.dart:22:20)
#2 _AddFishState._uploadFile. (package:menu/add_dish_route.dart:86:18)
#3 _rootRunUnary (dart:async/zone.dart:1132:38)
#4 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#5 _FutureListener.handleError (dart:async/future_impl.dart:144:20)
#6 Future._propagateToListeners.handleError (dart:async/future_impl.dart:651:47)
#7 Future._propagateToListeners (dart:async/future_impl.dart:672:24)
#8 Future._completeError (dart:async/future_impl.dart:491:5)
#9 _SyncCompleter._completeError (dart:async/future_impl.dart:55:12)
#10 _Completer.completeError (dart:async/future_impl.dart:27:5)
shared_preferences 版本过旧, 导致原生项目编译时有许多警告。 可以考虑一下升级shared_preferences的版本。
source code in bmob_user.dart
//Map转String
//发送请求
Map result = await BmobDio.getInstance().put(
Bmob.BMOB_API_REQUEST_UPDATE_USER_PASSWORD +
objectId,
data: getParamsJsonFromParamsMap(data));
the 'Bmob.BMOB_API_REQUEST_UPDATE_USER_PASSWORD' is
static const String BMOB_API_REQUEST_UPDATE_USER_PASSWORD = BMOB_API_VERSION + "/updateUserPassword";
the 'Bmob.BMOB_API_REQUEST_UPDATE_USER_PASSWORD' should be
static const String BMOB_API_REQUEST_UPDATE_USER_PASSWORD = BMOB_API_VERSION + "/updateUserPassword/";
IOS和Android里的关联查询都有$relatedTo,为什么flutter里的却没有,官网举的例子也有问题,因为看代码并不能关联起来,求解答。
有时并不需要model转换,只想要直接获取一个Map,需要考虑轻度使用时的成本.
The plugin data_plugin
uses a deprecated version of the Android embedding.
To avoid unexpected runtime failures, or future build failures, try to see if this plugin supports the Android V2 embedding. Otherwise, consider removing it since a future release of Flutter will remove these deprecated APIs.
If you are plugin author, take a look at the docs for migrating the plugin to the V2 embedding: https://flutter.dev/go/android-plugin-migration.
请问 appHost 这个参数传什么,试了好多都不行。。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.