Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I write a paragraph with bullet points using Flutter?

Using HTML I can add a bullet points to a paragraph like this:

<ul>
   <li> example </li>
   <li> example </li>
   <li> example </li>
<ul>

How can I write bullet point form in Flutter?

new Text(''),
like image 610
lesego finger Avatar asked Aug 04 '18 22:08

lesego finger


People also ask

How do you give Bullets in flutter?

You can create a separate class to generate the bullet item that you can further easily modify as per your design. i.e you can use different bullet styles like instead of circle rectangle, triangle, any other icon. I have just added the option to add the custom padding. Highly active question.

How do you put a paragraph in bullet points?

Place your cursor where you want a bulleted list. Click Home> Paragraph, and then click the arrow next to Bullets. Choose a bullet style and start typing.


1 Answers

If you don't want to download another library (e.g. flutter_markdown), and one or more of your list items have lengthy text that spans several rows, I'd go with Raegtime's answer. However, since it assumes a string with line breaks, I want to make a version for a list with strings, which is a more common scenario. In the code below, Column makes the list items come on different rows, and Row makes the bullet points have empty space below themselves.

import 'package:flutter/material.dart';

class UnorderedList extends StatelessWidget {
  UnorderedList(this.texts);
  final List<String> texts;

  @override
  Widget build(BuildContext context) {
    var widgetList = <Widget>[];
    for (var text in texts) {
      // Add list item
      widgetList.add(UnorderedListItem(text));
      // Add space between items
      widgetList.add(SizedBox(height: 5.0));
    }

    return Column(children: widgetList);
  }
}

class UnorderedListItem extends StatelessWidget {
  UnorderedListItem(this.text);
  final String text;

  @override
  Widget build(BuildContext context) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        Text("• "),
        Expanded(
          child: Text(text),
        ),
      ],
    );
  }
}

We can use it as such:

UnorderedList([
    "What conclusions can we draw from the implementation?",
    "Are there any changes that need to be introduced permanently?"
])

And get the result: Picture of example result

like image 97
Mjaustro Avatar answered Sep 16 '22 19:09

Mjaustro