Flutter笔记-基础组件
图片和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
- TextEditingController 编辑框控制器,设置,获取,选择,监听文本改变事件。
- FucusNode 是否占有键盘焦点。
- InputDecoration TextField外观显示,提示文本,背景颜色,边框等。
- 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笔记-基础组件的更多相关文章
- vue学习笔记(八)组件校验&通信
前言 在上一章博客的内容中vue学习笔记(七)组件我们初步的认识了组件,并学会了如何定义局部组件和全局组件,上一篇内容仅仅只是对组件一个简单的入门,并没有深入的了解组件当中的其它机制,本篇博客将会带大 ...
- Flutter笔记(一)
Android/iOS移动端开发 原生开发 Android原生应用通常指使用Java或Kotlin语言直接调用Android SDK开发的应用程序:而iOS原生应用通常指使用Objective-C或S ...
- Flutter 布局类组件:简介
前言 布局类组件都会包含一个或多个子组件,不同的布局类组件对子组件排版(layout)方式不同. 我们知道,Element树才是最终的绘制树,Element树是通过Widget树来创建的(通过Widg ...
- winform快速开发平台 -> 基础组件之分页控件
一个项目控件主要由及部分的常用组件,当然本次介绍的是通用分页控件. 处理思想:我们在处理分页过程中主要是针对数据库操作. 一般情况主要是传递一些开始位置,当前页数,和数据总页数以及相关关联的业务逻辑. ...
- CentOS安装LNMP环境的基础组件
注:以下所有操作均在CentOS 6.5 x86_64位系统下完成. 在安装LNMP环境之前,请确保已经使用yum安装了以下各类基础组件(如果系统已自带,还可以考虑yum update下基础组件): ...
- jQuery学习笔记 - 基础知识扫盲入门篇
jQuery学习笔记 - 基础知识扫盲入门篇 2013-06-16 18:42 by 全新时代, 11 阅读, 0 评论, 收藏, 编辑 1.为什么要使用jQuery? 提供了强大的功能函数解决浏览器 ...
- Ext学习-基础组件介绍
1.目标 学习对象获取,组件基础,事件模型以及学习ExtJS中的基础组件的应用. 2.内容 1.对象获取 2.组件原理以及基础 3.事件模型 4.常用组件的介绍 3.学习步骤 1 ...
- 如何从零开始实现一个soa远程调用服务基础组件
说起soa远程调用基础组件,最著名的莫过于淘宝的dubbo了,目前很多的大型互联网公司都有一套自己的远程服务调用分布式框架,或者是使用开源的(例如dubbo),或者是自己基于某种协议(例如hessia ...
- android学习——必学基础组件
android基础组件是一个Android的开发人员必须要了解,且深刻理解的东西: 1.应用程序基础 2.应用程序组件 2.1.活动(Activities) 2.2.服务(Services) 2.3. ...
- Android 基础组件
基础组件 所有的控件都可以在java代码中创建出来,并且大部分的属性都对应set和get方法,比如 View view = new View(Context context) context是上下文 ...
随机推荐
- 文心一言 VS 讯飞星火 VS chatgpt (209)-- 算法导论15.4 6题
六.设计一个 O(nlgn) 时间的算法,求一个 n 个数的序列的最长单调递增子序列.(提示:注意到,一个长度为 i 的候选子序列的尾元素至少不比一个长度为 i-1 候选子序列的尾元素小.因此,可以在 ...
- 【技术积累】Java 8 新特性
一.Lambda表达式 Lambda 是一个匿名函数,我们可以把 Lambda表达式理解为是一段可以传递的代码(将代码像数据一样进行传递).可以写出更简洁.更灵活的代码.作为一种更紧凑的代码风格,使J ...
- golang开发:环境篇(三)开发利器Goland安装
这节主要介绍下golang开发的最主要的IDE,Goland.可以有效提高开发效率.用过一段时间 IntelliJ+GO插件,其实功能上跟goland差不多.不过团队的其它开发者基本都是Goland, ...
- SpringMVC简介 & 原理
特点 1.轻量级,简单易学 2.高效,基于请求响应的MVC框架 3.与Spring兼容性好,与之无缝接合(就是它的一部分) 4.约定优于配置(maven) 5.功能强大:支持RESTful 数据验证 ...
- day14--Java常用类之字符串相关类02
Java常用类 2.字符串相关类 String.StringBuilder.StringBuffer类是三个字符串相关类. String类代表不可变字符序列,StringBuilder类和String ...
- CMakeLists.txt 编写要点 && 一个关于install()的深坑
PS:要转载请注明出处,本人版权所有. PS: 这个只是基于<我自己>的理解, 如果和你的原则及想法相冲突,请谅解,勿喷. 前置说明 本文作为本人csdn blog的主站的备份.(Bl ...
- dubbo 泛化调用场景下,如何调用下游的泛型对象入参
dubbo泛化调用时,除了java原生的collection,map泛型对象,业务自定义的泛型对象是不支持泛化调用的,无法正确的填充下游数据对象.两种解法: 泛化调用的时候把泛型具体类型的全限定类路径 ...
- FLTK基于cmake编译以及使用(Windows、macOS以及Linux)
最近因为一些学习的原因,需要使用一款跨平台的轻量级的GUI+图像绘制 C/C++库.经过一番调研以后,最终从GTK+.FLTK中选出了FLTK,跨平台.够轻量.本文将在Windows.macOS以及L ...
- 喜报|3DCAT成为国内首批适配Vision Pro内容开发者
近日,苹果在上海总部举办了国内首场 Apple Vision Pro 开发者实验室活动,3DCAT作为国内领先的实时渲染云平台参与了此次活动,成为国内首批适配 Vision Pro 的内容开发者之一. ...
- Java问题汇总,持续更新到GitHub
目录介绍 00.Java问题汇总 01.具体问题 好消息 博客笔记大汇总[16年3月到至今],包括Java基础及深入知识点,Android技术博客,Python学习笔记等等,还包括平时开发中遇到的bu ...