fluuter学习之旅 - 列表组件

LisrView列表组件

普通列表

import 'package:flutter/material.dart';
import 'package:flutter_test01/myfont.dart'; //自定义的包导入格式:import 'package:项目名/dart名称,dart'

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text("我的应用 - ICON"),
        ),
        body: const MyHomePage(),
      ),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({Key? key}) : super(key: key);

  
  Widget build(BuildContext context) {
    return ListView(
      children: const [
        SizedBox(
          height: 100,
        ),
        Text("你好1"),
        SizedBox(
          height: 100,
        ),
        Text("你好2"),
        SizedBox(
          height: 100,
        ),
        Text("你好3"),
        SizedBox(
          height: 100,
        ),
        Text("你好4"),
        SizedBox(
          height: 100,
        ),
        Text("你好5"),
        SizedBox(
          height: 100,
        ),
        Text("你好6"),
      ],
    );
  }
}

Icon列表

ListTitle组件

class MyHomePage extends StatelessWidget {
  const MyHomePage({Key? key}) : super(key: key);

  
  Widget build(BuildContext context) {
    return ListView(
      children: const <Widget>[
        //<Widget>
        ListTile(
          leading: Icon(
            MyFont.bilibili,
            size: 20,
            color: Colors.blue,
          ),
          title: Text("我的bilibili"),
        )
      ],
    );
  }
}

Icon组件请参考

图文列表

class MyHomePage extends StatelessWidget {
  const MyHomePage({Key? key}) : super(key: key);

  
  Widget build(BuildContext context) {
    return ListView(
      children: <Widget>[
        //<Widget>
        ListTile(
          leading: Image.network("http://124.223.18.34:5555/static/images/gdyg/gdygFM.jpg"),
          title: const Text("孤独摇滚"),
          subtitle: const Text("看到波奇酱,让社恐的你身临其境"),
        )
      ],
    );
  }
}

添加Image请参考

可滑动的水平列表

列表组件常用参数

名称类型说明
scrollDirectionAxisAxis.horizontal水平列表,Axis.vertical垂直列表
paddingEdgeInsetsGeometry内边距
resolvebool组件反向排序
childrenList列表元素

动态列表

定义List的方法

List listData = [/*{...},{...}*/];
class MyHomePage extends StatelessWidget {
  const MyHomePage({Key? key}) : super(key: key);
  List<Widget> _initListData(){
    var list = listData.map((value){
      return ListTile(
          leading: Image.network(value["valueName"]),
          title: const Text(value["valueName"]),
          subtitle: const Text(value["valueName"]),
        )
    })
    return list.toList()
  }
  
  Widget build(BuildContext context) {
    return ListView(
      children: <Widget>[
        //<Widget>
        
      ],
    );
  }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

结城明日奈是我老婆

支持一下一直热爱程序的菜鸟吧

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

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

打赏作者

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

抵扣说明:

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

余额充值