小编use*_*643的帖子

后端使用Vite

我们使用 Vite 作为前端(在 SvelteKit 内),它可以很好地创建 SSR 和前端代码。

\n

我特别喜欢通过 esbuild 预捆绑第 3 方软件包。

\n

有人可以告诉我是否可以将 Vite 捆绑管道用于仅后端项目(基于 koa 的 Nodejs 服务器)?

\n

node.js nodejs-server vite

37
推荐指数
2
解决办法
5万
查看次数

ListTile 中的前导图像溢出

我有一个ListViewListTile。每个ListTile都有一个titlewith TextsubtitlewithTextleadingwith Image

现在,图像太大并且垂直延伸到下一行,与那里的图像重叠。

如何确保图像保持在边界内?

编辑:

我不想给图像一个固定的大小,而是让它调整到由标题+副标题的固有高度给出的列表图块的高度。

flutter flutter-layout flutter-image

16
推荐指数
2
解决办法
3万
查看次数

对可变参数模板参数的元迭代

我想概括以下模式:

template<class A1, class A2, class A3>
class Foo {
protected:
  template<class T>
  void foo(const T& t) {...do stuff...}
public:
  void bar(const A1& a) { foo(a); }
  void bar(const A2& a) { foo(a); }
  void bar(const A3& a) { foo(a); }
};
Run Code Online (Sandbox Code Playgroud)

上述方法不会随着一些不断增加的论点而扩展.所以,我想做:

template<class As...>
class Foo {
protected:
  template<class T>
  void foo(const t& a) {...do stuff...}
public:
  for each type A in As declare:
  void bar(const A& a) { foo(a); }
};
Run Code Online (Sandbox Code Playgroud)

有办法吗?

c++ templates variadic-templates c++11

15
推荐指数
4
解决办法
828
查看次数

列中扩展小部件的特定最小和最大尺寸

我有一个带有一组扩展小部件的列。

有没有办法控制它们扩展的范围?我希望一个小部件仅扩展到特定大小,并使其余小部件可用于其他小部件。

编辑:

因为我得到了两个可能具有误导性的答案,所以我想澄清一下。我想要这样的东西:

Expanded(flex: 1, minSize: 50, maxSize: 200, child: ...)
Run Code Online (Sandbox Code Playgroud)

这意味着这个展开的小部件的 flex 为 1,但不应小于 50 和大于 200。

flutter flutter-layout

14
推荐指数
4
解决办法
8204
查看次数

在 flutter 中测试/模拟文件 IO

我有一个简单的测试:

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

Future<void> main() async {
  testWidgets(
    'Simple empty test',
    (WidgetTester tester) async {
      print("1");
      await Directory('/tmp').exists();
      print("2");
      await tester.pumpWidget(Container());
    },
  );
}
Run Code Online (Sandbox Code Playgroud)

打印后冻结1。我知道 Flutter 在假异步区域中运行测试,并且我知道我需要使用 runAsync 来运行具有真实 IO 的代码。

但是,是否也可以以某种方式注入模拟 IO 文件系统并在没有 runAsync 的情况下运行测试?

flutter flutter-test

11
推荐指数
2
解决办法
3998
查看次数

默认情况下不可为空:如何启用实验?

我刚刚在 DartPad 中尝试了以下操作:

void main() {
  int? x;
}
Run Code Online (Sandbox Code Playgroud)

并得到以下错误:

Error compiling to JavaScript:
main.dart:2:6:
Error: This requires the 'non-nullable' experiment to be enabled.
Run Code Online (Sandbox Code Playgroud)
  1. 如何启用该实验?我正在使用 Flutter SDK。

  2. 实验是否已经支持零安全静态分析?

dart

10
推荐指数
3
解决办法
9008
查看次数

TypeScript 索引签名中“[key: string]”和“[key in string]”之间的区别

考虑以下使用:in定义索引签名的示例:

interface Colon {
  [key : string]: number;
}

interface ColonOpt {
  [key : string]?: number; // does not compile
}

interface In {
  [key in string]: number; // does not compile
}

interface InNested {
  a: {
    [key in string]: number;
  };
}

interface InNestedOpt {
  a: {
    [key in string]?: number;
  };
}
Run Code Online (Sandbox Code Playgroud)

我有点困惑为什么有些可以编译而有些不能。in在索引签名中使用vs有什么区别:

