import 'package:flutter/material.dart';

void main(){
runApp(MyApp());
} class MyApp extends StatelessWidget{
@override
Widget build(BuildContext context) {
// TODO: implement build
return MaterialApp(
home:Scaffold(
appBar: AppBar(
title:Text("flutter demo")
),
body:HomeContent()
)
);
}
} class HomeContent extends StatelessWidget{
@override
Widget build(BuildContext context) {
// TODO: implement build
return Center(
child: Container(
child: Text(
'hello world 学无止境的最高境界!!!',
textAlign:TextAlign.left,
overflow:TextOverflow.ellipsis ,
// overflow:TextOverflow.fade ,
maxLines: 1,
textScaleFactor: 1.8,
style:TextStyle(
fontSize: 16.0,
color:Colors.red,
// color:Color.fromARGB(a, r, g, b)
fontWeight: FontWeight.w800,
fontStyle: FontStyle.italic,
decoration:TextDecoration.lineThrough,
decorationColor:Colors.white,
decorationStyle: TextDecorationStyle.dashed,
letterSpacing: 5.0 ) ),
height: 300.0,
width: 300.0,
decoration: BoxDecoration(
color: Colors.yellow,
border: Border.all(
color: Colors.blue,
width: 2.0
),
borderRadius: BorderRadius.all(
// Radius.circular(150), //圆形
Radius.circular(10),
)
),
// padding:EdgeInsets.all(20), // padding:EdgeInsets.fromLTRB(10, 30, 5, 0) margin: EdgeInsets.fromLTRB(10, 30, 5, 0), // transform:Matrix4.translationValues(100,0,0) // transform:Matrix4.rotationZ(0.3) // transform:Matrix4.diagonal3Values(1.2, 1, 1) alignment: Alignment.bottomLeft, ),
);
} }

Flutter Text 组件

TextAlign属性

TextAlign属性就是文本的对齐方式,它的属性值有如下:

  • center: 文本以居中形式对齐,这个也算比较常用的了。
  • left:左对齐,经常使用,让文本居左进行对齐,效果和start一样。
  • right :右对齐,使用频率也不算高。
  • start:以开始位置进行对齐,类似于左对齐。
  • end: 以为本结尾处进行对齐,不常用。有点类似右对齐.
  • justfy 两端对齐

最常用的三个:left(左对齐)、center(居中对齐)、right(右对齐)

maxLines属性

设置最多显示的行数,比如我们现在只显示1行。代码如下:

child:Text(
'Hello',
textAlign:TextAlign.left,
maxLines: 1,
)

overflow属性

overflow属性是用来设置文本溢出时,如何处理,它有下面几个常用的值供我们选择。

  • clip:直接切断,剩下的文字就没有了,感觉不太友好,体验性不好。
  • ellipsis:在后边显示省略号,体验性较好,这个在工作中经常使用。
  • fade: 溢出的部分会进行一个渐变消失的效果,当然是上线的渐变,不是左右的哦。

style属性

style属性

字体的样式设置

下面是 TextStyle 的参数 :

名称

功能

decoration

文字装饰线(none 没有线,lineThrough 删 除线,overline 上划线,underline 下划线)

decorationColor

文字装饰线颜色

decorationStyle

文字装饰线风格([dashed,dotted]虚线, double 两根线,solid 一根实线,wavy 波浪 线)

wordSpacing

单词间隙(如果是负值,会让单词变得更紧 凑

letterSpacing

字母间隙(如果是负值,会让字母变得更紧 凑)

fontStyle

文字样式(italic 斜体,normal 正常体)

fontSize

文字大小

color

文字颜色

fontWeight

字体粗细(bold 粗体,normal 正常体)

Container容器组件

Container(容器控件)在Flutter是经常使用的控件,它就相当于HTML里的<div>标签,每个页面或者说每个视图都离不开它。

alignment属性

其实容器的作用就是方便我们进行布局的,Flutter这点也作的很好,我们先来看容器属性中的Alignment

这个属性针对的是Container内child的对齐方式,也就是容器子内容的对齐方式,并不是容器本身的对齐方式。

先作一个效果:建立一个容器,然后容器内加入一段文字, 并让它居中对齐。

topCenter:顶部居中对齐
topLeft:顶部左对齐
topRight:顶部右对齐
center:水平垂直居中对齐
centerLeft:垂直居中水平居左对齐
centerRight:垂直居中水平居右对齐
bottomCenter 底部居中对齐
bottomLeft:底部居左对齐
bottomRight:底部居右对齐
      child:Container(
child:new Text('Hello',style: TextStyle(fontSize: 40.0),),
alignment: Alignment.center,
),

设置宽、高和颜色属性

设置宽、高和颜色属性是相对容易的,只要在属性名称后面加入浮点型数字就可以了, 示例代码如下:

child:Container(
child:new Text('Hello,style: TextStyle(fontSize: 40.0),),
alignment: Alignment.center,
width:200.0,
height:40.0,
color: Colors.lightBlue,
),

padding属性

padding的属性就是一个内边距,它和你使用的前端技术CSS里的padding表现形式一样,指的是Container边缘和child内容的距离。设置内边距为10的示例代码如下:

child:Container(
child:new Text('Hello',style: TextStyle(fontSize: 40.0),),
alignment: Alignment.topLeft,
width:200.0,
height:40.0,
color: Colors.lightBlue,
padding:const EdgeInsets.all(10.0),
),

核心代码:

padding:const EdgeInsets.all(10.0),

意思是设置Container的内边距是10,左右上下全部为10

如果设置不一样,则使用下列的方法实现:

EdgeInsets.fromLTRB(value1,value2,value3,value4) 
padding:const EdgeInsets.fromLTRB(10.0,30.0,0.0,0.0),  //上边距为30,左边距为10

margin属性

margin是外边距,只的是container和外部元素的距离。

方法同padding使用相同

 margin: const EdgeInsets.all(10.0),
margin:const EdgeInsets.fromLTRB(10.0,30.0,0.0,0.0),//上外边距为30,左外边距为10

decoration属性

decoration是 container 的修饰器,主要的功能是设置背景和边框。

比如你需要给背景加入一个渐变,这时候需要使用BoxDecoration这个类,代码如下(需要注意的是如果你设置了decoration,就不要再设置color属性了,因为这样会冲突)。

child:Container(
child:new Text('Hello JSPang',style: TextStyle(fontSize: 40.0),),
alignment: Alignment.topLeft,
width:200.0,
height:40.0,
padding:const EdgeInsets.fromLTRB(10.0,30.0,0.0,0.0),
margin: const EdgeInsets.all(10.0),
decoration:new BoxDecoration(
gradient:const LinearGradient(
colors:[Colors.lightBlue,Colors.greenAccent,Colors.purple]
)
),
),

设置边框

设置边框可以在decoration里设置border属性,比如你现在要设置一个红色边框,宽度为2。代码如下:

decoration:new BoxDecoration(
gradient:const LinearGradient(
colors:[Colors.lightBlue,Colors.greenAccent,Colors.purple]
),
border:Border.all(width:2.0,color:Colors.red)
),

设置圆角,圆形等外框

decoration: BoxDecoration(
color: Colors.yellow,
border: Border.all(
color: Colors.blue,
width: 2.0
),
borderRadius: BorderRadius.all(
// Radius.circular(150), //圆形
Radius.circular(10),
)
),

transform 属性

让 Container 容易进行一些旋转之类的

// transform:Matrix4.translationValues(100,0,0)
// transform:Matrix4.rotationZ(0.3)
transform:Matrix4.diagonal3Values(1.2, 1, 1)

Flutter Container容器组件、Text文本组件详解的更多相关文章

  1. rich-text 副文本组件 text文本组件

    rich-text 副文本组件 要知道我们小程序常用的标签是view 但是我们想使用div   span  h1 i 标签等等,这种带特性的标签,怎么办的,我们就可以使用我们的 rich-text组件 ...

  2. 【Flutter学习】基本组件之文本组件Text

    一,概述 文本组件(Text)负责显示文本和定义显示样式, 二,继承关系 Object > Diagnosticable > DiagnosticableTree > Widget ...

  3. Flutter学习笔记(15)--MaterialApp应用组件及routes路由详解

    如需转载,请注明出处:Flutter学习笔记(15)--MaterialApp应用组件及routes路由详解 最近一段时间生病了,整天往医院跑,也没状态学东西了,现在是好了不少了,也该继续学习啦!!! ...

  4. 详解Android中的四大组件之一:Activity详解

    activity的生命周期 activity的四种状态 running:正在运行,处于活动状态,用户可以点击屏幕,是将activity处于栈顶的状态. paused:暂停,处于失去焦点的时候,处于pa ...

  5. SpringMVC 框架系列之组件概述与配置详解

    在上一篇文章 SpringMVC 框架系列之初识与入门实例 的实例中,我们已经知道,SpringMVC 框架是一个 web 层的框架,本篇文章就详细解释一下 SpringMVC 框架具体文件的配置以及 ...

  6. 【docker-compose】docker-compose.yml文本内容详解 + docker-compose命令详解 + docker-compose启动服务容器时区设置

    参考地址:https://blog.csdn.net/Kiloveyousmile/article/details/79830810 参考地址:https://docs.docker.com/comp ...

  7. Spring组件扫描<context:component-scan/>详解

    引言 最近使用Spring,发现有很多依赖注入的内容,特别是DAO,百思不得其解,后来才知道是Spring的依赖注入.Spring可以批量将一个目录下所有的植入@Repository 注解或者@Ser ...

  8. Android组件化框架项目详解

    简介 什么是组件化? 项目发展到一定阶段时,随着需求的增加以及频繁地变更,项目会越来越大,代码变得越来越臃肿,耦合会越来越多,开发效率也会降低,这个时候我们就需要对旧项目进行重构即模块的拆分,官方的说 ...

  9. vue2.0父子组件以及非父子组件通信传参详解

    1.父组件传递数据给子组件 父组件数据如何传递给子组件呢?可以通过props属性来实现 父组件: <parent> <child :child-msg="msg" ...

随机推荐

  1. 用js刷剑指offer(数组中的逆序对)

    题目描述 题目描述 在数组中的两个数字,如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对.输入一个数组,求出这个数组中的逆序对的总数P.并将P对1000000007取模的结果输出. 即输出P ...

  2. Java精通并发-wait与sleep方法字节码分析

    在上一次https://www.cnblogs.com/webor2006/p/11372521.html中对于Thread类和Runnable接口有了一个基本的认识,这次咱们继续巩固基础,首先先新建 ...

  3. 使用navicat创建数据库

    1.  打开navicat 2.  选中数据库连接“root”右键->新建数据库 3. 填写数据库名称,注意名称不要以数字开头,不要有中文.空格.特殊字符等 4. 选择“字符集”,常用的为utf ...

  4. 《发际线总是和我作队》第九次作业:Beta冲刺Scrum Meeting3

    项目 内容 这个作业属于哪个课程 软件工程 这个作业的要求在哪里 实验十三 团队作业9:Beta冲刺与团队项目冲刺 团队名称 发际线总和我作队 作业学习目标 (1)掌握软件黑盒测试技术:(2)掌握软件 ...

  5. 神经网络(11)--具体实现:unrolling parameters

    我们需要将parameters从矩阵unrolling到向量,这样我们就可以使用adanced optimization routines. unroll into vectors costFunct ...

  6. 【Python学习】Python3 基本数据类型

    参考学习地址:https://www.runoob.com/python3/python3-data-type.html Python3 基本数据类型 Python 中的变量不需要声明.每个变量在使用 ...

  7. greenplum 下载地址

    一.推荐使用下面下载地址 https://network.pivotal.io/products/pivotal-gpdb#/releases/158026/file_groups/1083 二.官网 ...

  8. RookeyFrame 线下 添加Model

    1.在Model层添加一个类,继承BaseEntity,如: (将就demo里面的类改了一下) using Rookey.BusSys.Model.Base; using Rookey.BusSys. ...

  9. C位运算符的使用

    #include <stdio.h> int main(void) { //位运算符 & | ^ ~ printf("8|2=%d\n",8|2);// 10 ...

  10. P1108 低价购买——最长下降子序列+方案数

    P1108 低价购买 最长下降子序列不用多讲:关键是方案数: 在求出f[i]时,我们可以比较前面的f[j]; 如果f[i]==f[j]&&a[i]==a[j] 要将t[j]=0,去重: ...