Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
562 views
in Technique[技术] by (71.8m points)

flutter - pageview inside Singlechildscrollview

I am trying to put a pageview in a singlechildscrollview returned by a dragablescrollablesheet so that it begins from the half of the screen, can scroll from the bottom to the top of the screen by the singlechildscrollview and also scroll horizontally by the pageview. Here is the code:

DraggableScrollableSheet(
        initialChildSize: 0.4,
          minChildSize: 0.399,
          builder: (context,scrollcontroller) {
            return SingleChildScrollView(
            controller: scrollcontroller,
              scrollDirection: Axis.vertical,
              child: PageView(
                    scrollDirection: Axis.horizontal,
                            children:[
                                Container(
                                  padding: EdgeInsets.only(top:MediaQuery.of(context).size.height/2),
                                  decoration: BoxDecoration(
                                      borderRadius: const BorderRadius.only(
                                        bottomLeft: Radius.circular(80.0),
                                        topRight: Radius.circular(80.0),
                                      ),
                                      color: Colors.red
                                  ),
                                  height: MediaQuery.of(context).size.height,
                                  width:  MediaQuery.of(context).size.width,
                                ),
                                Container(
                                  decoration: BoxDecoration(
                                      borderRadius: const BorderRadius.only(
                                        bottomLeft: Radius.circular(80.0),
                                        topRight: Radius.circular(80.0),
                                      ),
                                      color: Colors.deepOrange
                                  ),
                                  height: MediaQuery.of(context).size.height,
                                  width:  MediaQuery.of(context).size.width,
                                ),
                                Container(
                                  decoration: BoxDecoration(
                                      borderRadius: const BorderRadius.only(
                                        bottomLeft: Radius.circular(80.0),
                                        topRight: Radius.circular(80.0),
                                      ),
                                      color: Colors.black
                                  ),
                                  height: MediaQuery.of(context).size.height,
                                  width:  MediaQuery.of(context).size.width,
                                ),
                          ]
                          )
            );
        }
      )

but this error occures:

======== 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:///C:/Users/georg/AndroidStudioProjects/flutter_app/lib/UI/welcome.dart:97:26
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#bea84 relayoutBoundary=up5 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...  parentData: <none> (can use size)
...  constraints: BoxConstraints(w=411.4, 0.0<=h<=Infinity)
...  size: MISSING
...  behavior: deferToChild
...  listeners: signal
RenderObject: RenderPointerListener#bea84 relayoutBoundary=up5 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
  parentData: <none> (can use size)
  constraints: BoxConstraints(w=411.4, 0.0<=h<=Infinity)
  size: MISSING
  behavior: deferToChild
  listeners: signal
...  child: RenderSemanticsGestureHandler#081a5 relayoutBoundary=up6 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...    parentData: <none> (can use size)
...    constraints: BoxConstraints(w=411.4, 0.0<=h<=Infinity)
...    size: MISSING
...    gestures: <none>
...    child: RenderPointerListener#489ba relayoutBoundary=up7 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      parentData: <none> (can use size)
...      constraints: BoxConstraints(w=411.4, 0.0<=h<=Infinity)
...      size: MISSING
...      behavior: opaque
...      listeners: down
...      child: RenderSemanticsAnnotations#21d33 relayoutBoundary=up8 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...        parentData: <none> (can use size)
...        constraints: BoxConstraints(w=411.4, 0.0<=h<=Infinity)
...        size: MISSING
...        child: RenderIgnorePointer#10f37 relayoutBoundary=up9 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...          parentData: <none> (can use size)
...          constraints: BoxConstraints(w=411.4, 0.0<=h<=Infinity)
...          size: MISSING
...          ignoring: false
...          ignoringSemantics: false
====================================================================================================

