Guides
Creating Custom Controllers
Extend Forui controllers with custom logic and pass them to widgets.
Suppose you extend a controller, e.g. FPopoverController, to add custom logic. You have 2 options when passing the
custom controller to a widget.
Managed Control with External Controller
Pass the custom controller via a managed control.
1class CustomController extends FPopoverController {2 CustomController({required super.vsync});34 // Custom logic here.5}67class MyWidget extends StatefulWidget {8 const MyWidget({super.key});910 @override11 State<MyWidget> createState() => _MyWidgetState();12}1314class _MyWidgetState extends State<MyWidget>15 with SingleTickerProviderStateMixin {16 late final CustomController _controller;1718 @override19 void initState() {20 super.initState();21 _controller = CustomController(vsync: this);22 }2324 @override25 void dispose() {26 _controller.dispose();27 super.dispose();28 }2930 @override31 Widget build(BuildContext context) => FPopover(32 control: .managed(controller: _controller),33 child: const Placeholder(),34 popoverBuilder: (_, _) => const Placeholder(),35 );36}37The downside of this approach is that you have to manage the controller's lifecycle yourself.
Extend Managed Control
Alternatively, you can extend managed control (FPopoverManagedControl) to create your custom controller.
1class CustomController extends FPopoverController {2 final int customValue;34 CustomController({required this.customValue, required super.vsync});5}67class CustomManagedControl extends FPopoverManagedControl {8 final int customValue;910 CustomManagedControl({required this.customValue});1112 @override13 CustomController createController(TickerProvider vsync) =>14 CustomController(customValue: customValue, vsync: vsync);15}1617// Usage:18final example = FPopover(19 control: CustomManagedControl(customValue: 42),20 child: const Placeholder(),21 popoverBuilder: (_, _) => const Placeholder(),22);23This way, the widget manages the controller's lifecycle for you.