• Stars
    star
    587
  • Rank 76,145 (Top 2 %)
  • Language
    Dart
  • License
    Apache License 2.0
  • Created over 4 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Official Getx CLI
Documentation languages
pt_BR en_US - this file zh_CN

Official CLI for the GetXβ„’ framework.

// To install:
pub global activate get_cli 
// (to use this add the following to system PATH: [FlutterSDKInstallDir]\bin\cache\dart-sdk\bin

flutter pub global activate get_cli

// To create a flutter project in the current directory:
// Note: By default it will take the folder's name as project name
// You can name the project with `get create project:my_project`
// If the name has spaces use `get create project:"my cool project"`
get create project

// To generate the chosen structure on an existing project:
get init

// To create a page:
// (Pages have controller, view, and binding)
// Note: you can use any name, ex: `get create page:login`
// Nota: use this option if the chosen structure was Getx_pattern
get create page:home

// To create a screen
// (Screens have controller, view, and binding)
// Note: you can use any name, ex: `get screen page:login`
// Nota: use this option if the chosen structure was CLEAN (by Arktekko)
get create screen:home 

// To create a new controller in a specific folder:
// Note: you don't need to reference the folder,
// Getx will search automatically for the home folder
// and add your controller there.
get create controller:dialogcontroller on home

// To create a new view in a specific folder:
// Note: you don't need to reference the folder,
// Getx will automatically search for the home folder
// and insert your view there.
get create view:dialogview on home

// To create a new provider in a specific folder:
get create provider:user on home

// To generate a localization file:
// Note: 'assets/locales' directory with your translation files in json format
get generate locales assets/locales

// To generate a class model:
// Note: 'assets/models/user.json' path of your template file in json format
// Note: on  == folder output file
// Getx will automatically search for the home folder
// and insert your class model there.
get generate model on home with assets/models/user.json

//to generate the model without the provider
get generate model on home with assets/models/user.json --skipProvider

//Note: the URL must return a json format
get generate model on home from "https://api.github.com/users/CpdnCristiano"

// To install a package in your project (dependencies):
get install camera

// To install several packages from your project:
get install http path camera

// To install a package with specific version:
get install path:1.6.4

// You can also specify several packages with version numbers

// To install a dev package in your project (dependencies_dev):
get install flutter_launcher_icons --dev

// To remove a package from your project:
get remove http

// To remove several packages from your project:
get remove http path

// To update CLI:
get update
// or `get upgrade`

// Shows the current CLI version:
get -v
// or `get -version`

// For help
get help

Exploring the CLI

let's explore the existing commands in the cli

Create project

  get create project

Using to generate a new project, you can choose between Flutter and get_server, after creating the default directory, it will run a get init next command

Init

  get init

Use this command with care it will overwrite all files in the lib folder. It allows you to choose between two structures, getx_pattern and clean.

Create page

  get create page:name

this command allows you to create modules, it is recommended for users who chose to use getx_pattern.

creates the view, controller and binding files, in addition to automatically adding the route.

You can create a module within another module.

  get create page:name on other_module

When creating a new project now and use on to create a page the CLI will use children pages.

Create Screen

  get create screen:name

similar to the create page, but suitable for those who use Clean

Create controller

  get create controller:dialog on your_folder

create a controller in a specific folder.

Using with option You can now create a template file, the way you prefer.

run

  get create controller:auth with examples/authcontroller.dart on your_folder

or with url run

  get create controller:auth with 'https://raw.githubusercontent.com/jonataslaw/get_cli/master/samples_file/controller.dart.example' on your_folder

input:

@import

class @controller extends GetxController {
  final  email = ''.obs;
  final  password = ''.obs;
  void login() {
  }

}

output:

import 'package:get/get.dart';

class AuthController extends GetxController {
  final email = ''.obs;
  final password = ''.obs;
  void login() {}
}

Create view

  get create view:dialog on your_folder

create a view in a specific folder

Generate Locates

create the json language files in the assets/locales folder.

input:

pt_BR.json

{
  "buttons": {
    "login": "Entrar",
    "sign_in": "Cadastrar-se",
    "logout": "Sair",
    "sign_in_fb": "Entrar com o Facebook",
    "sign_in_google": "Entrar com o Google",
    "sign_in_apple": "Entrar com a  Apple"
  }
}

en_US.json

{
  "buttons": {
    "login": "Login",
    "sign_in": "Sign-in",
    "logout": "Logout",
    "sign_in_fb": "Sign-in with Facebook",
    "sign_in_google": "Sign-in with Google",
    "sign_in_apple": "Sign-in with Apple"
  }
}

Run :

get generate locales assets/locales

output:

abstract class AppTranslation {

  static Map<String, Map<String, String>> translations = {
    'en_US' : Locales.en_US,
    'pt_BR' : Locales.pt_BR,
  };

}
abstract class LocaleKeys {
  static const buttons_login = 'buttons_login';
  static const buttons_sign_in = 'buttons_sign_in';
  static const buttons_logout = 'buttons_logout';
  static const buttons_sign_in_fb = 'buttons_sign_in_fb';
  static const buttons_sign_in_google = 'buttons_sign_in_google';
  static const buttons_sign_in_apple = 'buttons_sign_in_apple';
}

abstract class Locales {

