图片和Icon

加载网络图片以及本地图片
 Image(
image: NetworkImage(
"https://img-s-msn-com.akamaized.net/tenant/amp/entityid/BB12IU4R.img?w=80&h=80&m=4&q=60"),
width: 100.0,
),
Image(image: AssetImage("graphics/ic_launcher.png"),
width: 100.0,
height: 100.0,
)
color和colorBlendMode 进行颜色混合处理
 Image(
image: AssetImage("graphics/ic_launcher.png"),
width: 100.0,
height: 100.0,
color: Colors.blue,
colorBlendMode: BlendMode.difference,
)

整体的例子:

加载网络图片

import 'package:flutter/cupertino.dart';

class ImageAndIconRoute extends StatelessWidget {
@override
Widget build(BuildContext context) {
var assetImage = AssetImage("graphics/ic_launcher.png");
return SingleChildScrollView(
child: Column(
children: <Image>[
Image(
image: assetImage,
width: 100,
height: 100,
fit: BoxFit.fill,
),
Image(
image: assetImage,
width: 100,
height: 100,
fit: BoxFit.contain,
),
Image(
image: assetImage,
width: 100,
height: 100,
fit: BoxFit.cover,
),
Image(
image: assetImage,
width: 100,
height: 100,
fit: BoxFit.fitWidth,
),
Image(
image: assetImage,
width: 100,
height: 100,
fit: BoxFit.fitHeight,
),
Image(
image: assetImage,
width: 100,
height: 100,
fit: BoxFit.none,
),
].map((e) {
return Row(
children: <Widget>[
Padding(
padding: EdgeInsets.all(16.0),
child: SizedBox(
width: 100,
child: e,
),
),
Text(e.fit.toString())
],
);
}).toList()),
);
}
}

单选开关和复选框

switch和checkbox,继承StateLessWidget

点击switch和checkbox会触发onchange回调

import 'package:flutter/material.dart';
// StatefulWidget 维护状态需要继承这个
class SwitchAndCheckboxRoute extends StatefulWidget{
const SwitchAndCheckboxRoute({super.key}); @override
SwitchAndCheckboxRouteSate createState() => SwitchAndCheckboxRouteSate();
} class SwitchAndCheckboxRouteSate extends State<SwitchAndCheckboxRoute>{
bool switchSelected = true;
bool checkboxSelected = true;
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
Switch(
value:switchSelected, onChanged: (bool value) {
setState(() {
switchSelected = value;
});
},),
Checkbox(value: checkboxSelected,
activeColor: Colors.red,
onChanged: (bool? value) {
setState(() {
checkboxSelected = value!;
});
},
)
],
);
}
}
输入框以及表单

输入框组件TextField

  1. TextEditingController 编辑框控制器,设置,获取,选择,监听文本改变事件。
  2. FucusNode 是否占有键盘焦点。
  3. InputDecoration TextField外观显示,提示文本,背景颜色,边框等。
  4. KeyboardType 键盘输入类型
  • text 文件输入键盘
  • multiline 多行文本
  • number 数字键盘
  • phone 电话号码键盘
  • datatime 日期输入键盘
  • emailAddress 电子邮件
  • url url输入键盘

输入框例子:

            Column(
children: const <Widget>[
TextField(
autofocus: true,
decoration: InputDecoration(
labelText: "用户名",
hintText: "请输入用户名",
prefixIcon: Icon(Icons.person)
),
),
TextField(
autofocus: true,
decoration: InputDecoration(
labelText: "密码",
hintText: "请输入密码",
prefixIcon: Icon(Icons.lock)
),
obscureText: true,
) ],
)

效果

控制焦点
import 'package:flutter/material.dart';

