Flutter 的一些小技巧
1. 获取状态栏高度
import 'dart:ui';
MediaQueryData.fromWindow(window).padding.top
2. 设置AppBar的高度
Scaffold(
appBar: PreferredSize(
child: AppBar(
),
preferredSize: Size.fromHeight(screenSize.height * 0.07))
);
3. 系统默认的AppBar、TabBar高度
在Dart Packages/flutter/src/material/constans.dart
/// The height of the toolbar component of the [AppBar].
const double kToolbarHeight = 56.0; /// The height of the bottom navigation bar.
const double kBottomNavigationBarHeight = 56.0; /// The height of a tab bar containing text.
const double kTextTabBarHeight = 48.0; /// The amount of time theme change animations should last.
const Duration kThemeChangeDuration = Duration(milliseconds: ); /// The radius of a circular material ink response in logical pixels.
const double kRadialReactionRadius = 20.0; /// The amount of time a circular material ink response should take to expand to its full size.
const Duration kRadialReactionDuration = Duration(milliseconds: ); /// The value of the alpha channel to use when drawing a circular material ink response.
const int kRadialReactionAlpha = 0x1F; /// The duration of the horizontal scroll animation that occurs when a tab is tapped.
const Duration kTabScrollDuration = Duration(milliseconds: ); /// The horizontal padding included by [Tab]s.
const EdgeInsets kTabLabelPadding = EdgeInsets.symmetric(horizontal: 16.0); /// The padding added around material list items.
const EdgeInsets kMaterialListPadding = EdgeInsets.symmetric(vertical: 8.0);
4. 获取当前时间戳
var now = new DateTime.now();
print(now.millisecondsSinceEpoch); //单位毫秒,13位时间戳 /** 或者 */
/** 返回当前时间戳 */
static int currentTimeMillis() {
return new DateTime.now().millisecondsSinceEpoch;
}
5.时间戳转化成日期
var now = new DateTime.now();
var a=now.millisecondsSinceEpoch; //时间戳
print(DateTime.fromMillisecondsSinceEpoch(a));
6. 获取控件大小和相对屏幕位置
.首先先需要对控件进行渲染
初始化GlobalKey :GlobalKey anchorKey = GlobalKey(); .在需要测量的控件的下面添加key:
child: Text("点击弹出悬浮窗",
style: TextStyle(fontSize: ),
key: anchorKey
), .获取控件的坐标:
RenderBox renderBox = anchorKey.currentContext.findRenderObject();
var offset = renderBox.localToGlobal(Offset.zero); 控件的横坐标:offset.dx
控件的纵坐标:offset.dy 如果想获得控件正下方的坐标:
RenderBox renderBox = anchorKey.currentContext.findRenderObject();
var offset = renderBox.localToGlobal(Offset(0.0, renderBox.size.height)); 控件下方的横坐标:offset.dx
控件下方的纵坐标:offset.dy .获取控件的大小:
RenderBox renderBox = anchorKey.currentContext.findRenderObject();
final size = renderBox.size;
7.有网络请求的地方基本上就有md5
dart有内置的md5加密包,先引入头文件:
import 'dart:convert';
import 'package:convert/convert.dart';
import 'package:crypto/crypto.dart';
md5加密方法:
// md5 加密
String generateMd5(String data) {
var content = new Utf8Encoder().convert(data);
var digest = md5.convert(content);
// 这里其实就是 digest.toString()
return hex.encode(digest.bytes);
}
8. flutter 引入图片资源
可以单个图片引入,也可以整个文件夹引入
Flutter 的一些小技巧的更多相关文章
- 前端网络、JavaScript优化以及开发小技巧
一.网络优化 YSlow有23条规则,中文可以参考这里.这几十条规则最主要是在做消除或减少不必要的网络延迟,将需要传输的数据压缩至最少. 1)合并压缩CSS.JavaScript.图片,静态资源CDN ...
- Git小技巧 - 指令别名及使用Beyond Compare作为差异比较工具
前言 本文主要写给使用命令行来操作Git的用户,用于提高Git使用的效率.至于使用命令还是GUI(Tortoise Git或VS的Git插件)就不在此讨论了,大家根据自己的的喜好选择就好.我个人是比较 ...
- 分享两个BPM配置小技巧
1.小技巧 流程图修改后发布的话版本号会+1,修改次数多了之后可能会导致版本号很高,这个时候可以将流程导出,然后删除对应的流程包再导入,发布数据模型和流程图之后,版本清零 2.小技巧 有的同事入职后使 ...
- linux系统维护时的一些小技巧,包括系统挂载新磁盘的方法!可收藏!
这里发布一些平时所用到的小技巧,不多,不过会持续更新.... 1.需要将history创建硬链接ln 全盘需要备份硬链接 ln /etc/xxx /home/xxx 2.root用户不可以远程 /et ...
- JS处理事件小技巧
今天,就分享一下我自己总结的一些JS的小技巧: ①防止鼠标选中事件 <div class="mask" onselectstart="return false&qu ...
- iOS:小技巧(不断更新)
记录下一些不常用技巧,以防忘记,复制用. 1.获取当前的View在Window的frame: UIWindow * window=[[[UIApplication sharedApplication] ...
- css小技巧(1)
1.-webkit-overflow-scrolling: touch; 解决ios滑动时无缓冲问题 2.::-webkit-scrollbar 设置ios滑动时是否显示滚动条 3.::selecti ...
- 最强 Android Studio 使用小技巧和快捷键
写在前面 本文翻译自 Android Studio Tips by Philippe Breault,一共收集了62个 Android Studio 使用小技巧和快捷键. 根据这些小技巧的使用场景,本 ...
- ios开发中的小技巧
在这里总结一些iOS开发中的小技巧,能大大方便我们的开发,持续更新. UITableView的Group样式下顶部空白处理 //分组列表头部空白处理 UIView *view = [[UIViewal ...
随机推荐
- 【Java基础-实验7】Banking_7 -添加银行透支扣款系统的 thorw异常机制
实验基本要求: 实验题目 7:(在6基础上修改) 将建立一个 OverdraftException 异常,它由 Account 类的withdraw()方法 抛出. 实验目的: 自定义异常 实验说明: ...
- [ 转载 ]hashCode及HashMap中的hash()函数
hashCode及HashMap中的hash()函数 一.hashcode是什么 要理解hashcode首先要理解hash表这个概念 1. 哈希表 hash表也称散列表(Hash table),是 ...
- DeviceSupport 路径
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSuppor
- appium+python 【Mac】UI自动化测试封装框架介绍 <四>---脚本的调试
优秀的脚本调试定位问题具备的特点: 1.方便调试. 2.运行报错后容易定位出现的问题. 3.日志的记录清晰 4.日志可被存储,一般测试结果的分析在测试之后会进行,那么日志的存储将会为后期的分析问题带来 ...
- Web UI开发速速种草—Kendo UI for jQuery网格编辑操作概述
Kendo UI for jQuery最新试用版下载 Kendo UI目前最新提供Kendo UI for jQuery.Kendo UI for Angular.Kendo UI Support f ...
- Educational Codeforces Round 72 (Rated for Div. 2) B题
Problem Description: You are fighting with Zmei Gorynich — a ferocious monster from Slavic myths, a ...
- 003_linuxC++之_namespace使用
(一)引入namespace原因: 假如有很多跟人共同完成一项工程,工程中难免会有函数定义一样的名称,不可能一个一个的询问这个函数 你定义过了没有,所以引入namespace #include < ...
- Java集合总结(一):列表和队列
java中的具体容器类都不是从头构建的,他们都继承了一些抽象容器类.这些抽象容器类,提供了容器接口的部分实现,方便具体容器类在抽象类的基础上做具体实现.容器类和接口的关系架构图如下: 虚线框表示接口, ...
- c++ 使用类生成随机数
// generate algorithm example #include <iostream> // cout #include <algorithm> // genera ...
- OpenJudge1.5.6:整数序列的元素最大跨度值
描述 给定一个长度为n的非负整数序列,请计算序列的最大跨度值(最大跨度值 = 最大值减去最小值). 输入一共2行,第一行为序列的个数n(1 <= n <= 1000),第二行为序列的n个不 ...