Flutter Interview Questions and Answers
Ques 11. What is the 'MaterialApp' widget used for?
The 'MaterialApp' widget in Flutter is used to set up the material design for a Flutter application. It provides features like navigation, theming, and accessibility that are common in material design.
Example:
void main() {
runApp(MaterialApp(
home: MyHomePage(),
));
}
Ques 12. How can you handle user input in Flutter?
User input in Flutter can be handled using widgets such as 'TextField' for text input, 'GestureDetector' for gestures, and 'InkWell' for handling taps. Additionally, you can use the 'onPressed' callback for buttons.
Example:
TextField(
onChanged: (text) {
print('User input: $text');
},
)
Ques 13. What is 'Flutter Packages' and how can they be used?
'Flutter Packages' are reusable pieces of code that can be added to a Flutter project to provide specific functionalities. They are managed using the 'pubspec.yaml' file, and developers can use the 'pub get' command to fetch and install packages.
Example:
dependencies:
http: ^0.13.3
Ques 14. What is the purpose of the 'Navigator' in Flutter?
The 'Navigator' in Flutter is used for managing the navigation stack. It allows developers to push and pop screens, navigate between different pages, and control the flow of the application.
Example:
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondScreen()),
);
Ques 15. What is the 'Pubspec.yaml' file in Flutter?
The 'Pubspec.yaml' file is a configuration file in Flutter projects that defines the metadata, dependencies, and other settings for the project. It is used by the 'pub' tool to manage project dependencies.
Example:
name: my_flutter_app
dependencies:
flutter:
sdk: flutter
Most helpful rated by users: