Flutter开发之Widget学习
一、Text 组件
属性
- clip:直接切断溢出的文字。
- ellipsis:在后边显示省略号(...) 常用
- fade: 渐变消失效果
style文字的样式
body: new Center(
child: new Text('非淡泊无以明志,非宁静无以致远。(诸葛亮)',
textAlign: TextAlign.left,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 20,
color: Color.fromARGB(255, 0, 0, 255),
decoration: TextDecoration.underline,
decorationStyle: TextDecorationStyle.solid,
fontStyle: FontStyle.italic,
)),
),
二、Container组件
body: new Center(
child: new Container(
child: new Text(
'非淡泊无以明志,非宁静无以致远。(诸葛亮)',
style: TextStyle(fontSize: 30.0),
),
alignment: Alignment.topLeft,
width: 500.0,
height: 200.0,
//color: Colors.lightBlue,
//padding: const EdgeInsets.all(10), //内边距
padding: const EdgeInsets.fromLTRB(10.0, 50.0, 0, 0),
margin: const EdgeInsets.all(20.0),
decoration: new BoxDecoration(
gradient: const LinearGradient(
colors: [Colors.lightBlue, Colors.green, Colors.purple]
),
border: Border.all(width: 5.0,color:Colors.red
),
),
),
),
三、Image组件
加入图片的方式:
- Image.asset 项目资源图片
- Image.file (绝对路径) 系统资源图片
- Image.network(url) 网络资源图片
fit属性
- BoxFit.fill
- BoxFit.contain
- BoxFit.cover
repeat属性
- ImageRepeat.repeat 横向和纵向都重复,铺满整个容器
- ImageRepeat.repeatX 横向重复
- ImageRepeat.repeatY 纵向重复
body: new Center(
child: new Container(
child: new Image.network(
'https://profile.csdnimg.cn/0/5/2/1_jyd0124',
fit: BoxFit.cover,
//color: Colors.lightBlue,
//colorBlendMode: BlendMode.darken, //图片混合模式(colorBlendMode)和color属性配合使用
),
width: 300.0,
height: 200.0,
color: Colors.lightGreen,
)
),
四、ListView组件
列表使用
body: new ListView(
children: <Widget>[
/*new Image.network(
'https://cdn2.jianshu.io/assets/web/banner-s-club-aa8bdf19f8cf729a759da42e4a96f366.png'),
new Image.network(
'https://cdn2.jianshu.io/assets/web/banner-s-7-1a0222c91694a1f38e610be4bf9669be.png'),
*/ //图片列表使用
new ListTile(
leading: new Icon(
Icons.perm_camera_mic,
),
title: new Text('perm_camera_mic'),
),
new ListTile(
leading: new Icon(
Icons.perm_phone_msg,
),
title: new Text('perm_phone_msg'),
),
],
),
横向列表:ListView组件里加一个scrollDirection属性
body: new Center(
child: new Container(
height: 200.0,
child: new ListView(
scrollDirection: Axis.horizontal, //Axis.vertical:纵向列表
children: <Widget>[
new Container(
width: 230.0,
color: Colors.lightBlue,
),
new Container(
width: 230.0,
color: Colors.lightGreen,
),
],
))),
Dart语言List的声明方式:
- var myList = List(): 非固定长度的声明。
- var myList = List(2): 固定长度的声明。
- var myList= List<String>():固定类型的声明方式。
- var myList = [1,2,3]: 对List直接赋值
import 'package:flutter/material.dart'; void main() =>
runApp(MyApp(items: List<String>.generate(1000, (i) => 'item $i'))); class MyApp extends StatelessWidget {
final List<String> items;
MyApp({Key key, @required this.items}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'ListView Dome',
home: new Scaffold(
appBar: new AppBar(title: new Text('ListView Widget')),
body: new ListView.builder(
itemCount: items.length,
itemBuilder: (context, index) {
return new ListTile(
title: new Text('${items[index]}'),
);
}),
),
);
}
}
五、GridView组件
常用属性:
- crossAxisSpacing:网格间的空当。
- crossAxisCount:一行放置的网格数量
body: GridView.count(
padding: EdgeInsets.all(20.0),
crossAxisSpacing: 10.0,
crossAxisCount: 3,
children: <Widget>[
const Text('I am j.y.d'),
const Text('I love flutter'),
const Text('jyd0124.com'),
const Text('2020/02/06'),
const Text('Come on,China!'),
const Text('Come on,Wuhan!'),
],
),
官方已经不鼓励使用这种方法,另一种写法为
body: GridView(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
mainAxisSpacing: 2.0,
crossAxisSpacing: 2.0,
childAspectRatio: 0.75,
),
children: <Widget>[
new Image.network('http://img5.mtime.cn/mg/2019/10/02/105324.67493314_170X256X4.jpg',fit:BoxFit.cover),
new Image.network('http://img5.mtime.cn/mg/2019/09/26/092514.83698073_170X256X4.jpg',fit:BoxFit.cover),
new Image.network('http://img5.mtime.cn/mg/2019/11/07/111316.10093613_170X256X4.jpg',fit:BoxFit.cover),
new Image.network('http://img5.mtime.cn/mg/2019/12/13/094432.64997517_170X256X4.jpg',fit:BoxFit.cover),
new Image.network('http://img31.mtime.cn/mt/2014/02/22/230757.74994253_220X124X4.jpg',fit:BoxFit.cover),
new Image.network('http://img5.mtime.cn/mg/2019/07/10/164947.40820910_170X256X4.jpg',fit:BoxFit.cover),
],
),
- childAspectRatio:宽高比
- mainAxisSpacing:横向网格空档
- crossAxisSpacing: 向纵向网格空挡
至此,使用组件的学习就到这儿了,下篇我们将学习布局的相关知识!
Flutter开发之Widget学习的更多相关文章
- Flutter开发之Widget布局和页面导航
一.水平布局Row Row控件可以分为非灵活排列和灵活排列两种,灵活的可以在外边加入Expanded使用 两者混用: import 'package:flutter/material.dart'; v ...
- IOS开发之XCode学习011:UISwitch控件
此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能: 1.定义UIswitch控件,添加UIswitc ...
- 安卓开发之viewpager学习(头条显示)
activity_luancher.xml代码如下: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res ...
- iOS开发之git学习
本人是参考廖雪峰的git学习的.他写的非常详细,我在这里就是把我学习中的总结以及碰到的坑写出来. /* 初始化git仓库:git init */ /* 添加文件到git仓库 */ 分两步: 第一步:追 ...
- IOS开发之XCode学习012:Slider和ProgressView
此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能: 1.定义UISlider和UIProgressV ...
- IOS开发之XCode学习010:定时器和视图对象
此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能: 1.通过点击"启动定时器"按钮 ...
- IOS开发之XCode学习009:UIViewController使用
此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能: 通过点击屏幕事件,调用ViewController ...
- IOS开发之XCode学习008:UIViewController基础
此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 红色框选部分用A代替,AppDelegate类在程序框架启动时,如果在i ...
- IOS开发之XCode学习007:UIWindow对象
此文学习来源为:http://study.163.com/course/introduction/1002858003.htm #import "AppDelegate.h" @i ...
随机推荐
- 洛谷$P2572\ [SCOI2010]$ 序列操作 线段树/珂朵莉树
正解:线段树/珂朵莉树 解题报告: 传送门$w$ 本来是想写线段树的,,,然后神仙$tt$跟我港可以用珂朵莉所以决定顺便学下珂朵莉趴$QwQ$ 还是先写线段树做法$QwQ$? 操作一二三四都很$eas ...
- $vjudge-dp$专题题解
因为感觉题解写不了多少,,,就懒得一道道题目慢慢写了,汇总了算了$QAQ$ 昂然后因为我估计以后还会有些什么$dp$专题啊$balabala$的,,,然后谢总肯定又会建一堆小组啥的,,,所以还是放个链 ...
- CentOS8安装fastdfs6.06
目录 一.准备环境 二.解压并编译安装 1.解压下载好的包 2.编译安装 2.1.编译安装 libfastcommon 2.2.编译安装 fastdfs 2.3.安装 nginx 和 fastdfs- ...
- 1064 朋友数 (20 分)C语言
如果两个整数各位数字的和是一样的,则被称为是"朋友数",而那个公共的和就是它们的"朋友证号".例如 123 和 51 就是朋友数,因为 1+2+3 = 5+1 ...
- Quartz.NET总结(八)如何根据自己需要配置Topshelf 服务
前面讲了如何使用Topshelf 快速开发windows服务, 不清楚的可以看之前的这篇文章:https://www.cnblogs.com/zhangweizhong/category/771057 ...
- 最强常用开发库总结 - JSON库详解
最强常用开发库总结 - JSON库详解 JSON应用非常广泛,对于Java常用的JSON库要完全掌握.@pdai JSON简介 JSON是什么 JSON 指的是 JavaScript 对象表示法(Ja ...
- mysql索引创建和使用细节
最近困扰自己很久的膝盖积液手术终于做完,在家养伤,逛技术博客看到easyswoole开发组成员仙士可博客有关mysql索引方面的知识,自己打算重温下. 正常业务起步数据表数据量较少,不用考虑使用索引, ...
- mongodb学习(三)——函数使用的小技巧
$group 下 $sum 函数 Returns a sum of numerical values. Ignores non-numeric values 只能对数字求和,非数字没有作用 查询一段时 ...
- 《深入理解 Java 虚拟机》读书笔记:虚拟机性能监控与故障处理工具
正文 一.JDK 的命令行工具 JDK 的 bin 目录下提供了一些用于监视虚拟机和故障处理的命令行工具. 名称 主要作用 jps JVM Process Status Tool,显示正在运行的虚拟机 ...
- python检查是否是闰年
检查的依据: 闰年可以被4整除不能被100整除,或者可以被400整除. year = int(input("请输入年份:")) if year % 4 == 0 and year ...