Home > Mobile >  How to hold a paragraph in a container in flutter?
How to hold a paragraph in a container in flutter?

Time:03-20

I am trying to hold the bio of the app user on a Card. The bio could be of any length as I am reading it from API. So I can't add maxlines property of the Text widget. So I did something like the code below.

@override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(Sizes.componentSideMargin),
      child: Card(
        elevation: 7,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(15.0),
        ),
        child: Expanded(
          child: Container(
            padding: const EdgeInsets.all(Sizes.componentSideMargin),
            child: Column(
              mainAxisSize: MainAxisSize.max,
              children: [
                Text("About $name"),
                const SizedBox(
                  height: 12,
                ),
                Expanded(child: Text(bio)),
              ],
            ),
          ),
        ),
      ),
    );
  }

For now, I have passed the below text as 'bio'.

static const LOREM_IPSUM =
      '''Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent nibh justo, ultrices quis mi. Lorem ipsum dolor sit amet consectetur adipisicing elit. Maxime mollitia, molestiae quas vel sint commodi repudiandae consequuntur voluptatum laborum numquam blanditiis harum quisquam eius sed odit fugiat iusto fuga praesentium optio, eaque rerum!''';

But it gave me the below error.

E/flutter ( 7697): #61     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2466:11)
E/flutter ( 7697): #62     RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:131:19)
E/flutter ( 7697): #63     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2466:11)
E/flutter ( 7697): #64     RenderIgnorePointer.hitTest (package:flutter/src/rendering/proxy_box.dart:3317:31)
E/flutter ( 7697): #65     RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:131:19)
E/flutter ( 7697): #66     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2466:11)
E/flutter ( 7697): #67     RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:131:19)
E/flutter ( 7697): #68     RenderFractionalTranslation.hitTestChildren.<anonymous closure> (package:flutter/src/rendering/proxy_box.dart:2775:22)
E/flutter ( 7697): #69     BoxHitTestResult.addWithPaintOffset (package:flutter/src/rendering/box.dart:785:31)
E/flutter ( 7697): #70     RenderFractionalTranslation.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:2769:19)
E/flutter ( 7697): #71     RenderFractionalTranslation.hitTest (package:flutter/src/rendering/proxy_box.dart:2755:12)
E/flutter ( 7697): #72     RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:131:19)
E/flutter ( 7697): #73     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2466:11)
E/flutter ( 7697): #74     RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:131:19)
E/flutter ( 7697): #75     _RenderFocusTrap.hitTest (package:flutter/src/widgets/routes.dart:2141:19)
E/flutter ( 7697): #76     RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:131:19)
E/flutter ( 7697): #77     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2466:11)
E/flutter ( 7697): #78     RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:131:19)
E/flutter ( 7697): #79     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2466:11)
E/flutter ( 7697): #80     RenderOffstage.hitTest (package:flutter/src/rendering/proxy_box.dart:3436:31)
E/flutter ( 7697): #81     RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:131:19)
E/flutter ( 7697): #82     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2466:11)
E/flutter ( 7697): #83     _RenderTheatre.hitTestChildren.<anonymous closure> (package:flutter/src/widgets/overlay.dart:773:25)
E/flutter ( 7697): #84     BoxHitTestResult.addWithPaintOffset (package:flutter/src/rendering/box.dart:785:31)
E/flutter ( 7697): #85     _RenderTheatre.hitTestChildren (package:flutter/src/widgets/overlay.dart:768:33)
E/flutter ( 7697): #86     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2466:11)
E/flutter ( 7697): #87     RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:131:19)
E/flutter ( 7697): #88     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2466:11)
E/flutter ( 7697): #89     RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:131:19)
E/flutter ( 7697): #90     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2466:11)
E/flutter ( 7697): #91     RenderAbsorbPointer.hitTest (package:flutter/src/rendering/proxy_box.dart:3534:17)
E/flutter ( 7697): #92     RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:131:19)
E/flutter ( 7697): #93     RenderProxyBoxWithHitTestBehavior.hitTest (package:flutter/src/rendering/proxy_box.dart:178:19)
E/flutter ( 7697): #94     RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:131:19)
E/flutter ( 7697): #95     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2466:11)
E/flutter ( 7697): #96     RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:131:19)
E/flutter ( 7697): #97     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2466:11)
E/flutter ( 7697): #98     RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:131:19)
E/flutter ( 7697): #99     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2466:11)
E/flutter ( 7697): #100    RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:131:19)
E/flutter ( 7697): #101    RenderBox.hitTest (package:flutter/src/rendering/box.dart:2466:11)
E/flutter ( 7697): #102    RenderView.hitTest (package:flutter/src/rendering/view.dart:185:14)
E/flutter ( 7697): #103    RendererBinding.hitTest (package:flutter/src/rendering/binding.dart:531:16)
E/flutter ( 7697): #104    GestureBinding._handlePointerEventImmediately (package:flutter/src/gestures/binding.dart:346:7)
E/flutter ( 7697): #105    GestureBinding.handlePointerEvent (package:flutter/src/gestures/binding.dart:338:5)
E/flutter ( 7697): #106    GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:296:7)
E/flutter ( 7697): #107    GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:279:7)
E/flutter ( 7697): #108    _rootRunUnary (dart:async/zone.dart:1442:13)
E/flutter ( 7697): #109    _CustomZone.runUnary (dart:async/zone.dart:1335:19)
E/flutter ( 7697): #110    _CustomZone.runUnaryGuarded (dart:async/zone.dart:1244:7)
E/flutter ( 7697): #111    _invoke1 (dart:ui/hooks.dart:170:10)
E/flutter ( 7697): #112    PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:331:7)
E/flutter ( 7697): #113    _dispatchPointerDataPacket (dart:ui/hooks.dart:94:31)
E/flutter ( 7697): 

Please guide me, what is the actual way to do so. Thank you so much.

CodePudding user response:

try this

return  Padding(
      padding: const EdgeInsets.all(10),
      child: Card(
        elevation: 7,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(15.0),
        ),
        child:  Container(
            padding: const EdgeInsets.all(10),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                Text("About $name"),
                const SizedBox(
                  height: 12,
                ),
                 Text(bio)
              ],
            ),
          
        ),
      ),
    );
  • Related