Flutter个人bug记录

3,591 阅读5分钟

初始化和dispose,初始化的super放最前面,dispose放最后面才没bug

  void initState() {
    super.initState();
    id = widget.id;
    map = {"id": id};
    _getDataList();
  }
  void dispose(){
    controller1.dispose();
    super.dispose();

  }

Could not resolve all files for configuration ':connectivity:lintClassPath'.

maven一定要房子jcenter上面

根 build.gradle

    repositories {

        maven{ url 'https://maven.aliyun.com/repository/google' }
        maven{ url 'https://maven.aliyun.com/repository/jcenter' }
        maven{url 'http://maven.aliyun.com/nexus/content/groups/public'}
        jcenter()//不要删了
        google()//不要删了
    }

r\example\android\gradlew.bat" exited abnormally:

出现这种情况有很多种错误,下面解决方式最常见,不包成功

www.jianshu.com/p/ff64e4ff3…

同上的文件夹 可以flutter clean一下
allprojects {
    repositories {
//        google()
//        jcenter()
        maven{ url 'https://maven.aliyun.com/repository/google' }
        maven{ url 'https://maven.aliyun.com/repository/jcenter' }
        maven{url 'http://maven.aliyun.com/nexus/content/groups/public'}
    }
}

3 项目迁移出错

一般是看看flutter sdk有无放置正确,packages get 再run

如果不行,可能是签名文件没放进来,也可能是没用的插件影响了。

我就有一次一直提示

WARNING: API 'variant.getMergeAssets()' is obsolete and has been replaced with 'variant.getMergeAssetsProvider()'.
It will be removed at the end of 2019.
WARNING: API 'variantOutput.getProcessResources()' is obsolete and has been replaced with 'variantOutput.getProcessResourcesProvider()'.
It will be removed at the end of 2019.
WARNING: This version of image_picker will break your Android build if it or its dependencies aren't compatible with AndroidX.

但是结果只是注释掉没用的barcode-scan插件即可

4 升级flutter sdk报错

1.打包安装包报错

/C:/flutter_windows_v1.12.13+hotfix.5/flutter/packages/flutter/lib/src/semantics/semantics.dart:3644:45: Error: Getter not found: 'isLink'.
  bool get isLink => _hasFlag(SemanticsFlag.isLink);
很多类似这样的

做的尝试:

  • flie-》project struture=》libraries=》flutter for android版本改正
  • 修改系统path环境变量
  • file=》setting=》flutter环境变量和dart环境
Execution failed for task ':app:compileFlutterBuildReleaseArm'.
> Process 'command 'C:\flutter\bin\flutter.bat'' finished with non-zero exit value 1

还是报这样的错,最后做了向androidX手动迁移的操作,重启AS,可以了 主要是错是我发现了插件冲突-》具体看下面解决(目前不会解决)

2.单纯手机run报错

  If you're running an application and need to access the binary messenger before `runApp()` has been called (for example, during plugin initialization), then you need to explicitly call the `WidgetsFlutterBinding.ensureInitialized()` first.
    If you're running a test, you can call the `TestWidgetsFlutterBinding.ensureInitialized()` as the first line in your test's `main()` method to initialize the binding.
   

解决办法是在 runApp 之前,调用 WidgetsFlutterBinding.ensureInitialized(); 即可解决 注意:如果你不是放在了 main() 方法里边的第一行,而且还发现无效,那么尝试把他放到 main() 里边的第一行再试试,应该会 OK

插件冲突问题

barcode-scan和wifi-iot冲突

运行了wifi插件,barcode-scan会显示sdk的location错误

运行barcode-scan,会显示插件版本应该向androidX迁移,但是毫无思路的

暂时跪这里

5 runtime和compile不一致

error: ‘androidx.core:core’ has different version for the compile (1.0.0) and runtime (1.0.1)

在这个路径…/android/build.gradle (不是这个路径…/android/app/build.grade) 添加如下配置:

subprojects {
    project.configurations.all {
    resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'androidx.core' &&
           !details.requested.name.contains('androidx')) {
        details.useVersion "1.0.1"
            }
    }
    }    
}

一般这样也还是搞不定,要项目迁移到androidX

6:对话框里的widget不安全

[ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: Looking up a deactivated widget's ancestor is unsafe.
E/flutter (30558): At this point the state of the widget's element tree is no longer stable.
E/flutter (30558): To safely refer to a widget's ancestor in its dispose() method, save a reference to the ancestor by calling inheritFromWidgetOfExactType() in the widget's didChangeDependencies() method.

stackoverflow.com/questions/5…

起因:想在弹框中退出当前页面

showdialog点击确定取消的时候默认会关弹框的

showDialog(
        context: context,
        builder: (context) => //把这里的context改成其他名字,我是diacontext,解决
            CustomDialog(
                 confirmCallback: (){
                      CommonUtil.closePage(context);//这里的context上面有两个,所以不安全吧
                 }
                

如果不行,

创建变量 
GlobalKey<ScaffoldState> _key = new GlobalKey();
在Scaffold中加
    key:_key,

再不行,参考上面的网站

MissingPluginException(No implementation found for method canLaunch on channel plugins.flutter.io/url_launcher)

热加载不能注册和原生有关的插件,重启android studio即可,或者右上角的stop,再run

The getter 'alertDialogLabel' was called on null

引入国际化之后报的错误, 参考:blog.csdn.net/julystroy/a…

图片http安全认证

DioError [DioErrorType.DEFAULT]: 与服务器连接发生错误 出现这个error的一个原因是请求图片资源时,请求的url是http的导致请求不到,此时需要忽略安全证书才能请求到

postman 右上角扳手 setting 里有一个ssl是on的,关掉

blog.csdn.net/weixin_3422…

www.jianshu.com/p/90d693395…

2.x版本和1.x版本的不一样,要注意

        DefaultHttpClientAdapter adapter = dio.httpClientAdapter;
        adapter.onHttpClientCreate  = (HttpClient client){

          client.badCertificateCallback = (X509Certificate cert ,String host ,int port){

            return true;

          };};

DIO

www.jianshu.com/p/efe97666c… blog.csdn.net/shenji12/ar…

Invalid argument(s): The source must not be null

stackoverflow.com/questions/4…

问题的根源在于int.parse

去掉多余的方法;就好

Concurrent modification during iteration: Instance(length:1) of '_GrowableList'.

blog.csdn.net/IcyDate/art…

Dart也为我们提供了循环并删除的方法,removeWhere()。

List list = [1, 2, 3, 4];
 
// 这里使用了箭头函数,后面的表达式为true时会删除当前值
list.removeWhere((value) => value == 2); 
// 当然也能用{}
list.removeWhere((value) {
    retrun value == 2;
});

error:← CustomMultiChildLayout ← AnimatedBuilder

The following assertion was thrown building Container(padding: EdgeInsets(0.0, 13.6, 0.0, 10.5), bg:
I/flutter (26627): BoxDecoration(color: Color(0xfff5f5f5)), constraints: BoxConstraints(0.0<=w<=Infinity, h=Infinity)):
I/flutter (26627): Incorrect use of ParentDataWidget.
I/flutter (26627): Expanded widgets must be placed inside Flex widgets.
I/flutter (26627): Expanded(no depth, flex: 1, dirty) has no Flex ancestor at all.
I/flutter (26627): The ownership chain for the parent of the offending Expanded was:
I/flutter (26627):   Padding ← DecoratedBox ← ConstrainedBox ← Container ← MediaQuery ← LayoutId-[<_ScaffoldSlot.body>]
I/flutter (26627): ← CustomMultiChildLayout ← AnimatedBuilder ← DefaultTextStyle ← AnimatedDefaultTextStyle ← ⋯

加个Column

错误:

 body: Container(
        color: MyColors.grey_f5,
        height: double.infinity,
        padding: EdgeInsets.only(bottom: Adapt.dp(10), top: Adapt.dp(13)),
        child: Expanded(child: SmartRefresher(
          enablePullDown: true,
          enablePullUp: true,

改正:

 body: Container(
          color: MyColors.grey_f5,
          padding: EdgeInsets.only(top: Adapt.dp(17), bottom: Adapt.dp(20)),
          child: Column(children: <Widget>[
            Expanded(child: SmartRefresher(
              enablePullDown: true,
              enablePullUp: true,
              header: WaterDropHeader(),

(你们看了也不懂的,别看了我瞎写的)

一个坑

Navigator.pop(context,'x');

h页面可以通过点击进入页面a和b

h进入页面a,页面a返回前一个页面会传值‘x’

a通过路由替换进入页面b,b亦返回前一个页面传值‘x’

通过a进入的b此时返回不会传值页面h ‘x’

猜测是因为传给了a