class FocusTestRoute extends StatefulWidget{
const FocusTestRoute({super.key}); @override
FocusTestRouteState createState()=>FocusTestRouteState();
} class FocusTestRouteState extends State<FocusTestRoute>{
// FocusNode 控制焦点用
FocusNode focusNode1 = FocusNode();
FocusNode focusNode2 = FocusNode();
// 移动焦点,设置默认焦点用
late FocusScopeNode focusScopeNode; @override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: <Widget>[
TextField(
autofocus: true,
focusNode: focusNode1,
decoration: const InputDecoration(
labelText: "input1"
),
),
TextField(
focusNode: focusNode2,
decoration: const InputDecoration(
labelText: "input2"
),
),
Builder(builder: (ctx){
return Column(
children: <Widget>[
TextButton(
child: const Text("移动焦点"),
onPressed: (){
if(null==focusScopeNode){
focusScopeNode = FocusScope.of(context);
}else{
// 焦点移动到第二个TextField
focusScopeNode.requestFocus(focusNode2);
}
},
),
TextButton(
child: const Text("隐藏键盘"),
onPressed: (){
focusNode1.unfocus();
focusNode2.unfocus();
},
)
],
);
})
],
),
);
}
}
进度条

LinearProgressIndicator 横向进度条

valueColor 进度条颜色

value 进度

 LinearProgressIndicator(
backgroundColor: Colors.grey[200],
valueColor: const AlwaysStoppedAnimation(Colors.blue),
),
LinearProgressIndicator(
backgroundColor: Colors.grey[200],
valueColor: const AlwaysStoppedAnimation(Colors.blue),
value: 0.5,
)

圆形进度条

CircularProgressIndicator(
backgroundColor: Colors.grey[200],
valueColor: const AlwaysStoppedAnimation(Colors.blue),
value: .5,
)

指定进度条宽高SizedBox

SizedBox(
height: 10,
child: LinearProgressIndicator(
backgroundColor: Colors.grey[200],
valueColor: const AlwaysStoppedAnimation(Colors.blue),
),
),

10s由绿变红例子

import 'package:flutter/material.dart';

class ProgressRoute extends StatefulWidget {
const ProgressRoute({super.key}); @override
ProgressRouteState createState() => ProgressRouteState();
} class ProgressRouteState extends State<ProgressRoute>
with SingleTickerProviderStateMixin {
late AnimationController animationController; @override
initState() {
animationController =
AnimationController(vsync: this, duration: const Duration(seconds: 10));
animationController.forward();
animationController.addListener(() => setState(() {}));
super.initState();
} @override
void dispose() {
animationController.dispose();
super.dispose();
} @override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Column(
children: <Widget>[
Padding(padding: const EdgeInsets.all(16),
child: LinearProgressIndicator(
backgroundColor: Colors.grey[200],
valueColor: ColorTween(begin: Colors.green, end: Colors.red).animate(animationController),
value: animationController.value,
)
), ],
),
);
}
}

