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
Which package is commonly used in Flutter to fetch data from REST APIs? a) http b) dio c) fetch d) fetchData
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()
Which of the following Flutter widgets is used to display fetched data in a list? a) ListView b) GridView c) Column d) Table
To convert a JSON response into a Dart object, you use the method: a) jsonDecode() b) jsonParse() c) toObject() d) decodeJson()
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
In Flutter, you handle the data fetching process using: a) FutureBuilder b) StreamBuilder c) ListView d) FutureProvider
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()
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
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()
To handle API data asynchronously, you use: a) Futures b) Streams c) Async/Await d) Sync/Async
Managing HTTP Requests with http or Dio
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
How do you send a POST request with the Dio package? a) Dio.post() b) Dio.request() c) Dio.send() d) Dio.get()
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
In Dio, to handle request timeout, which option do you set? a) timeout() b) setTimeout() c) connectTimeout() d) requestTimeout()
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
To send headers in a request using Dio, you use: a) headers() b) setHeaders() c) options: Options(headers: {…}) d) addHeaders()
What function does Dio use to perform a PUT request? a) Dio.put() b) Dio.request() c) Dio.send() d) Dio.putRequest()
What type of data does the Dio package return after a request? a) String b) JSON c) Response object d) Future
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
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
SharedPreferences in Flutter is typically used for storing: a) Large binary data b) Simple key-value pairs c) Complex data structures d) Multimedia files
Which local storage solution in Flutter supports NoSQL database-like functionality? a) SharedPreferences b) Hive c) SQLite d) SharedMemory
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
To store a boolean value in SharedPreferences, you use the method: a) setBool() b) setBoolean() c) addBool() d) storeBool()
In Hive, what data type is used to store objects? a) ObjectBox b) HiveObject c) Box d) ListBox
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
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
To read data from SharedPreferences in Flutter, you use the method: a) get() b) read() c) load() d) fetch()
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
SQLite can be accessed in Flutter using: a) sqflite package b) hive package c) shared_preferences package d) sqlite package