A lightweight and customizable http client that allows you to create offline-first dart app easily.

Related tags

Templates unruffled
Overview

Enjoyable & customizable offline-first REST API client

Pub Version GitHub

Unruffled is lightweight and customizable http client that allows you to create offline-first easily.

Features

  • 🧘 Stay safe by automatically managing offline storage & connectivity errors
  • 🚀 Very customizable
  • 💻 All platforms supported
  • 🤖 Intuitive & simple API
  • 🔒 Strong encryption with Hive

Getting Started

Check out the Quick Start documentation to get started.

Quick start

1. Add to pubspec.yaml

dependencies:
  json_annotation: ^4.5.0
  unruffled: ^1.0.0

dev_dependencies:
  build_runner: any
  json_serializable: ^6.2.0
  unruffled_generator: ^1.0.0

NOTE : Unruffled relies to json_annotation and json_serializable to work as expected, please ensure to add theme in your dependencies.

2. Declare models

Declare models used by your remote service and generate Unruffled adapters.

@UnruffledData()
@JsonSerializable()
class User extends DataModel<User> {
  @override
  @JsonKey(name: '_id') // e.g MongoDB item has '_id' as unique identifier
  int? id;
  
  String name;
  
  String surname;
  
  int age;

  User({super.key, this.id, required this.name, required this.surname, required this.age});
}

Build your flutter directory to generate a UserAdapter()

flutter pub run build_runner build

NOTE: Your class must construct a String? key and Object? id and pass it to super();

  • id refers to your remote object ID\
  • key refers to your local object ID generated by unruffled

3. Register adapters

For all platforms except web, use path_provider to generate a directory path.

final dir = await getApplicationSupportDirectory(); // path_provider package
var unruffled = Unruffled(
      baseDirectory: dir,
      defaultBaseUrl: 'http://example.com',
      dio: dio,
  )
  .registerRepository(UserRepository());

4. Initialize Unruffled

Before using Unruffled, ensure to initialize it.

await unruffled.init();

🚀 That's it, you're ready to go !

Usage

1. Create a user

Define a user and call User repository.

final testUser = User(name: 'John', surname: 'Doe');
final repository = unruffled.repository<User>();

Create your user by calling post() method.

var user = await repository.post(model: testUser);

2. Get a user

var user = await repository.get(key: user.key);

3. Delete a user

var user = await repository.delete(key: user.key);

4. Query users

QueryBuilder lets you apply filters on your queries.

Filters will be applied automatically on local queries.
To enable filters on remote queries, you must implement following method :

Note : For a complete working example, check unruffled_feathersjs

mixin CustomRemoteRepository<T extends DataModel<T>> on RemoteRepository<T> {
  @override
  Map<String, dynamic> parseLimit(int limit) => {};

  @override
  Map<String, dynamic> parsePage(int page) => {};

  @override
  Map<String, dynamic> parseSort(SortCondition<R> sort) => {};
  
  @override
  Map<String, dynamic> parseEqual(FilterCondition<T> condition) => {};

  @override
  Map<String, dynamic> parseNotEqual(FilterCondition<T> condition) => {};

  @override
  Map<String, dynamic> parseGreaterThan(FilterCondition<T> condition) => {};

  @override
  Map<String, dynamic> parseLessThan(FilterCondition<T> condition) => {};

  @override
  Map<String, dynamic> parseInValues(FilterCondition<T> condition) => {};

  @override
  Map<String, dynamic> parseOrCondition(List<FilterOperation<T>> operations) => {};

  @override
  Map<String, dynamic> parseAndCondition(List<FilterOperation<T>> operations) => {};
}

QueryBuilder usage :

List<User> users = await repository.getAll(
  queryBuilder: QueryBuilder(
    filterGroup: FilterGroup.or(
      filters: [
        FilterCondition.equal(property: UserField.surname(), value: 'Doe'),
        FilterCondition.greaterThan(property: UserField.age(), value: 18, include: true),
      ],
    ),
    limit: 10,
    page: 1,
    sort: SortCondition(property: UserField.age(), sort: SortType.desc),
  ),
);

5. Manage connectivity isues

If connectivity errors occur, Unruffled stores automatically requests to retry them later, just call the global method :

final operations = unruffled.offlineOperations;
for (var remoteRepository in operations.keys) {
  await operations[remoteRepository].retry(remoteRepository);
}

Or call for each remote repository :

final operations = repository.offlineOperations;
for (var operation in operations) {
  await operation.retry(repository);
}
You might also like...

A Dart-native lightweight Apache Pulsar client primarily focused on the IoT telemetry domain

pulsar_iot_client A lightweight Apache Pulsar client primarily focused on the IoT telemetry domain. This project aims to improve the resulting perform

May 10, 2022

Weather app using Bloc architecture pattern & generic HTTP client with interface implementation and much more for more detail read Readme

Weather app using Bloc architecture pattern & generic HTTP client with interface implementation and much more for more detail read Readme

