Skip to content

bamlab/flutter_init

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 😁

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published