  static const en_US = {
   'buttons_login': 'Login',
   'buttons_sign_in': 'Sign-in',
   'buttons_logout': 'Logout',
   'buttons_sign_in_fb': 'Sign-in with Facebook',
   'buttons_sign_in_google': 'Sign-in with Google',
   'buttons_sign_in_apple': 'Sign-in with Apple',
  };
  static const pt_BR = {
   'buttons_login': 'Entrar',
   'buttons_sign_in': 'Cadastrar-se',
   'buttons_logout': 'Sair',
   'buttons_sign_in_fb': 'Entrar com o Facebook',
   'buttons_sign_in_google': 'Entrar com o Google',
   'buttons_sign_in_apple': 'Entrar com a  Apple',
  };

}

now just add the line in GetMaterialApp

    GetMaterialApp(
      ...
      translationsKeys: AppTranslation.translations,
      ...
    )

Generate model example

Create the json model file in the assets/models/user.json

input:

{
  "name": "",
  "age": 0,
  "friends": ["", ""]
}

Run :

get generate model on home with assets/models/user.json

output:

class User {
  String name;
  int age;
  List<String> friends;

  User({this.name, this.age, this.friends});

  User.fromJson(Map<String, dynamic> json) {
    name = json['name'];
    age = json['age'];
    friends = json['friends'].cast<String>();
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['name'] = this.name;
    data['age'] = this.age;
    data['friends'] = this.friends;
    return data;
  }
}

Separator file type

One day a user asked me, if it was possible to change what the final name of the file was, he found it more readable to use: my_controller_name.controller.dart, instead of the default generated by the cli: my_controller_name_controller. dart thinking about users like him we added the option for you to choose your own separator, just add this information in your pubsepc.yaml

Example:

get_cli:
  separator: "."

Configure Getx directory layout

When you create a page or screen, each module will have bindings, controllers, views sub directories.

If you prefer to have a flat file hierarchy, add the following lines to your pubspec.yaml:

get_cli:
    sub_folder: false

Are your imports disorganized?

To help you organize your imports a new command was created: get sort, in addition to organizing your imports the command will also format your dart file. thanks to dart_style. When using get sort all files are renamed, with the separator. To not rename use the --skipRename flag.

You are one of those who prefer to use relative imports instead of project imports, use the --relative option. get_cli will convert.

Internationalization of the cli

CLI now has an internationalization system.

to translate the cli into your language:

  1. create a new json file with your language, in the tranlations folder
  2. Copy the keys from the file, and translate the values
  3. send your PR.

TODO:

  • Support for customModels
  • Include unit tests
  • Improve generated structure
  • Add a backup system

More Repositories

1

getx

Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
Dart
10,238
star
2

get_server

A backend server that makes it possible to program with Flutter syntax and reuse existing code
Dart
466
star
3

get_storage

A fast, extra light and synchronous key-value storage to Get framework
Dart
324
star
4

readmore

A Flutter plugin than allow expand and collapse text dynamically
Dart
245
star
5

VideoCompress

Compress videos, remove audio, manipulate thumbnails, and make your video compatible with all platforms through this lightweight and efficient library.
Swift
209
star
6

flutter_state_managers

A repository that allows you to analyze size, performance, and metrics of Flutter state management approaches
Dart
70
star
7

getx-community

A collaborative repository of GetX usage examples.
35
star
8

easy

The easiest state manager for Flutter.
Dart
19
star
9

getsocket

Dart
18
star
10

getstream

GetStream is the lightest and most performative way of working with events at Dart.
Dart
18
star
11

bloc_boilerplate

A library that contains a well-defined bloc pattern, showing how easy it is to make API-REST requests and error handling using BLoC.
Dart
16
star
12

flutter_web_responsive

A Beauty and responsive flutter web concept
Dart
16
star
13

dart-server-nano

A light, fast, and friendly server written in Dart.
Dart
15
star
14

get_test

A package to facilitate unit tests with Getx
Dart
12
star
15

jonataslaw

10
star
16

corona_virus

Corona virus application using GET. Cases and deaths by country.
Dart
9
star
17

media_utils

An easy helper class to flutter with many support formats. Suport local and web files.
Dart
7
star
18

server_nano

A fast and lightweight HTTP server implementation in Rust.
Rust
5
star
19

picker

flutter plugin for selecting images from the Android and iOS, taking new pictures with the camera and saves photos/videos on Gallery
Objective-C
5
star
20

GameJAM2024

5
star
21

parse-route

A dart route parser package with support to params, urlParams, and wildcards routes
HTML
4
star
22

ikeyboard

A plugin that brings native iOS keyboard behavior to Flutter.
Dart
4
star
23

poprize-plugin-vite

JavaScript
2
star
24

whatsapp_flutter_web

Whatsapp Web messages clone using Flutter Web and Hasura
Dart
2
star
25

photoeditor

A library that lets you apply filters and effects to photos from your device's gallery or camera (android and iOS).
2
star
26

get_mutex

HTML
1
star
27

questioning-dataset

A dataset of questions/answers to fine tune IA models
Python
1
star
28

router_matcher

A rust router parser
Rust
1
star
29

get_packer

A high-performance serialization library for Dart, designed to efficiently pack and unpack data structures. It provides a fast and compact alternative to JSON encoding/decoding and MessagePack
Dart
1
star