flutter学习笔记(二)

常用的布局组件

ListView 

ListView(
    children: <Widget>[
        Image.asset(
            'assets/images/person_back.jpg',
            height: 100.0,
                fit: BoxFit.cover,
        ),
        ListTile(
            leading: Image.asset(
                'assets/images/avatar.jpeg',
                height: 30.0,
                fit: BoxFit.cover,
                alignment: Alignment.center
            ),
            title: Text(
                username,
                maxLines: 2,
                overflow: TextOverflow.ellipsis,
            ),
            subtitle: Text(phone),
                trailing: Icon(
                Icons.phone_in_talk,
                color: Colors.blueAccent,
            ),
            enabled: true, // 是否禁用
            selected: false, // 是否选中状态
            onTap: () => print('onTap'), // 点击事件
            onLongPress: () => print('onLongPress'), // 长按事件
        ),
        ListTile(
            leading: Icon(Icons.payment),
            title: Text(card),
        ),
        ListTile(
            leading: Icon(Icons.attach_money),
            title: Text(money),
        )
   ],
),

GridView

GridView(
    gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
        mainAxisSpacing: 2.0, // 纵轴网格间距
        crossAxisSpacing: 2.0, // 横向网格间距
        crossAxisCount: 3, // 每行显示的列数
        childAspectRatio: 1.0, // 宽高比
    ),
    padding: EdgeInsets.all(10.0),
    children: <Widget>[
        Image.asset(
            'assets/images/person_back.jpg',
            height: 100.0,
            fit: BoxFit.cover,
        ),
        Image.asset(
            'assets/images/person_back.jpg',
            height: 100.0,
            fit: BoxFit.cover,
        ),
        Image.asset(
            'assets/images/person_back.jpg',
            height: 100.0,
            fit: BoxFit.cover,
        ),
        Image.asset(
            'assets/images/person_back.jpg',
            height: 100.0,
            fit: BoxFit.cover,
        ),
        Image.asset(
            'assets/images/person_back.jpg',
            height: 100.0,
            fit: BoxFit.cover,
        ),
            
    ],
),
发布了3 篇原创文章 · 获赞 0 · 访问量 55

猜你喜欢

转载自blog.csdn.net/one_of_then/article/details/105283975