init 1.0.0 copy "init: ^1.0.0" to clipboard
init: ^1.0.0 copied to clipboard

Init widget to execute initialization methods declaratively

init #

logo

A simple Flutter widget to declaratively execute initialization logic in your widget tree. Used internally at Theodo Apps β€οΈπŸ’™πŸ’›.

Flutter widgets often require initialization logic (e.g., fetching data, setting up listeners) that is typically placed in initState, didChangeDependencies, or after the first frame. Managing this logic can lead to boilerplate and less reusable code, especially when you want to compose or reuse initialization patterns across widgets.

init provides an Init widget that lets you declaratively specify initialization and disposal logic as parameters, making your code cleaner, more modular, and easier to test.

Installation #

To use the Init widget, add init pachage to the dependencies:

dart pub add init
# or
flutter pub add init

You can also add the package manually to your pubspec.yaml:

dependencies:
  init: ^1.0.0

Then run:

flutter pub get

Usage #

Wrap any widget with Init and provide the desired callbacks:

import 'package:init/init.dart';

Init(
  onInit: () => print('Widget initialized'),
  onInitPostFrame: () => print('Widget initialized after frame'),
  onDidChangeDependencies: () => print('Dependencies changed'),
  onDispose: () => print('Widget disposed'),
  child: MyChildWidget(),
)

Parameters #

  • onInit: Called once in initState (for one-time setup)
  • onInitPostFrame: Called once after the first frame is rendered
  • onDidChangeDependencies: Called in didChangeDependencies
  • onDispose: Called in dispose
  • child: The widget to render

Example #

Init(
  onInit: () => print('Initializing...'),
  onDispose: () => print('Cleaning up...'),
  child: const Text('Hello!'),
)

πŸ‘‰ About Theodo Apps #

We are a 130 people company developing and designing universal applications with React Native and Flutter using the Lean & Agile methodology. To get more information on the solutions that would suit your needs, feel free to get in touch by email or through or contact form!

We will always answer you with pleasure 😁

5
likes
160
points
328
downloads

Publisher

verified publisherbam.tech

Weekly Downloads

Init widget to execute initialization methods declaratively

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on init