美文网首页
flutter 小tips

flutter 小tips

作者: 优优切克闹 | 来源:发表于2020-10-23 18:58 被阅读0次
    常用快捷键:

    展开/关闭代码块:   command + .
    跳转到 下/上 一个光标位置:   alt + command + →/←(右/左箭头)
    去除无用的import头文件:   ctrl +alt + o
    全局搜索:   command + shift + f
    快速更换/添加/移除widget:鼠标点到要操作的widget上,按下   alt + 回车
    一键复制:command + d
    flutter代码格式化:Mac:command + alt + f Windows:Ctrl+Alt+L


    颜色的各种写法
    Color c1 = Color(0xFF3CAAFA);
    Color c2 = Color.fromRGBO(60, 170, 250, 0.2);
    Color c3 = Color.fromARGB(255, 60, 170, 250);
    Color c5 = Colors.blue;
    Color c6 = Colors.red[600];
    

    项目不能新建directory的解决办法

    解决文件夹中嵌套文件夹呈现 xxx.yyy的格式(按下图取消勾选):
    image.png

    如何去除Flutter Text底部黄色双划线


    flutter 控件随着键盘弹出自适应上下移动 防止遮挡

    参考链接


    flutter项目拉下来如果有主模块有分模块 需要分别同时点一下这个
    image.png
    flutter中如何导入插件 .jar包( image.png

    例如MVP模板 StlIdePlugin)

    image.png
    image.png

    flutter 如何创建使用导入的MVP模板
    在Android studio顶部菜单栏上 选中STL 打开编辑栏


    image.png [图片上传失败...(image-528efb-1604388904315)]

    模板说明


    4162352772_25182499055_0E349706-BE37-4813-9718-6A8A1841124B.png

    flutter如何引入脚本(多语言 辅助R文件)


    image.png
    image.png
    image.png
    image.png

    如何跑脚本:


    image.png

    项目中如何使用:


    image.png

    附上脚本内容


    image.png

    flutter 多语言

    easy_localization


    APP账号密码登录流程:


    4013473354_25056636930_1572433628_25056422225_785FBA66-3915-4012-B3D6-4EC6A8B166BB.png

    APP自动登录流程


    4013473354_25056636141_1572433628_25056460520_509E9CA0-1158-4f78-8335-EC334EB74563.png

    flutter 自定义底部切圆角弹框

      void _clickMoreBtn() {
        showModalBottomSheet(
          context: context,
          backgroundColor: Colors.transparent, // 重点!!!
          builder: (BuildContext context) {
            return Container(
              height: 462.h,
              width: double.infinity,
              child: Center(child: OtherLoginWaySheet()),
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.only(
                  topLeft: Radius.circular(50.w),
                  topRight: Radius.circular(50.w),
                ),
              ),
            );
          },
        );
      }
    
    import 'package:flutter/cupertino.dart';
    import 'package:flutter/material.dart';
    import 'package:libcommon/res/colors.dart';
    import 'package:flutter_svg/flutter_svg.dart';
    import 'package:flutter_screenutil/flutter_screenutil.dart';
    import 'package:libcommon/generated/codegen_r_loader.g.dart';
    import 'package:stl_easy_localization/stl_easy_localization.dart';
    
    class OtherLoginWaySheet extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Container(
          child: Column(children: [
            Padding(
              padding: EdgeInsets.only(top: 80.w, bottom: 40.h),
              child: InkWell(
                onTap: () {
                  print("点击QQ登录");
                },
                child: Container(
                  width: 240.w,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      SizedBox(
                        width: 56.w,
                        height: 56.w,
                        child: SvgPicture.asset(
                          "assets/svg/fxchat_login_ic_login_qq.svg",
                          package: 'fxchat_login',
                        ),
                      ),
                      SizedBox(width: 20.w),
                      Text(R.fxchat_login_qq_login).tr(),
                    ],
                  ),
                ),
              ),
            ),
            Padding(
              padding: EdgeInsets.only(top: 30.0.h, bottom: 60.h),
              child: InkWell(
                onTap: () {
                  print("点击微博登录");
                },
                child: Container(
                  width: 240.w,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      SizedBox(
                        width: 56.w,
                        height: 56.w,
                        child: SvgPicture.asset(
                          "assets/svg/fxchat_login_ic_login_weibo.svg",
                          package: 'fxchat_login',
                        ),
                      ),
                      SizedBox(width: 20.w),
                      Text(R.fxchat_login_weibo_login).tr(),
                    ],
                  ),
                ),
              ),
            ),
            SizedBox(
              width: 654.w,
              height: 96.h,
              child: FlatButton(
                color: ColorsUtil.hexToColor("#eff1f4"),
                onPressed: () {
                  Navigator.of(context).pop();
                },
                child: Text(
                  R.fxchat_login_cancel.tr(),
                  style: TextStyle(
                      fontSize: 16,
                      fontWeight: FontWeight.w500,
                      color: ColorsUtil.hexToColor("#e61e222b")),
                ),
              ),
            ),
          ]),
        );
      }
    }
    
    

    使用Android studio 进行版本控制和冲突解决等


    image.png
    image.png
    image.png

    创建按钮装不下字的时候 需要新添加一行

    visualDensity: VisualDensity(horizontal: -4, vertical: -4),

    Container(
                width: 120.w,
                height: 56.h,
                child: FlatButton(
                  visualDensity: VisualDensity(horizontal: -4, vertical: -4),
                  color: Colors.yellow,
                  disabledColor: Colors.black12,
                  textColor: Colors.red,
                  disabledTextColor: Colors.grey,
                  onPressed: () {},
                  child: Text(
                    "同意",
                    style: TextStyle(fontSize: 14),
                  ),
                  shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(28.h)),
                ),
              )
    

    flutter 退出到指定页面

    STLRouter.of().navigator.pushNamedAndRemoveUntil(
            RouterFXChatMine.ROUTER_INNER_MINE_PAGE, (route) => route == null);
    

    使用Android studio 进行Git版本控制

    用Android studio打开你的本地项目,


    image.png
    image.png
    image.png
    image.png
    image.png
    image.png

    Git版本控制——保存修改到本地

    image.png

    flutter 清除应用库的缓存

    image.png

    flutter 清除缓存

    flutter clean


    image.png

    汇聊拉完代码需要在终端输入下面命令 batchUpgrade.sh是自己写的
    作用是快速 pub upgrade 各个模块

    ./batchUpgrade.sh

    image.png
    image.png

    对应的文件内容


    image.png
    // batchUpgrade.sh
    #!/bin/bash
    for subDir in  `ls`
    do 
        subPath="$(pwd)/$subDir"
        if [ -d "$subPath" ]  
        then
            #判断文件夹中是否包含 yaml文件
            needUpgrade=false
            for subFile in `ls $subPath`
            do
                if [ "${subFile##*.}"x = "yaml"x ]
                then
                    needUpgrade=true
                fi 
            done
    
            
            if [ $needUpgrade = true ]
            then
               cd $subPath
               flutter pub upgrade
               cd ..
            fi
        fi
    done
    
    #根目录下执行
    flutter pub upgrade
    
    

    相关文章

      网友评论

          本文标题:flutter 小tips

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