Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 在生成期间调用PagewiseLoadController setState()或markNeedsBuild()_Flutter_Dart - Fatal编程技术网

Flutter 在生成期间调用PagewiseLoadController setState()或markNeedsBuild()

Flutter 在生成期间调用PagewiseLoadController setState()或markNeedsBuild(),flutter,dart,Flutter,Dart,我使用的是flatter_页面依赖 class _TagImagesScreenState extends State<TagImagesScreenState> { @override Widget build(BuildContext context) { return Scaffold( body: Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment:

我使用的是flatter_页面依赖

class _TagImagesScreenState extends State<TagImagesScreenState> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        mainAxisSize: MainAxisSize.min,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          ...,
          PageWiseMemeList(widget.tag)
        ],
      ),
     );
最后实现了_buildMemeGridItem

  Widget _buildMemeGridItem(BuildContext context, DocumentSnapshot document) {
    @override
    Widget build(BuildContext context) {
      MemeFile meme = MemeFile.fromMap(document.data, document.documentID);

      return Container(
        child: GestureDetector(
          onLongPress: () {
            MemeShare().shareFile(meme);
          },
          onTap: () {
            Navigator.pushNamed(context, '/image_view',
                arguments: ImageViewerArguments(meme));
          },
          child: FadeInImage(
            fit: BoxFit.cover,
            placeholder: AssetImage('assets/images/placeholder.jpg'),
            image: CacheImage(meme.getGsPath()),
          ),
        ),
        padding: EdgeInsets.all(2.0),
      );
    }
  }
}

现在,当我尝试执行此代码时,总是会出现以下错误:

════════ Exception caught by foundation library ════════════════════════════════════════════════════
The following assertion was thrown while dispatching notifications for PagewiseLoadController<dynamic>:
setState() or markNeedsBuild() called during build.

This PagewiseGridView<dynamic> 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. This exception is allowed because the framework builds parent widgets before children, which means a dirty descendant will always be built. Otherwise, the framework might not visit this widget during this build phase.
The widget on which setState() or markNeedsBuild() was called was: PagewiseGridView<dynamic>
  state: PagewiseState<dynamic>#0fea7
The widget which was currently being built when the offending call was made was: SliverGrid
  delegate: SliverChildBuilderDelegate#1454c(estimated child count: 1)
  renderObject: RenderSliverGrid#bc245 relayoutBoundary=up2 NEEDS-LAYOUT NEEDS-PAINT
When the exception was thrown, this was the stack: 
#0      Element.markNeedsBuild.<anonymous closure> (package:flutter/src/widgets/framework.dart:3896:11)
#1      Element.markNeedsBuild (package:flutter/src/widgets/framework.dart:3911:6)
#2      State.setState (package:flutter/src/widgets/framework.dart:1168:14)
#3      PagewiseState.initState.<anonymous closure> (package:flutter_pagewise/flutter_pagewise.dart:201:39)
#4      ChangeNotifier.notifyListeners (package:flutter/src/foundation/change_notifier.dart:206:21)
...
The PagewiseLoadController<dynamic> sending notification was: Instance of 'PagewiseLoadController<dynamic>'
════════ 基金会例外════════════════════════════════════════════════════
为PagewiseLoadController发送通知时引发了以下断言:
在生成过程中调用setState()或markNeedsBuild()。
无法将此PagewiseGridView小部件标记为需要构建,因为框架已经在构建小部件的过程中。只有当一个小部件的祖先当前正在构建时,才可以将其标记为需要在构建阶段构建。此异常是允许的,因为框架在子部件之前构建父部件,这意味着将始终构建脏子部件。否则,框架可能不会在构建阶段访问此小部件。
调用setState()或markNeedsBuild()的小部件是:PagewiseGridView
状态:PagewiseState#0fea7
当发出有问题的调用时,当前正在构建的小部件是:SliverGrid
代表:SliverChildBuilderDelegate#1454c(估计子计数:1)
renderObject:RenderSliverGrid#bc245 relayoutBoundary=up2需要-布局需要-绘制
引发异常时,这是堆栈:
#0 Element.markNeedsBuild。(包:flatter/src/widgets/framework.dart:3896:11)
#1 Element.markNeedsBuild(包:flatter/src/widgets/framework.dart:3911:6)
#2 State.setState(包:flatter/src/widgets/framework.dart:1168:14)
#3 PagewiseState.initState。(套餐:页面颤振/页面颤振。省道:201:39)
#4 ChangeNotifier.notifyListeners(包:flatter/src/foundation/change\u notifier.dart:206:21)
...
发送通知的PagewiseLoadController为:“PagewiseLoadController”的实例
当我尝试调试时,我发现 PagewiseState在initState()中有以下代码

@覆盖
void initState(){
super.initState();
if(widget.pageLoadController==null){
此._controller=PagewiseLoadController(
pageFuture:widget.pageFuture,pageSize:widget.pageSize);
}
这是._effectiveController.init();
这个._controllerListener=(()=>setState((){}));
this.\u effectiveController.addListener(this.\u controllerListener);
}
不确定这是否是问题所在,但可能会有所帮助,第201行是:
this.\u controllerListener=(()=>setState((){}))

flatter\u pagewise.dart:201:39
-文件第201行第39列中有什么?这是我在项目中使用的颤振组件:this.\u controllerListener=(()=>setState((){}))
════════ Exception caught by foundation library ════════════════════════════════════════════════════
The following assertion was thrown while dispatching notifications for PagewiseLoadController<dynamic>:
setState() or markNeedsBuild() called during build.

This PagewiseGridView<dynamic> 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. This exception is allowed because the framework builds parent widgets before children, which means a dirty descendant will always be built. Otherwise, the framework might not visit this widget during this build phase.
The widget on which setState() or markNeedsBuild() was called was: PagewiseGridView<dynamic>
  state: PagewiseState<dynamic>#0fea7
The widget which was currently being built when the offending call was made was: SliverGrid
  delegate: SliverChildBuilderDelegate#1454c(estimated child count: 1)
  renderObject: RenderSliverGrid#bc245 relayoutBoundary=up2 NEEDS-LAYOUT NEEDS-PAINT
When the exception was thrown, this was the stack: 
#0      Element.markNeedsBuild.<anonymous closure> (package:flutter/src/widgets/framework.dart:3896:11)
#1      Element.markNeedsBuild (package:flutter/src/widgets/framework.dart:3911:6)
#2      State.setState (package:flutter/src/widgets/framework.dart:1168:14)
#3      PagewiseState.initState.<anonymous closure> (package:flutter_pagewise/flutter_pagewise.dart:201:39)
#4      ChangeNotifier.notifyListeners (package:flutter/src/foundation/change_notifier.dart:206:21)
...
The PagewiseLoadController<dynamic> sending notification was: Instance of 'PagewiseLoadController<dynamic>'
 @override
  void initState() {
    super.initState();

    if (widget.pageLoadController == null) {
      this._controller = PagewiseLoadController<T>(
          pageFuture: widget.pageFuture, pageSize: widget.pageSize);
    }

    this._effectiveController.init();

    this._controllerListener = (() => setState(() {}));

    this._effectiveController.addListener(this._controllerListener);
  }