一、Hello World的实现
fim(flutter import material.dart) //引入material.dart库
定义main方法(dart入口方法)
void main(){
runApp(MyApp()) //runApp(flutter入口方法)
}
//定义一个自定义组件
class MyApp extends StatelessWidget{
@override
Widget build(BuildContext context) {
return MaterialApp( //调用MaterialApp组件
home:Scaffold( //home主页用Scaffold脚手架来装饰
appBar:AppBar(
title:Text('Welcome to flutter'),
)
body:Center(
child:Text(
'hello world',
style: TextStyle(
color: Colors.red,
),
),
),
),
theme:ThemeData( //更改主题颜色
primarySwatch: Colors.green
),
);
}
}
二、循环列表ListView
class HomeContent extends StatelessWidget{
List _getData(){
List<Widget> list = new List();
for(var i=0;i<10;i++){
list.add(
ListTile(
title: Text("我是$i列表"),
),
);
}
return list;
}
@override
Widget build(BuildContext context) {
// TODO: implement build
return ListView(
children: this._getData()
);
}
}
动态列表
List<Widget> _getData(){
var templist = ListData.map((value){
return ListTile(
leading: Image.network(value["ImgUrl"]),
title: Text(value["title"]),
subtitle: Text(value["title"]),
);
});
return templist.toList();
}