Flutter Rocket
The ultimate power-up for your Flutter state management and API integration.
Flutter Rocket is a high-performance, lightweight state management and API integration solution. It simplifies how you handle data from your backend to your UI while providing premium performance optimizations out of the box.
π Key Features
- β‘ Ultra Performance: Selective rebuilds ensure only necessary widgets update.
- π Seamless API Integration: Built-in client with support for interceptors and caching.
- π οΈ Powerful Tooling: Generate optimized models instantly using Rocket CLI.
- π Minimal Boilerplate: Write less code, build more features.
- π¦ Modular Architecture: Use only what you need (Listenables, Models, Clients, Views).
- π‘οΈ Type Safe: Fully typed models and requests.
π¦ Package Ecosystem
| Package | Version | Description |
|---|---|---|
| flutter_rocket | Core bundle for Flutter. | |
| rocket_model | A typeβsafe, reactive model layer. | |
| rocket_client | HTTP client with caching. | |
| rocket_view | UI state management widgets. | |
| rocket_mini_view | A tiny, reactive widget. | |
| rocket_singleton | Fast, typeβsafe inβmemory storage. | |
| rocket_cache | A persistence and caching layer. | |
| rocket_cli | CLI for model generation. |
π Table of Contents
- Flutter Rocket
- Author
π¨ Graphic Tutorial
π¦ Installation
Add this to your pubspec.yaml:
dependencies:
flutter_rocket: ^latest_version
β‘ Quick Start
1. Define your Model
Use Rocket CLI to generate this automatically, or define it manually:
import 'package:flutter_rocket/flutter_rocket.dart';
const String postTitleField = "title";
class Post extends RocketModel<Post> {
String? title;
Post({this.title});
@override
void fromJson(Map<String, dynamic>? json, {bool isSub = false}) {
if (json == null) return;
title = json[postTitleField];
super.fromJson(json, isSub: isSub);
}
void updateFields({String? titleField}) {
List<String> fields = [];
if (titleField != null) {
title = titleField;
fields.add(postTitleField);
}
rebuildWidget(fromUpdate: true, fields: fields.isEmpty ? null : fields);
}
@override
Post get instance => Post();
}
2. Setup the Client
Initialize your client and save it to the Rocket singleton:
void main() {
RocketRequest request = RocketRequest(url: 'https://jsonplaceholder.typicode.com');
Rocket.add(rocketRequestKey, request);
runApp(MyApp());
}
3. Bind UI with RocketView
Display your data effortlessly:
class PostList extends StatelessWidget {
final Post postModel = Post();
@override
Widget build(BuildContext context) {
return RocketView(
model: postModel,
fetch: () => Rocket.get(rocketRequestKey).request('posts', model: postModel),
builder: (context, state) {
return ListView.builder(
itemCount: postModel.all!.length,
itemBuilder: (context, index) {
final post = postModel.all![index];
return Text(post.title!);
},
);
},
);
}
}
β¨ Premium Optimizations
Selective Rebuilds
Stop rebuilding your entire list when only one item changes. Specify fields in RocketView to listen to specific property updates.
RocketView(
model: currentPost,
fields: [postTitleField], // Only rebuilds when 'title' changes
builder: (context, state) => Text(currentPost.title!),
)
Automatic Bubbling
Nested models automatically notify their parents. If a Post inside a Posts list updates, the list view is notified automatically without any extra code.
π οΈ Advanced Features
Interceptors
Handle global logic like Auth headers or logging:
RocketClient(
url: 'https://api.example.com',
beforeRequest: (request) {
request.headers['Authorization'] = 'Bearer your_token';
return request;
},
);
Caching
Speed up your app with built-in caching:
RocketCache.init(); // Initialize first
client.request(
'posts',
model: post,
cacheKey: 'all_posts',
cacheDuration: Duration(days: 1),
);
π οΈ Rocket CLI
Generate your optimized models instantly from JSON strings or files.
# Install
dart pub global activate rocket_cli
# Run
rocket_cli -j '{"id":1, "title":"Hello"}' -n Post
π Links & Support
| Resource | Link |
|---|---|
| Documentation | Wiki |
| Examples | GitHub Examples |
| Community | Discussions |
| Bugs | Issue Tracker |
Author
Built with β€οΈ by the Jahez Team.