skip to Main Content

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 linensecond line'))),
  ));
}

2

Answers


  1. 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,)),
    
    Login or Signup to reply.
  2. 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 linensecond 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search