Skip to content

Commit 8eee567

Browse files
committed
🎨 add CI workflow for Dart testing and improve documentation structure
1 parent e31068b commit 8eee567

File tree

11 files changed

+1097
-6
lines changed

11 files changed

+1097
-6
lines changed

.github/workflows/test.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Dart CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
test:
13+
name: Analyze and Test
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Install Flutter
18+
uses: subosito/flutter-action@v2
19+
with:
20+
channel: stable
21+
- name: Pub Get
22+
run: dart pub get
23+
24+
- name: Check formatting
25+
run: dart format --set-exit-if-changed .
26+
27+
- name: Lint
28+
run: dart analyze . --fatal-infos
29+
30+
- name: Run Main Tests
31+
working-directory: ./packages/hyper_storage
32+
run: |
33+
dart pub run coverage:test_with_coverage
34+
dart pub run coverage:format_coverage --packages=../../.dart_tool/package_config.json --lcov -i coverage/coverage.json -o coverage/lcov.info
35+
- name: Run Shared Preferences Tests
36+
working-directory: ./packages/hyper_storage_shared_preference
37+
run: flutter test
38+
- name: Run Hive Tests
39+
working-directory: ./packages/hyper_storage_hive
40+
run: dart run test
41+
- name: Run Secure Storage Tests
42+
working-directory: ./packages/hyper_storage_secure
43+
run: flutter test
44+
- name: Run Flutter Storage Tests
45+
working-directory: ./packages/hyper_storage_flutter
46+
run: flutter test
47+
- name: Upload Coverage
48+
uses: codecov/codecov-action@v3
49+
with:
50+
files: coverage/lcov.info
51+
token: ${{ secrets.CODECOV_TOKEN }}

