查看您要用于构建移动应用程序的包,没有自定义类型的示例和解决方案 (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 的说明:
https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-rest-api-support-for-custom-content-types/#registering-a-custom-post-type-with-rest-api-support
然后在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