在flutter中,要用到富文本框,可以用extended_text_field第三方插件
class _MyHomePageState extends State<MyHomePage> {
TextEditingController controller = new TextEditingController();
String result;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("richText"),
),
body: Container(
child: Column(
children: [
ExtendedTextField(
controller: controller,
maxLines: 3,
),
SizedBox(height: 10),
TextButton(
onPressed: () {
setState(() {
result = controller.text;
});
},
child: Text("click"),
),
Text("$result"),
],
),
),
);
}
}
注意一定要用Scaffold。