如何使用 Flutter 编写带有数字点的段落?
How can I write a paragraph with number points using Flutter?
使用 HTML 我可以将有序列表点添加到这样的段落中:
<ol>
<li>Kopi</li>
<li>Teh</li>
</ol>
如何在Flutter中编写有序列表点表单?
new Text(''),
您可以使用包 https://pub.dev/packages/flutter_html
代码片段
Html(
data: """
<ol>
<li>Kopi</li>
<li>Teh</li>
</ol>
""",
//Optional parameters:
padding: EdgeInsets.all(8.0),
linkStyle: const TextStyle(
工作演示
完整代码
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:html/dom.dart' as dom;
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
),
body: new Center(
child: SingleChildScrollView(
child: Html(
data: """
<ol>
<li>Kopi</li>
<li>Teh</li>
</ol>
""",
//Optional parameters:
padding: EdgeInsets.all(8.0),
linkStyle: const TextStyle(
color: Colors.redAccent,
decorationColor: Colors.redAccent,
decoration: TextDecoration.underline,
),
onLinkTap: (url) {
print("Opening $url...");
},
onImageTap: (src) {
print(src);
},
//Must have useRichText set to false for this to work
customRender: (node, children) {
if (node is dom.Element) {
switch (node.localName) {
case "custom_tag":
return Column(children: children);
}
}
return null;
},
customTextAlign: (dom.Node node) {
if (node is dom.Element) {
switch (node.localName) {
case "p":
return TextAlign.justify;
}
}
return null;
},
customTextStyle: (dom.Node node, TextStyle baseStyle) {
if (node is dom.Element) {
switch (node.localName) {
case "p":
return baseStyle.merge(TextStyle(height: 2, fontSize: 20));
}
}
return baseStyle;
},
),
),
),
);
}
}
使用 HTML 我可以将有序列表点添加到这样的段落中:
<ol>
<li>Kopi</li>
<li>Teh</li>
</ol>
如何在Flutter中编写有序列表点表单?
new Text(''),
您可以使用包 https://pub.dev/packages/flutter_html
代码片段
Html(
data: """
<ol>
<li>Kopi</li>
<li>Teh</li>
</ol>
""",
//Optional parameters:
padding: EdgeInsets.all(8.0),
linkStyle: const TextStyle(
工作演示
完整代码
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:html/dom.dart' as dom;
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
),
body: new Center(
child: SingleChildScrollView(
child: Html(
data: """
<ol>
<li>Kopi</li>
<li>Teh</li>
</ol>
""",
//Optional parameters:
padding: EdgeInsets.all(8.0),
linkStyle: const TextStyle(
color: Colors.redAccent,
decorationColor: Colors.redAccent,
decoration: TextDecoration.underline,
),
onLinkTap: (url) {
print("Opening $url...");
},
onImageTap: (src) {
print(src);
},
//Must have useRichText set to false for this to work
customRender: (node, children) {
if (node is dom.Element) {
switch (node.localName) {
case "custom_tag":
return Column(children: children);
}
}
return null;
},
customTextAlign: (dom.Node node) {
if (node is dom.Element) {
switch (node.localName) {
case "p":
return TextAlign.justify;
}
}
return null;
},
customTextStyle: (dom.Node node, TextStyle baseStyle) {
if (node is dom.Element) {
switch (node.localName) {
case "p":
return baseStyle.merge(TextStyle(height: 2, fontSize: 20));
}
}
return baseStyle;
},
),
),
),
);
}
}