小编Fra*_*cca的帖子

Flutter 错误:“Widget 无法构建,因为已经在构建过程中”

我收到此错误:

I/flutter (29346): ??? EXCEPTION CAUGHT BY WIDGETS LIBRARY ????????????????????????????????????????????????????????????
I/flutter (29346): The following assertion was thrown building MainLogic(dirty, state: _MainLogic#9c794):
I/flutter (29346): setState() or markNeedsBuild() called during build.
I/flutter (29346): This InhWidget widget cannot be marked as needing to build because the framework is already in the
I/flutter (29346): process of building widgets. A widget can be marked as needing to be built during the build phase
I/flutter (29346): only if one of its ancestors is currently building. This …
Run Code Online (Sandbox Code Playgroud)

widget flutter inherited-widget

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

错误“无法将“动态”类型的值分配给“字符串”类型的变量。在 Dart 2.2

自上次飞镖更新(2.2)以来,我收到此错误,

'不能将'dynamic' 类型的值分配给'String' 类型的变量。

这对我来说没有多大意义。代码绝对是微不足道的:

    class EmployeeMirror {
  EmployeeMirror(this.id, this.name);

  EmployeeMirror.fromMap(Map<String, dynamic> _map) {
    id = _map['id'];      // error here
    name = _map['name'];  // and here
  }

  int id;
  String name;
}
Run Code Online (Sandbox Code Playgroud)

我认为无关紧要,但这是在 Aqueduct 项目中。

在此先感谢您的帮助

string dynamic dart aqueduct

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

如何在 Flutter 中使用 AnimatedList Widget

在优酷上看过这个视频

我正在尝试实现一个动画列表,

但我对动画不是很熟悉。

我应该插入的内容

位置:animation.drive(),

removeItem(_index,(context,animation)=> /// 我应该在这里做什么 ),);

这是代码(仅从“启动应用程序”中进行了一些更改)

      class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateMixin {
  List<int> _list = [];
  final GlobalKey<AnimatedListState> _listKey = GlobalKey<AnimatedListState>();


  void _addItem() {
    final int _index = _list.length;
    _list.insert(_index,_index);
    _listKey.currentState.insertItem(_index);
  }

  void _removeItem() {
    final int _index = _list.length-1;
    _listKey.currentState.removeItem(_index,(context,animation)=>  /// what I'm supposed to do here
    ),);
  }


  @override …
Run Code Online (Sandbox Code Playgroud)

dart flutter flutter-animation flutter-animatedlist

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

在流上使用时,Distinct() 似乎不会过滤掉相同的结果

请看一下这段代码=>

void main() async {
  Stream<int> _intStream() async* {
    for (int i = 0; i < 10; i++) yield i;
  }

  Stream<int> _even() => _intStream().where((int i) => i % 2 == 0);
  Stream<bool> _isEven(Stream<int> stream) => stream.map((int i) => i % 2 == 0);

  print('test 1: should print 5 [true] and 5 [false] alternate');
  await for (bool b in _isEven(_intStream())) {
    print('test 1: $b');
  }

  print('test 2: should print 5 [true]');
  await for (bool b in _isEven(_even())) {
    print('test 2: …
Run Code Online (Sandbox Code Playgroud)

asynchronous iterable stream dart flutter

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

SingleChildScrollView + Column:要么溢出,要么忽略 mainAxisAlignment

[已解决]我已经使用工作解决方案更新了 dartpad https://dartpad.dartlang.org/42415ce855bfcdc148eb03872c170c77


在dartpad上运行下面的代码并垂直调整浏览器页面的大小;

您会在右侧的示例中注意到

SingleChildScrollView不滚动并且Column溢出


import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) => const MaterialApp(
        home: MyHomePage(),
      );
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) => Material(
        child: Row(
          children: [
            SingleChildScrollView(
              scrollDirection: Axis.vertical,
              child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  Text('''without wrapping the column in fixed heigth
                   [MainAxisAlignment.spaceEvenly] doesn't work'''),
                  for …
Run Code Online (Sandbox Code Playgroud)

flutter flutter-layout

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

VSCODE无法在go模块中安装工具

在 VSCode 上启动 go 模块时,系统会提示我安装一些工具

在此输入图像描述

选择install安装失败,在vscode终端登录下面

VSCODE 一直对我大喊“安装失败”的东西,只是因为忽略了我的路径,如下所示

Tools environment: GOPATH=/home/go
Installing 1 tool at /home/go/bin in module mode.
  gopls

Installing golang.org/x/tools/gopls FAILED

1 tools failed to install.

gopls: failed to install gopls(golang.org/x/tools/gopls): Error: Command failed: /usr/local/go/bin/go get -v golang.org/x/tools/gopls
go: writing stat cache: mkdir /home/go: permission denied
go: downloading golang.org/x/tools/gopls v0.5.1
go: downloading golang.org/x/tools v0.0.0-20201017001424-6003fad69a88
go get golang.org/x/tools/gopls: mkdir /home/go: permission denied
 undefined  
Run Code Online (Sandbox Code Playgroud)

这些是我GOPATHGOROOT

Tools environment: GOPATH=/home/go
Installing 1 tool at /home/go/bin in module mode.
  gopls …
Run Code Online (Sandbox Code Playgroud)

go visual-studio-code go-modules

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

如何忽略“dart-lang/coverage”中的一行

用例

codecov认为super需要测试,

在此输入图像描述

不确定是否为此关键字编写测试

  • 将是有意义的
  • 如何编写这样的测试

在我的疑虑消除之前,我想将该线路排除在覆盖范围之外

问题

我如何忽略其中的一行dart-lang/coverage

code-coverage dart test-coverage flutter codecov

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

在“ onPressed / onTap”颤振器上调用“无效”时出错

我在onPressed / onTap中调用void时出错 onPressed没有详细信息 详细点按

我正在尝试按照以下说明在继承的小部件/状态中调用设置状态 https://medium.com/flutter-community/widget-state-buildcontext-inheritedwidget-898d671b7956

在我不熟练的专家看来,他在做同样的事情,但显然我错过了一些。你能帮我吗?

   class InhCore extends InheritedWidget {
  InhCore({Key key, @required Widget child, @required this.data})
      : super(key: key, child: child);

  final InhState data;

  @override
  bool updateShouldNotify(InhCore oldWidget) {
    return true;
  }
}

class InhWidget extends StatefulWidget {
  InhWidget({this.child});

  final Widget child;

  @override
  State<StatefulWidget> createState() => InhState();

  static InhState of(BuildContext context) {
    return (context.inheritFromWidgetOfExactType(InhCore) as InhCore).data;
  }
}

class InhState extends State<InhWidget> {
  final Map<String, int> cardMap = {
    'A':1,
    '2':2,
    '3':3,
    '4':4,
    '5':5,
    '6':6,
    '7':7,
    '8':8,
    '9':9, …
Run Code Online (Sandbox Code Playgroud)

void dart flutter

4
推荐指数
1
解决办法
976
查看次数

如何验证小部件是否“离屏”

赏金信息:如果出现以下情况,我会接受您的回答:

\n
    \n
  • 不是沿线的东西do this instead
  • \n
  • 代码示例大部分没有变化
  • \n
  • 产生成功的测试,而不仅仅是文档中的一些引用
  • \n
  • 不需要任何额外的包
  • \n
\n
\n
\n

[编辑:07/02/21] 在flutter 社区 上关注 Miyoyo#5957 ,\ndiscord@iapicca Convert widget position to global, get width height, add both, and see if the resulting bottom right position is on screen?并使用以下答案作为参考:

\n\n
\n

给出下面的代码示例(也可以在 dartpad 上运行

\n
import \'package:flutter_test/flutter_test.dart\';\nimport \'package:flutter/material.dart\';\n\nfinal _testKey = GlobalKey();\nconst _fabKey = ValueKey(\'fab\');\nfinal _onScreen = ValueNotifier<bool>(true);\n\nvoid main() => runApp(_myApp);\n\nconst _myApp = …
Run Code Online (Sandbox Code Playgroud)

testing dart flutter widget-test-flutter

4
推荐指数
1
解决办法
2443
查看次数

为什么 pubspec 环境 / sdk / 使用“ '&gt;=2.7.0 &lt;3.0.0' ”而不是“ ^2.7.0 ”

诚然,我对semver的理解非常有限

environment:
  sdk: ^2.7.0
Run Code Online (Sandbox Code Playgroud)

相当于这个

environment:
  sdk: '>=2.7.0 <3.0.0'
Run Code Online (Sandbox Code Playgroud)

此格式对于包发布是严格执行的

Package validation found the following error:
* ^ version constraints aren't allowed for SDK constraints since older versions of pub don't support them.
  Expand it manually instead:
  
  environment:
    sdk: ">=2.7.0 <3.0.0"
Sorry, your package is missing a requirement and can't be published yet.

Run Code Online (Sandbox Code Playgroud)

latterflutter 使用in 代替该方法有什么原因吗former

哪个可以说更熟悉和一致

yaml dart semantic-versioning flutter

3
推荐指数
1
解决办法
7659
查看次数