widget_did_build 0.0.1 widget_did_build: ^0.0.1 copied to clipboard
Flutter didbuildcallback
Widget Did Build #
When you find your self wanting to run a function once with context after a widget build has been completed, the current flutter system makes it difficult to accomplish.
This is a simple library that makes it easy to run a function that takes in a context
and runs once after the widget is built. Similar to componentDidMount
in React.
Usage #
- Change you state class from
class _MyAppState extends State<MyApp> {
}
to
class _MyAppState extends DidBuildState<MyApp> {
}
- Import the plugin
import 'package:widget_did_build/widget_did_build.dart';
-
Add and override the
didBuildMethod
in your state class -
Done.
This is what you state class will look like in the end
class _MyAppState extends DidBuildState<MyApp> { // Using DidBuildState instead of State
@override
void didBuild(BuildContext context) { // overriding and implement the didBuild method
// call your method here
}
@override
Widget build(BuildContext context) {
return Container();
}
}