Flutter Inter
Flutter Inter
Dart is
object oriented
strongly typed
Build Context
This is use to provide access to important runtime values like screen size and orientation
accessibility info like font and text direction
Render object translate render object into painting which can be run on gpu
Didchange dependensies
What is Flutter?
Answer: Flutter is an open-source UI software development kit created by Google for building
cross-platform applications for iOS, Android, web, and desktop from a single codebase.
Answer: Flutter uses Dart, a language developed by Google, for app development.
Answer: StatelessWidget is a widget that does not have mutable state and is immutable. Once
created, it cannot change its state.
Answer: BuildContext is a reference to the location of a widget in the widget tree. It allows
accessing theme data, inherited widgets, etc.
Answer: A Future represents a value that will be available at some point in the future, used for
asynchronous operations.
Answer: The main() method is the entry point of a Flutter app. It runs the app by
calling runApp() with the root widget.
Answer: MaterialApp is a wrapper widget that provides material design styling and functionality
to an app, such as navigation and theming.
Answer: The Build() method is called to rebuild the widget tree whenever the widget’s state
changes or when a new configuration is applied.
Answer: A GlobalKey is a special key that allows you to access the state of a widget from
anywhere in the app.
Answer: Column arranges widgets vertically, while Row arranges widgets horizontally.
Answer: The Expanded widget allows a child widget to take up remaining space within
a Column or Row.
Answer: Container is a versatile widget used for creating boxes that can have padding, margin,
decoration, and other properties.
What is the Stack widget used for?
Answer: The Stack widget is used to place widgets on top of each other, allowing for more
complex UI designs.
Answer: To make an element scrollable, you can use the ListView, SingleChildScrollView,
or GridView widget.
Answer: ListView.builder() is used for creating long, scrollable lists that are efficient because it
only renders items that are visible.
Answer: mainAxisAlignment aligns children along the main axis (horizontal for Row, vertical
for Column), and crossAxisAlignment aligns children along the cross axis.
Answer: GestureDetector is used to detect gestures such as taps, swipes, and drags.
Answer: Form is a container for form fields, such as TextFormField, used to validate and manage
user inputs in Flutter.
Answer: MediaQuery provides information about the screen's size, orientation, and pixel
density, which helps in making responsive layouts.
Answer: State management refers to managing and updating the state of an app, ensuring that
widgets rebuild when necessary.
Answer: setState() notifies the framework that the state of the widget has changed, causing it
to rebuild with the updated data.
Answer: BLoC (Business Logic Component) is a state management pattern that separates
business logic from the UI using streams.
Answer: Riverpod is an advanced and flexible state management solution for Flutter that allows
for easier testing and better error handling than Provider.
Answer: InheritedWidget allows data to be passed down the widget tree, while Provider is a
wrapper around InheritedWidget and offers a simpler, more powerful API for state
management.
Answer: Redux is a predictable state management solution for Flutter that is based on a
unidirectional data flow, allowing easy state updates with actions and reducers.
Answer: StreamBuilder is a widget that builds itself based on the latest snapshot of a stream,
useful for handling real-time data or asynchronous events.
Answer: ChangeNotifier is used to notify listeners when the state has changed so that widgets
can rebuild with the updated state.
Answer: ScopedModel is used to manage shared data and provide it to the widget tree. It
allows widgets to listen for changes and rebuild when the state updates.
Answer: You can make HTTP requests using the http package, which allows you to send requests
like GET, POST, PUT, and DELETE.
Answer: Dio is an advanced HTTP client for Flutter that provides features like interceptors,
request cancellation, and file downloading, unlike the simpler http package.
Answer: You can make a GET request using http.get(), passing in the URL and handling the
response.
Answer: async and await are used to handle asynchronous operations. async marks a function
as asynchronous, and await pauses the execution until the awaited operation completes.
Answer: Use http.post() and pass a map of data as the body in JSON format, often
using jsonEncode() to convert the data.
Answer: http.get() is used for fetching data from the server, while http.post() is used for sending
data to the server.
Answer: You can pass headers in the API call by including them in the headers parameter of the
request method, such as http.get(url, headers: {'Authorization': 'Bearer token'}).
5. Flutter Animations
Answer: AnimationController controls the animation by defining its duration, starting and
stopping the animation, and driving the animation.
Answer: Tween defines the range of values for an animation. It interpolates between a start and
end value during the animation.
Answer: Hero animations are used to create smooth transitions between two screens, where a
widget “flies” between the screens, typically used for shared elements like images.
Answer: AnimatedBuilder allows for more control over animation, whereas AnimatedWidget is
a simpler way to apply animations to widgets.
Answer: FadeTransition applies a fade effect to a widget, animating its opacity during a given
period.
Answer: RotationTransition animates a widget's rotation between specified start and end
angles.
Answer: SlideTransition animates the position of a widget along a given axis, creating a sliding
effect.
6. Flutter Navigation and Routing
Answer: Navigation in Flutter is the process of moving between different screens or routes in
the app. It is managed using the Navigator widget.
Answer: The Navigator widget is used to manage a stack of routes. It can push and pop routes
(screens) to control the app's navigation flow.
Answer: You can navigate to a new screen using Navigator.push(), which adds a new route to
the stack, or Navigator.pushReplacement() to replace the current route.
What is a MaterialPageRoute?
Answer: MaterialPageRoute is a widget that provides a standard page transition for route
navigation, commonly used with Navigator.push().
Answer: Data can be passed between screens using the Navigator.push() method by passing
arguments to the route's constructor or using the arguments property.
Answer: Named routing allows you to define routes with names in the MaterialApp and
navigate using Navigator.pushNamed().
Answer: You can return data from a route by using Navigator.pop(context, result),
where result is the data to return.
Answer: Navigator.pop() is used to remove the current route from the navigation stack and
return to the previous screen.
Answer: push() adds a new route to the stack, while pushReplacement() replaces the current
route with a new one.
7. Flutter Testing
Answer: Unit testing in Flutter involves testing individual components (functions, methods,
classes) of your app to ensure they behave as expected.
Answer: Unit tests can be run using the flutter test command, which runs the tests defined in
the test/ directory.
Answer: Widget testing involves testing widgets in isolation to ensure they render correctly and
interact with the user as expected.
Answer: Integration testing tests a complete workflow or flow of the app, ensuring all parts of
the app work together properly.
Answer: testWidgets() is used to write widget tests. It allows you to simulate user interactions
and verify the widget's UI behavior.
Answer: A Mock is a simulated object that mimics the behavior of real dependencies in unit
tests, typically used to avoid calling actual APIs or services.
Answer: setUp() runs before each test case, allowing you to set up necessary
conditions. tearDown() runs after each test case, used to clean up resources.
Answer: You can mock HTTP requests using the mockito package, allowing you to simulate
network calls without hitting real endpoints.
Answer: flutter_test is used for widget and unit testing, while integration_test is for testing
complete flows and interactions in the app, typically on real devices.
Answer: CustomPaint allows you to draw custom graphics like shapes, lines, or even complex
drawings directly onto the screen using a CustomPainter.
Answer: SliverAppBar is a type of app bar that integrates with custom scroll views and can
change appearance when scrolled.
Answer: ClipRRect is a widget that clips its child to a rounded rectangle, often used to create
circular images or rounded corners.
Answer: Draggable is a widget that enables a widget to be dragged across the screen.
Answer: Opacity is used to adjust the opacity of a widget, while FadeTransition animates the
opacity over time.
Answer: Align is used to position a widget within a parent container, allowing precise alignment
of child widgets.
Answer: AnimatedOpacity is a widget that automatically animates the opacity of its child widget
over a specified duration.
Answer: ReorderableListView is a widget that allows users to reorder list items by dragging
them.
What is the Expanded widget in Flutter?
Answer: Expanded is used to make a widget take up as much space as possible along the main
axis in a Row, Column, or Flex.
Answer: Flex is a layout widget that arranges its children in a flexible way along a single axis,
similar to Row and Column, but more customizable.
Answer: RepaintBoundary is used to isolate portions of the widget tree that need to be
redrawn, improving rendering performance.
Answer: Lazy loading is the process of loading content or data only when it is needed,
improving app startup and memory usage.
Answer: Use const constructors where possible, Key for stateful widgets, and avoid
calling setState() unnecessarily.
Answer: Avoid memory leaks by disposing controllers and streams properly, using
the dispose() method, and utilizing lazy loading techniques.
Answer: Use the DevTools suite to profile and analyze your Flutter app for performance
bottlenecks, memory usage, and rendering issues.
Answer: async and await allow non-blocking operations, freeing up the main thread and
improving app responsiveness.
Answer: The flutter performance tool helps track rendering performance and diagnose issues
with frame rendering and CPU usage.
Answer: Minimize the app size by reducing dependencies, using tree shaking to eliminate
unused code, and using the flutter build apk --split-per-architecture command.
Answer: A Flutter plugin is a package that provides access to native functionality such as
camera, GPS, or sensors, enabling Flutter apps to interact with platform-specific features.
Answer: Dependencies are added in the pubspec.yaml file under the dependencies section, and
the flutter pub get command is used to fetch them.
Answer: After adding a package to pubspec.yaml, import it in the Dart file and use the functions
or classes provided by the package.
Answer: The shared_preferences package is used for storing small amounts of data persistently,
such as user preferences or app settings.
Answer: url_launcher is a Flutter plugin that allows you to open URLs in the mobile browser,
send SMS, make phone calls, or open email apps.
Answer: image_picker is a Flutter plugin that allows users to pick images or videos from their
device gallery or camera.
Answer: sqflite is a Flutter plugin for SQLite database integration, allowing you to store
structured data locally on the device.
Answer: You can check the plugin’s documentation on pub.dev for compatibility with the
required Flutter version and the supported platforms.