zoukankan      html  css  js  c++  java
  • 前端入门flutter-10Flutter 页面布局 Flutter AspectRatio、Card卡片组件

        临近过年,也即将放假,公司事务多,私事也多。望明年如时雨天司----春来及时雨!

        依旧是页面布局章节,毕竟完美的布局才可以堵住UI、产品的嘴,赢得老板的心嘛,那么,开始咯!

       

      1 import 'package:flutter/material.dart';
      2 import 'package:flutter_app1/res/listData.dart';
      3 void main(){
      4   runApp(MyApp());
      5 }
      6 
      7 class MyApp extends StatelessWidget{
      8   @override
      9   Widget build(BuildContext context) {
     10     // TODO: implement build
     11     return MaterialApp(
     12       home: Scaffold(
     13         appBar: AppBar(
     14           title: Text('AspectRatio、Car卡片组件'),
     15         ),
     16         body: Mybody4(),
     17       ),
     18     );
     19   }
     20 }
     21 /*
     22             AspectRatio的作用white根据设置 调整child的宽度比(相对于父元素)
     23             AspectRatio首页会在布局限制条件允许的范围内尽可能的扩展,Widget的高度是由宽度和比率决定的,类似于BoxFit中的contain,按照比例企业尽量占满。
     24             如果在满足所有显示条件后无法找到一个可行的尺寸,AspectRation最终将会优先适应布局的限制条件,而忽略所设置的比率
     25  */
     26    class HomeContent extends StatelessWidget{
     27      @override
     28      Widget build(BuildContext context) {
     29     // TODO: implement build
     30     return AspectRatio(
     31         //aspectRatio宽高比(要看外层是否允许按照这个比例布局,这只是一个参考值)
     32         aspectRatio: 2/1,
     33         child: Container(
     34           color: Colors.pink,
     35         ),
     36     );
     37   }
     38    }
     39 
     40 
     41    /*
     42    Card组件是卡片组件块,内容可以有大多是类型的Widget构成,Card具有圆角和阴影的效果,看起来更有立体感
     43 
     44 常用属性
     45 
     46 margin:外边距
     47 child:子组件
     48 shape:Card的阴影效果,默认效果为圆角的长方形。
     49 
     50    * */
     51    class Mybody extends StatelessWidget{
     52      List<Widget> _getItemVIew(){
     53        var map = listData.map((value) {
     54          return Card(
     55            child: Column(children: <Widget>[
     56              AspectRatio(
     57                  aspectRatio: 2/1,
     58                child: Image.network(value["imageUrl"],fit: BoxFit.fill),
     59              ),
     60              ListTile(
     61                title: Text(value["title"]),
     62                subtitle: Text(value["author"]),
     63              )
     64            ],),
     65          );
     66        });
     67        return map.toList();
     68      }
     69      @override
     70      Widget build(BuildContext context) {
     71     // TODO: implement build
     72       return ListView(
     73         children: _getItemVIew(),
     74       );
     75   }
     76    }
     77    class Mybody2 extends StatelessWidget{
     78      @override
     79      Widget build(BuildContext context) {
     80     // TODO: implement build
     81     return ListView(
     82       children: <Widget>[
     83         Card(
     84           margin: EdgeInsets.all(10.0),
     85           child: Column(
     86             children: <Widget>[
     87               ListTile(
     88                 title: Text("张珊"),
     89                 subtitle: Text("业界架构师"),
     90               ),
     91               ListTile(
     92                 title: Text("电话:1657614357"),
     93               ),
     94               ListTile(
     95                 title: Text("地址:广东省广州市天河区水能大厦 "),
     96               ),
     97             ],
     98           ),
     99         ),
    100         Card(
    101           margin: EdgeInsets.all(10.0),
    102           child: Column(
    103             children: <Widget>[
    104               ListTile(
    105                 title: Text("李思"),
    106                 subtitle: Text("T0智能工程师"),
    107               ),
    108               ListTile(
    109                 title: Text("电话:1657614357"),
    110               ),
    111               ListTile(
    112                 title: Text("地址:广东省广州市天河区水能大厦"),
    113               ),
    114             ],
    115           ),
    116         ),
    117       ],
    118     );
    119   }
    120    }
    121    class Mybody3 extends StatelessWidget{
    122      @override
    123      Widget build(BuildContext context) {
    124     // TODO: implement build
    125     return ListView(
    126       children: <Widget>[
    127         Card(
    128           margin: EdgeInsets.all(10.0),
    129           child: Column(
    130             children: <Widget>[
    131               AspectRatio(
    132                   aspectRatio: 20/9,
    133                 child: Image.network("https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=2739171020,2681942617&fm=26&gp=0.jpg",fit: BoxFit.cover),
    134               ),
    135               ListTile(
    136                 leading: ClipOval(
    137                   child: Image.network("https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=2739171020,2681942617&fm=26&gp=0.jpg",fit: BoxFit.cover,height: 60.0, 60.0),
    138                 ),
    139                 title: Text("fgdsugu"),
    140                 subtitle: Text("dsgfsduyfufgefefuoygefyugfb"),
    141               )
    142             ],
    143           ),
    144         ),
    145         Card(
    146           margin: EdgeInsets.all(10.0),
    147           child: Column(
    148             children: <Widget>[
    149               AspectRatio(
    150                 aspectRatio: 20/9,
    151                 child: Image.network("https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=2739171020,2681942617&fm=26&gp=0.jpg",fit: BoxFit.cover),
    152               ),
    153               ListTile(
    154                 leading: CircleAvatar(
    155                   backgroundImage: NetworkImage("https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=2739171020,2681942617&fm=26&gp=0.jpg"),
    156                 ),
    157                 title: Text("fgdsugu"),
    158                 subtitle: Text("dsgfsduyfufgefefuoygefyugfb"),
    159               )
    160             ],
    161           ),
    162         ),
    163       ],
    164     );
    165   }
    166    }
    167 
    168 //   动态渲染
    169 class Mybody4 extends StatelessWidget{
    170   @override
    171   Widget build(BuildContext context) {
    172     // TODO: implement build
    173     return ListView(
    174       children:listData.map((value){
    175        return Card(
    176          margin: EdgeInsets.all(10.0),
    177          child: Column(
    178            children: <Widget>[
    179              AspectRatio(
    180                aspectRatio: 20/9,
    181                child: Image.network(value["imageUrl"],fit: BoxFit.cover),
    182              ),
    183              ListTile(
    184                leading: CircleAvatar(
    185                  backgroundImage: NetworkImage(value["imageUrl"]),
    186                ),
    187                title: Text(value["title"]),
    188                subtitle: Text(value["author"],maxLines: 2,overflow: TextOverflow.ellipsis,),
    189              )
    190            ],
    191          ),
    192        );
    193       }).toList(),
    194 
    195 
    196 
    197 
    198     );
    199   }
    200 }

                                          

                图(body4)                        图(body3)                         图(body2)

  • 相关阅读:
    Vue 数组响应
    Vue 事件监听
    Vue 分支循环
    Vue 计算属性与方法
    Vue 属性与样式
    Vue mustache语法&常用指令
    vue 基本介绍
    linux(centos7) 安装nginx
    python 创建虚拟环境(一个独立的环境)
    Python标准库学习--->1、内置函数(1-10个)
  • 原文地址:https://www.cnblogs.com/CMirs/p/14357688.html
Copyright © 2011-2022 走看看