【问题标题】:SingleChildScrollView is not working anywhereSingleChildScrollView 在任何地方都不起作用
【发布时间】:2021-09-07 20:22:45
【问题描述】:

为了修复Bottom Overflow 错误,我正在尝试使用SingleChildScrollView 小部件。我尝试将其包装到 ColumnScaffold,但错误很多。

以下是导致错误的代码:


class SignUp extends StatefulWidget {

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

class _SignUpState extends State<SignUp> {
  final formKey = GlobalKey<FormState>();

  final TextEditingController nameController = TextEditingController();
  final TextEditingController emailController = TextEditingController();
  final TextEditingController passwordController = TextEditingController();

  final nameNode = FocusNode();
  final emailNode = FocusNode();
  final passwordNode = FocusNode();

  bool isLoading = false;

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    nameController.dispose();
    emailController.dispose();
    passwordController.dispose();
    nameNode.dispose();
    emailNode.dispose();
    passwordNode.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    final isKeyboard = MediaQuery.of(context).viewInsets.bottom != 0;

    final appBar = AppBar(
      iconTheme: Theme.of(context).iconTheme,
      backgroundColor: Colors.transparent,
      leading: CustomBackButton(
        onPressed: () => print('Back Button Tapped'),
      ),
    );

    // ***** Checking for current Theme Mode *****
    var brightness = Theme.of(context).brightness;
    bool darkModeOn = brightness == Brightness.dark;

