当前位置:网站首页>Extension of flutter
Extension of flutter
2022-07-03 00:35:00 【Jian Zhao ZJ】
Extend the application of basic data types
extension IntExtension on int {
toSay() {
print('IntExtension Hello~');
}
}
extension StringExtension1 on String {
// The string is converted to Color object
toColor() {
var hexColor = this.replaceAll("#", "");
if (hexColor.length == 6) {
hexColor = "FF" + hexColor;
}
if (hexColor.length == 8) {
return Color(int.parse("0x$hexColor"));
}
}
// character string int
parseInt() {
return int.parse(this);
}
}
Application of extension in class
extension DateTimeExtension on DateTime {
toFormatString() {
//DateFormat dateFormat = new DateFormat("yyyy-MM-dd HH:mm:ss");
return "to_format_string";
}
}
Application of extensions in generics
extension HclList<T> on List<T> {
// Extended attributes
int get doubleLength => length * 2;
// Extended operation symbol
List<T> operator -() => reversed.toList();
// A linked list is divided into two
List<List<T>> split(int at) => <List<T>>[sublist(0, at), sublist(at)];
}
Expand on Widget Application in
extension HclWidget on Widget {
Widget marginAll(double margin) {
return Container(
alignment: Alignment.center,
margin: EdgeInsets.all(margin),
child: this,
);
}
}
边栏推荐
- Should you study kubernetes?
- Multiprocess programming (4): shared memory
- antv x6节点拖拽到画布上后的回调事件(踩大坑记录)
- NC17059 队列Q
- 多进程编程(三):消息队列
- How do educators find foreign language references?
- UART、RS232、RS485、I2C和SPI的介绍
- Luogu_ P1149 [noip2008 improvement group] matchstick equation_ Enumeration and tabulation
- helm 基础学习
- NC20806 区区区间间间
猜你喜欢

Angled detection frame | calibrated depth feature for target detection (with implementation source code)

Basic use of shell script

Pageoffice - bug modification journey

An excellent orm in dotnet circle -- FreeSQL

How SQLSEVER removes data with duplicate IDS

Maya fishing house modeling

logback配置文件

Rust所有权(非常重要)

AttributeError: ‘tuple‘ object has no attribute ‘layer‘问题解决

kubernetes资源对象介绍及常用命令(五)-(NFS&PV&PVC)
随机推荐
NC50528 滑动窗口
Blue decides red - burst CS teamserver password
pod生命周期详解
Go自定义排序
Helm basic learning
kubernetes资源对象介绍及常用命令(五)-(NFS&PV&PVC)
Where can I find foreign papers?
There is an unknown problem in inserting data into the database
CMake基本使用
Monitor container runtime tool Falco
Feature Engineering: summary of common feature transformation methods
Pageoffice - bug modification journey
关于Unity屏幕相关Screen的练习题目,Unity内部环绕某点做运动
What is the standard format of a 2000-3000 word essay for college students' classroom homework?
多进程编程(三):消息队列
Multiprocess programming (I): basic concepts
[IELTS reading] Wang Xiwei reading P2 (reading fill in the blank)
Introduction and use of ftrace tool
TypeError: Cannot read properties of undefined (reading ***)
写论文可以去哪些网站搜索参考文献?