Dolphin
Dolphin

Reputation: 38975

is it possible to make the TextSpan auto wrap in flutter

Now I am using this code to render some text:

import 'package:flutter/material.dart';

void main() async {
  runApp(MaterialApp(
      home: Scaffold(
    body: Form(
      key: GlobalKey(),
      child: Center(
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisSize: MainAxisSize.max,
          children: [
            SelectableText.rich(
              TextSpan(
                children: [
                  TextSpan(text: "sfwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww"),
                ],
              ),
            ),
          ],
        ),
      ),
    ),
  )));
}

but the text was overflow, is it possible to make it auto wrap accord the screen size and do not overflow? The rendered text was a dynamic string and I did not know the length.

Upvotes: 2

Views: 861

Answers (1)

OMi Shah
OMi Shah

Reputation: 6186

Wrap the SelectableText with the Flexible widget.

As:

Flexible(child: 
            SelectableText.rich(
              TextSpan(
                children: [
                  TextSpan(text: "sfwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww"),
                ],
              ),
            )),

Upvotes: 3

Related Questions