late_init 1.0.1 copy "late_init: ^1.0.1" to clipboard
late_init: ^1.0.1 copied to clipboard

outdated

Execute code at a later stage, but before build has been called for the first time. Useful for initializations that depends on the context

late_init #

Execute code at a later stage, but before build has been called for the first time. Useful for initializations that depends on the context

*This package was heavily inspired by after_layout

Quick Usage #

Add with LateInitMixin

Motivation #

If you want to display a widget that depends on the context (such as ModalRoute or Provider ), you can not use that in initState.

Usage #

This demo showcases how this package resolves the shortcomings shown above:

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Late Init - Example',
      home: new HomeScreen(),
    );
  }
}

class HomeScreen extends StatefulWidget {
  @override
  HomeScreenState createState() => new HomeScreenState();
}

class HomeScreenState extends State<HomeScreen> with LateInitMixin {
  @override
  void lateInitState() {
    final someId = ModalRoute.of(context).settings.arguments as String;
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(body: new Container(color: Colors.red));
  }
}
5
likes
0
pub points
57%
popularity

Publisher

unverified uploader

Execute code at a later stage, but before build has been called for the first time. Useful for initializations that depends on the context

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on late_init