Is it possible to format paragraph in flutter?

86 Views Asked by At

Is it possible to format paragraphs (alignment, indent, spacing) in flutter?

Like I do in MS Word:

enter image description here

import 'package:flutter/material.dart';

void main() {
  runApp(const MaterialApp(
    home: SafeArea(child: Scaffold(body: Text('first line\nsecond line'))),
  ));
}
3

There are 3 best solutions below

1
Adarsh Singh On

Use Expanded Widget to move it on second Line and use Text Align to Align the text

Expanded(child: Text("first line second line",textAlign: TextAlign.center,)),
1
pixel On

See i don't see any difference between alignment and indent(can help you if you explain me) so that can changed with textAlign property of Text widget. And about spacing im assuming you're referring to letter spacing that can manipulated with letterSpacing parameter of TextStyle.

import 'package:flutter/material.dart';

void main() {
  runApp(const MaterialApp(
    home: SafeArea(
        child: Scaffold(
      body: Expanded(
          child: Text(
        "First line\nsecond line",
        textAlign: TextAlign.left,
        style: TextStyle(letterSpacing: 5),
      )),
    )),
  ));
}

changing them can produce below result

a

b

And if you want different text stying too, than you can refer to RichText widget which can produce different text styling for individual paragraphs.

1
Munsif Ali On

you can try this:

Column(
  crossAxisAlignment: CrossAxisAlignment.start,
  children: [
    Padding(
      padding: EdgeInsets.only(left: 16.0),
      child: Text("Paragraph 1"),
    ),
    Padding(
      padding: EdgeInsets.only(left: 16.0),
      child: Text("Paragraph 2"),
    ),
  ],
)