WordPress是一个以PHP和MySQL为平台的自由开源的博客软件和内容管理系统。WordPress具有插件架构和模板系统。截至2018年4月,排名前1000万的网站中超过30.6%利用WordPress。WordPress是最受欢迎的网站内容管理系统。WordPress是当前因特网上最盛行的博客系统。
一样平常WordPress的后台都是用php java 等这些措辞来获取数据,这次Flutter也插入进来了,以是Flutter不止Android,iOS 实现措辞,它要做的事情还有很多很多,前方的道路还有很远,战斗从来没有停滞过,只要你感想,它就敢做,加油。
欢迎来到「技能刚刚好」作者,「技能刚刚好」是个人掩护,每天至少更新一篇Flutter技能文章,实时为大家播报Flutter最新。如果你刚好也在关注Flutter这门技能,那就跟我一起学习进步吧,你的赞,收藏,转发是对我个人最大的支持,掩护不易,欢迎关注。

近几年,移动端跨平台开拓技能层出不穷,从Facebook家的ReactNative,到阿里家WEEX,前端技能在移动端跨平台开拓中大展技艺,技能刚刚好作为一名Android开拓,经历了从Reactjs到Vuejs的不断学习。而在2018年,我们的主角变成了Flutter,这是Goolge开源的一个移动端跨平台办理方案,可以快速开拓精美的移动App。希望跟大家一起学习,一起进步!
本日就把这个插件分享给大家,就当是一个练手学习的项目,如果大家感兴趣可以进去看看。
插件地址:https://pub.dev/packages/flutter_wordpress
接入办法:
Flutter Wordpress #该库利用WordPress REST API V2为您的运用程序供应了一种与WordPress网站进行交互的办法。
哀求为了进行身份验证和利用管理员级别的REST API,您须要利用WordPress网站中两个盛行的身份验证插件之一:
运用密码WP REST API的JWT身份验证 (推举)1.导入库号
https://pub.dartlang.org/packages/flutter_wordpress
import 'package:flutter_wordpress/flutter_wordpress.dart' as wp;
2.实例化WordPress类
wp.WordPress wordPress;// adminName and adminKey is needed only for admin level APIswordPress = wp.WordPress( baseUrl: 'http://localhost', authenticator: wp.WordPressAuthenticator.JWT, adminName: '', adminKey: '',);
3.验证用户编号
Future<wp.User> response = wordPress.authenticateUser( username: 'ChiefEditor', password: 'chiefeditor@123',);response.then((user) { createPost(user);}).catchError((err) { print('Failed to fetch user: $err');});
4.获取帖子
Future<List<wp.Post>> posts = wordPress.fetchPosts( params: wp.ParamsPostList( context: wp.WordPressContext.view, pageNum: 1, perPage: 20, order: wp.Order.desc, orderBy: wp.PostsOrderBy.date, ), fetchAuthor: true, fetchFeaturedMedia: true, fetchComments: true,);
5.获取用户
Future<List<wp.User>> users = wordPress.fetchUsers( params: wp.ParamsUserList( context: wp.WordPressContext.view, pageNum: 1, perPage: 30, order: wp.Order.asc, orderBy: wp.UsersOrderBy.name, role: wp.UserRole.subscriber, ),);
6.获取评论
Future<List<wp.Comment>> comments = wordPress.fetchComments( params: wp.ParamsCommentList( context: wp.WordPressContext.view, pageNum: 1, perPage: 30, includePostIDs: [1], ),);
7.创建帖子编号
void createPost(wp.User user) { final post = wordPress.createPost( post: new wp.Post( title: 'First post as a Chief Editor', content: 'Blah! blah! blah!', excerpt: 'Discussion about blah!', author: user.id, commentStatus: wp.PostCommentStatus.open, pingStatus: wp.PostPingStatus.closed, status: wp.PostPageStatus.publish, format: wp.PostFormat.standard, sticky: true, ), ); post.then((p) { print('Post created successfully with ID: ${p.id}'); postComment(user, p); }).catchError((err) { print('Failed to create post: $err'); });}
8.揭橥评论
void postComment(wp.User user, wp.Post post) { final comment = wordPress.createComment( comment: new wp.Comment( author: user.id, post: post.id, content: "First!", parent: 0, ), ); comment.then((c) { print('Comment successfully posted with ID: ${c.id}'); }).catchError((err) { print('Failed to comment: $err'); });}总结
还是那句话,程序员不但是敲代码,还要每天学习,不管你是20岁,30岁,40岁,只假如程序员你就得一直学习,一直提高。
感激不雅观看技能刚刚好的文章,技能刚刚好是个人掩护,每天至少更新一篇Flutter技能文章,实时为大家播报Flutter最新。如果你刚好也在关注Flutter这门技能,那就跟我一起学习进步吧,你的赞,收藏,转发是对我个人最大的支持,掩护不易,欢迎关注。