Flutter Ghost Content API

A flutter wrapper around the Ghost Content API.

Blog post Explanation

See this Ghost Content API blog post for a more in-depth explanation of the package.

Usage

Before anything else, you will need to create a custom integration in your blog admin portal and make note of the Content API Key and URL.

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, you can 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).getPosts(),
        builder: (BuildContext context, AsyncSnapshot<PostsResponse> snapshot) {
          // Build your UI
        },
      ),
    );
  }
}

Alternatively, all calls through the Ghost Content API client returns a simple Future, so you can use any mechanism you need to for your app.

Example

See the Flutter Ghost App for Learn Software for real-world usage.

Tests

You can test this package by running the following commands:

  • flutter packages get
  • flutter test

Issues and Contributing

See the GitLab project.

Libraries

dart_ghost_content_api