Flutter快捷键(Mac & Android Studio)
2020-04-13 本文已影响0人
船长_
1.当前文件搜索
command + F
搜索HomeContent示例:
![](https://img.haomeiwen.com/i987457/dc6c7ccc61eafc5f.jpeg)
2. 当前文件替换
command + shift + R
3. 全局查找
command + shift + F
![](https://img.haomeiwen.com/i987457/3db66145f6ccc298.jpeg)
4. 全局替换
command + shift + R
5.全局搜索类/文件/关键字/(包括系统类,自定义类)
应用场景:搜索整个项目的一些文件资源,查看系统类的方法,全局搜索方法
command + O
如图,全局搜索图片timg
![](https://img.haomeiwen.com/i987457/01e793018a2b7370.jpeg)
6.全局搜索方法
command + option + O
![](https://img.haomeiwen.com/i987457/02c39cd391269f9d.jpeg)
7.将StatelessWidget转 StatefulWidget
鼠标选中需要转换的类名,或光标放到类名之间
option + enter
![](https://img.haomeiwen.com/i987457/b1ee2754c8010eb7.png)
8.抽取代码为单独的Widget
有时候代码嵌套太多,不方便阅读,抽取Widget为一个单独的类,提高代码的阅读性
// 鼠标选中需要转换的类名,或光标放到类名之间
command + option + W
注:这个组合快捷键如果不能使用,说明有冲突的,可以在设置中删除另外一个
![](https://img.haomeiwen.com/i987457/9e5ea3e0de2a02c4.png)
9.抽取代码为单独的方法,或者抽取成get方法
command + option + M
注意: 光标放到类名之间,不能选中类名
![](https://img.haomeiwen.com/i987457/c1ed570445d38da2.png)
10.查看抽象类的实现
command + option + B
![](https://img.haomeiwen.com/i987457/d93f122c7a55f1d5.png)
也可以点击右侧面板 Flutter Outline 查看当前文件的目录结构,快速的查找出当前抽象类的子类
![](https://img.haomeiwen.com/i987457/70f648e5a272df14.png)
11.快速创建一个StatelessWidget
stless
12.快速创建一个StatefulWidget
stful
13.格式化代码
command + option + L
如下代码,参数之间有多余的空格,或者缺少空格,可使用快捷键自动对齐,省去自己手动添加或者删除空格
child: Icon(Icons.pets, size:32, color: Colors.white),
14.自动缩进对齐/代码对齐
control + option + I
15.局部代码块展开/收缩
// 展开
command + 加号
// 收缩
command - 减号
16.页面内,类代码块展开/收缩
// 展开
command + shift + 加号
// 收缩
command + shift + 减号
![](https://img.haomeiwen.com/i987457/f79c10a37ac11cde.png)
17.隐藏左侧目录结构窗口
shift + esc
点击左上角Project展开窗口
18.复制单行
command + D
不需要选中代码,只需要光标位置在需要复制的行即可
19.上下移动代码
option + shift + up/down
20.选择区域
option + 双击 up
注:多次点击up箭头可以扩大选中区域
21.热重载(hot reload)
command + \
22.热重启(hot restart)
command+ option + \
23.运行项目
control+ R
24.删除行
command+ delete
25.注释与取消注释,效果/**/
command+ option + /
26.if后面自动加(){ }
command+ shift + enter
27.快速生成模版代码块
command+ J
示例
for (var i = 0; i < password.length; ++i) {
var o = password[i];
}
28.Surround with快速调出if,for,try…catch,while等环绕代码
command+ option + T
选中需要嵌套的代码,使用这个组合快捷键可以包裹需要的代码块,如图
![](https://img.haomeiwen.com/i987457/500ff77976e00cc9.png)
29.添加或者移除widget
option + enter
![](https://img.haomeiwen.com/i987457/a7b2feec26e900d7.png)
30.选中代码缩进
选中代码 + tab
选中代码 + shift + tab
31.给Model所有下划线属性生成get和set方法,光标插入到类名
control + enter
![](https://img.haomeiwen.com/i987457/050d1465c4453fea.png)
示例代码
class TestModel {
String _message;
String get message => _message;
set message(String value) {
_message = value;
}
String _name;
int _timestamp;
String get name => _name;
set name(String value) {
_name = value;
}
int get timestamp => _timestamp;
set timestamp(int value) {
_timestamp = value;
}
}
32.快速导入头文件
option + enter