简体   繁体   中英

Why only few flutter plugins require WidgetsFlutterBinding.ensureInitialized()?

sqflite requires WidgetsFlutterBinding.ensureInitialized() but not xmpp_plugin , shared_preferences or device_info_plus ? As per my knowledge plugins require platform specific channels due to which WidgetsFlutterBinding.ensureInitialized() is placed in main() function of flutter app.

Most plugins should not require WidgetsFlutterBinding.ensureInitialized because the WidgetsFlutterBinding instance normally is initialized automatically. Some plugins require that it be explicitly called because they need the instance to be initialized earlier.

From the WidgetsFlutterBinding.ensureInitialized documentation :

You only need to call this method if you need the binding to be initialized before calling runApp .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM