Flutter--基础组件

Flutter 万物皆组件
Text
属性释义
textAlign文本对齐方式
maxLines最大行数
textScaleFactor字体显示倍率,默认值为10
overflow配合maxLines使用,超出最大行数可以用省略号或渐变效果
styleTextStyle对象
textSpan实现类似富文本
TextStyle参数
属性释义
decoration文字装饰线(none 没有线,lineThrough 删 除线,overline 上划线,underline 下划线)
decorationColor文字装饰线颜色
decorationStyle文字装饰线风格
wordSpacing单词间隙,负值让单词更加紧凑
letterSpacing字母间隙,负值让字母更紧凑
fontStyle文字样式(italic 斜体,normal 正常体)
fontSize文字大小
color文字颜色
fontWeight字体粗细
return MaterialApp(
  title: "Startup Name Generator",
  home: new Scaffold(
    appBar: new AppBar(
      title: new Text("Text"),
    ),
    body: new Center(
      child: new Text(
          "hello",
      textAlign: TextAlign.center,
      maxLines: 2,
      overflow: TextOverflow.ellipsis,
      style: new TextStyle(
        decorationColor: Color(0xff123FFF),
        decoration: TextDecoration.underline,
        fontSize: 20,
        color: Color(0xFFFFD700)
      ),),
    ),
  ),
);
Icon
body: new Center(
  child: new Icon(
    Icons.build,
    color: Colors.red,
    semanticLabel: "user",
    size: 64,
    textDirection: TextDirection.rtl,
  ),
),
Image
方法释义
Image.asset(String name)从AssetBundler中获取图片
Image.network(String src)从网络中获取图片
Image.file(File file)从File中获取图片
Image.memory(Unit8List butes)从Unit8List中获取图片
属性释义
alignment图片对齐方式
color和colorBlendMode设置图片的背景颜色,通常和 colorBlendMode 配合一起 使用,这样可以是图片颜色和背景色混合
fitfit 属性用来控制图片的拉伸和挤压,这都是根据父容器来的
repeat平铺
width宽度,一般结合 ClipOval 才能看到效果
height高度,一般结合 ClipOval 才能看到效果
return Center(  
    child: Container(  
          child: Image.network( "http://pic.baike.soso.com/p/20130828/20130828161137-1346445960.jpg", 
           alignment: Alignment.topLeft, 
           color: Colors.red, 
           colorBlendMode: BlendMode.colorDodge, 
           // repeat: ImageRepeat.repeatX, 
           fit: BoxFit.cover, ), 
           width: 300.0, 
           height: 400.0, 
           decoration: BoxDecoration(  
                color: Colors.yellow  
           ), 
      ), 
 );
// 获取网络图
child: new Image(image: 
NetworkImage("https://www.baidu.com/img/bd_logo1.png?where=super"),width: 50,)

// 获取本地文件夹图片
1. 新建images文件夹,并将图片放于该文件夹下
2. 在pubspec.yaml声明以下添加的图片文件
flutter:  
    uses-material-design: true
assets: 
    - images/1.jpg

child: Container(  
    child: Image.asset("images/a.jpeg", 
    fit:BoxFit.cover  
    ),
    width: 300.0, 
    height: 300.0, 
    decoration: BoxDecoration(  
        color: Colors.yellow  
    ),
 ),,
Image实践 – 实现圆角图片

Widget build(BuildContext context) {
  return Center(
    child: Container(
      width: 300.0,
      height: 300.0,
      decoration: BoxDecoration(
          color: Colors.yellow,
          borderRadius: BorderRadius.circular(150),
          image: DecorationImage(
            image: new NetworkImage("url"),
            fit: BoxFit.cover,
          )),
    ),
  );
}
实现圆形图片
return Center(
  child: Container(
      child: ClipOval(
    child: Image.network(
      "",
      width: 150.0,
      height: 150.0,
    ),
  )),
);

Button
child: RaisedButton(
  color:Colors.blue,
  child: Text("RaisedButton"),
  textColor: Colors.white,
  onPressed: () => {},
),
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wjxbless

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值