在 SingleChildScrollView 中使用扩展的网页浏览

时间:2021-06-15 03:51:20

标签: flutter dart flutter-layout

我正在尝试创建一个小部件,其中包含一个 SingleChildScrollView 并且在其中包含一个具有扩展页面视图的列。

 Widget build(BuildContext context) {
    return Container(
      // padding: EdgeInsets.only(bottom: 90),
      color: Color(0xffF5F5F5),
      child: Column(
        children: [
          topBar(context),
          Expanded(
            child: Scaffold(
              body: SingleChildScrollView(
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Container(
                      padding: EdgeInsets.only(left: 15),
                      child: TitlesPageView(
                        height: 70,
                        controller: controller,
                        hasgradient: true,
                        titles: [
                          "Geral",
                          "Endereço",
                          "Contatos",
                          "Rede Sociais",
                          "Observações",
                          "Campos Customizados",
                          "Outras Informações"
                        ],
                      ),
                    ),
                    Flexible(
                      child: PageView(
                          controller: controller,
                          children:[Geral(conta: widget.conta)]),
                    ),
                  ],
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }

但由于某种原因,我收到了这个错误:

======== Exception caught by rendering library =====================================================
The following NoSuchMethodError was thrown during performLayout():
The method 'toStringAsFixed' was called on null.
Receiver: null
Tried calling: toStringAsFixed(1)

The relevant error-causing widget was: 
  PageView file:///home/vitor/Documents/Codigo_Font/GetCRM/getcrm/lib/src/Bills/ui/details.dart:103:30
When the exception was thrown, this was the stack: 
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1      ViewportOffset.debugFillDescription (package:flutter/src/rendering/viewport_offset.dart:248:39)
#2      ScrollPosition.debugFillDescription (package:flutter/src/widgets/scroll_position.dart:896:11)
#3      ScrollPositionWithSingleContext.debugFillDescription (package:flutter/src/widgets/scroll_position_with_single_context.dart:261:11)
#4      ViewportOffset.toString (package:flutter/src/rendering/viewport_offset.dart:233:5)
...
The following RenderObject was being processed when the exception was fired: RenderPointerListener#7148b relayoutBoundary=up19 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...  parentData: <none> (can use size)
...  constraints: BoxConstraints(0.0<=w<=392.7, 0.0<=h<=Infinity)
...  size: MISSING
...  behavior: deferToChild
...  listeners: signal
RenderObject: RenderPointerListener#7148b relayoutBoundary=up19 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
  parentData: <none> (can use size)
  constraints: BoxConstraints(0.0<=w<=392.7, 0.0<=h<=Infinity)
  size: MISSING
  behavior: deferToChild
  listeners: signal
...  child: RenderSemanticsGestureHandler#4a224 relayoutBoundary=up20 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...    parentData: <none> (can use size)
...    constraints: BoxConstraints(0.0<=w<=392.7, 0.0<=h<=Infinity)
...    size: MISSING
...    gestures: <none>
...    child: RenderPointerListener#3445a relayoutBoundary=up21 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      parentData: <none> (can use size)
...      constraints: BoxConstraints(0.0<=w<=392.7, 0.0<=h<=Infinity)
...      size: MISSING
...      behavior: opaque
...      listeners: down
...      child: RenderSemanticsAnnotations#f4663 relayoutBoundary=up22 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...        parentData: <none> (can use size)
...        constraints: BoxConstraints(0.0<=w<=392.7, 0.0<=h<=Infinity)
...        size: MISSING
...        child: RenderIgnorePointer#b52c5 relayoutBoundary=up23 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...          parentData: <none> (can use size)
...          constraints: BoxConstraints(0.0<=w<=392.7, 0.0<=h<=Infinity)
...          size: MISSING
...          ignoring: false
...          ignoringSemantics: false
====================================================================================================

======== Exception caught by rendering library =====================================================
The following assertion was thrown during performLayout():
RenderBox was not laid out: RenderPointerListener#7148b relayoutBoundary=up19 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1785 pos 12: 'hasSize'


Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=BUG.md

The relevant error-causing widget was: 
  PageView file:///home/vitor/Documents/Codigo_Font/GetCRM/getcrm/lib/src/Bills/ui/details.dart:103:30
When the exception was thrown, this was the stack: 
#2      RenderBox.size (package:flutter/src/rendering/box.dart:1785:12)
#3      RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:114:21)
#4      RenderObject.layout (package:flutter/src/rendering/object.dart:1777:7)
#5      RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:113:14)
#6      RenderObject.layout (package:flutter/src/rendering/object.dart:1777:7)
...
The following RenderObject was being processed when the exception was fired: _RenderScrollSemantics#cdbe2 relayoutBoundary=up18 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...  parentData: <none> (can use size)
...  constraints: BoxConstraints(0.0<=w<=392.7, 0.0<=h<=Infinity)
...  semantic boundary
...  size: MISSING
RenderObject: _RenderScrollSemantics#cdbe2 relayoutBoundary=up18 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
  parentData: <none> (can use size)
  constraints: BoxConstraints(0.0<=w<=392.7, 0.0<=h<=Infinity)
  semantic boundary
  size: MISSING
...  child: RenderPointerListener#7148b relayoutBoundary=up19 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...    parentData: <none> (can use size)
...    constraints: BoxConstraints(0.0<=w<=392.7, 0.0<=h<=Infinity)
...    size: MISSING
...    behavior: deferToChild
...    listeners: signal
...    child: RenderSemanticsGestureHandler#4a224 relayoutBoundary=up20 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      parentData: <none> (can use size)
...      constraints: BoxConstraints(0.0<=w<=392.7, 0.0<=h<=Infinity)
...      size: MISSING
...      gestures: <none>
...      child: RenderPointerListener#3445a relayoutBoundary=up21 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...        parentData: <none> (can use size)
...        constraints: BoxConstraints(0.0<=w<=392.7, 0.0<=h<=Infinity)
...        size: MISSING
...        behavior: opaque
...        listeners: down
...        child: RenderSemanticsAnnotations#f4663 relayoutBoundary=up22 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...          parentData: <none> (can use size)
...          constraints: BoxConstraints(0.0<=w<=392.7, 0.0<=h<=Infinity)
...          size: MISSING
====================================================================================================

我已经尝试将 SingleChildScrollView 包装在 LayoutBuilder 中,比如建议答案 https://stackoverflow.com/a/56327933/11099584,但这对我也不起作用。

1 个答案:

答案 0 :(得分:0)

用具有首选大小的容器包装 SingleChildScrollView 小部件,例如Container(width: 300, height: 300, child: /some widget) 而不是“300”,您可以写 MediaQuery.of(context).size.width 以使用设备宽度/高度。

相关问题