分享 正在使用 Flutter 开发一款 Ruby-China 的客户端

Laotree · December 10, 2020 · Last by xinyuewaisong replied at January 02, 2021 · 1155 hits

大家好
最近在学习 Flutter,想基于 Ruby-China 的 Api 编写一个客户端
现在我已经写出了话题列表、用户主页
后续我会持续更新这个项目,如果有任何指导和意见,欢迎给我留言
如果有对 Flutter 和 Ruby-China API 有兴趣的同学可以加入我的练手项目

我也有遇到一些困难和疑惑,希望大家不吝赐教

  • 开发过程中我使用的 iOS 模拟器进行排版,但是当我写了一会儿拿 Android 模拟器看的时候会出现很多不合适的样式,比如文字显示不全,请问怎么克服?

flutter-ruby-china 源码
下载链接,密码 ruby

字体乱了 android 5.02 api 21

flutter 大法好,我也用 ruby-china 魔改了一个网站,app 也用的 flutter http://apk.yufuxiansheng.com/yfxs

4 Floor has deleted
Reply to huobazi

我现在在写登录的功能,但是我发现 ruby-china 的 api 文档 没有直接的账号登录的接口(可能我阅读的不仔细) 提供的 /oauth/authorize 并不是 API 我现在想到的方法是:

  • 用 webview 让用户在 ruby-china 的网页登录
  • 登录成功后,回调时,拦截特定 url,把 auth code 存下来
  • 使用 code 换 access token

请问您是怎么实现的?希望不吝赐教

Reply to tablecell

进行了修复,谢谢反馈😄

Reply to Laotree

使用 Oauth2 的 password 模式

接口是 https://ruby-china.org/oauth/token


final String _authEndpoint = Config.OauthBasetURL + "/oauth/authorize";
final String _tokenEndpoint = Config.OauthBasetURL + "/oauth/token";

final String _clientId = Config.OauthClientId;

Future<ResultData<Oauth2Credentials>> login(
    {String username, String password}) async {
  if (username == null || (username != null && username.isEmpty))
    return Future.error('用户名不能为空.');
  if (password == null || (password != null && password.isEmpty))
    return Future.error('密码不能为空.');

  var data = FormData.fromMap({
    "client_id": _clientId,
    "grant_type": "password",
    "username": username,
    "password": password,
  });
  var response =
      await HttpManager.instance.request(_tokenEndpoint, "post", data: data);

  if (response.ok) {
    var credentials = Oauth2Credentials.fromJson(response.data);
    return  ResultData<Oauth2Credentials>(true, response.code,
        data: credentials, meta: response.data["meta"], raw: response.raw);
  } else {
    var error = {
      'error': '登陆错误',
      'message': ['用户名或密码错误'],
    };

    return  ResultData<Oauth2Credentials>(
      false,
      response.code,
      data: null,
      error: Error.fromJson(error),
      raw: response.raw,
    );
  }
}

也可以参考 https://github.com/ruby-china/ruby-china-ios/blob/master/ruby-china-ios/Libraries/OAuth2.swift#L66

Reply to huobazi

在手机上看 主题的时间在左面挤在一起了 是否应该放到右面 眼评论区一致 分类如果不用做导航的话可以放在内容的开头或者结尾

Reply to tablecell

多谢反馈

You need to Sign in before reply, if you don't have an account, please Sign up first.