先上图:
<code>import 'package:flutter/material.dart';
main(){
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const MaterialApp(
debugShowCheckedModeBanner: false,
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("简单的ListView"),
centerTitle: true,
),
body: const MyContentPage()
);
}
}
class MyContentPage extends StatelessWidget {
const MyContentPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: ListView(
children: const <Widget>[
MyHomePageItem("这是title_01","这是description","https://tva1.sinaimg.cn/large/006y8mN6gy1g72j6nk1d4j30u00k0n0j.jpg"),
SizedBox(height: 8),
MyHomePageItem("这是title_02","这是description","https://tva1.sinaimg.cn/large/006y8mN6gy1g72imm9u5zj30u00k0adf.jpg"),
SizedBox(height: 8),
MyHomePageItem("这是title_03","这是description","https://tva1.sinaimg.cn/large/006y8mN6gy1g72imqlouhj30u00k00v0.jpg"),
],
),
);
}
}
class MyHomePageItem extends StatelessWidget {
final String title;
final String desc;
final String imageUrl;
const MyHomePageItem(this.title,this.desc,this.imageUrl,{Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
border: Border.all(),
),
child: Column(
children: <Widget>[
Text(title),
Text(desc),
Image.network(imageUrl),
],
),
);
}
}</code>
文章评论