Mastering Dart libraries and packages is essential for effective development. This chapter covers using built-in libraries, installing and managing packages via pub.dev, and importing/exporting libraries in Dart.
1. Using Built-in Libraries
Deleted Question
What is the purpose of the dart:io library in Dart? a) For performing mathematical operations b) For handling input/output operations c) For network communication d) For asynchronous programming
Deleted Question
What does the dart:convert library in Dart provide? a) Handling dates and times b) JSON encoding and decoding c) Asynchronous programming d) File operations
Deleted Question
How can you use built-in libraries in Dart? a) By manually defining them b) By importing them using the import keyword c) By referencing them in functions d) By initializing them as variables
What is the main function of the dart:math library? a) Perform string manipulations b) Handle numerical calculations and random numbers c) Manage network requests d) Convert data formats
The dart:async library is used for which feature in Dart? a) Handling user interfaces b) Managing asynchronous operations like Futures and Streams c) Managing input and output d) Performing mathematical operations
What is the correct syntax to import a Dart built-in library? a) import 'dart:library_name'; b) import library_name.dart; c) use 'dart:library_name'; d) include 'dart:library_name';
What does the dart:convert library primarily handle in Dart? a) Handling files b) Encoding and decoding JSON c) Performing network requests d) Working with dates
2. Installing and Managing Packages via pub.dev
What is pub.dev in Dart? a) A tool for compiling Dart code b) A package manager for Dart c) A built-in Dart library d) A testing framework
How do you add an external package to a Dart project? a) Use the import keyword b) Download the package manually c) Add the package to pubspec.yaml and run pub get d) Install the package globally
What is the role of the pubspec.yaml file in a Dart project? a) It contains Dart code b) It manages metadata and dependencies of the project c) It defines UI components d) It stores compiled binaries
Which command is used to install dependencies in a Dart project from pubspec.yaml? a) dart get b) dart install c) pub get d) dart pub install
How do you specify a version of a package in pubspec.yaml? a) version: package_version b) dependencies: package_name: version c) packages: version d) library: package_version
How do you update the packages in a Dart project? a) dart update b) dart upgrade c) pub upgrade d) pub get --upgrade
Which command is used to remove an unused package from a Dart project? a) dart pub remove package_name b) pub remove c) dart remove d) pub get --remove
What is the purpose of the pubspec.lock file in Dart? a) To store code examples b) To lock package versions c) To manage environment variables d) To store compiled Dart files
What does the pub get command do in Dart? a) Creates a new Dart project b) Downloads and installs dependencies listed in pubspec.yaml c) Runs the Dart application d) Compiles Dart code
Where can you find official Dart packages for your project? a) On GitHub b) On pub.dev c) In Dart’s dart:core library d) In the lib directory
3. Importing and Exporting Libraries
What is the purpose of the import statement in Dart? a) To include external libraries or packages b) To export Dart files c) To define global variables d) To invoke functions from libraries
How do you import a library from a local file in Dart? a) import 'path/to/library.dart'; b) import file://path/to/library.dart; c) include 'path/to/library.dart'; d) import 'local_library.dart';
Can you import a library multiple times in Dart? a) Yes, but only once in each file b) No, libraries can only be imported once per project c) Yes, it will be ignored if imported multiple times d) Yes, there is no limit on imports
How do you import all libraries from a Dart package? a) import 'dart:all'; b) import package:library_name/all.dart'; c) import * from 'library'; d) import 'package:library_name/library.dart';
What is the syntax to export a Dart library to make its content available to other files? a) export 'library_name.dart'; b) export package:library_name; c) use 'library_name.dart'; d) import export 'library_name.dart';
Which statement in Dart allows the reuse of library content across files? a) use b) export c) import d) include
How do you access a specific class from an imported Dart library? a) Directly after importing b) By using the library’s namespace c) By calling use() method d) By referencing the class in pubspec.yaml
How do you import an external package that’s hosted on pub.dev? a) By adding it to pubspec.yaml and running pub get b) By using the dart import command c) By manually downloading and placing it in the project d) By linking to the package in the lib directory
Can you import both built-in and external libraries in the same Dart file? a) Yes, both can be imported together b) No, only one type is allowed per file c) Yes, but only built-in libraries can be imported after external ones d) No, external libraries cannot be used with built-in libraries
Which of the following is the correct way to use an imported library’s function in Dart? a) library_name.function_name(); b) use function_name(); c) import function_name(); d) export function_name();
Answers Table
QNo
Answer (Option with Text)
1
a) dart
2
b) For handling input/output operations
3
d) dart
4
b) JSON encoding and decoding
5
d) dart
6
b) By importing them using the import keyword
7
b) Handle numerical calculations and random numbers
8
b) Managing asynchronous operations like Futures and Streams
9
a) import 'dart:library_name';
10
b) Encoding and decoding JSON
11
b) A package manager for Dart
12
c) Add the package to pubspec.yaml and run pub get
13
b) It manages metadata and dependencies of the project
14
c) pub get
15
b) dependencies: package_name: version
16
c) pub upgrade
17
a) dart pub remove package_name
18
b) To lock package versions
19
b) Downloads and installs dependencies listed in pubspec.yaml
20
b) On pub.dev
21
a) To include external libraries or packages
22
a) import 'path/to/library.dart';
23
c) Yes, it will be ignored if imported multiple times
24
d) import 'package:library_name/library.dart';
25
a) export 'library_name.dart';
26
b) export
27
b) By using the library’s namespace
28
a) By adding it to pubspec.yaml and running pub get