Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
11 views12 pages

Flutter Inter

Uploaded by

zakriakhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views12 pages

Flutter Inter

Uploaded by

zakriakhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Flutter

A declarative, multi-platform UI framework written in dart.

Multiplatform means they are run on different devices.

Dart is

object oriented

strongly typed

single threaded event loop

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

Init state we should initialize into instant resourcces

Did update widgets

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.

What programming language is used for Flutter development?

Answer: Flutter uses Dart, a language developed by Google, for app development.

What is a StatelessWidget in Flutter?

Answer: StatelessWidget is a widget that does not have mutable state and is immutable. Once
created, it cannot change its state.

What is a StatefulWidget in Flutter?


Answer: StatefulWidget is a widget that has mutable state. It can rebuild itself when the state
changes.

What is the BuildContext in Flutter?

Answer: BuildContext is a reference to the location of a widget in the widget tree. It allows
accessing theme data, inherited widgets, etc.

What is a Future in Dart?

Answer: A Future represents a value that will be available at some point in the future, used for
asynchronous operations.

What is the main() method in Flutter?

Answer: The main() method is the entry point of a Flutter app. It runs the app by
calling runApp() with the root widget.

What is the role of MaterialApp widget?

Answer: MaterialApp is a wrapper widget that provides material design styling and functionality
to an app, such as navigation and theming.

What is a Build() method?

Answer: The Build() method is called to rebuild the widget tree whenever the widget’s state
changes or when a new configuration is applied.

What is a GlobalKey in Flutter?

Answer: A GlobalKey is a special key that allows you to access the state of a widget from
anywhere in the app.

2. Flutter Layouts and Widgets

What is the difference between Column and Row?

Answer: Column arranges widgets vertically, while Row arranges widgets horizontally.

What is an Expanded widget?

Answer: The Expanded widget allows a child widget to take up remaining space within
a Column or Row.

What is the purpose of Container in Flutter?

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.

How do you make an element scrollable in Flutter?

Answer: To make an element scrollable, you can use the ListView, SingleChildScrollView,
or GridView widget.

What is ListView.builder() used for?

Answer: ListView.builder() is used for creating long, scrollable lists that are efficient because it
only renders items that are visible.

What is the difference between mainAxisAlignment and crossAxisAlignment?

Answer: mainAxisAlignment aligns children along the main axis (horizontal for Row, vertical
for Column), and crossAxisAlignment aligns children along the cross axis.

What is the GestureDetector widget used for?

Answer: GestureDetector is used to detect gestures such as taps, swipes, and drags.

What is a Form widget in Flutter?

Answer: Form is a container for form fields, such as TextFormField, used to validate and manage
user inputs in Flutter.

What is the MediaQuery widget used for?

Answer: MediaQuery provides information about the screen's size, orientation, and pixel
density, which helps in making responsive layouts.

3. State Management in Flutter

What is state management in Flutter?

Answer: State management refers to managing and updating the state of an app, ensuring that
widgets rebuild when necessary.

What is setState() in Flutter?

Answer: setState() notifies the framework that the state of the widget has changed, causing it
to rebuild with the updated data.

What is the Provider package in Flutter?


Answer: The Provider package is used for state management by providing a way to manage and
share data across the widget tree.

What is BLoC in Flutter?

Answer: BLoC (Business Logic Component) is a state management pattern that separates
business logic from the UI using streams.

What is Riverpod in Flutter?

Answer: Riverpod is an advanced and flexible state management solution for Flutter that allows
for easier testing and better error handling than Provider.

What is the difference between InheritedWidget and 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.

What is Redux in Flutter?

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.

What is StreamBuilder in Flutter?

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.

What is the purpose of ChangeNotifier in Flutter?

Answer: ChangeNotifier is used to notify listeners when the state has changed so that widgets
can rebuild with the updated state.

How do you use ScopedModel for state management?

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.

4. Networking and HTTP in Flutter

How do you make an HTTP request in Flutter?

Answer: You can make HTTP requests using the http package, which allows you to send requests
like GET, POST, PUT, and DELETE.

How do you handle JSON data in Flutter?


Answer: JSON data can be handled using the dart:convert library, which
provides jsonDecode() to convert JSON into Dart objects.

What is Dio, and how is it different from the http package?