weather Weather application for current weather, hourly forecast for 48 hours, Daily forecast for 7 days and national weather alerts. How to Run Insta

Oct 29, 2022

Generates a new Flutter app with http client, theme, routing and localization features.

Starter Template Generates a new Flutter app with http client, theme, routing and localization features. Brick Uses: dio as http client pretty_dio_log

Nov 3, 2022

You can create a star easily and decide how many angle or color of the star, even the fat and progress of the star.

You can create a star easily and decide how many angle or color of the star, even the fat and progress of the star.

Apr 14, 2021

This library allows you to create editable tables and spreadsheets with ease, either by providing initial row and column count to display an empty table or use it with predefined rows and column data sets.

This library allows you to create editable tables and spreadsheets with ease, either by providing initial row and column count to display an empty table or use it with predefined rows and column data sets.

Editable ⚡️ A highly customizable, editable table package for Flutter projects. Specs This package allows you to create editable tables and spreadshee

Dec 7, 2022

A new flutter package project which contains lots of beautiful alert dialog that will help you lot to create beautiful awesome alert box very quickly and easily.

A new flutter package project which contains lots of beautiful alert dialog that will help you lot to create beautiful awesome alert box very quickly and easily.

A new flutter package project which contains lots of beautiful alert dialog that will help you lot to create beautiful awesome alert box very quickly and easily.

Jan 8, 2022

This is a university marketplace, where students buy and sell products and services online or offline. Mainly to connect the two parties together.

marktorder A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if th

Jan 10, 2022

WhereIsMoney - A money expense tracker with online and offline capabilities

WhereIsMoney 🤳 A money expense tracker to help you know where your money is goi

Feb 6, 2022

Flutter plugin (android) for sharing bytes and files Offline, (Based on the android Nearby Connections API)

nearby_connections An android flutter plugin for the Nearby Connections API Currently supports Bytes and Files. Transfer Data between multiple connect

Nov 21, 2022
Owner
T. Milian
T. Milian
Automatically generate profile picture with random first name and background color. But you can still provide pictures if you have them. As the default color, based on the name of the first letter. :fire: :fire: :fire:

FLUTTER PROFILE PICTURE Automatically generate profile picture with random first name and background color. But you can still provide pictures if you

Aditya Dharmawan Saputra 10 Dec 20, 2022
Charlatan - A library for configuring and providing fake http responses to your dio HTTP client.

charlatan This package provides the ability to configure and return fake HTTP responses from your Dio HTTP Client. This makes it easy to test the beha

Betterment 14 Nov 28, 2022
Powerful, helpfull, extensible and highly customizable API's that wrap http client to make communication easier with Axelor server with boilerplate code free.

flutter_axelor_sdk Powerful, helpful, extensible and highly customizable API's that wrap http client to make communication easier with Axelor server w

Abd al-Rahman al-Ktefane 5 Dec 25, 2022
An easy-to-use flutter http network requests handler with more functionality than http but more simpler than dio.

network_requests An easy-to-use flutter http network requests handler with more functionality than http but more simpler than dio. Platform Supported

Coder_Manuel 3 Dec 15, 2022
A most easily usable cookie management library in Dart. With SweetCookieJar, you can easily manage cookie on your application.

A most easily usable cookie management library in Dart! 1. About 1.1. Introduction 1.1.1. Install Library 1.1.2. Import It 1.1.3. Use SweetCookieJar 1

Kato Shinya 9 Oct 27, 2022
A most easily usable cache management library in Dart. With CacheStorage, you can easily manage cache on your application.

A most easily usable cache management library in Dart! 1. About 1.1. Introduction 1.1.1. Install Library 1.1.2. Import It 1.1.3. Use CacheStorage 1.2.

Kato Shinya 1 Dec 13, 2021
A most easily usable RESAS API wrapper in Dart. With this library, you can easily integrate your application with the RESAS API.

A most easily usable RESAS API wrapper library in Dart! 1. About 1.1. What Is RESAS? 1.2. Introduction 1.2.1. Install Library 1.2.2. Import It 1.2.3.

Kato Shinya 2 Apr 7, 2022
This package adds CustomRefreshIndicator widget that allows you to create whatever indicator you want.

Custom Refresh Indicator A flutter package that allows you to easily create a custom refresh indicator widget. TLDR; ONLINE DEMO! QUICK START CustomRe

Kamil Klyta 315 Dec 16, 2022
A powerful Http client for Dart, which supports Interceptors, FormData, Request Cancellation, File Downloading, Timeout etc.

dio_http A powerful Http client for Dart, which supports Interceptors, Global configuration, FormData, Request Cancellation, File downloading, Timeout

null 46 Dec 19, 2021
A powerful Http client for Dart, which supports Interceptors, FormData, Request Cancellation, File Downloading, Timeout etc.

Language: English | 中文简体 dio A powerful Http client for Dart, which supports Interceptors, Global configuration, FormData, Request Cancellation, File

Flutter中国开源项目 11.2k Jan 3, 2023