Flutter修炼手册

Flutter报错集合

2019-06-18  本文已影响1人  Flutter小菜鸡

问题一

重现情景

添加了一个widget的decoration属性并设置了gradient的clors渐变数组之后报错

flutter: Cannot provide both a color and a decoration
flutter: The color argument is just a shorthand for "decoration: new BoxDecoration(color: color)".
flutter: 'package:flutter/src/widgets/container.dart': Failed assertion: line 271 pos 15: 'color == null ||
flutter: decoration == null'
flutter:
flutter: Either the assertion indicates an error in the framework itself, or we should provide substantially
flutter: more information in this error message to help you determine and fix the underlying cause.
flutter: In either case, please report this assertion by filing a bug on GitHub:
flutter:   https://github.com/flutter/flutter/issues/new?template=BUG.md
flutter:
flutter: When the exception was thrown, this was the stack: 

错误代码

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Text widget',
      home:Scaffold(
        body: Center(
          child: Container(
            child: Text(' sadasd  dada',style:TextStyle(fontSize:40.0)),
            alignment: Alignment.topLeft,
            width: 500.0,
            height: 400.0,
            color: Colors.lightBlue,
            padding: const EdgeInsets.all(10.0),
            margin: const EdgeInsets.all(10.0),
            decoration: BoxDecoration(
              gradient:const LinearGradient(
                colors: [Colors.lightGreen,Colors.lightBlueAccent,Colors.lightBlueAccent],
              )
            ),
          ),
        ),
      ),
    );
  }
}

错误原因

由于设置了text的color属性又同事设置了gradient的colors属性,冲突导致报错,个人理解为color和gradient的colors属性都是对backgroundColor做了赋值操作,同时设置并不会按顺序执行,而会报错。

解决方法

color和gradient的colors属性两者取一个

问题二

重现情景

由于是多人协作开发,所以git上传之后,Xcode添加pod依赖之后,本地配置信息一并被pod install命令写入xconfig文件中,导致文件经常冲突,或者项目前一秒还可以运行,pull之后各种路径配置问题。下面这只是其中的一种情况

Xcode's output:
↳
    === BUILD TARGET Runner OF PROJECT Runner WITH CONFIGURATION Debug ===
    2019-06-19 15:01:48.796 defaults[89639:2599246] 
    The domain/default pair of
    (/Users/sf_linnan/Desktop/code/scmw-ios/stock_flutter/build/ios/Debug-iphonesimulator/
    Runner.app/Frameworks/Flutter.framework/Info.plist, CFBundleExecutable) does not exist
    fatal error: lipo: can't map input file:
    /Users/sf_linnan/Desktop/code/scmw-ios/stock_flutter/build/ios/Debug-iphonesimulator/R
    unner.app/Frameworks/Flutter.framework/ (Invalid argument)
    fatal error: lipo: can't map input file:
    /Users/sf_linnan/Desktop/code/scmw-ios/stock_flutter/build/ios/Debug-iphonesimulator/R
    unner.app/Frameworks/Flutter.framework/ (Invalid argument)
    Failed to extract x86_64 for
    /Users/sf_linnan/Desktop/code/scmw-ios/stock_flutter/build/ios/Debug-iphonesimulator/R
    unner.app/Frameworks/Flutter.framework/. Running lipo -info:
    fatal error: lipo: can't map input file:
    /Users/sf_linnan/Desktop/code/scmw-ios/stock_flutter/build/ios/Debug-iphonesimulator/R
    unner.app/Frameworks/Flutter.framework/ (Invalid argument)

Could not build the application for the simulator.
Error launching application on iPhone XR.

错误分析

按照提示我进入了本地项目目录,看到flutter.framework 缺失app可执行文件。可能是因为flutter run 初始化运行环境时没有加载成功导致。因为flutter编译iOS项目时,需要在Xcode环境中运行pod install,可能是由于git pull 操作之后覆盖掉了之前本地的配置,导致冲突,所以没有初始化成功。这种说法我自己也不太确定,还没有找到具体的原因

image.png
可以看到我是缺失了可执行文件flutter 和 info.plist 和icudlt.dat三个文件。
解决方法

删除Flutter.framework,重新执行flutter run操作,可以看到

image.png
上一篇下一篇

猜你喜欢

热点阅读