美文网首页Flutter
Flutter中自定义Templates

Flutter中自定义Templates

作者: 翀鹰精灵 | 来源:发表于2020-06-18 18:54 被阅读0次

    在开发过程中我们习惯给新建的类添加一些注释信息,创建日期、时间和作者等。但是flutter中新建的dart文件默认是没有这些备注信息的,属于手动添加Templates

    步骤如下:
    一、Android Studio -> Preferences -> Editor ->File and Code Templates
    001.png
    File -> New -> Edit File Templates
    二、选中Files标签页,点击+号,Name栏输入StatelessWidget,下面的输入框输入以下代码
    class ${NAME} extends StatelessWidget {
    }
    
    002.png

    设置Dart File的文件模板为

    //
    //  ${NAME}
    //  ${PROJECT_NAME}
    //
    //  Created by ${USER} on${DATA} .
    //  Copyright ©${DATA} ${PROJECT_NAME}. All rights reserved.
    //
    
    003.png

    Tips: 添加更多的注释信息可查看下面的描述

    Predefined variables will take the following values:
    ${PACKAGE_NAME}
     
    name of the package in which the new file is created
    ${NAME}
     
    name of the new file specified by you in the New <TEMPLATE_NAME> dialog
    ${USER}
     
    current user system login name
    ${DATE}
     
    current system date
    ${TIME}
     
    current system time
    ${YEAR}
     
    current year
    ${MONTH}
     
    current month
    ${MONTH_NAME_SHORT}
     
    first 3 letters of the current month name. Example: Jan, Feb, etc.
    ${MONTH_NAME_FULL}
     
    full name of the current month. Example: January, February, etc.
    ${DAY}
     
    current day of the month
    ${DAY_NAME_SHORT}
     
    first 3 letters of the current day name. Example: Mon, Tue, etc.
    ${DAY_NAME_FULL}
     
    full name of the current day. Example: Monday, Tuesday, etc.
    ${HOUR}
     
    current hour
    ${MINUTE}
     
    current minute
    ${PROJECT_NAME}
     
    the name of the current project
    
    点击Apply/OK,我们的Templates就创建好。新建一个.dart的文件,输入stl快速创建StatelessWidget文件,如下图所示,就有注释信息了。
    004.png
    至此,模板设置完毕,如果需要可继续添加StatefulWidget以及更多需要这些注释信息的类文件。

    相关文章

      网友评论

        本文标题:Flutter中自定义Templates

        本文链接:https://www.haomeiwen.com/subject/ngfpxktx.html