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

  1. Open your bash_profile
sudo open ~/.bash_profile
  1. Add this alias to your bash_profile
...
alias metro='flutter pub run nylo_framework:main'
  1. Then run the following
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

 appicons
  appicons:build


Make controller

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

flutter pub run nylo_framework:main make:controller profile_controller

Or with the alias metro

metro make:controller profile_controller

This is 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.

flutter pub 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 exiting class if it already exists.

metro make:model product --force

Using the --storage flag will create a new model that is storable to the users local storage.

metro make:model product --storable

Learn more on Storable models here.


Make page

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

flutter pub run nylo_framework:main make:page product_page

Or with the alias metro

metro make:page product_page

This is 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.

flutter pub 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.

flutter pub 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.

flutter pub 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.

flutter pub 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.

flutter pub 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.

flutter pub 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 varibles 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 has 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 a 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 created.


Make event

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

flutter pub run nylo_framework:main make:event login_event

Or with the alias metro

metro make:api_service login_event

This is 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.

flutter pub 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.

flutter pub run nylo_framework:main make:theme bright_theme

Or with the alias metro

metro make:theme bright_theme


Build App Icons

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

flutter pub run flutter_launcher_icons:main

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