jolt_setup 4.0.0-dev.1
jolt_setup: ^4.0.0-dev.1 copied to clipboard
Setup Widget API and Flutter hooks for building reactive widgets with Jolt signals, featuring automatic resource cleanup and lifecycle management.
Jolt Setup #
Setup-based widgets and hooks for Jolt-powered Flutter components.
jolt_setup lets a widget run setup once, create the state and resources it needs there, and keep later rebuilds focused on rendering. Hooks own long-lived pieces such as signals, animation controllers, focus nodes, timers, and lifecycle listeners, and clean them up with the widget.
SetupWidget #
import 'package:flutter/material.dart';
import 'package:jolt_setup/jolt_setup.dart';
class WelcomeLogo extends SetupWidget<WelcomeLogo> {
const WelcomeLogo({super.key});
@override
setup(context, props) {
final controller = useAnimationController(
duration: const Duration(milliseconds: 250),
);
onMounted(controller.forward);
return () => FadeTransition(
opacity: controller,
child: const FlutterLogo(size: 72),
);
}
}
Use SetupWidget when you want a dedicated widget type and immutable widget fields, but still want setup to create and own long-lived resources once.
SetupMixin #
import 'package:flutter/material.dart';
import 'package:jolt_setup/jolt_setup.dart';
class WelcomePanel extends StatefulWidget {
const WelcomePanel({super.key});
@override
State<WelcomePanel> createState() => _WelcomePanelState();
}
class _WelcomePanelState extends State<WelcomePanel>
with SetupMixin<WelcomePanel> {
late AnimationController controller;
void show() => controller.forward();
void hide() => controller.reverse();
@override
setup(context) {
controller = useAnimationController(
duration: const Duration(milliseconds: 250),
);
return () => Column(
mainAxisSize: MainAxisSize.min,
children: [
FadeTransition(
opacity: controller,
child: const FlutterLogo(size: 72),
),
Row(
mainAxisSize: MainAxisSize.min,
children: [
FilledButton(
onPressed: show,
child: const Text('Show'),
),
const SizedBox(width: 12),
OutlinedButton(
onPressed: hide,
child: const Text('Hide'),
),
],
),
],
);
}
}
Use SetupMixin when you still want a normal State<T> class and its instance methods, but want setup hooks to own the resources used by that state object.
The package also includes SetupBuilder for local composition, plus hooks for reactive state, controllers, listenables, focus, scroll, animation, timers, and lifecycle callbacks.
License #
This project is licensed under the MIT License. See the LICENSE file for details.