Flutter 四:基础部件

1.Text:文字与文字样式

import 'package:flutter/material.dart';
class BaseDemo extends StatelessWidget{
  final TextStyle _textStyle=TextStyle(
    fontSize:16.0,
  );
  final String _author='李白';
  final String _title='将进酒';
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Text(
      '《$_title》——$_author。君不见黄河之水天上来,奔流到海不复回。君不见高堂明镜悲白发,朝如青丝暮成雪。人生得意须尽欢,莫使金樽空对月。天生我材必有用,千金散尽还复来。烹羊宰牛且为乐,会须一饮三百杯。',
      textAlign: TextAlign.left,//对齐方式
      style: _textStyle,//文字样式
      maxLines: 3,//最多三行
      overflow: TextOverflow.ellipsis,//多出来的用省略号代替
    );
  }
}

在这里插入图片描述

2.RichText:行内多样式的文字

import 'package:flutter/material.dart';
class BaseDemo extends StatelessWidget{
  
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return RichText(
      text: TextSpan(
        text:'ninghao',
        style:TextStyle(
          color: Colors.deepPurpleAccent,
          fontSize: 34.0,
          fontStyle: FontStyle.italic,
          fontWeight: FontWeight.w100,
        ),
        children: [//子部件,其他样式
          TextSpan(
            text: '.net',
            style: TextStyle(
              fontSize:17.0,
              color:Colors.grey,
            ),
          )
        ]
      )
    );
  }
}

在这里插入图片描述

3.Container:容器

import 'package:flutter/material.dart';
class BaseDemo extends StatelessWidget{
  
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(//容器
      color:Colors.grey[100],
      child:Row(//Row小部件可以放一些水平放置的部件
      children:<Widget>[
        Container(
          child:Icon(Icons.pool,size:32.0,color:Colors.white),
          color: Color.fromRGBO(3, 54, 255, 1.0),
          padding: EdgeInsets.all(16.0),//内边距
          margin: EdgeInsets.all(8.0),//外边距
          width:90.0,
          height: 90.0,

        )
      ]

      )
    );
  }
}

在这里插入图片描述

4.BoxDecoration:装饰盒子

出现这个错,是因为重复添加了color
在这里插入图片描述

import 'package:flutter/material.dart';
class BaseDemo extends StatelessWidget{
  
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(//容器
      color:Colors.grey[100],
      child:Row(//Row小部件可以放一些水平放置的部件
      mainAxisAlignment: MainAxisAlignment.center,//主轴对齐,居中
      children:<Widget>[
        Container(
          child:Icon(Icons.pool,size:32.0,color:Colors.white),
          //color: Color.fromRGBO(3, 54, 255, 1.0),
          padding: EdgeInsets.all(16.0),//内边距
          margin: EdgeInsets.all(8.0),//外边距
          width:90.0,
          height: 90.0,
          decoration: BoxDecoration(//装饰盒子
            color:Color.fromRGBO(3, 54, 255, 1.0),
          ),
        )
      ]

      )
    );
  }
}

在这里插入图片描述

5.BoxDecoration:边框(border)

上下添加边框:

decoration: BoxDecoration(//装饰盒子
            color:Color.fromRGBO(3, 54, 255, 1.0),
            border: Border(
              top:BorderSide(color: Colors.indigoAccent[100],width: 3.0,style: BorderStyle.solid),
              bottom:BorderSide(color: Colors.indigoAccent[100],width: 3.0,style: BorderStyle.solid),
            )
          ),

周围都添加边框:

border: Border.all(color: Colors.indigoAccent[100],width: 3.0,style: BorderStyle.solid),

在这里插入图片描述

6.圆角效果

borderRadius: BorderRadius.circular(16.0),//圆角效果,圆形的盒子不能有圆角效果

在这里插入图片描述
单独设置:

borderRadius: BorderRadius.only(
              topLeft:Radius.circular(64.0),//左上角
              bottomLeft:Radius.circular(64.0),//左下角
            )//圆角效果,圆形的盒子不能有圆角效果

在这里插入图片描述

decoration: BoxDecoration(//装饰盒子
            color:Color.fromRGBO(3, 54, 255, 1.0),
            border: Border.all(color: Colors.indigoAccent[100],width: 3.0,style: BorderStyle.solid),//边框效果
            borderRadius: BorderRadius.only(
              topLeft:Radius.circular(64.0),//左上角
              bottomLeft:Radius.circular(64.0),//左下角
            )//圆角效果
          ),

