flutter_rocket
상태 관리 및 요청을 위한 강력한 패키지입니다.
🚀 Flutter Rocket 🚀 Flutter Rocket으로 높이 날아오세요 - Flutter 개발자를 위한 최고의 패키지
아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
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.
| Package | Version | Description |
|---|---|---|
| flutter_rocket | pub package | Core bundle for Flutter. |
| rocket_model | pub package | A type‑safe, reactive model layer. |
| rocket_client | pub package | HTTP client with caching. |
| rocket_view | pub package | UI state management widgets. |
| rocket_mini_view | pub package | A tiny, reactive widget. |
| rocket_singleton | pub package | Fast, type‑safe in‑memory storage. |
| rocket_cache | pub package | A persistence and caching layer. |
| rocket_cli | pub package | CLI for model generation. |
Flutter Rocket Architecture
Add this to your pubspec.yaml:
dependencies:
flutter_rocket: ^latest_version
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();
}
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());
}
Display your data effortlessly:
class PostList extends StatelessWidget {
final Post postModel = Post();
@override
Widget build(BuildContext context) {
return RocketView(
model: postModel,
fetch: ({bool refresh = false}) => 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!);
},
);
},
);
}
}
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!),
)
Nested models automatically notify their parents. If a Post inside a Posts list updates, the list view is notified automatically without any extra code.
Handle global logic like Auth headers or logging:
RocketClient(
url: 'https://api.example.com',
beforeRequest: (request) {
request.headers['Authorization'] = 'Bearer your_token';
return request;
},
);
Speed up your app with built-in caching:
RocketCache.init(); // Initialize first
client.request(
'posts',
model: post,
cacheKey: 'all_posts',
cacheDuration: Duration(days: 1),
);
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
| Resource | Link |
|---|---|
| Documentation | Wiki |
| Examples | GitHub Examples |
| Community | Discussions |
| Bugs | Issue Tracker |
Built with ❤️ by the Jahez Team.