1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { // TODO: implement build return new MaterialApp( title: 'flutter demo', home: _home(), ); } }
class _home extends StatefulWidget { @override State<StatefulWidget> createState() { return _homeState(); } }
class _homeState extends State<_home> { @override Widget build(BuildContext context) { // TODO: implement build return new Scaffold( appBar: new AppBar( title: Text("title"), centerTitle: true, ), body: new Column( //垂直布局 children: <Widget>[ //控件组 Text( "Hello world", textAlign: TextAlign.center, //可以选择左对齐、右对齐还是居中。注意,对齐的参考系是Text widget本身。本例中虽然是指定了居中对齐, // 但因为Text文本内容宽度不足一行,Text的宽度和文本内容长度相等,那么这时指定对齐方式是没有意义的, // 只有Text宽度大于文本内容长度时指定此属性才有意义。 ), Text( "Hello world! I'm Jack. " * 4,//文字重复4次 maxLines: 1,//最大行数 overflow: TextOverflow.ellipsis,//超出显示省略号 ), Text( "Hello world", textScaleFactor: 1.5,//代表文本相对于当前字体大小的缩放因子,相对于去设置文本的样式style属性的fontSize,它是调整字体大小的一个快捷方式。 // 该属性的默认值可以通过MediaQueryData.textScaleFactor获得,如果没有MediaQuery,那么会默认值将为1.0。 ), ], )); } }
|