一、Text 组件

属性

 textAlign: TextAlign.left,                           -----文本对齐方式
 maxLines: 1,                                            -----显示最大行
 overflow: TextOverflow.clip,                 -----文本溢出的处理方式
  • 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组件

 Alignment属性,Container内child的对齐方式,也就是容器子内容的对齐方式,并不是容器本身的对齐方式。
padding         内边距
margin           外边距
decoration     装饰器
使用:

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组件

加入图片的方式:

  1. Image.asset                  项目资源图片
  2. Image.file (绝对路径)    系统资源图片
  3. 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学习的更多相关文章

  1. Flutter开发之Widget布局和页面导航

    一.水平布局Row Row控件可以分为非灵活排列和灵活排列两种,灵活的可以在外边加入Expanded使用 两者混用: import 'package:flutter/material.dart'; v ...

  2. IOS开发之XCode学习011:UISwitch控件

    此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能:  1.定义UIswitch控件,添加UIswitc ...

  3. 安卓开发之viewpager学习(头条显示)

    activity_luancher.xml代码如下: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res ...

  4. iOS开发之git学习

    本人是参考廖雪峰的git学习的.他写的非常详细,我在这里就是把我学习中的总结以及碰到的坑写出来. /* 初始化git仓库:git init */ /* 添加文件到git仓库 */ 分两步: 第一步:追 ...

  5. IOS开发之XCode学习012:Slider和ProgressView

    此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能:  1.定义UISlider和UIProgressV ...

  6. IOS开发之XCode学习010:定时器和视图对象

    此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能: 1.通过点击"启动定时器"按钮 ...

  7. IOS开发之XCode学习009:UIViewController使用

    此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能: 通过点击屏幕事件,调用ViewController ...

  8. IOS开发之XCode学习008:UIViewController基础

    此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 红色框选部分用A代替,AppDelegate类在程序框架启动时,如果在i ...

  9. IOS开发之XCode学习007:UIWindow对象

    此文学习来源为:http://study.163.com/course/introduction/1002858003.htm #import "AppDelegate.h" @i ...

随机推荐

  1. 给你的 ASP.NET Core 程序插上 Feature Flag 的翅膀

    前言 我们知道,目前大多数应用程序在正式发布到生产环境之前都会经历多个不同的测试环境,通过让应用程序在多个不同的环境中运行来及时发现并解决问题,避免在线上发生不必要的损失.这是对于整个软件的发布流程来 ...

  2. C# event 事件

    事件第二篇:https://www.cnblogs.com/FavoriteMango/p/11731485.html 曾经面试碰到一道设计题: 现有一个人,一群鸟,人有一把手枪,当人开枪时,所有的鸟 ...

  3. 20191024-3 互评Alpha阶段作品——扛把子组

    此作业要求参见:https://edu.cnblogs.com/campus/nenu/2019fall/homework/9860 基于NABCD评论作品,及改进建议 1.根据(不限于)NABCD评 ...

  4. LOJ 北校门外的回忆 倍增+线段树

    正解:倍增+线段树 解题报告: 传送门! $umm$这题有个对正解毫无启发的部分分还有个正解,都挺神仙的所以我都写了趴$QAQ$ 先说部分分 可以考虑把$x$向$x+lowbit(x)$连边,然后当$ ...

  5. Java异常处理原则与技巧总结

    一  处理原则 Java异常代码中我们使用异常的目的是让异常的异常类型来提示“什么”被抛出了--- 即出了什么问题:用异常的栈打印信息来跟踪异常在“哪里”抛出 --- 即哪里出了问题: 异常提示信息来 ...

  6. 「BZOJ1385」「Baltic2000」Division expression 解题报告

    Division expression Description 除法表达式有如下的形式: \(X_1/X_2/X_3.../X_k\) 其中Xi是正整数且\(X_i \le 1000000000(1 ...

  7. K8S与harbor的集成

    文章编写在有道云笔记,采用MarkDown编写,迁移太麻烦了,具体链接如下: http://note.youdao.com/noteshare?id=a9d344951e1fbb761ef7e4979 ...

  8. Date、Time类型拼接成字符串

    Date.Time类型拼接成字符串 语言用的是kotlin,和Java类似 var time = "" val sdf1 = SimpleDateFormat("yyyy ...

  9. linux下压缩包的解压

    linux下 最常见的是 .tar.gz 包和.tar.bz2包 .tar.gz格式的压缩包解压命令是:          tar   -zxvf   xx.tar.gz .tar.bz2格式的压缩包 ...

  10. CF854C Planning优先队列|set

    C. Planning 传送门 Helen works in Metropolis airport. She is responsible for creating a departure sched ...