packages/hyper_storage/README.md

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,39 @@
1-
# hyper_storage
2-
3-
[![pub version](https://img.shields.io/pub/v/hyper_storage.svg)](https://pub.dev/packages/hyper_storage)
4-
5-
A simple and unified key-value storage for Dart and Flutter applications, supporting multiple backends.
1+
<h1 align="center">hyper_storage</h1>
2+
3+
<p align="center">
4+
<a href="https://pub.dev/packages/hyper_storage">
5+
<img src="https://img.shields.io/pub/v/hyper_storage?label=pub.dev&labelColor=333940&logo=dart&color=00589B">
6+
</a>
7+
<a href="https://github.com/hyper-designed/hyper_storage/actions/workflows/test.yml">
8+
<img src="https://img.shields.io/github/actions/workflow/status/hyper-designed/hyper_storage/test.yml?branch=main&label=tests&labelColor=333940&logo=github">
9+
</a>
10+
<a href="https://app.codecov.io/gh/hyper-designed/hyper_storage">
11+
<img src="https://img.shields.io/codecov/c/github/hyper-designed/hyper_storage?logo=codecov&logoColor=fff&labelColor=333940">
12+
</a>
13+
<br/>
14+
<a href="https://twitter.com/birjuvachhani">
15+
<img src="https://img.shields.io/badge/follow-%40birjuvachhani-1DA1F2?style=flat&label=follow&color=1DA1F2&labelColor=333940&logo=twitter&logoColor=fff">
16+
</a>
17+
<a href="https://twitter.com/saadardati">
18+
<img src="https://img.shields.io/badge/follow-%40saadardati-F0A1F2?style=flat&label=follow&color=0F77dd&labelColor=333940&logo=twitter&logoColor=fff">
19+
</a>
20+
<a href="https://github.com/hyper-designed/hyper_storage">
21+
<img src="https://img.shields.io/github/stars/hyper-designed/hyper_storage?style=flat&label=stars&labelColor=333940&color=8957e5&logo=github">
22+
</a>
23+
</p>
24+
25+
<p align="center">
26+
<a href="#getting-started">Quickstart</a> •
27+
<a href="https://pub.dev/documentation/hyper_storage/latest/topics/Introduction-topic.html">Documentation</a> •
28+
<a href="https://pub.dev/packages/hyper_storage/example">Example</a>
29+
</p>
30+
31+
<p align="center">
32+
<b>Hyper Storage</b>unifies local <b>key-value</b> storage in Flutter with a single, consistent API.
33+
Switch between <b><a href="https://pub.dev/packages/shared_preferences">shared_preferences</a></b>, <b><a href="https://pub.dev/packages/hive_ce">hive_ce</a></b>, <b><a href="https://pub.dev/packages/flutter_secure_storage">flutter_secure_storage</a></b> or any custom backend without changing a single line of app logic.
34+
</p>
35+
36+
---
637

738
## Features
839

@@ -11,6 +42,8 @@ A simple and unified key-value storage for Dart and Flutter applications, suppor
1142
-**Typed Storage:** Store and retrieve data with type safety.
1243
-**JSON Serialization:** Store and retrieve custom objects by providing `toJson` and `fromJson` functions.
1344
-**Named Containers:** Organize your data into named containers for better structure.
45+
-**Custom Serializable Objects Support:** Easily store and retrieve custom objects by providing serialization functions.
46+
-**Reactivity:** Listen to changes in the storage and react accordingly.
1447
-**Asynchronous:** All operations are asynchronous, making it suitable for Flutter applications.
1548
-**Cross-Platform:** Works on mobile, web, and desktop platforms.
1649
-**Fully Tested:** Comprehensive test coverage to ensure reliability.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
dartdoc:
2+
categories:
3+
"Introduction":
4+
markdown: docs/introduction.md
5+
displayName: Introduction
6+
"Getting Started":
7+
markdown: docs/getting_started.md
8+
displayName: "Getting Started"
9+
Backends:
10+
markdown: docs/backends.md
11+
displayName: Backends
12+
"Item Holders":
13+
markdown: docs/item_holders.md
14+
displayName: "Item Holders"
15+
Containers:
16+
markdown: docs/containers.md
17+
displayName: Containers
18+
Reactivity:
19+
markdown: docs/reactivity.md
20+
displayName: Reactivity
21+
categoryOrder:
22+
- "Introduction"
23+
- "Getting Started"
24+
- "Backends"
25+
- "Containers"
26+
- "Item Holders"
27+
- "Reactivity"
28+
showUndocumentedCategories: true
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
# Table of Contents
2+
3+
- [Available Backends](#available-backends)
4+
- [In-Memory Backend](#in-memory-backend)
5+
- [Shared Preferences Backend](#shared-preferences-backend)
6+
- [Hive Backend](#hive-backend)
7+
- [Secure Storage Backend](#secure-storage-backend)
8+
- [Custom Backends](#custom-backends)
9+
- [Using Multiple Backends](#using-multiple-backends)
10+
11+
# Available Backends
12+
13+
## In-Memory Backend:
14+
15+
A simple, built-in, in-memory backend for temporary storage. This backend is useful for testing and scenarios where data
16+
persistence is not required. Data stored in this backend will be lost when the application is closed or restarted.
17+
18+
```dart
19+
import 'package:hyper_storage/hyper_storage.dart';
20+
21+
void main() async {
22+
final storage = await HyperStorage.init(backend: InMemoryBackend());
23+
}
24+
```
25+
26+
> In memory backend is backed by a simple `Map`. It is not suitable for production use cases where data persistence is
27+
> required.
28+
29+
## [Shared Preferences Backend](https://pub.dev/packages/hyper_storage_shared_preferences):
30+
31+
A persistent storage backend using SharedPreferences, which is ideal for storing small amounts of data in a key-value
32+
format. This backend is commonly used for user preferences and settings. This is an ideal choice for applications that
33+
need to store simple data that is also accessible outside the app (e.g., user preferences) and do not require high
34+
security. For example, sharing data between Flutter and native Android/iOS code for various use-cases like widgets,
35+
live activities, native runners, etc.
36+
37+
```dart
38+
import 'package:hyper_storage/hyper_storage.dart';
39+
import 'package:hyper_storage_shared_preferences/hyper_storage_shared_preferences.dart';
40+
41+
void main() async {
42+
final storage = await HyperStorage.init(backend: SharedPreferencesBackend());
43+
}
44+
```
45+
46+
> Hyper Storage uses `SharedPreferencesAsync` API under the hood, which is a fully asynchronous API for
47+
> `SharedPreferences`.
48+
49+
## [Hive Backend](https://pub.dev/packages/hyper_storage_hive):
50+
51+
A persistent storage backend using Hive, a lightweight and fast key-value database written in pure Dart. This backend
52+
is suitable for storing larger amounts of data and supports complex data types.
53+
54+
```dart
55+
import 'package:hyper_storage/hyper_storage.dart';
56+
import 'package:hyper_storage_hive/hyper_storage_hive.dart';
57+
58+
void main() async {
59+
final storage = await HyperStorage.init(backend: HiveBackend());
60+
}
61+
```
62+
63+
The package also provides a `LazyHiveBackend`, which initializes Hive lazily. This is useful in scenarios where you want
64+
to defer the initialization of Hive until it's actually needed, potentially improving startup performance.
65+
66+
```dart
67+
import 'package:hyper_storage/hyper_storage.dart';
68+
import 'package:hyper_storage_hive/hyper_storage_hive.dart';
69+
70+
void main() async {
71+
// Initialize Hive before using LazyHiveBackend.
72+
await Hive.initFlutter();
73+
final storage = await HyperStorage.init(backend: LazyHiveBackend());
74+
}
75+
```
76+
77+
> Hive backend requires initialization of Hive before use. Hyper Storage do not handle Hive initialization for you.
78+
> You need to initialize Hive in your application before using the Hive backend. For example:
79+
80+
## [Secure Storage Backend](https://pub.dev/packages/hyper_secure_storage):
81+
82+
A secure storage backend using [`flutter_secure_storage`](https://pub.dev/packages/flutter_secure_storage), which
83+
provides a way to store sensitive data securely. This backend is ideal for storing credentials, tokens, and other
84+
sensitive information.
85+
86+
```dart
87+
import 'package:hyper_storage/hyper_storage.dart';
88+
import 'package:hyper_secure_storage/hyper_secure_storage.dart';
89+
90+
void main() async {
91+
final storage = await HyperStorage.init(backend: SecureStorageBackend());
92+
}
93+
```
94+
95+
You can optionally provide an instance `FlutterSecureStorage` to the `SecureStorageBackend` constructor to customize its
96+
behavior.
97+
98+
```dart
99+
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
100+
import 'package:hyper_storage/hyper_storage.dart';
101+
102+
import 'package:hyper_secure_storage/hyper_secure_storage.dart';
103+
104+
void main() async {
105+
final secureStorage = FlutterSecureStorage(
106+
aOptions: AndroidOptions(encryptedSharedPreferences: true),
107+
iOptions: IOSOptions(accessibility: KeychainAccessibility.first_unlock),
108+
);
109+
110+
final storage = await HyperStorage.init(
111+
backend: SecureStorageBackend(secureStorage: secureStorage),
112+
);
113+
}
114+
```
115+
116+
## Custom Backends
117+
118+
Hyper Storage is designed to be extensible, allowing you to create your own custom backends by implementing the
119+
`StorageBackend` interface. This enables you to integrate with any storage solution that fits your application's
120+
requirements.
121+
122+
```dart
123+
// Define your custom backend by implementing the StorageBackend interface.
124+
class YourCustomBackend implements StorageBackend {
125+
// Implement all required methods here.
126+
}
127+
```
128+
129+
Then, you can use your custom backend with Hyper Storage as follows:
130+
131+
```dart
132+
import 'package:hyper_storage/hyper_storage.dart';
133+
import 'package:your_custom_backend/your_custom_backend.dart';
134+
135+
void main() async {
136+
final storage = await HyperStorage.init(backend: YourCustomBackend());
137+
}
138+
```
139+
140+
## Using Multiple Backends
141+
142+
You can also use multiple backends in your application by creating separate `HyperStorage` instances for each backend.
143+
144+
```dart
145+
import 'package:hyper_storage/hyper_storage.dart';
146+
import 'package:hyper_storage_shared_preferences/hyper_storage_shared_preferences.dart';
147+
import 'package:hyper_storage_hive/hyper_storage_hive.dart';
148+
149+
void main() async {
150+
final sharedPreferencesStorage = await HyperStorage.newInstance(backend: SharedPreferencesBackend());
151+
final hiveStorage = await HyperStorage.newInstance(backend: HiveBackend());
152+
153+
// Use sharedPreferencesStorage for user preferences
154+
await sharedPreferencesStorage.setString('theme', 'dark');
155+
156+
// Use hiveStorage for app data
157+
await hiveStorage.setString('user_data', 'some complex data');
158+
}
159+
```

0 commit comments

Comments
 (0)