    return KeyboardDismisser(
      gestures: [
        GestureType.onTap,
        GestureType.onVerticalDragDown,
      ],
      child: Scaffold(
        resizeToAvoidBottomInset: false,
        appBar: isLoading ? null : appBar,
        body: SafeArea(
          child: Form(
            key: formKey,
            child: AutofillGroup(
              child: Center(
                child: SingleChildScrollView(
                  child: Padding(
                    padding: EdgeInsets.symmetric(horizontal: 5.w),
                    child: Column(
                      children: [
                        SizedBox(height: 2.h),
                        if (!isKeyboard) BuildHeader(title: 'Welcome Onboard'),
                        if (!isKeyboard) SizedBox(height: 2.5.h),
                        BuildNameField(nameController: nameController, nameNode: nameNode, emailNode: emailNode),
                        SizedBox(height: 2.5.h),
                        BuildEmailField(emailController: emailController, emailNode: emailNode, passwordNode: passwordNode),
                        SizedBox(height: 2.5.h),
                        BuildPasswordField(passwordController: passwordController, passwordNode: passwordNode),
                        SizedBox(height: 2.5.h),
                        buildEmailSignUpButton(),
                        SizedBox(height: 2.h),
                        BuildAccountExistsButton(),
                        Spacer(),
                        BuildDividerRow(darkModeOn: darkModeOn),
                        Spacer(),
                        buildGoogleSignUpButton(darkModeOn),
                        SizedBox(height: 3.h),
                        buildAppleSignUpButton(darkModeOn),
                        Spacer(),
                        BuildFooter(),
                      ],
                    ),
                  ),
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }

我收到以下错误,我不得不截断很多错误,因为它超过了允许的限制:

======== Exception caught by rendering library =====================================================
The following assertion was thrown during performLayout():
RenderFlex children have non-zero flex but incoming height constraints are unbounded.

When a column is in a parent that does not provide a finite height constraint, for example if it is in a vertical scrollable, it will try to shrink-wrap its children along the vertical axis. Setting a flex on a child (e.g. using Expanded) indicates that the child is to expand to fill the remaining space in the vertical direction.
These two directives are mutually exclusive. If a parent is to shrink-wrap its child, the child cannot simultaneously expand to fit its parent.

Consider setting mainAxisSize to MainAxisSize.min and using FlexFit.loose fits for the flexible children (using Flexible rather than Expanded). This will allow the flexible children to size themselves to less than the infinite remaining space they would otherwise be forced to take, and then will cause the RenderFlex to shrink-wrap the children rather than expanding to fit the maximum constraints provided by the parent.

If this message did not help you determine the problem, consider using debugDumpRenderTree():
  https://flutter.dev/debugging/#rendering-layer
  http://api.flutter.dev/flutter/rendering/debugDumpRenderTree.html
The affected RenderFlex is: RenderFlex#6b876 relayoutBoundary=up14 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
  needs compositing
  parentData: offset=Offset(20.6, 0.0) (can use size)
  constraints: BoxConstraints(0.0<=w<=370.3, 0.0<=h<=Infinity)
  size: MISSING
  direction: vertical
  mainAxisAlignment: start
  mainAxisSize: max
  crossAxisAlignment: center
  verticalDirection: down
...  child 1: RenderConstrainedBox#b86cb NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...    parentData: offset=Offset(0.0, 0.0); flex=null; fit=null
...    constraints: MISSING
...    size: MISSING
...    additionalConstraints: BoxConstraints(0.0<=w<=Infinity, h=13.7)
...  child 2: RenderPositionedBox#4f180 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...    parentData: offset=Offset(0.0, 0.0); flex=null; fit=null
...    constraints: MISSING
...    size: MISSING
...    alignment: Alignment.centerLeft
...    textDirection: ltr
...    widthFactor: expand
...    heightFactor: expand
...    child: RenderParagraph#eb54e NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      parentData: offset=Offset(0.0, 0.0)
...      constraints: MISSING
...      size: MISSING
...      textAlign: start
...      textDirection: ltr
...      softWrap: wrapping at box width
...      overflow: clip
...      locale: en_US
...      maxLines: unlimited
...      text: TextSpan
...        debugLabel: (((englishLike display1 2014).merge(blackMountainView headline4)).copyWith).copyWith
...        inherit: false
...        color: Color(0x8a000000)
...        family: Roboto_700
...        familyFallback: Roboto
...        size: 27.4
...        weight: 700
...        baseline: alphabetic
...        decoration: TextDecoration.none
...        "Welcome Onboard"
...  child 3: RenderConstrainedBox#20957 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...    parentData: offset=Offset(0.0, 0.0); flex=null; fit=null
...    constraints: MISSING
...    size: MISSING
...    additionalConstraints: BoxConstraints(0.0<=w<=Infinity, h=17.1)
...  child 4: RenderConstrainedBox#dede6 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...    needs compositing
...    parentData: offset=Offset(0.0, 0.0); flex=null; fit=null
...    constraints: MISSING
...    size: MISSING
...    additionalConstraints: BoxConstraints(w=370.3, 0.0<=h<=Infinity)
...    child: RenderMouseRegion#22641 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      needs compositing
...      parentData: <none>
...      constraints: MISSING
...      size: MISSING
...      listeners: enter, exit
...      cursor: SystemMouseCursor(text)
...      child: RenderIgnorePointer#749a8 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...        needs compositing
...        parentData: <none>
...        constraints: MISSING
...        size: MISSING
...        ignoring: false
...        ignoringSemantics: implicitly false
...        child: RenderSemanticsAnnotations#40667 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...          needs compositing
...          parentData: <none>
...          constraints: MISSING
...          size: MISSING
...  child 5: RenderConstrainedBox#67979 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...    parentData: offset=Offset(0.0, 0.0); flex=null; fit=null
...    constraints: MISSING
...    size: MISSING
...    additionalConstraints: BoxConstraints(0.0<=w<=Infinity, h=17.1)
...  child 6: RenderConstrainedBox#97d0d NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...    needs compositing
...    parentData: offset=Offset(0.0, 0.0); flex=null; fit=null
...    constraints: MISSING
...    size: MISSING
...    additionalConstraints: BoxConstraints(w=370.3, 0.0<=h<=Infinity)
...    child: RenderMouseRegion#7eeba NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      needs compositing
...      parentData: <none>
...      constraints: MISSING
...      size: MISSING
...      listeners: enter, exit
...      cursor: SystemMouseCursor(text)
...      child: RenderIgnorePointer#01dea NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...        needs compositing
...        parentData: <none>
...        constraints: MISSING
...        size: MISSING
...        ignoring: false
...        ignoringSemantics: implicitly false
...        child: RenderSemanticsAnnotations#e03be NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...          needs compositing
...          parentData: <none>
...          constraints: MISSING
...          size: MISSING
...  child 7: RenderConstrainedBox#a5e4d NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...    parentData: offset=Offset(0.0, 0.0); flex=null; fit=null
...    constraints: MISSING
...    size: MISSING
...    additionalConstraints: BoxConstraints(0.0<=w<=Infinity, h=17.1)
...  child 8: RenderConstrainedBox#2f682 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...    needs compositing
...    parentData: offset=Offset(0.0, 0.0); flex=null; fit=null
...    constraints: MISSING
...    size: MISSING
...    additionalConstraints: BoxConstraints(w=370.3, 0.0<=h<=Infinity)
...    child: RenderMouseRegion#bcb98 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      needs compositing
...      parentData: <none>
...      constraints: MISSING
...      size: MISSING
...      listeners: enter, exit
...      cursor: SystemMouseCursor(text)
...      child: RenderIgnorePointer#f66bd NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...        needs compositing
...        parentData: <none>
...        constraints: MISSING
...        size: MISSING
...        ignoring: false
...        ignoringSemantics: implicitly false
...        child: RenderSemanticsAnnotations#7e929 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...          needs compositing
...          parentData: <none>
...          constraints: MISSING
...          size: MISSING
...  child 9: RenderConstrainedBox#1714f NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...    parentData: offset=Offset(0.0, 0.0); flex=null; fit=null
...    constraints: MISSING
...    size: MISSING
...    additionalConstraints: BoxConstraints(0.0<=w<=Infinity, h=17.1)
...    child 1: RenderConstrainedBox#3498e NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      parentData: offset=Offset(0.0, 0.0); flex=1; fit=FlexFit.tight
...      constraints: MISSING
...      size: MISSING
...      additionalConstraints: BoxConstraints(0.0<=w<=Infinity, h=0.0)
...      child: RenderPositionedBox#1b64a NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...        parentData: <none>
...        constraints: MISSING
...        size: MISSING
...        alignment: Alignment.center
...        textDirection: ltr
...        widthFactor: expand
...        heightFactor: expand
...        child: RenderPadding#eb6fd NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...          parentData: offset=Offset(0.0, 0.0)
...          constraints: MISSING
...          size: MISSING
...          padding: EdgeInsets.zero
...          textDirection: ltr
...    child 2: RenderConstrainedBox#eb389 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      parentData: offset=Offset(0.0, 0.0); flex=null; fit=null
...      constraints: MISSING
...      size: MISSING
...      additionalConstraints: BoxConstraints(w=20.6, 0.0<=h<=Infinity)
...    child 3: RenderParagraph#93a61 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      parentData: offset=Offset(0.0, 0.0); flex=null; fit=null
...      constraints: MISSING
...      size: MISSING
...      textAlign: start
...      textDirection: ltr
...      softWrap: wrapping at box width
...      overflow: clip
...      locale: en_US
...      maxLines: unlimited
...      text: TextSpan
...        debugLabel: ((englishLike body1 2014).merge(blackMountainView bodyText2)).merge(unknown)
...        inherit: false
...        color: Color(0xdd000000)
...        family: Roboto
...        size: 16.5
...        weight: 500
...        baseline: alphabetic
...        decoration: TextDecoration.none
...        "OR"
...    child 4: RenderConstrainedBox#50550 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      parentData: offset=Offset(0.0, 0.0); flex=null; fit=null
...      constraints: MISSING
...      size: MISSING
...      additionalConstraints: BoxConstraints(w=20.6, 0.0<=h<=Infinity)
...    child 5: RenderConstrainedBox#2a7e1 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      parentData: offset=Offset(0.0, 0.0); flex=1; fit=FlexFit.tight
...      constraints: MISSING
...      size: MISSING
...      additionalConstraints: BoxConstraints(0.0<=w<=Infinity, h=0.0)
...      child: RenderPositionedBox#0e343 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...        parentData: <none>
...        constraints: MISSING
...        size: MISSING
...        alignment: Alignment.center
...        textDirection: ltr
...        widthFactor: expand
...        heightFactor: expand
...        child: RenderPadding#afb85 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...          parentData: offset=Offset(0.0, 0.0)
...          constraints: MISSING
...          size: MISSING
...          padding: EdgeInsets.zero
...          textDirection: ltr
...  child 15: RenderConstrainedBox#451dd NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...    parentData: offset=Offset(0.0, 0.0); flex=1; fit=FlexFit.tight
...    constraints: MISSING
...    size: MISSING
...    additionalConstraints: BoxConstraints(w=0.0, h=0.0)
...    child 1: RenderParagraph#19d0c NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      parentData: offset=Offset(0.0, 0.0); flex=null; fit=null
...      constraints: MISSING
...      size: MISSING
...      textAlign: center
...      textDirection: ltr
...      softWrap: wrapping at box width
...      overflow: clip
...      locale: en_US
...      maxLines: unlimited
...      text: TextSpan
...        debugLabel: ((englishLike body1 2014).merge(blackMountainView bodyText2)).merge(unknown)
...        inherit: false
...        color: Color(0xbf000000)
...        family: Roboto
...        size: 13.7
...        weight: 400
...        baseline: alphabetic
...        decoration: TextDecoration.none
...        "By using Netwersity you agree to it's"
...    child 2: RenderConstrainedBox#e36ee NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      parentData: offset=Offset(0.0, 0.0); flex=null; fit=null
...      constraints: MISSING
...      size: MISSING
...      additionalConstraints: BoxConstraints(0.0<=w<=Infinity, h=3.4)
...    child 3: RenderFlex#ffd54 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      parentData: offset=Offset(0.0, 0.0); flex=null; fit=null
...      constraints: MISSING
...      size: MISSING
...      direction: horizontal
...      mainAxisAlignment: center
...      mainAxisSize: max
...      crossAxisAlignment: center
...      textDirection: ltr
...      verticalDirection: down
...      child 1: RenderSemanticsGestureHandler#bd90f NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...        parentData: offset=Offset(0.0, 0.0); flex=null; fit=null
...        constraints: MISSING
...        size: MISSING
...        behavior: deferToChild
...        gestures: tap
...        child: RenderPointerListener#43b96 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...          parentData: <none>
...          constraints: MISSING
...          size: MISSING
...          behavior: deferToChild
...          listeners: down
...      child 2: RenderConstrainedBox#a0757 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...        parentData: offset=Offset(0.0, 0.0); flex=null; fit=null
...        constraints: MISSING
...        size: MISSING
...        additionalConstraints: BoxConstraints(w=4.1, 0.0<=h<=Infinity)
...      child 3: RenderParagraph#55e37 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...        parentData: offset=Offset(0.0, 0.0); flex=null; fit=null
...        constraints: MISSING
...        size: MISSING
...        textAlign: center
...        textDirection: ltr
...        softWrap: wrapping at box width
...        overflow: clip
...        locale: en_US
...        maxLines: unlimited
...        text: TextSpan
...          debugLabel: ((englishLike body1 2014).merge(blackMountainView bodyText2)).merge(unknown)
...          inherit: false
...          color: Color(0xbf000000)
...          family: Roboto
...          size: 13.7
...          weight: 400
...          baseline: alphabetic
...          decoration: TextDecoration.none
...          "and"
...      child 4: RenderConstrainedBox#fac5c NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...        parentData: offset=Offset(0.0, 0.0); flex=null; fit=null
...        constraints: MISSING
...        size: MISSING
...        additionalConstraints: BoxConstraints(w=4.1, 0.0<=h<=Infinity)
...      child 5: RenderSemanticsGestureHandler#52395 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...        parentData: offset=Offset(0.0, 0.0); flex=null; fit=null
...        constraints: MISSING
...        size: MISSING
...        behavior: deferToChild
...        gestures: tap
...        child: RenderPointerListener#92253 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...          parentData: <none>
...          constraints: MISSING
...          size: MISSING
...          behavior: deferToChild
...          listeners: down
...    child 4: RenderConstrainedBox#b1d09 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      parentData: offset=Offset(0.0, 0.0); flex=null; fit=null
...      constraints: MISSING
...      size: MISSING
...      additionalConstraints: BoxConstraints(0.0<=w<=Infinity, h=13.7)
The creator information is set to: Column ← Padding ← _SingleChildViewport ← IgnorePointer-[GlobalKey#13af8] ← Semantics ← Listener ← _GestureSemantics ← RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#94304] ← Listener ← _ScrollableScope ← _ScrollSemantics-[GlobalKey#6bebf] ← RepaintBoundary ← ⋯
The nearest ancestor providing an unbounded width constraint is: _RenderSingleChildViewport#cf013 relayoutBoundary=up12 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...  needs compositing
...  parentData: <none> (can use size)
...  constraints: BoxConstraints(0.0<=w<=411.4, 0.0<=h<=603.4)
...  size: MISSING

See also: https://flutter.dev/layout/

If none of the above helps enough to fix this problem, please don't hesitate to file a bug:
  https://github.com/flutter/flutter/issues/new?template=2_bug.md
The relevant error-causing widget was: 
  Column file:///Users/sas/Projects/Development/App/Flutter/my_app/lib/screens/sign_up.dart:81:28
When the exception was thrown, this was the stack: 
#0      RenderFlex.performLayout.<anonymous closure> (package:flutter/src/rendering/flex.dart:926:9)
#1      RenderFlex.performLayout (package:flutter/src/rendering/flex.dart:929:6)
#2      RenderObject.layout (package:flutter/src/rendering/object.dart:1779:7)
#3      RenderPadding.performLayout (package:flutter/src/rendering/shifted_box.dart:233:12)
#4      RenderObject.layout (package:flutter/src/rendering/object.dart:1779:7)
...
The following RenderObject was being processed when the exception was fired: RenderFlex#6b876 relayoutBoundary=up14 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...  needs compositing
...  parentData: offset=Offset(20.6, 0.0) (can use size)
...  constraints: BoxConstraints(0.0<=w<=370.3, 0.0<=h<=Infinity)
...  size: MISSING
...  direction: vertical
...  mainAxisAlignment: start
...  mainAxisSize: max
...  crossAxisAlignment: center
...  verticalDirection: down
RenderObject: RenderFlex#6b876 relayoutBoundary=up14 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
  needs compositing
  parentData: offset=Offset(20.6, 0.0) (can use size)
  constraints: BoxConstraints(0.0<=w<=370.3, 0.0<=h<=Infinity)
  size: MISSING
  direction: vertical
  mainAxisAlignment: start
  mainAxisSize: max
  crossAxisAlignment: center
  verticalDirection: down
...  child 1: RenderConstrainedBox#b86cb NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...    parentData: offset=Offset(0.0, 0.0); flex=null; fit=null
...    constraints: MISSING
...    size: MISSING
...    additionalConstraints: BoxConstraints(0.0<=w<=Infinity, h=13.7)
...  child 2: RenderPositionedBox#4f180 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...    parentData: offset=Offset(0.0, 0.0); flex=null; fit=null
...    constraints: MISSING
...    size: MISSING
...    alignment: Alignment.centerLeft
...    textDirection: ltr
...    widthFactor: expand
...    heightFactor: expand
...    child: RenderParagraph#eb54e NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      parentData: offset=Offset(0.0, 0.0)
...      constraints: MISSING
...      size: MISSING
...      textAlign: start
...      textDirection: ltr
...      softWrap: wrapping at box width
...      overflow: clip
...      locale: en_US
...      maxLines: unlimited
...      text: TextSpan
...        debugLabel: (((englishLike display1 2014).merge(blackMountainView headline4)).copyWith).copyWith
...        inherit: false
...        color: Color(0x8a000000)
...        family: Roboto_700
...        familyFallback: Roboto
...        size: 27.4
...        weight: 700
...        baseline: alphabetic
...        decoration: TextDecoration.none
...        "Welcome Onboard"
...  child 3: RenderConstrainedBox#20957 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...    parentData: offset=Offset(0.0, 0.0); flex=null; fit=null
...    constraints: MISSING
...    size: MISSING
...    additionalConstraints: BoxConstraints(0.0<=w<=Infinity, h=17.1)
...  child 4: RenderConstrainedBox#dede6 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...    needs compositing
...    parentData: offset=Offset(0.0, 0.0); flex=null; fit=null
...    constraints: MISSING
...    size: MISSING
...    additionalConstraints: BoxConstraints(w=370.3, 0.0<=h<=Infinity)
...    child: RenderMouseRegion#22641 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      needs compositing
...      parentData: <none>
...      constraints: MISSING
...      size: MISSING
...      listeners: enter, exit
...      cursor: SystemMouseCursor(text)
...      child: RenderIgnorePointer#749a8 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...        needs compositing
...        parentData: <none>
...        constraints: MISSING
...        size: MISSING
...        ignoring: false
...        ignoringSemantics: implicitly false
...        child: RenderSemanticsAnnotations#40667 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...          needs compositing
...          parentData: <none>
...          constraints: MISSING
...          size: MISSING
...  child 5: RenderConstrainedBox#67979 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...    parentData: offset=Offset(0.0, 0.0); flex=null; fit=null
...    constraints: MISSING
...    size: MISSING
...    additionalConstraints: BoxConstraints(0.0<=w<=Infinity, h=17.1)

======== Exception caught by rendering library =====================================================
RenderBox was not laid out: RenderPadding#79c8b relayoutBoundary=up13 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1930 pos 12: 'hasSize'
The relevant error-causing widget was: 
  SingleChildScrollView file:///Users/sas/Projects/Development/App/Flutter/my_app/lib/screens/sign_up.dart:78:24
====================================================================================================
.
.
.
======== Exception caught by rendering library =====================================================
RenderBox was not laid out: _RenderSingleChildViewport#cf013 relayoutBoundary=up12 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1930 pos 12: 'hasSize'
The relevant error-causing widget was: 
  SingleChildScrollView file:///Users/sas/Projects/Development/App/Flutter/my_app/lib/screens/sign_up.dart:78:24
====================================================================================================

【问题讨论】:

    标签: flutter dart flutter-layout flutter-dependencies flutter-web


    【解决方案1】:

    终于从这个问题How to use Expanded in SingleChildScrollView?找到了解决这个问题的方法

    这是对我有用的解决方案:

    LayoutBuilder(
      builder: (context, constraint) {
        return SingleChildScrollView(
          child: ConstrainedBox(
            constraints: BoxConstraints(minHeight: constraint.maxHeight),
            child: IntrinsicHeight(
              child: Column(
                children: <Widget>[
                  Text("Header"),
                  Expanded(
                    child: Container(
                      color: Colors.red,
                    ),
                  ),
                  Text("Footer"),
                ],
              ),
            ),
          ),
        );
      },
    )
    

    【讨论】:

    • 虽然测试通过使用上述解决方案发现了一个问题,即验证 TextFormFields 后的错误消息没有显示出来。不知道如何解决这个问题。
    【解决方案2】:

    代码的问题是,Column 尝试收缩包装并适合SingleChildScrollView。但是,您的 Column 小部件可能没有给出异常的有限大小。也许将Column 放在Expanded 小部件中可以考虑溢出(无限长度)并使列可滚动。

    child: SingleChildScrollView(
      child: Padding(
        padding: EdgeInsets.symmetric(horizontal: 5.w),
        child: Expanded(  // This widget is added here
          child: Column(...),
        ),
      ),
    ),
    

    尝试上面的代码很可能会解决您的问题。

    编辑:

    上述解决方案可能无法解决问题。

    以下链接是类似问题的参考,OP 能够解决该问题并添加了相同的答案。

    How to use Expanded in SingleChildScrollView? 类似情况的答案。如果您也检查那里可能会有用。

    【讨论】:

    • 如果您在发布之前运行此代码,您会看到一条错误消息:incorrect use of parent widget Padding 只能在行/列/flex 小部件中使用。而且它也不会解决 OPs 错误。
    • 感谢@immadisairaj 的帮助。但它没有成功。这对我来说就像一场噩梦。
    • 感谢您指出 Huthaifa。我希望@xpetta 查看我在接受的答案中附加的链接,他们使用 MainAxisSize.min 和 FlexFit.loose 使用灵活而不是在列的任何子项中展开可能会解决问题。
    • 感谢您指出链接@immadisairaj,它确实帮助我解决了这个问题。
    【解决方案3】:

    我也发现了同样的问题。

    解决方案:-

    替换

    SingleChildScrollView(
      physics: BouncingScrollPhysics()
                      child: Padding(
                        padding: EdgeInsets.symmetric(horizontal: 5.w),
                        child: ListView(
                          physics: NeverScrollableScrollPhysics(),
    

    SingleChildScrollView(
                  child: Padding(
                    padding: EdgeInsets.symmetric(horizontal: 5.w),
                    child: Column(
    

    它肯定会起作用。

    【讨论】:

    • 感谢 Prashant Vaddoriya 的回答,但它没有用 :(
    • 移除 SingleChildScrollView 并用 ListView 替换列。它应该工作....
    猜你喜欢
    • 2017-01-01
    • 2018-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-04
    • 1970-01-01
    • 2022-08-05
    相关资源
    最近更新 更多