flutter_wordpress 0.1.4

  • Readme
  • Changelog
  • Example
  • Installing
  • 91

Flutter Wordpress #

This library uses WordPress REST API V2 to provide a way for your application to interact with your WordPress website.

Screenshots #

Requirements #

For authentication and usage of administrator level REST APIs, you need to use either of the two popular authentication plugins in your WordPress site:

  1. Application Passwords
  2. JWT Authentication for WP REST API (recommended)

Getting Started #

1. Import library #

https://pub.dartlang.org/packages/flutter_wordpress

import 'package:flutter_wordpress/flutter_wordpress.dart' as wp;

2. Instantiate WordPress class #

wp.WordPress wordPress;

// adminName and adminKey is needed only for admin level APIs
wordPress = wp.WordPress(
  baseUrl: 'http://localhost',
  authenticator: wp.WordPressAuthenticator.JWT,
  adminName: '', 
  adminKey: '',
);

3. Authenticate User #

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. Fetch Posts #

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. Fetch Users #

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. Fetch Comments #

Future<List<wp.Comment>> comments = wordPress.fetchComments(
  params: wp.ParamsCommentList(
    context: wp.WordPressContext.view,
    pageNum: 1,
    perPage: 30,
    includePostIDs: [1],
  ),
);

7. Create Post #

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. Post Comment #

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');
  });
}

Future Work #

  1. Implementing OAuth 2.0 authentication.

[0.1.4] - 27/02/2019

  • Updated homepage URL

[0.1.3] - 26/02/2019

  • Update example. Update post fetching to include author, comments. Add fetching comments as a hierarchy.

[0.1.2] - 16/02/2019

  • Add fetch categories, tags, pages. Add create post, comments.

[0.1.1] - 14/02/2019

  • Update README.md. Add fetch users list, fetch comments list.
  • Implemented authorization function and fetching of Posts with parameters

[0.1.0] - Added Models

  • Created model classes for Wordpress REST API and implemented user authentication function using JWT authentication system.

[0.0.1] - TODO: Init.

  • Under Development. Nothing works now.

example/README.md

Flutter Wordpress Example #

Basic login, displaying posts and comments have been implemented in this example flutter app.

Screenshots #

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_wordpress: ^0.1.4

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_wordpress/flutter_wordpress.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
81
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
91
Learn more about scoring.

We analyzed this package on Oct 18, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
http ^0.12.0+1 0.12.0+2
Transitive dependencies
async 2.4.0
charcode 1.1.2
collection 1.14.11 1.14.12
http_parser 3.1.3
meta 1.1.7
path 1.6.4
pedantic 1.8.0+1
sky_engine 0.0.99
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test