【Flutter】基础组件

2019-03-22  本文已影响0人  diva_dance

TextStyle 文本样式

Text 文本

正常字体

  Text(
    '正常文本'
  )

下划线,中划线

image.png
    Text(
      '下划线文本',
      style: TextStyle(
        decoration: TextDecoration.underline
      ),
    ),
    Text(
      '中划线文本',
      style: TextStyle(
          decoration: TextDecoration.lineThrough
      ),
    ),
    Text(
      '上划线文本',
      style: TextStyle(
          decoration: TextDecoration.overline
      ),
    ),

粗体


image
  Text(
      '加粗文本',
      style: TextStyle(
        fontWeight: FontWeight.bold
      ),
    ),
    Text(
      '加粗文本',
      style: TextStyle(
          fontWeight: FontWeight.w200
      ),
    ),

斜文本


image.png
  Text(
      '斜体文本',
      style: TextStyle(
        fontStyle: FontStyle.italic
      ),
    ),

字体大小


image
    Text(
      '大号文本',
      style: TextStyle(
        fontSize: 30
      ),
    ),

    Text(
      '中号文本',
      style: TextStyle(
        fontSize: 20
      ),
    ),

    Text(
      '小号文本',
      style: TextStyle(
        fontSize: 10
      ),
    ),

如果需要显示富文本需要使用 Text.rich 和 textSpan


image
Text.rich(
  TextSpan(
    style: TextStyle(
      color: Colors.red
    ),
    text: 'hello world',
    children: [
      TextSpan(
        style: TextStyle(
            color: Colors.blue
        ),
        text: 'hello world'
      )
    ]
  )
);

这么展示富文本也太费劲了。

Image

return Image.asset(
  'assets/images/title.png',
  semanticLabel: '这是一张 title 图片',
  excludeFromSemantics: false,
  width: 60,
  height: 60,
  fit: BoxFit.contain,
  alignment: Alignment.bottomCenter,
  matchTextDirection: true,
  filterQuality: FilterQuality.high
);

属性

创建图片容器的方法有下面几种:

  return Image.asset(
      'assets/images/title.png'
  );
return Image.network(
   'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1553355447588&di=7df0e766c457cd950a09f3c3d016cb9a&imgtype=0&src=http%3A%2F%2Fdn-p-tystore.qbox.me%2Fp%2Fchapter%2Fattachment%2FEtIUE_bte-%2FEgfvEBITe_-W4B6ve_2wElu16gjT7UL68vmn6MiB6m9tJh9pHUfV9t2.jpg'
);

Icon

return Icon(
  Icons.star,
  color: Colors.red,
);

Icons 提供了很多内置的图标,如果需要别的图标可以借鉴 :
https://blog.csdn.net/kangshaojun888/article/details/86719741

Placeholder 占位符

image
return Placeholder(
  color: Colors.red, // 颜色
  strokeWidth: 2.0, // 线条的宽度
  fallbackHeight: 100,
  fallbackWidth: 100, // 当占位符处于宽度无界的情况时使用的宽度。
);
上一篇 下一篇

猜你喜欢

热点阅读