typescript

8
推荐指数
0
解决办法
437
查看次数

仅当要转换的函数具有至少两个参数时,才将函数隐式转换为二阶函数

我有隐式转换和高阶函数的问题.似乎只有转换函数至少有两个参数,函数到二阶函数的隐式转换才有效.

作品:

implicit def conv(foo: Integer => String): String => String = null
Run Code Online (Sandbox Code Playgroud)

不起作用:

implicit def conv(foo: Integer => String): String => String => String = null
Run Code Online (Sandbox Code Playgroud)

作品:

implicit def conv(foo: (Integer, Integer) => String): String => String => String = null
Run Code Online (Sandbox Code Playgroud)

完整的失败点示例:

{
    implicit def conv(foo: Integer => String): String => String = null

    def baadf00d(foo: Integer): String = null

    def deadbeef(foo: String => String) = null

    deadbeef(conv(baadf00d))

    deadbeef(baadf00d)
}

{
    implicit def conv(foo: Integer => String): String => …
Run Code Online (Sandbox Code Playgroud)

scala implicit-conversion higher-order-functions

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

错误:这需要启用“不可为空”的实验

我正在玩非空类型,并将其添加到我的analysis_options.yaml

analyzer:
  enable-experiment:
    - non-nullable
Run Code Online (Sandbox Code Playgroud)

我有一个利用可空性扩展的代码生成器。可视代码适合我的代码。

现在,我尝试运行:

flutter packages pub run build_runner watch 
Run Code Online (Sandbox Code Playgroud)

我收到此错误消息:

[SEVERE] Failed to snapshot build script .dart_tool/build/entrypoint/build.dart.
This is likely caused by a misconfigured builder definition.
[SEVERE] xyz.dart:95:7: Error: This requires the 'non-nullable' experiment to be enabled.Try enabling this experiment by adding it to the command line when compiling and running.
Run Code Online (Sandbox Code Playgroud)

我怎么--enable-experiment:non-nullableflutter packages pub run

如果我运行,也会发生相同的情况:

flutter build ios
Run Code Online (Sandbox Code Playgroud)

我收到错误消息:

  lib/main.dart:61:26: Error: This requires the 'non-nullable' experiment to be enabled. …
Run Code Online (Sandbox Code Playgroud)

dart flutter

6
推荐指数
4
解决办法
284
查看次数

重写运算符==是否有助于避免重建?

我有一个无状态小部件

\n\n
class Foo extends StatelessWidget {\n  final String text;\n  A(this.text);\n  Widget build(BuildContext _) => Text(text);\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

让\xe2\x80\x99s 说我在小部件树中的某个位置创建了\xe2\x80\x98Foo\xe2\x80\x99 的实例,并且(很少)更改\xe2\x80\x98text\xe2\x80\x99。当然,每当我创建 \xe2\x80\x98Foo\xe2\x80\x99 的新实例时,即使它具有相同的 \xe2\x80\x98text\xe2\x80\x99,它的 \xe2\x80\x98build\xe2 \x80\x99 将被调用。

\n\n

引入 \xe2\x80\x99operator==\xe2\x80\x98 来检查 \xe2\x80\x98text\xe2\x80\x99 是否会避免重建?

\n\n

编辑:小部件树中仅放置了一个 \xe2\x80\x98Foo\xe2\x80\x99 实例,但它 \xe2\x80\x99 始终是每个父版本的新实例。

\n\n

编辑:

\n\n

我想我在 Flutter 代码库中找到了 \xe2\x80\x98framework.dart\xe2\x80\x99 中的位置:

\n\n
if (child.widget == newWidget) {\n    if (child.slot != newSlot)\n      updateSlotForChild(child, newSlot);\n    return child;\n  }\n
Run Code Online (Sandbox Code Playgroud)\n\n

因此,如果 Widget 覆盖 \xe2\x80\x98operator ==\xe2\x80\x98,则 \xe2\x80\x98equal\xe2\x80\x99 的同一 Widget 类的两个实例不会将子树标记为脏因此不会触发子树 \xe2\x80\x98build\xe2\x80\x99。

\n\n

因此,覆盖 \xe2\x80\x98operator ==\xe2\x80\x98 可以帮助优化性能!

\n\n

有人可以证实吗?

\n\n …

flutter

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