======== Exception caught by rendering library =====================================================
RenderBox was not laid out: RenderPointerListener#bea84 relayoutBoundary=up5 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1785 pos 12: 'hasSize'
The relevant error-causing widget was: 
  PageView file:///C:/Users/georg/AndroidStudioProjects/flutter_app/lib/UI/welcome.dart:97:26
====================================================================================================

======== Exception caught by rendering library =====================================================
RenderBox was not laid out: _RenderScrollSemantics#99f96 relayoutBoundary=up4 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1785 pos 12: 'hasSize'
The relevant error-causing widget was: 
  PageView file:///C:/Users/georg/AndroidStudioProjects/flutter_app/lib/UI/welcome.dart:97:26
====================================================================================================

======== Exception caught by rendering library =====================================================
RenderBox was not laid out: RenderRepaintBoundary#7030a relayoutBoundary=up3 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1785 pos 12: 'hasSize'
The relevant error-causing widget was: 
  PageView file:///C:/Users/georg/AndroidStudioProjects/flutter_app/lib/UI/welcome.dart:97:26
====================================================================================================

======== Exception caught by rendering library =====================================================
RenderBox was not laid out: RenderCustomPaint#adaca relayoutBoundary=up2 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1785 pos 12: 'hasSize'
The relevant error-causing widget was: 
  PageView file:///C:/Users/georg/AndroidStudioProjects/flutter_app/lib/UI/welcome.dart:97:26
====================================================================================================

======== Exception caught by rendering library =====================================================
RenderBox was not laid out: RenderRepaintBoundary#40087 relayoutBoundary=up1 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1785 pos 12: 'hasSize'
The relevant error-causing widget was: 
  SingleChildScrollView file:///C:/Users/georg/AndroidStudioProjects/flutter_app/lib/UI/welcome.dart:94:24
====================================================================================================

======== Exception caught by rendering library =====================================================
RenderBox was not laid out: _RenderSingleChildViewport#15c06 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1785 pos 12: 'hasSize'
The relevant error-causing widget was: 
  SingleChildScrollView file:///C:/Users/georg/AndroidStudioProjects/flutter_app/lib/UI/welcome.dart:94:24
====================================================================================================

======== Exception caught by rendering library =====================================================
RenderBox was not laid out: RenderIgnorePointer#004d6 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1785 pos 12: 'hasSize'
The relevant error-causing widget was: 
  SingleChildScrollView file:///C:/Users/georg/AndroidStudioProjects/flutter_app/lib/UI/welcome.dart:94:24
====================================================================================================

======== Exception caught by rendering library =====================================================
RenderBox was not laid out: RenderSemanticsAnnotations#601ea NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1785 pos 12: 'hasSize'
The relevant error-causing widget was: 
  SingleChildScrollView file:///C:/Users/georg/AndroidStudioProjects/flutter_app/lib/UI/welcome.dart:94:24
====================================================================================================

======== Exception caught by rendering library =====================================================
RenderBox was not laid out: RenderPointerListener#a0a1e NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1785 pos 12: 'hasSize'
The relevant error-causing widget was: 
  SingleChildScrollView file:///C:/Users/georg/AndroidStudioProjects/flutter_app/lib/UI/welcome.dart:94:24
====================================================================================================

======== Exception caught by rendering library =====================================================
RenderBox was not laid out: RenderSemanticsGestureHandler#bd3e8 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1785 pos 12: 'hasSize'
The relevant error-causing widget was: 
  SingleChildScrollView file:///C:/Users/georg/AndroidStudioProjects/flutter_app/lib/UI/welcome.dart:94:24
====================================================================================================

======== Exception caught by rendering library =====================================================
RenderBox was not laid out: RenderPointerListener#065b1 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1785 pos 12: 'hasSize'
The relevant error-causing widget was: 
  SingleChildScrollView file:///C:/Users/georg/AndroidStudioProjects/flutter_app/lib/UI/welcome.dart:94:24
=================================================================================================

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Thank you all it worked for me just by wrapping the page view in a container with fixed hight


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...