小编jon*_*nyc的帖子

CustomPainter 使用 Listenable 重绘

CustomPainter 类似乎有几种触发重绘的方法。

我让我的画家使用 shouldRepaint 方法,但是,我希望我的画家对可听的更改做出反应,而不是轮询更改。

Flutter 文档指出

触发重绘的最有效方法是:

扩展这个类并为 > CustomPainter 的构造函数提供一个 repaint 参数,当需要重绘时,该对象会通知它的侦听器。扩展Listenable(例如通过ChangeNotifier)并实现CustomPainter,以便对象本身直接提供通知。

我尝试将可听的传递给自定义画家,但是当可听的更新时,未按照文档中的说明调用绘画方法

在任何一种情况下,CustomPaint 小部件或 RenderCustomPaint 渲染对象都将侦听 Listenable 并在动画滴答作响时重新绘制,

class CursorPainter extends CustomPainter {
  Listenable _repaint;
  Player player;
  BuildContext context;

  // Pass in repaint (listenable)
  CursorPainter({repaint, this.context}) {
    _repaint = repaint;
    player = Provider.of<Player>(context, listen: false);
  }

  @override
  void paint(Canvas canvas, Size size) {
  // Paint logic...
  }

  @override
  bool shouldRepaint(CursorPainter lastTrackPainter) {
     // Tried returning both true and false here to no avail. Method is continually called. …
Run Code Online (Sandbox Code Playgroud)

dart flutter

7
推荐指数
1
解决办法
2343
查看次数

如何在 Typescript 中排除编译文件但包含测试文件?

文件结构

函数/lib/src/...src .ts 文件
函数/lib/test/...测试文件
函数/tsconfig.json

当我在 tsconfig.json.include 中包含测试文件目录时,属性 linting 在我的测试文件中工作正常。但是,当我运行 tsc 时,测试文件被编译成 js。

当我从 tsconfig.json include 属性中删除测试目录时,我的所有 Jest 方法的测试文件中都会出现如下错误:

找不到名称“测试”。您需要为测试运行程序安装类型定义吗?尝试npm i @types/jestnpm i @types/mocha

tsconfig.json 如下所示

{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "outDir": "lib",
    "sourceMap": true,
    "strict": true,
    "target": "es2017"
  },
  "compileOnSave": true,
  "include": [
    "src",
  ],

}
Run Code Online (Sandbox Code Playgroud)

jest.config.js 如下所示

module.exports = {
  preset: 'ts-jest',
  testEnvironment: 'node',
};
Run Code Online (Sandbox Code Playgroud)

如何获得 Jest 方法识别并且不被编译测试文件所困扰?

typescript jestjs ts-jest

7
推荐指数
1
解决办法
1692
查看次数

使用 Cloud Functions 通过 Firestore 观看集合组

我正在开发一个使用 collectionGroups 的 Firestore DB。

所讨论的 collectionGroup 是“Fights”的集合。

当创建新的战斗时,我想使用云函数中的 onCreate 方法来监视新的“战斗”条目,然后向其中添加一些元数据。理想情况下它看起来像下面的伪代码

export const placeFightersInEvent = functions.firestore
  .collectionGroup('fights/{fightId}')
  .onCreate(async (fightSnapshot, context) => {
    // get metadata and add to the newly created 'fight'
  });
Run Code Online (Sandbox Code Playgroud)

我正在使用最新版本的 firebase 函数和 admin sdk,但我似乎找不到可用的函数来执行此操作。可以用这种方式观看收藏组吗?

firebase google-cloud-functions google-cloud-firestore

5
推荐指数
1
解决办法
1087
查看次数