MCQs on Working with APIs and Data Persistence | Flutter API Integration MCQs Question and Answer

Introduction to Flutter MCQ Questions and Answers on Working with APIs and Data Persistence
Flutter allows seamless integration with APIs and offers various ways to manage data persistence. Mastering how to fetch and display data from REST APIs, manage HTTP requests, and store data locally using tools like SQLite, Hive, and SharedPreferences is crucial for building robust apps. These Flutter MCQ questions and answers will help solidify your understanding.


Flutter MCQs: Working with APIs and Data Persistence

Fetching and Displaying Data from REST APIs

  1. Which package is commonly used in Flutter to fetch data from REST APIs?
    a) http
    b) dio
    c) fetch
    d) fetchData
  2. What method is used in the http package to perform a GET request?
    a) http.get()
    b) http.request()
    c) http.fetch()
    d) http.getRequest()
  3. Which of the following Flutter widgets is used to display fetched data in a list?
    a) ListView
    b) GridView
    c) Column
    d) Table
  4. To convert a JSON response into a Dart object, you use the method:
    a) jsonDecode()
    b) jsonParse()
    c) toObject()
    d) decodeJson()
  5. When handling network errors, the http package returns:
    a) A 404 error code
    b) A Dart exception
    c) A Future object
    d) A response with status code 200
  6. In Flutter, you handle the data fetching process using:
    a) FutureBuilder
    b) StreamBuilder
    c) ListView
    d) FutureProvider
  7. How do you ensure that the UI updates after fetching data in Flutter?
    a) Use setState()
    b) Use FutureBuilder()
    c) Use ChangeNotifierProvider()
    d) Use ListView()
  8. The http package in Flutter supports which HTTP methods?
    a) GET, POST, PUT, DELETE
    b) GET, POST, PATCH, HEAD
    c) GET, DELETE, PUT
    d) GET, PUT, POST, OPTIONS
  9. How do you parse the response body of a REST API call in Flutter?
    a) response.body()
    b) response.parse()
    c) jsonDecode(response.body)
    d) response.json()
  10. To handle API data asynchronously, you use:
    a) Futures
    b) Streams
    c) Async/Await
    d) Sync/Async

Managing HTTP Requests with http or Dio

  1. Which of the following is true about the Dio package in Flutter?
    a) It is used only for POST requests
    b) It provides additional features over http
    c) It does not support JSON responses
    d) It is slower than the http package
  2. How do you send a POST request with the Dio package?
    a) Dio.post()
    b) Dio.request()
    c) Dio.send()
    d) Dio.get()
  3. What is the main advantage of using Dio over http for API requests?
    a) Dio has better error handling
    b) Dio is only for GET requests
    c) Dio cannot handle JSON data
    d) Dio requires more setup
  4. In Dio, to handle request timeout, which option do you set?
    a) timeout()
    b) setTimeout()
    c) connectTimeout()
    d) requestTimeout()
  5. Which of the following is a feature of Dio not present in the http package?
    a) Interceptors
    b) GET requests
    c) Timeout handling
    d) Request headers
  6. To send headers in a request using Dio, you use:
    a) headers()
    b) setHeaders()
    c) options: Options(headers: {…})
    d) addHeaders()
  7. What function does Dio use to perform a PUT request?
    a) Dio.put()
    b) Dio.request()
    c) Dio.send()
    d) Dio.putRequest()
  8. What type of data does the Dio package return after a request?
    a) String
    b) JSON
    c) Response object
    d) Future
  9. Which of the following is the primary difference between Dio and the http package?
    a) Dio is slower than http
    b) Dio handles both GET and POST requests
    c) Dio provides a higher-level abstraction
    d) Dio allows more customization of requests
  10. To handle response data after a Dio request, you use:
    a) response.data()
    b) response.body()
    c) response.json()
    d) response.content()

Local Storage: SharedPreferences, Hive, and SQLite

  1. SharedPreferences in Flutter is typically used for storing:
    a) Large binary data
    b) Simple key-value pairs
    c) Complex data structures
    d) Multimedia files
  2. Which local storage solution in Flutter supports NoSQL database-like functionality?
    a) SharedPreferences
    b) Hive
    c) SQLite
    d) SharedMemory
  3. The primary purpose of SQLite in Flutter is to:
    a) Store simple preferences
    b) Save key-value pairs
    c) Provide a local relational database
    d) Cache network requests
  4. To store a boolean value in SharedPreferences, you use the method:
    a) setBool()
    b) setBoolean()
    c) addBool()
    d) storeBool()
  5. In Hive, what data type is used to store objects?
    a) ObjectBox
    b) HiveObject
    c) Box
    d) ListBox
  6. SQLite in Flutter allows you to:
    a) Store key-value pairs only
    b) Execute raw SQL queries
    c) Save data to a local file
    d) Use a NoSQL approach
  7. Which of the following is a feature of SQLite in Flutter?
    a) Local NoSQL storage
    b) Ability to execute raw SQL
    c) Automatic data encryption
    d) Real-time syncing
  8. To read data from SharedPreferences in Flutter, you use the method:
    a) get()
    b) read()
    c) load()
    d) fetch()
  9. Which of the following is true about Hive in Flutter?
    a) Hive stores data in key-value format
    b) Hive uses SQL for querying data
    c) Hive does not support encryption
    d) Hive is slower than SQLite
  10. SQLite can be accessed in Flutter using:
    a) sqflite package
    b) hive package
    c) shared_preferences package
    d) sqlite package

Answer Key

QnoAnswer (Option with Text)
1a) http
2a) http.get()
3a) ListView
4a) jsonDecode()
5b) A Dart exception
6a) FutureBuilder
7a) Use setState()
8a) GET, POST, PUT, DELETE
9c) jsonDecode(response.body)
10a) Futures
11b) It provides additional features over http
12a) Dio.post()
13a) Dio has better error handling
14c) connectTimeout()
15a) Interceptors
16c) options: Options(headers: {…})
17a) Dio.put()
18c) Response object
19d) Dio allows more customization of requests
20a) response.data()
21b) Simple key-value pairs
22b) Hive
23c) Provide a local relational database
24a) setBool()
25c) Box
26b) Execute raw SQL queries
27b) Ability to execute raw SQL
28a) get()
29a) Hive stores data in key-value format
30a) sqflite package

4o mini

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top