This section introduces Flutter commands and Android Studio shortcuts to improve development efficiency.
Flutter command
Create a Flutter App
- Create a Flutter for the default language
// Default languages iOS Swift, Android kotlin flutter create flutter_appCopy the code
- Create a Flutter App with the specified native language
IOS Swift, Android kotlin flutter create -i Swift -a kotlin flutter_app Android java flutter create -i objc -a java flutter_appCopy the code
Create the Flutter Plugin
- Plug-ins can contain native code
- Create a plug-in using
--template=plugin
Parameters to performflutter create
--org
Represents your organization, typically represented by a reverse domain name, used to identify packages
Flutter create --org com.example --template=plugin flutter_demo // Specifies the development language to use flutter create --org com.example --template=plugin --platforms=android,ios -i objc -a java flutter_demoCopy the code
Create a Flutter Module
There is only Dart code in this, no native code
flutter create -t module flutter_module
Copy the code
About the dependence
- Install dependencies
flutter packages get
Copy the code
- Update the rely on
flutter packages upgrade
Copy the code
- Configure the mirror
Configure a domestic mirror in.bash_profile or.zshrc
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
Copy the code
Common shortcut keys for the project
// Check flutter status, It is important to know the problem with your environment configuration. Flutter doctor // Lists all connected devices, flutter Devices // Run the specified simulator or the real machine, flutter run -d deviceId // Run all emulators, flutter run -d all start iOS emulators --launch apple_iOS_simulator // Run IOS real machine Flutter run -d 00008030-0012215c3c3a802E // View all branches of the Flutter SDK Flutter Channel switch SDK branch flutter channel stable Does not include the flutter SDK, Flutter packages get // Update all dependencies of the Flutter project. Does not include flutter SDK flutter packages upgrade // View the flutter logs // View the help information of the command flutter help // Upgrade the flutter version flutter upgradeCopy the code
The equipment list
Simulator list
Project commissioning
// Hot update directly refresh $r // hot update restart refresh $r // exit running emulator $qCopy the code
packaging
//Android package flutter build apk //iOS package flutter build iOS --debug build iOS --releaseCopy the code
AndroidStudio shortcuts
Because Flutter is developed through Android Studio, the tool’s shortcuts need to be mastered. Using them skillfully can greatly improve the development efficiency and reduce some errors.
shortcuts
CMD + , Enter preferences CMD + / Comments Ctrl + Option + O Delete unused import Option + Enter Automatically import unimported files CMD + -/+ fold/expand code block CMD + Shift + -/+ Fold/expand all code blocks CMD +. CMD + L Locate the line where the code resides CMD + [Cursor goes back to the previous edit position CMD +] Cursor goes back to the next edit position CMD + Y View the properties of the selected class CMD + O Quickly open (used to quickly open a file) CMD + Option + L Formatting code Option + Shift + Up/Down moving Up and Down line Command + Shift + Up/Down moving Up and Down methodCopy the code
The Flutter plugin contains the following templates
-
Prefix stless: Create a subclass of StatelessWidget.
-
Prefix STful: Create a subclass of StatefulWidget and associate it with a State subclass.
-
Prefix Stanim: Create a subclass of StatefulWidget and associate the State subclass with an initialization field for the AnimationController.
You can also define custom Templates by going to Settings > Editor > Live Templates.
Creating code blocks
Preferences -> Editor -> Live Templates You can view the added Flutter code blocks, including their short name, description and content. Enter STL to create the StatelessWidget. We can also add some common code blocks, it is very convenient to use.
Automatic formatting code
Preferences -> Languages & Frameworks -> Editor, then select Format Code on Save and Organize Imports on Save. And then I’m going to hit OK and the code will be formatted automatically
Welcome to follow, like and forward.