directus 0.4.3 directus: ^0.4.3 copied to clipboard
The unofficial SDK for Directus, with REST API and auth. Compatible with Flutter.
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> test() async {
final result = await sdk.items('reviews').readMany(
query: Query(limit: 5, offset: 0, fields: ['*']),
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: test(),
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()),
),
);
},
),
),
),
);
}
}