Answer: Dio is an advanced HTTP client for Flutter that provides features like interceptors,
request cancellation, and file downloading, unlike the simpler http package.

How do you handle exceptions during HTTP requests in Flutter?

Answer: You handle exceptions using try-catch blocks. Common exceptions


include SocketException, TimeoutException, and HttpException.

How do you make a GET request using the http package?

Answer: You can make a GET request using http.get(), passing in the URL and handling the
response.

What is the purpose of async and await in Flutter?

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.

How do you send data in a POST request in Flutter?

Answer: Use http.post() and pass a map of data as the body in JSON format, often
using jsonEncode() to convert the data.

What is the difference between http.get() and http.post()?

Answer: http.get() is used for fetching data from the server, while http.post() is used for sending
data to the server.

What is the purpose of using FutureBuilder with networking requests?

Answer: FutureBuilder is used to handle asynchronous data fetching, automatically updating


the UI based on the state of the future (loading, error, or data available).

How do you make an API call with headers in Flutter?

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

How do you implement animations in Flutter?


Answer: Animations in Flutter can be implemented using the AnimationController, Tween,
and AnimatedBuilder widgets to control and apply animation properties.

What is the AnimationController in Flutter?

Answer: AnimationController controls the animation by defining its duration, starting and
stopping the animation, and driving the animation.

What is the purpose of Tween in animations?

Answer: Tween defines the range of values for an animation. It interpolates between a start and
end value during the animation.

What is an AnimatedContainer widget in Flutter?

Answer: AnimatedContainer automatically animates changes in its properties, such as size,


color, or border radius, over a given duration.

What is a Hero animation in Flutter?

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.

What is the difference between AnimatedBuilder and AnimatedWidget?

Answer: AnimatedBuilder allows for more control over animation, whereas AnimatedWidget is
a simpler way to apply animations to widgets.

What is CurvedAnimation used for in Flutter?

Answer: CurvedAnimation modifies the animation’s progression using a curve, providing a


smoother or more complex motion effect.

What is the purpose of FadeTransition?

Answer: FadeTransition applies a fade effect to a widget, animating its opacity during a given
period.

What is RotationTransition used for?

Answer: RotationTransition animates a widget's rotation between specified start and end
angles.

What is a SlideTransition in Flutter?

Answer: SlideTransition animates the position of a widget along a given axis, creating a sliding
effect.
6. Flutter Navigation and Routing

What is navigation in Flutter?

Answer: Navigation in Flutter is the process of moving between different screens or routes in
the app. It is managed using the Navigator widget.

What is the Navigator widget in Flutter?

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.

How do you navigate to a new screen in Flutter?

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().

How do you pass data between screens in Flutter?

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.

What is named routing in Flutter?

Answer: Named routing allows you to define routes with names in the MaterialApp and
navigate using Navigator.pushNamed().

How do you return data from a route in Flutter?

Answer: You can return data from a route by using Navigator.pop(context, result),
where result is the data to return.

What is Navigator.pop() used for in Flutter?

Answer: Navigator.pop() is used to remove the current route from the navigation stack and
return to the previous screen.

What is the difference between push() and pushReplacement()?

Answer: push() adds a new route to the stack, while pushReplacement() replaces the current
route with a new one.

How do you use the Navigator for deep linking in Flutter?


Answer: Deep linking can be handled in Flutter by setting up named routes and using
the onGenerateRoute callback to handle incoming deep links.

7. Flutter Testing

What is unit testing in Flutter?

Answer: Unit testing in Flutter involves testing individual components (functions, methods,
classes) of your app to ensure they behave as expected.

How do you run unit tests in Flutter?

Answer: Unit tests can be run using the flutter test command, which runs the tests defined in
the test/ directory.

What is widget testing in Flutter?

Answer: Widget testing involves testing widgets in isolation to ensure they render correctly and
interact with the user as expected.

What is integration testing in Flutter?

Answer: Integration testing tests a complete workflow or flow of the app, ensuring all parts of
the app work together properly.

What is the purpose of the testWidgets() function?

Answer: testWidgets() is used to write widget tests. It allows you to simulate user interactions
and verify the widget's UI behavior.

What is a Mock in Flutter testing?

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.

What is the setUp() and tearDown() function in Flutter testing?

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.

How do you mock HTTP requests in Flutter tests?

