Explore core Flutter basics with this quiz designed to assess foundational knowledge of widgets, state management, layouts, and Dart syntax used in mobile app development. Enhance your understanding of essential Flutter concepts for building robust cross-platform applications.
Which widget is typically used to allow vertical scrolling of a list of items in a Flutter mobile app?
Explanation: ListView enables vertical or horizontal scrolling of a list of widgets, making it suitable for displaying long, scrollable content. Column arranges children in a vertical alignment but does not provide scrolling by default. Container is mainly used for styling and layout purposes, while Stack overlays widgets on top of each other. Only ListView is built specifically for scrollable lists.
What is the main difference between StatelessWidget and StatefulWidget in Flutter?
Explanation: StatefulWidget is designed to maintain and update its internal state during the app's lifecycle, making it ideal for widgets that change, such as forms or animations. StatelessWidget, in contrast, always renders the same way given the same input. Both widget types require a build method, so saying StatelessWidget requires it but StatefulWidget does not is incorrect. Performance differences are context-dependent, and StatelessWidget doesn't update itself automatically.
If you want to apply padding of 16 pixels to all sides of a widget, which Flutter widget should you use?
Explanation: The Padding widget wraps its child and applies specified padding on all or specific sides, making it the correct choice for spacing around a widget. SizedBox is used for creating space with fixed width or height, but does not apply padding. Align positions a child within its parent but does not add padding, and Positioned is used within Stack for absolute positioning. None of the distractors modify the internal spacing of a widget like Padding.
Which symbol is used in Dart to denote that a variable can be null, such as 'String? name;'?
Explanation: The question mark after a type in Dart indicates that the variable may be nullable. The exclamation mark is used for null assertion, which forces the variable to be non-null, but does not make it nullable. Hash and at symbols are not used for nullability in Dart. Only the question mark correctly denotes a nullable type.
What does the hot reload feature allow you to do while developing a Flutter app?
Explanation: Hot reload helps developers see immediate effects of code changes without needing to restart the app or lose the current state, thus speeding up the development process. It does not affect app performance directly, nor does it relate to exporting across platforms or device connectivity. Only the first option accurately describes the purpose of hot reload.