0

In the following code

import 'package:flutter/material.dart';

final Color darkBlue = Color.fromARGB(255, 18, 32, 47);

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: Center(
          child: MyWidget(),
        ),
      ),
    );
  }
}

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final text = Text(
        'When large fortunes fall into the hands of some people, they become strong in the light of it, and in the shadow of strength and wealth they dream that they can live out of their homeland and be happy and proud, they will soon realize that they have made mistakes, and the greatness of every nation On the ruins of his homeland and cease!',
        style: Theme.of(context).textTheme.headline4);

    return Column(
      mainAxisSize: MainAxisSize.min,
      mainAxisAlignment: MainAxisAlignment.start,
      children: [
        Row(
          children: [
            Column(
              children: [
                text,
              ],
            ),
          ],
        )
      ],
    );
  }
}

I have a Text widget in a Column in Row in another Column , As text is in Row it is single row and overflowed, I want to make it multiline to I wrap it with Flexible

    return Column(
      mainAxisSize: MainAxisSize.min,
      mainAxisAlignment: MainAxisAlignment.start,
      children: [
        Row(
          children: [
            Column(
              children: [
                Flexible(child: text),
              ],
            ),
          ],
        )
      ],
    );

What is wrong here? Why I have RenderFlex children have non-zero flex but incoming height constraints are unbounded. ?

1 Answer 1

1

You must wrap column with flexible, not text itself. Please try this. It's working for me.

Column(
    mainAxisSize: MainAxisSize.min,
    mainAxisAlignment: MainAxisAlignment.start,
    children: [
      Row(
        children: [
          Flexible(child: Column(
            children: [
              text
            ],
          ),)
        ],
      )
    ],
  )
Sign up to request clarification or add additional context in comments.

2 Comments

Yes, Can you explain why?
Using a Flexible widget gives a child of a Row, Column, or Flex the flexibility to expand to fill the available space in the main axis (e.g., horizontally for a Row or vertically for a Column), but, unlike Expanded, Flexible does not require the child to fill the available space. In your case, overflow error is occuring from Column, which is container of Text. That's why you must wrap Column with Flexible, not just Text.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.