directus 0.5.2 copy "directus: ^0.5.2" to clipboard
directus: ^0.5.2 copied to clipboard

outdated

The unofficial SDK for Directus, with REST API and auth. Compatible with Flutter.

example/lib/main.dart

import 'dart:convert';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:directus/directus.dart';

void main() async {
  final sdk = await Directus('http://localhost:8055').init();
  runApp(MyApp(sdk));
}

class MyApp extends StatelessWidget {
  final Directus sdk;

  MyApp(this.sdk);

  /// Get posts.
  Future<DirectusListResponse<Map<String, dynamic>>> getPosts() => sdk.items('posts').readMany();

  /// Get settings.
  Future<DirectusResponse<DirectusSettings>> getSettings() => sdk.settings.read();

  Future<dynamic> getReviews() async {
    sdk.custom.options.headers['Custom-Header'] = 'some-value';
    final result = await sdk.items('reviews').readMany(
        query: Query(
            limit: 5, offset: 0, fields: ['*'], meta: Meta(filterCount: true, totalCount: true)),
        filters: Filters({'is_positive': Filter.eq(false)}));

    result.data.forEach((project) => print(project['title']));
    return;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Directus Demo',
      theme: ThemeData(
        primarySwatch: Colors.green,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: Text('Directus Example'),
        ),
        body: Center(
          child: FutureBuilder<dynamic>(
            future: getReviews(),
            builder: (context, snapshot) {
              if (!snapshot.hasData) {
                return Container();
              }
              return Placeholder();
              final posts = snapshot.data.data;
              return ListView.builder(
                itemCount: posts.length,
                itemBuilder: (context, index) => ListTile(
                  title: Text(posts[index]['title']),
                  trailing: Text(posts[index]['id'].toString()),
                ),
              );
            },
          ),
        ),
      ),
    );
  }
}
38
likes
0
pub points
80%
popularity

Publisher

verified publisherdirectus.io

The unofficial SDK for Directus, with REST API and auth. Compatible with Flutter.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

dio, flutter, json_annotation, meta, shared_preferences

More

Packages that depend on directus