flutter_rocket 0.0.11 copy "flutter_rocket: ^0.0.11" to clipboard
flutter_rocket: ^0.0.11 copied to clipboard

Powerful package for state management & request.

Flutter Rocket #

The ultimate power-up for your Flutter state management and API integration.

Pub License: MIT Flutter CI

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 pub package Core bundle for Flutter.
rocket_model pub package Base model and state logic.
rocket_client pub package HTTP client with caching.
rocket_view pub package UI state management widgets.
rocket_cli pub package CLI for model generation.

📖 Table of Contents #


🎨 Graphic Tutorial #

Flutter Rocket Architecture Explore the Miro Board


📦 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

Resource Link
Documentation Wiki
Examples GitHub Examples
Community Discussions
Bugs Issue Tracker

Author #

Built with ❤️ by the Jahez Team.