controller_builder 1.0.0+1 copy "controller_builder: ^1.0.0+1" to clipboard
controller_builder: ^1.0.0+1 copied to clipboard

Widget for abstracting initializing and disposing TextEditingController, ChangeNotifiers, etc.

example/lib/main.dart

import 'dart:developer';

import 'package:controller_builder/controller_builder.dart';
import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(home: ControllerBuilderExample());
  }
}

class ControllerBuilderExample extends StatelessWidget {
  const ControllerBuilderExample({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Padding(
          padding: const EdgeInsets.all(8.0),
          child: ControllerBuilder<TextEditingController>(
            create: () {
              final controller = TextEditingController(text: 'Hello, world!');
              return controller..addListener(someListener);
            },
            builder: (context, controller) {
              return TextField(
                controller: controller,
                onChanged: log,
              );
            },
            dispose: (controller) {
              controller
                ..removeListener(someListener)
                ..dispose();
            },
          ),
        ),
      ),
    );
  }
}

void someListener() {}
0
likes
160
points
0
downloads

Publisher

unverified uploader

Weekly Downloads

Widget for abstracting initializing and disposing TextEditingController, ChangeNotifiers, etc.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on controller_builder