flutter报错

发布于:2024-05-07 ⋅ 阅读:(23) ⋅ 点赞:(0)

组件相关

  1. type ‘List’ is not a subtype of type ‘List’

children: CardList.map((item) => Container( 加上 *** < Widget>*** 正常

  1. type ‘(dynamic, dynamic) => Container’ is not a subtype of type ‘(CardType) => Widget’ of ‘f’
 children: CardList.map<Widget>((item, index) => Container(

正确使用 map 的索引值应该加上 .asMap().entries.map 转化为实例,key/value形式

children: CardList.asMap()
.entries
.map<Widget>((item) => Container(
  width: (MediaQuery.of(context).size.width -
          (JwSizes.width30 * 5)) /
      4,
  child: GestureDetector(
      onTap: () => checkCard(item.key),
      child: Column(
        children: [
          Image.asset(
            item.value.image,
            height: JwSizes.width32,
            fit: BoxFit.fitWidth,
          ),
          SizedBox(height: JwSizes.height6),
          Text(item.value.title, style: common13TextStyle)
        ],
      )),
))
.toList(),
  1. flutter GestureDetector 点击无效 手势冲突

GestureDetector 内嵌套 chart图表,希望点击后跳转,却展示 图表tootip 没有跳转
https://book.flutterchina.club/chapter8/gesture_conflict.html#_8-4-5-%E8%A7%A3%E5%86%B3%E6%89%8B%E5%8A%BF%E5%86%B2%E7%AA%81

// 使用 Listener 替代 GestureDetector 
 Listener(
                  // TODO 点击跳转无效,被子组件影响
                  behavior: HitTestBehavior.opaque,
                  onPointerUp: (PointerUpEvent event) {
                    controller.gotoGroup(item.value);
                  }
  1. flutter 唤起键盘 OverlayEntry状态丢失

OverlayEntry中包含 输入框,每当唤起键盘后,OverlayEntry属性mounted 改为了 false 无法remove掉

解决 在 事件 onPressed 中将页面中定义的具体组件赋值给 状态控制器中定义的 OverlayEntry overlayEntry,
防止 键盘唤起后,状态丢失。

连接设备相关

  1. 连接不到设备
    在这里插入图片描述
  2. flutter docker > Unable to run “adb”, check your Android SDK installation and ANDROID_SDK_ROOT environment variable:
    adb.exe 23288 23684 fdevent_poll.cpp:64] failed to create f
    • 打开控制面板->防火墙->允许应用通过Windows防火墙
    • 允许的应用界面:先点击 更改设置按钮→再点击允许其他应用按钮
    • 选择添加允许的应用(adb.exe)

运行相关

  1. Could not connect to the Gradle daemon.
    Daemon uid: 36b1cf53-4fc6-450a-9f6d-5feea276380b with diagnostics:
    Daemon pid: 16588
  • 重新安装 flutter
  • 关闭防火墙

框架功能使用相关

  1. 设置横竖屏,出现闪烁

原因: 页面横竖屏切换需要一定时间,同时触发了页面更新

Future<bool> zoomChart({bool? flag}) async {
    isZoom.value = flag ?? !isZoom.value;
    if (isZoom.value) {
      await SystemChrome.setPreferredOrientations([
        DeviceOrientation.landscapeLeft,
        DeviceOrientation.landscapeRight,
      ]);
    } else {
      await SystemChrome.setPreferredOrientations([
        DeviceOrientation.portraitUp,
        DeviceOrientation.portraitDown,
      ]);
    }
    update();
    return true;
  }
  1. removeInvalidNode all the node in jank list is out of time