wordpress - Dart Flutter - 使用 Chopper 获取 WordPress 自定义帖子类型
问题描述
我正在使用 Google Flutter Framework 构建移动设备,并使用 Wordpress 作为我的应用程序的后端。我想使用 Flutter API 的 Chopper Retrofit 在 Flutter 中以 JSON 格式获取 Wordpress 自定义帖子类型数据。
谁能帮我构建一个示例代码,以便我可以轻松开始?我使用过这个(Flutter Wordpress),但我不知道如何使用自定义帖子类型。
https://github.com/dreamsoftin/flutter_wordpress
或者,如果有人知道如何使用它并获取自定义帖子类型,那么对我来说会更容易。
请帮忙!谢谢!
解决方案
查看您要用于构建移动应用程序的包,没有自定义类型的示例和解决方案(https://github.com/dreamsoftin/flutter_wordpress),但您可以分叉它,并将其扩展为特定的自定义帖子类型。我将向您展示如何执行此操作的示例(不包括自定义字段):
在flutter_wordpress/lib/constants.dart
在第 10 行之后添加
const URL_POSTS = '$URL_WP_BASE/posts';
自定义帖子的端点行。假设您有自定义帖子,您将添加一个端点books
:
const URL_BOOKS = '$URL_WP_BASE/books';
在此处查看有关此内容以及如何为自定义帖子类型启用 REST API 的说明:
然后在flutter_wordpress/lib/requests/文件夹中,找到、克隆并重命名文件:
params_post_list.dart到 params_book_list.dart
并将此处重命名class ParamsPostList
为类ParamsBookList
在文件夹flutter_wordpress/lib/schemas/中找到
post.dart复制并重命名为book.dart
并将此处重命名class Post
为类Book
然后在文件flutter_wordpress/lib/flutter_wordpress.dart 中:
找到行import 'schemas/post.dart';
,然后添加行import 'schemas/book.dart';
找到行 export 'requests/params_post_list.dart';
,然后添加行export 'requests/params_book_list.dart';
找到行export 'schemas/post.dart';
,然后添加行export 'schemas/book.dart';
然后找函数
async.Future<List<Post>> fetchPosts()
Future<Post> _postBuilder()
async.Future<Post> createPost({@required Post post})
复制这些函数重命名并替换Post
为Book
(区分大小写)
注意:URL_POSTS
在复制的函数中查找并重命名为URL_BOOKS
推荐阅读
- reactjs - 为什么 React 需要一个封闭标签来返回多个兄弟元素?
- node.js - 访问用户 jenkins 发起的 pm2 状态
- angular - 在 subject.next 之后,角度 observable 不加载服务
- spring-boot - springboot的JDBCTemplate如何使用回滚
- python - pyqtgraph 的 OpenGL 导入失败
- javascript - CSS 隐藏属性的文本内容
- visual-studio-code - 为什么我的 VSCode 终端不会改变样式?
- jquery - 使用 jQuery 计算 2 个日期输入 datetimepicker 的日差?
- weka - 在 WEKA,J48 中,将 minNumObj 设置为 1 有意义吗?
- mysql - 索引是 SQL 中的约束吗?