DEV Community

loading...

Connect Wordpress API to Flutter

idawnwon profile image idawnwon ・2 min read

After explored WordPress, I found it is really an easy-to-use yet powerful CMS backend. I decided to use Flutter to develop a front-end, CRUD data directly from WordPress through API.

1. Configure "JWT Authentication for WP-API"

This is a plugin for WordPress.

1.1 Search and Download "JWT Authentication for WP-API" in WordPress Plugin Market. (DON'T activate it for now.)

1.2 Edit .htaccess file, add lines below, between <IfModule mod_rewrite.c> and </IfModule> tag.

RewriteEngine on
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
Enter fullscreen mode Exit fullscreen mode

1.3 Edit wp-config.php file, add lines below, right after define('AUTH_KEY', '...');define('SECURE_AUTH_KEY', '...');define('LOGGED_IN_KEY', '...');define('NONCE_KEY', '...');define('AUTH_SALT', '...');define('SECURE_AUTH_SALT', '...');define('LOGGED_IN_SALT', '...');define('NONCE_SALT', '...');

define('JWT_AUTH_SECRET_KEY', 'YOUR_KEY_HERE');
define('JWT_AUTH_CORS_ENABLE', true);
Enter fullscreen mode Exit fullscreen mode

Replace 'YOUR_KEY_HERE' with your key. Strongly recommend you to get one random key at this trusted site.
Alt TextJust copy anyone you like.

1.4 Activate "JWT Authentication for WP-API" in your WordPress panel.

2. Edit pubspec.yaml file

This file locates in your flutter project folder.
Add following lines under dependencies: block:

flutter_wordpress: ^0.2.0
flutter_html: ^1.1.0
url_launcher: ^5.7.10
Enter fullscreen mode Exit fullscreen mode

The version numbers are not constant. I googled each one's latest version on November 24, 2020. Maybe there would be newer versions at the time you are reading here.

Thanks to Morten Rand-Hendriksen's tutorial on Lynda.com

Hope this helps!

So proud to be a coder!

Discussion (0)

pic
Editor guide