contentful 1.1.3

contentful-dart #

pub package

This Dart package is a small abstraction on top of the Contentful Delivery API.

Usage #

To use this plugin, install contentful as a dependency in your pubspec.yaml.


The following example uses equatable and json_annotation to create a Contentful Entry model. For more information about json_annotation, see:

Contentful adds system fields to their JSON responses, so you need to create a separate fields class and pass it to the Entry<T> class generic.

You can also add relationships as a field attribute and they will get injected if they are included in the JSON response. See here for more details:

import 'package:equatable/equatable.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:contentful/contentful.dart';

part 'event.g.dart';

class Event extends Entry<EventFields> {
    SystemFields sys,
    EventFields fields,
  }) : super(sys: sys, fields: fields);

  static Event fromJson(Map<String, dynamic> json) => _$EventFromJson(json);

  Map<String, dynamic> toJson() => _$EventToJson(this);

class EventFields extends Equatable {
  }) : super([title, slug, relations]);

  final String title;
  final String slug;
  final List<Event> relations;

  static EventFields fromJson(Map<String, dynamic> json) =>

  Map<String, dynamic> toJson() => _$EventFieldsToJson(this);

Here is how you would use your Event class.

import 'package:contentful/contentful.dart';
import 'event.dart';

class EventRepository {
  final Client contentful;

  Future<Event> findBySlug(String slug) async {
    final collection = await contentful.getEntries<Event>({
      'content_type': 'event',
      'fields.slug': slug,
      'limit': '1',
      'include': '10',
    }, Event.fromJson);

    return collection.items.first;

Future<void> main() async {
  final repo = EventRepository(Client('SPACE_ID', 'ACCESS_TOKEN'))
  final event = await repo.findBySlug('myevent');
  print('Title: ${event.fields.title}');

Use this package as a library

1. Depend on it

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

  contentful: ^1.1.3

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or 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:contentful/contentful.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jan 16, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4

Maintenance issues and suggestions

Provide a file named (-20 points)

Changelog entries help developers follow the progress of your package. See the example generated by stagehand.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and contentful.dart. Packages with multiple examples should provide example/

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
equatable ^1.0.0 1.0.2
http ^0.12.0 0.12.0+4
json_annotation ^3.0.0 3.0.1
meta ^1.1.6 1.1.8
Transitive dependencies
async 2.4.0
charcode 1.1.2
http_parser 3.1.3
path 1.6.4
pedantic 1.9.0
source_span 1.6.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
build_runner ^1.0.0
collection ^1.14.12 1.14.12
json_serializable ^3.2.0
test ^1.9.4