How to add new line to Text in Flutter?

This Article is posted by seven.srikanth at 9/21/2019 6:30:24 AM



In this article, I'm going to share a simple example of how to add new line to Text in Flutter. 
 
Before:
After:
This can be achieved by adding \n into your text widget as below.
Text('Hello, \n How are you?',)
Here is the code from main.dart file to achieve this.
import 'package:flutter/material.dart';

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  double padValue = 0;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: Text("Text Example"),
          ),
          body: Center(
            child: Container(
                child: Text(
              'Hello,  \n How are you?',
              textAlign: TextAlign.center,
              overflow: TextOverflow.ellipsis,
              style: TextStyle(fontWeight: FontWeight.bold),
            )),
          )),
    );
  }
}
Thanks, 
Srikanth

Tags: New Line; break line;








0 Comments
Login to comment.
Recent Comments












© 2018 - Fluttercentral | Email to me - seven.srikanth@gmail.com