Easily restore your project to a previous version with our new Instant One-click Backup Recovery

Headless CMS for Flutter

Hygraph is the ideal Headless CMS for Flutter websites and applications. Read further to learn how our API-first CMS allows you to add components to your Flutter apps in minutes and enable your website's content to be managed from a powerful CMS.

Step #1 - Initialize the GraphQL Client

In order to start using content from a headless CMS in your flutter app, first, you will need to add the graphql_flutter package to your pubspec.yaml file.

Once you have done that initialize the GraphQL client with your API endpoint and any necessary configurations, such as headers for authorization. Just like in the example on the right.

import 'package:flutter/material.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
void main() {
final HttpLink httpLink = HttpLink(
'https://api-<region>.hygraph.com/v2/<some hash>/master',
);
// Replace 'YOUR_AUTH_TOKEN' with the actual token.
final AuthLink authLink = AuthLink(
getToken: () async => 'Bearer YOUR_HYGRAPH_TOKEN',
);
// Use the authLink to concatenate it with the httpLink
final Link link = authLink.concat(httpLink);
final ValueNotifier<GraphQLClient> client = ValueNotifier(
GraphQLClient(
link: link,
cache: GraphQLCache(store: InMemoryStore()),
),
);
final app = GraphQLProvider(
client: client,
child: MyApp(),
);
runApp(app);
}

Step #2 - Use the widget in your UI code

Once you've got the client set up, you can use it to send queries to the server. The fetchProducts function is where you define the GraphQL query, requesting specific fields for products such as name, description, image URL, availability, and slug.

When you call the getProducts function, it uses the GraphQL client to send the query to the server. If the query is successful, the server responds with the requested data, which you can then use in your Flutter app. This could involve displaying the products in a list or grid view, showing product details, and so on.

class ProductList extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Query(
options: QueryOptions(
document: gql(
r'''
query GetProducts {
products {
name
description
slug
availability
image
}
}
''',
),
),
builder: (QueryResult result, { VoidCallback? refetch, FetchMore? fetchMore }) {
if (result.hasException) {
return Text(result.exception.toString());
}
if (result.isLoading) {
return CircularProgressIndicator();
}
List products = result.data['products'];
return ListView.builder(
itemCount: products.length,
itemBuilder: (context, index) {
final product = products[index];
return ListTile(
title: Text(product['name']),
subtitle: Text(product['description']),
trailing: product['availability']
? Icon(Icons.check_circle, color: Colors.green)
: Icon(Icons.remove_circle, color: Colors.red),
onTap: () {
// Navigate to product details page
},
);
},
);
},
);
}
}

Start building with Flutter

We made it really easy to set up your project in Hygraph and use our GraphQL API within your Flutter project.

Quickstart

Check out our docs to see how you can quickly set up your Hygraph project and enable the content API for your Flutter website or app.

Learn GraphQL

Hygraph is GraphQL-native Headless CMS offers precise data retrieval, minimizing over-fetching and optimizing efficiency.

Examples

Look at some of the example projects to see Hygraph in action.

Why Hygraph

Choosing Hygraph for your Flutter project

Integrating a GraphQL-native headless CMS with a Flutter application streamlines the development process significantly. Developers can query exactly what they need, reducing over-fetching of unnecessary data and under-fetching which may require additional requests. This precision ensures that the Flutter app remains lightweight and performs swiftly, as the data transfer is minimized and tailored to the app's needs.

From a content editor's perspective, a headless CMS decouples content management from the app's presentation layer. This separation empowers non-technical editors to update content without delving into code, ensuring the content remains dynamic and fresh without developer intervention.

flutter cms

Developer Experience

We try to be the most un-opinionated CMS on the market with a wide collection of open source example projects to get you started.

Headless CMS

As a headless CMS (i.e. API based content management), you can be as modular and flexible as you need. We even support multiplatform content management.

Management API

Hygraph boasts a flexible and powerful management API to manage your content and schema, as well as a blazing fast content API.

Get started for free, or request a demo to discuss larger projects