Flutter笔记-基础组件的更多相关文章

  1. vue学习笔记(八)组件校验&通信

    前言 在上一章博客的内容中vue学习笔记(七)组件我们初步的认识了组件,并学会了如何定义局部组件和全局组件,上一篇内容仅仅只是对组件一个简单的入门,并没有深入的了解组件当中的其它机制,本篇博客将会带大 ...

  2. Flutter笔记(一)

    Android/iOS移动端开发 原生开发 Android原生应用通常指使用Java或Kotlin语言直接调用Android SDK开发的应用程序:而iOS原生应用通常指使用Objective-C或S ...

  3. Flutter 布局类组件:简介

    前言 布局类组件都会包含一个或多个子组件,不同的布局类组件对子组件排版(layout)方式不同. 我们知道,Element树才是最终的绘制树,Element树是通过Widget树来创建的(通过Widg ...

  4. winform快速开发平台 -> 基础组件之分页控件

    一个项目控件主要由及部分的常用组件,当然本次介绍的是通用分页控件. 处理思想:我们在处理分页过程中主要是针对数据库操作. 一般情况主要是传递一些开始位置,当前页数,和数据总页数以及相关关联的业务逻辑. ...

  5. CentOS安装LNMP环境的基础组件

    注:以下所有操作均在CentOS 6.5 x86_64位系统下完成. 在安装LNMP环境之前,请确保已经使用yum安装了以下各类基础组件(如果系统已自带,还可以考虑yum update下基础组件): ...

  6. jQuery学习笔记 - 基础知识扫盲入门篇

    jQuery学习笔记 - 基础知识扫盲入门篇 2013-06-16 18:42 by 全新时代, 11 阅读, 0 评论, 收藏, 编辑 1.为什么要使用jQuery? 提供了强大的功能函数解决浏览器 ...

  7. Ext学习-基础组件介绍

    1.目标    学习对象获取,组件基础,事件模型以及学习ExtJS中的基础组件的应用. 2.内容   1.对象获取   2.组件原理以及基础   3.事件模型   4.常用组件的介绍 3.学习步骤 1 ...

  8. 如何从零开始实现一个soa远程调用服务基础组件

    说起soa远程调用基础组件,最著名的莫过于淘宝的dubbo了,目前很多的大型互联网公司都有一套自己的远程服务调用分布式框架,或者是使用开源的(例如dubbo),或者是自己基于某种协议(例如hessia ...

  9. android学习——必学基础组件

    android基础组件是一个Android的开发人员必须要了解,且深刻理解的东西: 1.应用程序基础 2.应用程序组件 2.1.活动(Activities) 2.2.服务(Services) 2.3. ...

  10. Android 基础组件

    基础组件 所有的控件都可以在java代码中创建出来,并且大部分的属性都对应set和get方法,比如 View view = new View(Context context)  context是上下文 ...

随机推荐

  1. CPNtools协议建模安全分析(一)

    本文根据最近整理的CPNtools论文和CPNtools官网上的说明,以及参照了乌克兰敖德萨 ---国家电信研究院运输和通信部关于   电信系统协议仿真关于CPNtools的学生讲义.基于此和和自己的 ...

  2. npm install --legacy-peer-deps 安装出现依赖包冲突的解决方案

    npm install --legacy-peer-deps 安装出现依赖包冲突的解决方案 为什么 在安装依赖包的时候,会有依赖包的冲突 比如A包引用了C的1.0版本 B包依赖了C的1.1版本 win ...

  3. QSAN: A Quantum-probability based Signed Attention Network for Explainable False Information Detection-CIKM20

    一.摘要 在社交媒体上的虚假信息检测具有挑战性,因为它通常需要烦冗的证据收集,但又缺乏可用的比较信息.从用户评论中挖掘出的线索作为群体智慧,可能对这项任务有相当大的好处. 然而,考虑到内容和评论的隐式 ...

  4. 基于2.4G私有协议的无线取餐系统设及实现

    前记  最近在使用TLSR8355做几个小产品.正好赶上有客户需要一个无线取餐系统解决方案.笔者分析了一下需求.该芯片有充足的按键,LED灯,GPIO接口等.做这一款产品是顺道的事情. 需求梳理  功 ...

  5. python 文件操作常用方法

    一 python文件创建 import os import argparse def file_write(file_name,msg): f = open(file_name,"a&quo ...

  6. 从零开始写 Docker(六)---实现 mydocker run -v 支持数据卷挂载

    本文为从零开始写 Docker 系列第六篇,实现类似 docker -v 的功能,通过挂载数据卷将容器中部分数据持久化到宿主机. 完整代码见:https://github.com/lixd/mydoc ...

  7. 使用JdbcTemplate

    1.使用JdbcTemplate的execute()方法执行SQL语句 Java代码  收藏代码 jdbcTemplate.execute("CREATE TABLE USER (user_ ...

  8. Linux 上 libcurl库 curl_easy_perform Crash(signal 11 - SIGSEGV)

    PS:要转载请注明出处,本人版权所有. PS: 这个只是基于<我自己>的理解, 如果和你的原则及想法相冲突,请谅解,勿喷. 前置说明   本文作为本人csdn blog的主站的备份.(Bl ...

  9. 移植openssh-7.5p1(包括openssl-1.0.2l、zlib-1.2.11)到HISI3520d(部署篇)

    PS:要转载请注明出处,本人版权所有. PS: 这个只是基于<我自己>的理解, 如果和你的原则及想法相冲突,请谅解,勿喷. 前置说明   本文作为本人csdn blog的主站的备份.(Bl ...

  10. Java8的核心功能就是Lambda和Streaming API

    Java8的核心功能就是Lambda和Streaming API