Answer: You can mock HTTP requests using the mockito package, allowing you to simulate
network calls without hitting real endpoints.

What is the purpose of the expect() function in Flutter tests?


Answer: The expect() function is used to assert the result of a test, ensuring that the tested
output matches the expected value.

What is the difference between flutter_test and integration_test in Flutter?

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.

8. Flutter Widgets and Advanced UI

What is CustomPaint used for in Flutter?

Answer: CustomPaint allows you to draw custom graphics like shapes, lines, or even complex
drawings directly onto the screen using a CustomPainter.

What is SliverAppBar in Flutter?

Answer: SliverAppBar is a type of app bar that integrates with custom scroll views and can
change appearance when scrolled.

What is ClipRRect in Flutter?

Answer: ClipRRect is a widget that clips its child to a rounded rectangle, often used to create
circular images or rounded corners.

What is Draggable widget in Flutter?

Answer: Draggable is a widget that enables a widget to be dragged across the screen.

What is the difference between Opacity and FadeTransition?

Answer: Opacity is used to adjust the opacity of a widget, while FadeTransition animates the
opacity over time.

What is the purpose of Align widget in Flutter?

Answer: Align is used to position a widget within a parent container, allowing precise alignment
of child widgets.

What is AnimatedOpacity in Flutter?

Answer: AnimatedOpacity is a widget that automatically animates the opacity of its child widget
over a specified duration.

What is ReorderableListView in Flutter?

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.

What is the Flex widget in Flutter?

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.

9. Flutter Performance Optimization

How do you optimize app performance in Flutter?

Answer: Optimize performance by reducing widget rebuilds, using const constructors,


using ListView.builder for long lists, and offloading heavy computations to isolate threads.

What is RepaintBoundary in Flutter?

Answer: RepaintBoundary is used to isolate portions of the widget tree that need to be
redrawn, improving rendering performance.

What is lazy loading in Flutter?

Answer: Lazy loading is the process of loading content or data only when it is needed,
improving app startup and memory usage.

How do you prevent excessive widget rebuilding in Flutter?

Answer: Use const constructors where possible, Key for stateful widgets, and avoid
calling setState() unnecessarily.

How do you manage memory efficiently in Flutter?

Answer: Avoid memory leaks by disposing controllers and streams properly, using
the dispose() method, and utilizing lazy loading techniques.

How can you profile your Flutter app for performance?

Answer: Use the DevTools suite to profile and analyze your Flutter app for performance
bottlenecks, memory usage, and rendering issues.

What is the importance of async and await in performance?

Answer: async and await allow non-blocking operations, freeing up the main thread and
improving app responsiveness.

How do you handle image optimization in Flutter?


Answer: Use cached_network_image package, reduce image sizes, and use appropriate formats
like WebP to optimize images.

What is the flutter performance tool?

Answer: The flutter performance tool helps track rendering performance and diagnose issues
with frame rendering and CPU usage.

How do you minimize the size of your Flutter app?

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.

10. Flutter Plugin and Package Integration

What is a Flutter plugin?

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.

How do you add a dependency in Flutter?

Answer: Dependencies are added in the pubspec.yaml file under the dependencies section, and
the flutter pub get command is used to fetch them.

How do you use a package in Flutter?

Answer: After adding a package to pubspec.yaml, import it in the Dart file and use the functions
or classes provided by the package.

What is shared_preferences used for in Flutter?

Answer: The shared_preferences package is used for storing small amounts of data persistently,
such as user preferences or app settings.

What is the firebase_core package used for in Flutter?

Answer: firebase_core is required to initialize Firebase in a Flutter app, enabling Firebase


services like Firestore, Authentication, and Firebase Analytics.

What is url_launcher used for in Flutter?

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.

How do you configure native code with Flutter?


Answer: Native code configuration is done in the android/ and ios/ directories of the Flutter
project. You modify the respective platform files for native functionality.

What is image_picker used for in Flutter?

Answer: image_picker is a Flutter plugin that allows users to pick images or videos from their
device gallery or camera.

What is sqflite used for in Flutter?

Answer: sqflite is a Flutter plugin for SQLite database integration, allowing you to store
structured data locally on the device.

How do you check if a plugin is compatible with your Flutter version?

Answer: You can check the plugin’s documentation on pub.dev for compatibility with the
required Flutter version and the supported platforms.

You might also like