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" `
getcreate project
// To generate the chosen structure on an existing project:
getinit
// 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
getcreate 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)
getcreate 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.
getcreate controller:dialogcontrolleronhome
// 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.
getcreate view:dialogviewonhome
// To create a new provider in a specific folder:
getcreate provider:useronhome
// To generate a localization file:
// Note: 'assets/locales' directory with your translation files in json format
getgenerate 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.
getgenerate modelonhomewithassets/models/user.json
//to generate the model without the provider
getgenerate modelonhomewithassets/models/user.json--skipProvider
//Note: the URL must return a json format
getgenerate modelonhome from"https://api.github /users/CpdnCristiano"
// To install a package in your project (dependencies):
getinstall camera
// To install several packages from your project:
getinstall http path camera
// To install a package with specific version:
getinstall path:1.6.4
// You can also specify several packages with version numbers
// To install a dev package in your project (dependencies_dev):
getinstall flutter_launcher_icons--dev
// To remove a package from your project:
getremove http
// To remove several packages from your project:
getremove http path
// To update CLI:
getupdate
// or `get upgrade`
// Shows the current CLI version:
get-v
// or `get -version`
// For help
gethelp
let's explore the existing commands in the cli
get create project
Using to generate a new project, you can choose betweenFlutterandget_server,after creating the default directory, it will run aget init
next command
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_patternandclean.
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 useon
to create a page the CLI will usechildren pages.
get create screen:name
similar to thecreate page
,but suitable for those who use Clean
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 /jonataslaw/get_cli/master/samples_file/controller.dart.example'on your_folder
input:
@import
class@controllerextendsGetxController{
finalemail=''.obs;
finalpassword=''.obs;
voidlogin() {
}
}
output:
import'package:get/get.dart';
classAuthControllerextendsGetxController{
finalemail=''.obs;
finalpassword=''.obs;
voidlogin() {}
}
get create view:dialog on your_folder
create a view in a specific folder
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:
getgenerate locales assets/locales
output:
abstractclassAppTranslation{
staticMap<String,Map<String,String>> translations={
'en_US':Locales.en_US,
'pt_BR':Locales.pt_BR,
};
}
abstractclassLocaleKeys{
staticconstbuttons_login='buttons_login';
staticconstbuttons_sign_in='buttons_sign_in';
staticconstbuttons_logout='buttons_logout';
staticconstbuttons_sign_in_fb='buttons_sign_in_fb';
staticconstbuttons_sign_in_google='buttons_sign_in_google';
staticconstbuttons_sign_in_apple='buttons_sign_in_apple';
}
abstractclassLocales{
staticconsten_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',
};
staticconstpt_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,
...
)
Create the json model file in the assets/models/user.json
input:
{
"name":"",
"age":0,
"friends":["",""]
}
Run:
getgenerate modelonhomewithassets/models/user.json
output:
classUser{
Stringname;
intage;
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() {
finalMap<String,dynamic> data=newMap<String,dynamic>();
data['name']=this.name;
data['age']=this.age;
data['friends']=this.friends;
returndata;
}
}
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:"."
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 yourpubspec.yaml
:
get_cli:
sub_folder:false
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 todart_style.
When using get sort all files are renamed, with theseparator.
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.
CLI now has an internationalization system.
to translate the cli into your language:
- create a new json file with your language, in thetranslationsfolder
- Copy the keys from thefile,and translate the values
- send your PR.
TODO:
- Support for customModels
- Include unit tests
- Improve generated structure
- Add a backup system