flutter_ghost_content_api 0.0.1 flutter_ghost_content_api: ^0.0.1 copied to clipboard
A Flutter wrapper around the Ghost Content API
Flutter Ghost Content API #
A flutter wrapper around the Ghost Content API.
Usage #
Firstly, create a new custom app integration in your Ghost publication and make a note of the content API key.
Next, create a GhostContentAPIProvider
at the root of your Flutter application:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GhostContentAPIProvider(
client: GhostContentAPIClient(
version: 'v2',
url: 'https://your-subdomain.ghost.io',
contentAPIkey: 'your content api key',
),
child: MaterialApp(
title: 'Flutter Demo',
home: MyHomePage(),
),
);
}
}
Finally, use a FutureBuilder
anywhere you would like to access your Ghost content:
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Flutter Ghost"),
),
body: FutureBuilder(
future: GhostContentAPIProvider.of(context).client.getPosts(),
builder: (BuildContext context, AsyncSnapshot<PostsResponse> snapshot) {
// Build your UI
},
),
);
}
}
Example #
See my Flutter Ghost App for Learn Software.
Tests #
Run:
flutter packages get
flutter test