When to use Getx Distil
Getx Distil is a distilled version of the popular GetX ecosystem, focusing on ultra‑fast micro‑state handling and scoped dependency injection (DI) without the extra baggage of the full GetX package. It provides a minimal API that lets you create tiny, observable state objects that update only the widgets that need them, resulting in lower memory overhead and faster rebuild cycles. The package is ideal for developers who love GetX's simplicity but want a leaner solution for large‑scale apps or performance‑critical screens.
When to reach for Getx Distil? If you find yourself building apps with many isolated features—such as onboarding flows, settings screens, or modular feature bundles—where each feature needs its own tiny state container, Distil shines. It encourages a scoped approach: you instantiate a controller only where it is required, and the framework automatically disposes of it when the widget tree leaves scope. This eliminates the risk of lingering singletons and makes testing straightforward, because each controller can be instantiated in isolation.
In a typical Flutter architecture, Getx Distil sits at the intersection of state management and dependency injection. You can place it alongside clean architecture layers, using it in the presentation layer to expose UI‑friendly observables, while keeping business logic in domain or data layers untouched. Because the package does not prescribe a particular folder structure, it works equally well with MVVM, Clean, or Feature‑First architectures. Its scoped DI model also plays nicely with service locators or repository patterns, allowing you to inject repositories, use‑cases, or API clients directly into a Distil controller.
Getting started is straightforward. After adding the dependency with `flutter pub add getx_distil`, you create a controller that extends `DistilController` and expose observable fields using the `Rx` wrapper. Widgets listen to these fields via the `DistilBuilder` widget, which rebuilds only when the observed values change. The API mirrors GetX’s familiar syntax, so existing GetX users face a shallow learning curve. For example, a counter controller can be defined in a few lines, and the UI updates instantly without manual `setState` calls.
While Getx Distil is production‑ready, there are a few cautions for large teams. Because the package encourages many small controllers, it’s important to establish naming conventions and folder organization to avoid a scattered codebase. Also, the package does not include advanced routing or middleware features that the full GetX provides, so you’ll need a separate solution for navigation if you rely on those capabilities. Finally, keep an eye on Flutter’s stable channel compatibility; the package targets Flutter 3.0 and above, and you should test on each platform (mobile, web, desktop) to ensure the scoped DI behaves as expected.
For beginners, Getx Distil offers a gentle entry point into reactive programming. The minimal API reduces boilerplate, and the built‑in disposal logic means you can focus on UI and business logic rather than lifecycle management. Whether you’re prototyping a new feature or scaling an existing app, Distil gives you the performance of a micro‑state engine with the developer ergonomics that GetX is known for.
Pros
- tiny runtime footprint
- scoped DI eliminates global singletons
- familiar GetX‑style syntax
- automatic disposal of controllers
- works across all Flutter platforms
Watch outs
- no built‑in routing or middleware
- requires disciplined folder structure
- limited to micro‑state patterns
Setup notes
Add the package to your project with the following command: ``` flutter pub add getx_distil ``` Then run `flutter pub get` and import the library where needed: ```dart import 'package:getx_distil/getx_distil.dart'; ```
Requires Flutter 3.0 or newer. Works on iOS, Android, web, macOS, Windows, and Linux. No platform‑specific native code, so no additional setup for Android or iOS.
```dart
import 'package:flutter/material.dart';
import 'package:getx_distil/getx_distil.dart';
class CounterController extends DistilController {
final count = RxInt(0);
void increment() => count.value++;
}
class CounterPage extends StatelessWidget {
final CounterController _c = DistilScope.create(() => CounterController());
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Getx Distil Counter')),
body: Center(
child: DistilBuilder(
builder: (_) => Text('Count: ${_c.count.value}', style: const TextStyle(fontSize: 24)),
),
),
floatingActionButton: FloatingActionButton(
onPressed: _c.increment,
child: const Icon(Icons.add),
),
);
}
}
```