Notice: You're viewing an old version of the Nylo documentation.
Consider upgrading your project to Nylo 6.x.
Basics

Metro CLI tool



Introduction

Metro is a CLI tool that works under the hood of the Nylo framework. It provides a lot of helpful tools to speed up development.


Install

Mac guide

Run the below command from the terminal

echo "alias metro='dart run nylo_framework:main'" >>~/.bash_profile && source ~/.bash_profile

If you open a project that uses Nylo, try to run the following in the terminal.

metro

You should see an output similar to the below.

Usage: 
    command [options] [arguments]

Options
    -h

All commands:

 make
  make:controller
  make:model
  make:page
  make:stateless_widget
  make:stateful_widget
  make:theme
  make:event
  make:provider
  make:api_service
  make:theme
  make:route_guard


Make controller

You can make a new controller by running the below in the terminal.

dart run nylo_framework:main make:controller profile_controller

Or with the alias metro

metro make:controller profile_controller

This will create a new controller if it doesn't exist within the lib/app/controllers/ directory.


Make model

You can make a new model by running the below in the terminal.

dart run nylo_framework:main make:model product

Or with the alias metro

metro make:model product

It will place the newly created model in lib/app/models/.

If you plan to use the same model to represent objects from your API's, add it to your lib/config/decoders.dart modelDecoders map.

Arguments:

Using the --force flag will overwrite an existing class if it already exists.

metro make:model product --force


Make page

You can make a new page by running the below in the terminal.

dart run nylo_framework:main make:page product_page

Or with the alias metro

metro make:page product_page

This will create a new page if it doesn't exist within the lib/resources/pages/ directory. Nylo also supports the use of controllers. Use the below command to create a new page with a controller.

metro make:page product_page -c

Create a page with a controller.


Make stateless widget

You can make a new stateless widget by running the below in the terminal.

dart run nylo_framework:main make:stateless_widget product_rating_widget

Or with the alias metro

metro make:stateless_widget product_rating_widget

The above will create a new widget if it doesn't exist within the lib/resources/widgets/ directory.


Make stateful widget

You can make a new stateful widget by running the below in the terminal.

dart run nylo_framework:main make:stateful_widget product_rating_widget

Or with the alias metro

metro make:stateful_widget product_rating_widget

The above will create a new widget if it doesn't exist within the lib/resources/widgets/ directory.


Make API Service

You can make a new API service by running the below in the terminal.

dart run nylo_framework:main make:api_service user

Or with the alias metro

metro make:api_service user_api_service

You can provide the --url="https://myapi.com" option to create an API Service that will use the url as the Base URL.

dart run nylo_framework:main make:api_service user --url="https://myapi-baseurl.com"

You can provide a --model="User" option to tell Nylo to create a new API Service with the following methods: find, create, delete, update and fetchAll.

dart run nylo_framework:main make:api_service user --model="User"

It will place the newly created API service in lib/app/networking/.


Use Postman to Make API Services

You can make new API services using Postman v2.1 collection files.

First, you must export your postman collection into a JSON file (using v2.1).

This should give you a file like JsonPlaceHolder.postman_collection.json.

You will need to copy this file into your Nylo project. Copy the exported file into the public/assets/postman directory.

E.g. public/assets/postman/JsonPlaceHolder.postman_collection.json. After copying the file into the above directory, go to the terminal and run the following command.

dart run nylo_framework:main make:api_service json_placeholder --postman="JsonPlaceHolder.postman_collection.json"

Or with the alias metro

metro make:api_service json_placeholder --postman="JsonPlaceHolder.postman_collection.json"

This will create new ApiServices for your postman collections.

If your Postman collections include variables such as "BASE_URL" or others. You can define them in Nylo by opening the postman.json file which is located at the root of your Nylo project. Then, inside this file, add your variables.

E.g.

{
  "global": {
    "BASE_URL": "https://myapi.site.dev",
    "VERSION": "2.0"
  }
}

It will also add Models to your project if your Postman collections have a saved response. You can check if your collection has saved responses by going to your Postman collection, then selecting a request. You should see a dropdown which will contain any saved responses.

If your collection doesn't contain a saved response, you will need to use Postman to make an HTTP request and then save the response. The name of the saved response will be used as the name of the Model that Nylo will create.


Make event

You can make a new event by running the below in the terminal.

dart run nylo_framework:main make:event login_event

Or with the alias metro

metro make:api_service login_event

This will create a new event in lib/app/events.

You will also need to add the event to your lib/config/events.dart map for it to be used.


Make provider

Create new providers in your application using the below command.

dart run nylo_framework:main make:provider firebase_provider

Or with the alias metro

metro make:provider firebase_provider

It will place the newly created provider in lib/app/providers/.

You will also need to add the provider to your lib/config/providers.dart map for it to be used.


Make theme

You can make themes by running the below in the terminal.

dart run nylo_framework:main make:theme bright_theme

Or with the alias metro

metro make:theme bright_theme


Make Route Guard

You can make a route guard by running the below in the terminal.

dart run nylo_framework:main make:route_guard premium_content

Or with the alias metro

metro make:route_guard premium_content


Build App Icons

You can generate all the app icons for IOS and Android by running the below command.

dart run flutter_launcher_icons:main

This uses the flutter_icons configuration in your pubspec.yaml file.