小编Dav*_*ego的帖子

尝试在消费者小部件(提供程序包)内推送 Navigator 中的替换项时出现“构建期间调用 setState() 或 markNeedsBuild()”错误

本周我开始在 flutter 中进行开发,但我无法解决这个问题。

\n\n

我正在构建一个登录页面,该页面调用 API 进行登录,然后重定向到主页。\n这是第一个代码块中生成的异常。Navigator.pushReplacement\n此时apiCall.isFetching为 false,导致获取结束并apiCall.response包含所需的数据。

\n\n

异常详细信息:

\n\n
\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90 Exception caught by widgets library \xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\nThe following assertion was thrown building Consumer<ApiCallChangeNotifier>(dirty, dependencies: [InheritedProvider<ApiCallChangeNotifier>]):\nsetState() or markNeedsBuild() called during build.\n\nThis Overlay widget cannot be marked as needing to build because the framework is already in the process of building widgets.  A widget can be marked as needing to be built during the build phase only if one of its ancestors is currently building. …
Run Code Online (Sandbox Code Playgroud)

dart flutter flutter-provider

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

水平 SingleChildScrollView 内的垂直 ListView

我需要构建一个页面,其中包含分组在一行中的对象列表。需要垂直滚动(以显示更多组)和水平滚动(以显示组子项)。\n垂直和水平滚动需要完全移动项目。\n类似这样的内容:https ://gph.is/g/ 46gjW0q

\n\n

我正在使用以下代码执行此操作:

\n\n
Widget _buildGroups() {\n    return SingleChildScrollView(\n      scrollDirection: Axis.horizontal,\n      child: Container(\n        width: 2000,\n        child: ListView.builder(\n          scrollDirection: Axis.vertical,\n          itemCount: boardData.length,\n          itemBuilder: (context, index) {\n            return Row(children: _buildSingleGroup(index));\n          },\n        ),\n      ),\n    );\n}\n\nList<Widget> _buildSingleGroup(int groupIndex) {\n    return List.generate(...);\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

我需要它是水平动态的,但在这里,正如你所看到的,我需要设置一个宽度,否则会发生错误:

\n\n
\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90 Exception caught by rendering library \xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\nThe following assertion was thrown during performResize()\nVertical viewport was given unbounded width.\n\nViewports expand in the cross axis to fill their container and constrain their \nchildren to match their extent in the …
Run Code Online (Sandbox Code Playgroud)

flutter flutter-layout

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

如何在不显示键盘的情况下聚焦 TextField?

我需要关注文本字段但不显示键盘。当用户点击文本字段时才需要显示键盘。

我尝试了2种方法。

第一次尝试:

这样,键盘就会显示出来,而在屏幕构建后就会隐藏起来,这不太好看。

建造者:

TextFormField(
    controller: barcodeStringController,
    focusNode: myFocusNode,
    autofocus: true,
    textAlign: TextAlign.right,
    textInputAction: TextInputAction.done,
    textCapitalization: TextCapitalization.characters,
    style: TextStyle(fontSize: 20),
    maxLines: null,
    onTap: () {
      SystemChannels.textInput.invokeMethod('TextInput.show');
    },
    //... Other event listeners to handle submit
),
Run Code Online (Sandbox Code Playgroud)

并在 build() 之外:

void _onAfterBuild(BuildContext context) {
  SystemChannels.textInput.invokeMethod('TextInput.hide');
}
Run Code Online (Sandbox Code Playgroud)

第二次尝试:

这样键盘就隐藏在较低的位置,并且更容易看到。问题是 onTap 从未被调用,因此键盘永远不会显示,onTap 也不会显示。

建造者:

GestureDetector(
    onTap: () {
        SystemChannels.textInput.invokeMethod('TextInput.show');
    },
    child: TapOnlyFocusTextField(
        controller: barcodeStringController,
        focusNode: myFocusNode, //this is a TapOnlyFocusTextFieldFocusNode
        textAlign: TextAlign.right,
        textInputAction: TextInputAction.done,
        textCapitalization: TextCapitalization.characters,
        style: TextStyle(fontSize: 20),
        cursorColor: Colors.black, …
Run Code Online (Sandbox Code Playgroud)

dart flutter

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

为什么 flutter pub 缓存修复会下载以前使用的每个包版本?

该命令flutter pub cache repair会下载以前使用过的每个包版本,甚至是我不再使用的库。为什么?

有没有办法清理所有内容并仅下载最后一个软件包版本?

dart flutter

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

标签 统计

flutter ×4

dart ×3

flutter-layout ×1

flutter-provider ×1