How can I write a paragraph with bullet points usi

2019-06-18 03:00发布

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(''),

3条回答
你好瞎i
2楼-- · 2019-06-18 03:31

Using markdown for this is overkill. Using character is by far easier.

If you're too lazy to copy paste the character, here's a custom Text that does it for you:

class Bullet extends Text {
  const Bullet(
    String data, {
    Key key,
    TextStyle style,
    TextAlign textAlign,
    TextDirection textDirection,
    Locale locale,
    bool softWrap,
    TextOverflow overflow,
    double textScaleFactor,
    int maxLines,
    String semanticsLabel,
  }) : super(
          '•',
          key: key,
          style: style,
          textAlign: textAlign,
          textDirection: textDirection,
          locale: locale,
          softWrap: softWrap,
          overflow: overflow,
          textScaleFactor: textScaleFactor,
          maxLines: maxLines,
          semanticsLabel: semanticsLabel,
        );
}
查看更多
劫难
3楼-- · 2019-06-18 03:39

I tried using flutter_markdown and it seems to work. And of course you can change it to numbered/ordered or unordered list as you want.

enter image description here

import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:flutter/material.dart';
void main() => runApp(Demo());


class Demo extends StatelessWidget {
  final testData = ["Example1", "Example2", "Example3", "Example100"];



  @override
  Widget build(BuildContext context) {
    final _markDownData = testData.map((x) => "- $x\n").reduce((x, y) => "$x$y");

    return MaterialApp(
        home: Scaffold(
      body: Container(
        margin: EdgeInsets.all(40.0),
        child: Markdown(data: _markDownData)),
    ));
  }
}
查看更多
ら.Afraid
4楼-- · 2019-06-18 03:40

I would better use utf-code. For list I think more comfortably will be something like:

class DottedText extends Text {
  const DottedText(String data, {
    Key key,
    TextStyle style,
    TextAlign textAlign,
    TextDirection textDirection,
    Locale locale,
    bool softWrap,
    TextOverflow overflow,
    double textScaleFactor,
    int maxLines,
    String semanticsLabel,
  }) : super(
    '\u2022 $data',
    key: key,
    style: style,
    textAlign: textAlign,
    textDirection: textDirection,
    locale: locale,
    softWrap: softWrap,
    overflow: overflow,
    textScaleFactor: textScaleFactor,
    maxLines: maxLines,
    semanticsLabel: semanticsLabel,);
}
查看更多
登录 后发表回答