Skip to main content

Flutter Break Text String From Middle into Multiple Lines

In flutter if we have long lines of text then the text cannot convert into multiple lines itself. At the device screen it start rendering and when line gets full then next word will be moved into next line. But what if we want to break text into multiple lines so it looks sober. We break text into multiple lines using \n (Back slash + small n) combination. All we have to do is place \n in our text string and after reading \n it will break the line and move the next text into next line.

Flutter Break Text String From Middle into Multiple Lines:

1. Creating Text with \n .
Text(
          'Lorem Ipsum \n is simply dummy text \n of the printing \n and typesetting industry. \n Lorem Ipsum has been \n the industrys standard dummy text ever since the 1500.',
          style: TextStyle(fontSize: 30),
          textAlign: TextAlign.center,
        ),
2. Complete source code for main.dart file:
import 'package:flutter/material.dart';

void main() => runApp(App());

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: Scaffold(
          body: SafeArea(
              child: Center(
        child: Text(
          'Lorem Ipsum \n is simply dummy text \n of the printing \n and typesetting industry. \n Lorem Ipsum has been \n the industrys standard dummy text ever since the 1500.',
          style: TextStyle(fontSize: 30),
          textAlign: TextAlign.center,
        ),
      ))),
    );
  }
}
Screenshot:
Flutter Break Text String From Middle into Multiple Lines

Comments