為您解碼網(wǎng)站建設(shè)的點(diǎn)點(diǎn)滴滴
發(fā)表日期:2018-12 文章編輯:小燈 瀏覽次數(shù):2425
做 App 開(kāi)發(fā),甚至所有前端開(kāi)發(fā),文本控件應(yīng)該是用的最多的,用戶(hù)看到最多的基本上也都是文本控件相關(guān)的,這篇博客詳細(xì)介紹一下 Flutter 中的文本控件 Text
在 Flutter SDK 下,
flutter -> widgets -> text.dart源碼不大,加注釋總共才不到400行。
Text -> StatelessWidget ->Widget -> DiagnosticableTree ->Diagnosticable,這里可以看出Text 是直接繼承 StatelessWidget的。這里額外結(jié)介紹下Flutter 有兩種狀態(tài)控件:StatelessWidget(無(wú)狀態(tài)組件)、StatefulWidget(有狀態(tài)組件),這兩者的區(qū)別可以參考下走路不穿鞋oO作者寫(xiě)的
Flutter中StatefulWidget控件狀態(tài)管理的兩種方式
這讓我這個(gè)習(xí)慣用 XML 畫(huà)布局感到特別的不習(xí)慣。
class MyTextApp extends StatelessWidget { @override Widget build(BuildContext context) { return new MaterialApp( home: new Scaffold( body: new Center( child: new Text( "This is Text" ), ), ), ); }
image.png就這么簡(jiǎn)單我們完成了第一個(gè) Text 控件的使用,new Text("This is Text") .
這個(gè)我們只需要查看一下 Text 的構(gòu)造方法就知道了。
const Text(this.data, { Key key, this.style, this.textAlign, this.textDirection, this.locale, this.softWrap, this.overflow, this.textScaleFactor, this.maxLines, this.semanticsLabel, })