wordpress_api 0.1.2+4 wordpress_api: ^0.1.2+4 copied to clipboard
A WordPress API client for flutter with support for WooCommerce and custom namespaces.
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:wordpress_api/wordpress_api.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'WPAPI Demo'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final wp = WordPressAPI('260blog.com');
List<Map<String, dynamic>> posts;
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: FutureBuilder(
builder: (BuildContext context,
AsyncSnapshot<Map<String, dynamic>> snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.waiting:
return Center(
child: CircularProgressIndicator(),
);
break;
default:
final posts = json.decode(snapshot.data['data']);
return ListView.separated(
itemBuilder: (BuildContext context, int index) {
return ListTile(
title: Text(posts[index]['title']['rendered']),
);
},
itemCount: posts.length,
separatorBuilder: (BuildContext context, int index) {
return Divider(height: 16.0);
},
);
}
},
future: wp.getAsync('posts'),
));
}
}