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...

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

Aug 19, 2022

This package adds CustomRefreshIndicator widget that allows you to create whatever indicator you want.

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

Sep 13, 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

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

Sep 19, 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

Jul 16, 2022

A phone app that works as an offline lnurl-based point-of-sale.

LNURL-based Offline PoS app APK download: https://github.com/fiatjaf/lnurlpos-app/releases demo.mp4 Compatible with https://github.com/lnbits/lnbits-l

Apr 18, 2022

(Flutter)Minimal App With Offline Storage(Using HIVE) Functionality.

(Flutter)Minimal App With Offline Storage(Using HIVE) Functionality.

TaskZ (Minimal + Offline TODO List App) Minimal App With Offline Storage(Using HIVE) Functionality. Getting Started 👍 Any suggestion, improvement on

Mar 24, 2022
Owner
T. Milian
T. Milian
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 12 Aug 8, 2022
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 7 Aug 23, 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 4 Nov 12, 2021
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中国开源项目 11k Sep 21, 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 6 Sep 14, 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
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

Mike Zolotarov 5 May 10, 2022
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

Jibran Ahmed SiddiQui 8 Jan 28, 2022