7.BoxDecoration:阴影(borderShadow)

boxShadow: [
              BoxShadow(
              offset:Offset(0.0,7.0),//阴影偏移,x,y
              color: Color.fromRGBO(16,20, 188, 1.0),//颜色,默认黑色
              blurRadius: 20.0,//值越大,模糊程度越明显
              spreadRadius: -3.0,//控制阴影的扩撒程度,为正就会扩大,为负就会缩小
              ),   
            ]

在这里插入图片描述

8.BoxDecoration:形状(shape)

圆角效果,圆形的盒子不能有圆角效果
在这里插入图片描述

shape: BoxShape.circle,

在这里插入图片描述

9. BoxDecoration:渐变(gradient)

gradient: RadialGradient(//镜像渐变
              colors: [
                Color.fromRGBO(7, 102, 255, 1.0),
                Color.fromRGBO(3, 28, 128, 1.0),
              ],
            ),

在这里插入图片描述

gradient: LinearGradient(//RadialGradient镜像渐变,LinearGradient线性渐变,默认从左到右
              colors: [
                Color.fromRGBO(7, 102, 255, 1.0),
                Color.fromRGBO(3, 28, 128, 1.0),
              ],
              begin: Alignment.topCenter,//可设置渐变方向
              end: Alignment.bottomCenter,
            ),

在这里插入图片描述

10.BoxDecoration:背景图像(image)

decoration: BoxDecoration(//设置背景图片
        image:DecorationImage(
          image:NetworkImage('https://resources.ninghao.org/images/say-hello-to-barry.jpg'),
          alignment:Alignment.topCenter,
          //repeat: ImageRepeat.repeatY,//延Y轴重复
          fit:BoxFit.cover,//填充方式,填满
          colorFilter:ColorFilter.mode(//加滤镜
            Colors.indigoAccent[400].withOpacity(0.5),
            BlendMode.hardLight,
          ),
        )
      ),

在这里插入图片描述

完整dart

import 'package:flutter/material.dart';
class BaseDemo extends StatelessWidget{
  
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(//容器
      //color:Colors.grey[100],
      decoration: BoxDecoration(//设置背景图片
        image:DecorationImage(
          image:NetworkImage('https://resources.ninghao.org/images/say-hello-to-barry.jpg'),
          alignment:Alignment.topCenter,
          //repeat: ImageRepeat.repeatY,//延Y轴重复
          fit:BoxFit.cover,//填充方式,填满
          colorFilter:ColorFilter.mode(//加滤镜
            Colors.indigoAccent[400].withOpacity(0.5),
            BlendMode.hardLight,
          ),
        )
      ),
      child:Row(//Row小部件可以放一些水平放置的部件
      mainAxisAlignment: MainAxisAlignment.center,//主轴对齐,居中
      children:<Widget>[
        Container(
          child:Icon(Icons.pool,size:32.0,color:Colors.white),
          //color: Color.fromRGBO(3, 54, 255, 1.0),
          padding: EdgeInsets.all(16.0),//内边距
          margin: EdgeInsets.all(8.0),//外边距
          width:90.0,
          height: 90.0,
          decoration: BoxDecoration(//装饰盒子
            color:Color.fromRGBO(3, 54, 255, 1.0),
            border: Border.all(color: Colors.indigoAccent[100],width: 3.0,style: BorderStyle.solid),//边框效果
            //borderRadius: BorderRadius.circular(16.0),//圆角效果,圆形的盒子不能有圆角效果
            boxShadow: [
              BoxShadow(
              offset:Offset(0.0,7.0),//阴影偏移,x,y
              color: Color.fromRGBO(16,20, 188, 1.0),//颜色,默认黑色
              blurRadius: 20.0,//值越大,模糊程度越明显
              spreadRadius: -3.0,//控制阴影的扩撒程度,为正就会扩大,为负就会缩小
              ),   
            ],
            shape: BoxShape.circle,
            gradient: LinearGradient(//RadialGradient镜像渐变,LinearGradient线性渐变,默认从左到右
              colors: [
                Color.fromRGBO(7, 102, 255, 1.0),
                Color.fromRGBO(3, 28, 128, 1.0),
              ],
              begin: Alignment.topCenter,//可设置渐变方向
              end: Alignment.bottomCenter,
            ),
          ),
        )
      ]

      )
    );
  }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值