美文网首页工作生活
Flutter 踩坑合集亲测有效

Flutter 踩坑合集亲测有效

作者: 越长越圆 | 来源:发表于2019-07-04 11:16 被阅读0次

    couldn’t find “libflutter.so”

    flutter run 的时候有问题,build 就可以打进去
    //这样就可以了 
    flutter run  --target-platform android-arm
    

    flutter Could not find an option named "target-platform".

    如果没有这个可能flutter sdk把她remove 了 这个之前遇到过,解决方式是我把fluttetr sdk 分支 切到 stable(稳定版) 那个时候这个这个分支上还有
    

    flutter 打包把assets 目录下文件清空bug
    打开你flutter sdk 目录 flutter_tool/gradle/flutter 400 左右

       Task packageAssets = project.tasks.findByPath(":flutter:package${variant.name.capitalize()}Assets")
                Task cleanPackageAssets = project.tasks.findByPath(":flutter:cleanPackage${variant.name.capitalize()}Assets")
                Task copyFlutterAssetsTask = project.tasks.create(name: "copyFlutterAssets${variant.name.capitalize()}", type: Copy) {
                    dependsOn flutterTask
                    if (packageAssets && cleanPackageAssets) {
                      
                        dependsOn packageAssets
                        dependsOn cleanPackageAssets
                        into packageAssets.outputDir
                    } else {
                        dependsOn variant.mergeAssets
                        //把这里注释掉
                        // dependsOn "clean${variant.mergeAssets.name.capitalize()}"
                        into variant.mergeAssets.outputDir
                    }
                    with flutterTask.assets
                }
    

    android dialog 返回键回去的问题

    一般 loading 进度框 用dialog的方式,但是返回是通过Navigator.of(context).pop(); 取消
    流程发起网络(showDialog)->返回键(pop 一次)->网络成功(pop 回调一次) 就会pop 两次
    解决方式 是 showDialog 里面 widget WillPopScope 这个不对返回键操作就好了
    
    import 'package:flutter/material.dart';
    
    // ignore: must_be_immutable
    class LoadingDialog extends Dialog {
      LoadingDialog({Key key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return new Material(
            //创建透明层
            type: MaterialType.transparency, //透明类型
            child: new WillPopScope(
              onWillPop: () async {
                return Future.value(false);
              },
              child: new Center(
                //保证控件居中效果
                child: new SizedBox(
                  width: 120.0,
                  height: 120.0,
                  child: new Container(
                    decoration: ShapeDecoration(
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.all(
                          Radius.circular(8.0),
                        ),
                      ),
                    ),
                    child: new Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: <Widget>[
                        new CircularProgressIndicator(
                          backgroundColor: Color.fromRGBO(0, 0, 0, 0),
                          valueColor: AlwaysStoppedAnimation(Colors.white),
                        ),
                      ],
                    ),
                  ),
                ),
              ),
            ));
      }
    }
    

    Must be compiled first into .flat file.

    gradle.properties
    android.enableAapt2=false
    

    相关文章

      网友评论

        本文标题:Flutter 踩坑合集亲测有效

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