What does BuildContext do in Flutter?

BuildContext is, like it’s name is implying, the context in which a specific widget is built. If you’ve ever done some React before, that context is kind of similar to React’s context (but much smoother to use) ; with a few bonuses. Generally speaking, there are 2 use cases for context : Interact with your … Read more

Targeting S+ (version 31 and above) requires that an explicit value for android:exported be defined when intent filters are present]

Android 12 require you to add a piece of code to your main activity Go to your project folder and open AndroidManifest.xml file Add the below code in activity android:exported=”true” Reference: <activity android:name=”.MainActivity” android:exported=”true” android:launchMode=”singleTop” android:theme=”@style/LaunchTheme”> </activity>

How can I layout widgets based on the size of the parent?

You will want to use the LayoutBuilder widget which will build at layout time and provides the parent widget’s constraints. The LayoutBuilder takes in a build() function which has the the standard BuildContext along with the BoxConstraints as parameters that can be used to help dynamically render widgets based on size. Let’s build a simple … Read more

The argument type ‘Function’ can’t be assigned to the parameter type ‘void Function()?’ after null safety

Change your code to accept a VoidCallback instead of Function for the onPressed. By the way VoidCallback is just shorthand for void Function() so you could also define it as final void Function() onPressed; Updated code: class DrawerItem extends StatelessWidget { final String text; final VoidCallback onPressed; const DrawerItem({Key key, this.text, this.onPressed}) : super(key: key); … Read more