Flutter add remove library from command line

Use the library json_serializable for example, replace json_serializable with other library name for adding other libraries. Run the following command from the project root folder.

Add a library as a dependency. This command will add the library under dependencies in the pubspec.yaml

flutter pub add json_serializable

Add a library as dev dependency. This command will add the library under dev_dependencies in the pubspec.yaml

flutter pub add -d json_serializable

Remove a library. This command will remove the library under dependencies or dev_dependencies in the pubspec.yaml

flutter pub remove json_serializable

Here is what it looks like in the pubspec.yaml when the library json_serializable is added.

dependencies:
  flutter:
    sdk: flutter


  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2
  json_serializable: ^6.2.0

Search within Codexpedia

Custom Search

Search the entire web

Custom Search