它具有四种构造方法:
MaterialApp(
home: Scaffold(
body: ListView(
children: <Widget>[
ListTile(
leading: Icon(Icons.access_time),
title: Text('第1行'),
),
ListTile(
leading: Icon(Icons.access_time),
title: Text('第2行'),
)
],
),
),
),
import 'package:flutter/material.dart';
class Recommand extends StatelessWidget{
final List<String> items = new List<String>.generate(300, (i) => '第$i行');
@override
Widget build(BuildContext context) {
return MaterialApp(
title: '推荐',
home: Scaffold(
body: ListView.builder(
itemCount: items.length,
itemBuilder: (context, index){
return ListTile(
leading: Icon(Icons.access_time),
title: Text('${items[index]}'),
);
},
),
),
);
}
}
import 'package:flutter/material.dart';
class Popular extends StatelessWidget{
@override
Widget build(BuildContext context) {
final List<String> item = new List<String>.generate(300, (index) => '第$index行');
return MaterialApp(
home: Scaffold(
body: ListView.separated(
itemCount: item.length,
itemBuilder: (context, index){
return ListTile(
leading: Icon(Icons.access_time),
title: Text('${item[index]}'),
);
},
separatorBuilder: (context, index){
return Container(
constraints: BoxConstraints.tightFor(height: 1),
color: Colors.black45,
);
},
),
),
);
}
}
它有五种构造方法。
import 'package:flutter/material.dart';
class Cartoon extends StatelessWidget{
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: GridView.count(
crossAxisCount: 2,
children: <Widget>[
ListTile(
title: Text('item1'),
),
ListTile(
title: Text('item2'),
),
ListTile(
title: Text('item3'),
),
ListTile(
title: Text('item4'),
),
ListTile(
title: Text('item5'),
),
ListTile(
title: Text('item6'),
),
ListTile(
title: Text('item7'),
),
],
),
),
);
}
}
它有三种构造方法。
import 'package:flutter/material.dart';
class Movie extends StatelessWidget{
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: PageView(
onPageChanged: (index){
print('当前为第$index页');
},
children: <Widget>[
ListTile(
title: Text('第0页'),
),
ListTile(
title: Text('第1页'),
),
ListTile(
title: Text('第2页'),
),
],
),
),
);
}
}