controller_builder 1.0.0+1 controller_builder: ^1.0.0+1 copied to clipboard
Widget for abstracting initializing and disposing TextEditingController, ChangeNotifiers, etc.
controller_builder
#
Widget that abstracts common initialization and disposing of
TextEditingController
, ChangeNotifier
, etc.
ControllerBuilder<TextEditingController>(
// Create a controller (or any `ChangeNotifier`).
create: () {
final controller = TextEditingController(text: 'Hello, world!');
return controller..addListener(someListener);
},
// The controller you created in now available in the `builder` below.
builder: (context, controller) {
return TextField(
controller: controller,
onChanged: log,
);
},
// Dispose will be called automatically unless
// you provide a `dispose` callback like below.
// You assume responsibility to call dispose then.
dispose: (controller) {
controller
..removeListener(someListener)
..dispose();
},
)