美文网首页
flutter text(),Container(),listV

flutter text(),Container(),listV

作者: 阿克兰 | 来源:发表于2019-11-11 16:01 被阅读0次

text组件设置文本样式

 title: Text('查工程师',
            textAlign: TextAlign.center,
            maxLines: 1,
            overflow: TextOverflow.ellipsis,
           style: TextStyle(color: Color.fromRGBO(255, 255, 0, 1)),

          ),

Container组件

child:Container(
      child:new Text(
      'hello',
      style: TextStyle(color: Color.fromRGBO(255, 255, 0, 1))     
    ),
  alignment:Alignment.bottomCenter , // 设置文本居底
  width:500,
height:500,
color:colors.red ,//设置背景颜色
padding:const edgelnsets.all(20),
margin:const edgelnsets.all(20),
decoration:new BoxDecoration( // 设置容器渐变
    gradient:const LinearGradient(
        colors:[
          colors.red,
          colors.black
]
)
)
)

Container组件
decoration修饰器,设置容器的边框,padding,edgelnsets.all()统一设置;edgelnsets.fromltrb(1,2,3,2)分别设置

image的几种加入形式
container(
    child:new Image.network(
      'url',
      scale:1.6,
      fit:BoxFit.fill,// 铺满整个屏幕,contain适应内容,cover适应整个
      

    )
)

listview列表组件1

body:new ListView(
    children:<widget>[
          new ListTile(
            leading:new Icon(
               Icons.border_right
           ),
          title:new Text('这是文本')      
    ),
      new ListTile(
            leading:new Icon(
               Icons.border_right
           ),
          title:new Text('这是文本')      
    ),
      new ListTile(
            leading:new Icon(
               Icons.border_right
           ),
          title:new Text('这是文本')      
    )
]
)

listview列表2

body:new ListView(
    children:<widget>[
         new Image.network('src'),
          new Image.network('src'),
          new Image.network('src')
]
)

水平切换的列表1

body:center(
  child:container(
    height:200,
  child:new ListView(
    scrollDirrection:Axis.horizontal,// 设置水平切换的方法
   children:<Widget>[
      new container(
          width:180,
          color:colors.red
      ),
    new container(
          width:180,
          color:colors.blue
      )
]
)
)
)

水平切换的列表2

body:center(
  child:container(
    height:200,
  child:mylist()
)
)

class mylist extends statelesswidget{
    @override
    widget build(BuildContext context){
         return ListView(
   scrollDirrection:Axis.horizontal,// 设置水平切换的方法
   children:<Widget>[
      new container(
          width:180,
          color:colors.red
      ),
    new container(
          width:180,
          color:colors.blue
      )
]
             
    )
}
}

动态列表的使用

void main()=> runApp(MyApp(
    items:new List<String>.generate(
        1000,(i)=>"Item $i"
)
)
class MyApp extends StatelessWidget{
    final List<String> items;
    MyApp(
       {
    Key key,@required this.items
}
):super(key:key);
@override
widget build (BuildContent context){
   return MaterialApp(
    title:"名称",
    home:Scaffold(
      appBar:new AppBar(
       title:new text("这是text")
 ),
body:new listView.builder(
   itemCount:items.length,
   itemBulider:(context,index){
      return new ListTile(
     title:new Text(
       '${items[index]}'
)
 )
}
)
 )

)
}
}

border 分别设置

      decoration: BoxDecoration(
              // border: new Border.all(width: 0.5, color: Color(0xffcea457)),
              border: Border(
                left: BorderSide(color: Color(0xffcea457),width: 1),
                right: BorderSide(color: Color(0xffcea457),width: 1),
                bottom: BorderSide(color: Color(0xffcea457),width: 1),
                ),
            ),

相关文章

网友评论

      本文标题:flutter text(),Container(),listV

      本文链接:https://www.haomeiwen.com/subject/urutictx.html