Home > Back-end >  Flutter auto line break in Text Widget
Flutter auto line break in Text Widget

Time:11-15

I am very new to Flutter.

I am currently writing a simple memo app, with a list of titles shown like this: titles

Those Text widgets should be separate, but I have no idea how to break text line. Being specific, which widget should be used for the code below?

import 'package:flutter/material.dart';

void main() => runApp(const AppMain());

class AppMain extends StatelessWidget {
  const AppMain({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Memo',
      home: Scaffold(
        body: SafeArea(
            child: <WHICH WIDGET SHOULD I USE>(
                children: [
                    Text("The first text"),
                    Text("Second Memo Title"),
                    Text("Third One"),
                    Text("and so on"),
                ],
      ),
      debugShowCheckedModeBanner: false,
    );
  }
}

I have tried Wrap widget, but it does not break the Text in it.

Thanks.

CodePudding user response:

Use RichText widget which takes list of TextSpan widgets.

CodePudding user response:

RichText(
    text: TextSpan(
      style: DefaultTextStyle.of(context).style,
      children: [
        TextSpan(
          text: The first text,
        ),
        TextSpan(
          text: Second Memo Title,
      ],
    ),

This can help you. There is style property for TextSpan. You can use that to style your text.

  • Related