### 上拉加载下拉刷新
```
import 'dart:async';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter_easyrefresh/bezier_hour_glass_header.dart';
import 'package:flutter_easyrefresh/bezier_bounce_footer.dart';
import 'package:flutter_smart_park/widget/refresh/emptyWidget.dart'; List list = []; GlobalKey<EasyRefreshState> _easyRefreshKey = new GlobalKey<EasyRefreshState>();
GlobalKey<RefreshHeaderState> _headerKey = new GlobalKey<RefreshHeaderState>();
GlobalKey<RefreshFooterState> _footerKey = new GlobalKey<RefreshFooterState>(); new EasyRefresh(
key: _easyRefreshKey,
autoLoad: true, //自动加载
autoControl: false, //自动控制
firstRefresh: true, //首次加载
firstRefreshWidget: null,
refreshHeader: BezierHourGlassHeader(
key: _headerKey,
color: Theme.of(context).scaffoldBackgroundColor,
),
refreshFooter: BezierBounceFooter(
key: _footerKey,
color: Theme.of(context).scaffoldBackgroundColor,
),
child: new text('data'),
emptyWidget: new EmptyWidget(),
onRefresh: () async {
List a = [];
for (var i = 0; i < 10; i++) {
a.add(i);
} new Timer(new Duration(seconds: 2), () {
setState(() {
list.clear();
list.addAll(a);
});
_easyRefreshKey.currentState.callRefreshFinish();
});
},
loadMore: () async {
List a = [];
for (var i = 0; i < 10; i++) {
a.add(i);
} new Timer(new Duration(seconds: 2), () {
setState(() {
if (list.length < 20) {
list.addAll(a);
print(list.length);
}
});
_easyRefreshKey.currentState.callLoadMoreFinish();
});
},
),
``` ### 底部导航
```
bottomNavigationBar: BottomNavigationBar(
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(icon: Icon(Icons.home), title: Text('Home')),
BottomNavigationBarItem(icon: Icon(Icons.business), title: Text('Business')),
BottomNavigationBarItem(icon: Icon(Icons.school), title: Text('School')),
],
currentIndex: _selectedIndex,
fixedColor: Colors.deepPurple,
onTap: _onItemTapped,
), ``` ### listView 列表
```
new ListView.builder(
scrollDirection: Axis.horizontal, //横向
shrinkWrap:true, // 自动高度
physics: NeverScrollableScrollPhysics(), // 禁止滚动
itemCount: 10,
itemBuilder: (BuildContext context, int index) { },
),
``` ### text 文本
```
Text(
"Hello world "*6, //字符串重复六次
textAlign: TextAlign.center, //对齐方式
overflow: TextOverflow.ellipsis, // 文本溢出
maxLines: 3, // 最多显示的行数
textScaleFactor: 1.5,
style: TextStyle(
color: Colors.blue,
fontSize: 18.0,
height: 1.2,
fontFamily: "Courier",
background: new Paint()..color=Colors.yellow,
decoration:TextDecoration.underline,
decorationStyle: TextDecorationStyle.dashed
),
); // 一行文字多种样式
Text.rich(
TextSpan(
children: [
TextSpan(
text: "Home: "
),
TextSpan(
text: "https://flutterchina.club",
style: TextStyle(
color: Colors.blue
),
),
]
),
)
``` ### Container容器
```
new Container(
alignment: Alignment.center, //对齐方式
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Colors.lightBlue, Colors.greenAccent, Colors.purple],
begin: FractionalOffset(0, 0),
end: FractionalOffset(1, 1),
),
border: Border.all(
width: 2.0,
color: Colors.red,
),
image: DecorationImage( // 背景图片
image: AssetImage('assets/images/parkingbg.png'), //本地
centerSlice: Rect.fromLTRB(270.0, 180.0, 1360.0, 730.0),
),
),
),
``` ### Image图片
BoxFit.fill:全图显示,图片会被拉伸,并充满父容器。
BoxFit.contain:全图显示,显示原比例,可能会有空隙。
BoxFit.cover:显示可能拉伸,可能裁切,充满(图片要充满整个容器,还不变形)。
BoxFit.fitWidth:宽度充满(横向充满),显示可能拉伸,可能裁切。
BoxFit.fitHeight :高度充满(竖向充满),显示可能拉伸,可能裁切。
BoxFit.scaleDown:效果和contain差不多,但是此属性不允许显示超过源图片大小,可小不可大。 ImageRepeat.repeat : 横向和纵向都进行重复,直到铺满整个画布。
ImageRepeat.repeatX: 横向重复,纵向不重复。
ImageRepeat.repeatY:纵向重复,横向不重复。 ```
new Image.network(
'http://jspang.com/static/myimg/blogtouxiang.jpg',
scale:1.0,
fit:BoxFit.cover,
olorBlendMode: BlendMode.darken, //图片混合模式
repeat: ImageRepeat.repeat, //图片重复
), CachedNetworkImage(
imageUrl: 'https://pro.modao.cc/uploads4/images/3089/30894737/v2_pnb2pb.png',
placeholder: (context, url) => CircularProgressIndicator(),
errorWidget: (context, url, error) => Icon(Icons.error),
fit: BoxFit.cover,
width: ScreenUtil().setWidth(130),
height: ScreenUtil().setWidth(90),
),
``` ### GridView网格列表组件
```
new GridView(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
mainAxisSpacing: 2.0,
crossAxisSpacing: 2.0,
childAspectRatio: 0.7
),
children: <Widget>[
new Image.network('http://img5.mtime.cn/mt/2018/10/22/104316.77318635_180X260X4.jpg',fit: BoxFit.cover),
new Image.network('http://img5.mtime.cn/mt/2018/10/10/112514.30587089_180X260X4.jpg',fit: BoxFit.cover),
],
) new GridView.builder(
shrinkWrap: true,
physics: new NeverScrollableScrollPhysics(),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 4, //一行多少列
mainAxisSpacing: ScreenUtil().setWidth(LqruiStyle.borderWidth), //y轴距离
crossAxisSpacing:
ScreenUtil().setWidth(LqruiStyle.borderWidth), //x轴距离
childAspectRatio: 1.4, //框的比列
),
itemCount: homeIcon.length,
itemBuilder: (BuildContext context, int index) {
<!-- 内容 -->
},
),
``` ### Column垂直布局
```
new Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('I am JSPang'),
Text('my website is jspang.com'),
Text('I love coding')
],
)
``` ### Row横向布局
```
new Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Expanded(
child: Text('I am JSPang'),
)
Text('my website is jspang.com'),
Text('I love coding')
],
)
``` ### Stack层叠布局
```
var stack = new Stack(
alignment: const FractionalOffset(0.5, 0.8),
children: <Widget>[
new CircleAvatar(
backgroundImage: new NetworkImage('http://jspang.com/static//myimg/blogtouxiang.jpg'),
radius: 100.0,
),
new Container(
decoration: new BoxDecoration(
color: Colors.lightBlue,
),
padding: EdgeInsets.all(5.0),
child: new Text('JSPang 技术胖'),
),
new Positioned(
bottom:10.0,
right:10.0,
child: new Text('技术胖'),
),
],
);
``` ### Card卡片组件布局
```
new Card(
child: Column(
children: <Widget>[
ListTile(
title:new Text('吉林省吉林市昌邑区',style: TextStyle(fontWeight: FontWeight.w500),),
subtitle: new Text('技术胖:1513938888'),
leading: new Icon(Icons.account_box,color: Colors.lightBlue,),
),
new Divider(),
ListTile(
title:new Text('北京市海淀区中国科技大学',style: TextStyle(fontWeight: FontWeight.w500),),
subtitle: new Text('胜宏宇:1513938888'),
leading: new Icon(Icons.account_box,color: Colors.lightBlue,),
),
new Divider(),
ListTile(
title:new Text('河南省濮阳市百姓办公楼',style: TextStyle(fontWeight: FontWeight.w500),),
subtitle: new Text('JSPang:1513938888'),
leading: new Icon(Icons.account_box,color: Colors.lightBlue,),
),
new Divider(),
],
),
);
``` ### 路由
```
import 'package:fluro/fluro.dart';
import 'package:flutter_smart_park/routes/routes.dart'; Routes.router
.navigateTo(context, '${Routes.xxx}?id=1',
transition: TransitionType.inFromRight)
.then((result) {
print(result);
}); Routes.router.navigateTo(
context,
'${Routes.userSignUp}',
transition: TransitionType.inFromRight,
); Navigator.of(context).pop(); ``` ### 文本左右布局
```
Widget page(title, text) {
return new Container(
margin: EdgeInsets.only(top: ScreenUtil().setWidth(10)),
child: Row(
children: <Widget>[
Expanded(
child: Text(
'$title',
style: TextStyle(
color: Color(LqruiStyle.colorText2),
fontSize: ScreenUtil().setSp(14),
),
),
),
Expanded(
flex: 0,
child: Text(
'$text',
style: TextStyle(
fontSize: ScreenUtil().setSp(14),
),
),
),
],
),
);
}
``` ### 文本默认样式
```
new DefaultTextStyle(
//1.设置文本默认样式
style: TextStyle(
color:Colors.red,
fontSize: 20.0,
),
textAlign: TextAlign.start,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text("hello world"),
Text("I am Jack"),
Text("I am Jack",
style: TextStyle(
inherit: false, //2.不继承默认样式
color: Colors.grey
),
),
],
),
);
``` ### 页面加载事件
```
@override
void initState() {
super.initState();
print('111111111111111111111111111');
}
``` ### 输入法弹起导致容器越界
```
1. 包一层SingleChildScrollView
2. 设置Scaffold resizeToAvoidBottomPadding: false,
``` ### 切换后页面状态的保持
```
// 子页面
class _HomePageState extends State<HomePage> with AutomaticKeepAliveClientMixin {
@override
bool get wantKeepAlive =>true;
} // 使用 IndexedStack
new IndexedStack(
index: currentIndex,
children: tabBodies
)
``` ### 点击事件
```
new GestureDetector(
child: new Text("忘记密码"),
onTap: () => {}, //点击
onDoubleTap: () => {}, //双击
onLongPress: () => {}, //长按
),
``` ### 输入框
```
Container(
child: TextField(
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
labelText: "Email",
hintText: "电子邮件地址",
prefixIcon: Icon(Icons.email),
border: InputBorder.none //隐藏下划线
)
),
decoration: BoxDecoration(
// 下滑线浅灰色,宽度1像素
border: Border(bottom: BorderSide(color: Colors.grey[200], width: 1.0))
),
) Theme(
data: Theme.of(context).copyWith(
hintColor: Color(LqruiStyle.dividerColor), //定义下划线颜色
inputDecorationTheme: InputDecorationTheme(
labelStyle:
TextStyle(color: Colors.grey), //定义label字体样式
hintStyle: TextStyle(
color: Colors.grey, fontSize: 14.0) //定义提示文本样式
),
),
child: Form(),
),
``` ### 圆角容器
```
new ClipOval( //默认全圆角
child: Container(
width: 100,
height: 100,
color: Colors.red,
),
), new ClipRRect( //自定义
borderRadius: BorderRadius.circular(50)
child: Container(
width: 100,
height: 100,
color: Colors.red,
),
), // shape属性
new Container(
width: 72.0,
height: 72.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
image: AssetImage(
Utils.getImgPath('ali_connors'),
),
),
),
)
``` ### 下拉框
```
DropdownButtonHideUnderline( //隐藏下划线盒子
child: DropdownButton(
items: items, //下拉菜单item点击之后的回调
hint: new Text('下拉选择你想要的数据'), //当没有默认值的时候可以设置的提示
value: widget.select, //下拉菜单选择完之后显示给用户的值
onChanged: widget.onChanged, //下拉菜单item点击之后的回调
elevation: 24, //设置阴影的高度
// isDense: true,
//减少按钮的高度。默认情况下,此按钮的高度与其菜单项的高度相同。如果isDense为true,
则按钮的高度减少约一半。 这个当按钮嵌入添加的容器中时,非常有用
isExpanded: true,
iconSize: ScreenUtil().setSp(30), //设置三角标icon的大小
),
);
``` ### 单边框
```
decoration: BoxDecoration(
border: Border(
left: BorderSide(
width: ScreenUtil().setWidth(5),
color: Color(LqruiStyle.primaryColor),
style: BorderStyle.solid,
),
),
),
``` ### 模拟器分辨率
```
414 736 154
360 640 160
``` ### 状态栏去阴影
```
import 'dart:io';
import 'package:flutter/services.dart'; if (Platform.isAndroid) {
SystemUiOverlayStyle systemUiOverlayStyle = SystemUiOverlayStyle(
statusBarColor: Colors.red,
);
SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
} appBar中 elevation: 0,
```
### 接收参数
```
final id;
final title;
ApplyReim({Key key, @required this.id, this.title}) : super(key: key);
``` ### 子组件传参 => 父组件
```
// 父组件
var data;
void onDataChange(val) {
setState(() {
data = val;
});
}
@override
Widget build(BuildContext context) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ChildTwo(data4Two: data4Two, callback: (val) => onDataChange(val)), // 子组件
Container(
child: Column(
children: <Widget>[
Text('子组件2, 传过来的值: ' + '$data'),
]
),
)
],
),
);
}
// 子组件接收callback,并在某事件中触发 widget.callback(...要返回的数据...);
PhotoDetail({Key key, @required this.list, this.index}) : super(key: key);
``` ### 监听Widget宽/高
```
import 'package:flustars/flustars.dart'; double cardHeight; Builder(
builder: (BuildContext context) {
WidgetUtil widgetUtil = new WidgetUtil();
widgetUtil.asyncPrepare(context, true, (Rect rect) {
Rect rect = WidgetUtil.getWidgetBounds(context);
setState(() {
cardHeight = rect.height.toInt();
});
});
return ...;
}
)
``` ### 进度条
```
LinearProgressIndicator(
backgroundColor: Color(0x42000000),
value: 10 / 30, // value值为null时为一个动画
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
),
```

### Text属性详解

https://www.jianshu.com/p/70376c16bdef

flutter-开发总结的更多相关文章

  1. 浅谈Flutter(一):搭建Flutter开发环境

    学习内容来自: Flutter中文网  . Flutter实战 -------------------------------------------------------------------- ...

  2. 安装与配置Flutter开发环境

    这篇博客我们介绍了Flutter,并且对比了H5,React Native,Flutter. 由于Flutter是跨平台的开发框架,开发一次可以同时运行在Android和iOS上面,所以我们开发时最好 ...

  3. MAC安装flutter开发环境

    #最近在学flutter开发,写一篇记录一下安装的过程 1.配置flutter镜像地址  vim ~/.bash_profile 命令行输入后回车,打开.bash_profile配置镜像地址 expo ...

  4. Flutter开发环境(Window)配置及踩坑记录

    Flutter 是 Google 用以帮助开发者在 iOS 和 Android 两个平台开发高质量原生 UI 的移动 SDK.Flutter 兼容现有的代码,免费且开源,在全球开发者中广泛被使用. F ...

  5. Flutter开发中的几个常用函数

    几个Flutter开发中的常用函数 /** 返回当前时间戳 */ static int currentTimeMillis() { return new DateTime.now().millisec ...

  6. [Dart] Flutter开发中的几个常用函数

    几个Flutter开发中的常用函数 /** 返回当前时间戳 */ static int currentTimeMillis() { return new DateTime.now().millisec ...

  7. Flutter 开发环境搭建

    Flutter 开发环境搭建 官方的资料相对还是比较全面的,包含了很多中文的资料信息.官方对咱们国家的开发人员还是很友好的. 安装教程:https://flutter.io/get-started/i ...

  8. mac 上配置flutter开发环境

    (ios,Android,Xcode,Android Studio,VScode,IDEA) 1)安装Flutter SDK 2)iOS 环境配置 3)Android Studio配置 4)VS co ...

  9. 重磅开源|AOP for Flutter开发利器——AspectD

    https://github.com/alibaba-flutter/aspectd 问题背景 随着Flutter这一框架的快速发展,有越来越多的业务开始使用Flutter来重构或新建其产品.但在我们 ...

  10. 搭建Flutter开发环境需要注意的几个小Tips

    目录 下载SDK 安装 Android Stdio + SDK + tool SDK + 创建模拟器 + 插件(flutter和dart) Xcode + cocoapods VSCode + Flu ...

随机推荐

  1. 【朝花夕拾】四大组件之(一)Broadcast篇

    前言 笔者最近在探究ANR及源码的过程中,发现对Broadcast的一些应用层面上的知识有的感觉比较生疏,有的记忆不准确,有的认识不完整.所谓“基础不牢,地动山摇”,于是就梳理了一下Broadcast ...

  2. 限定项目的 Node.js 版本

    限定项目运行所需的 Node.js 版本可保证项目在一个稳定可预期的环境中运行,减少不必要的故障.甚至有些依赖库只能工作于某些版本下.同时,不加以限制的话,在多人合作的项目中恐怕会引起环境不一致带来的 ...

  3. springboot~configserver里对重要信息进行RSA加密

    简介 参考:https://springcloud.cc/spring-cloud-dalston.html#_encryption_and_decryption_2 RSA非对称加密有着非常强大的安 ...

  4. 【转载】java final 关键字的几种用法

    原文链接点这里,感谢博主分享 在java的关键字中,static和final是两个我们必须掌握的关键字.不同于其他关键字,他们都有多种用法,而且在一定环境下使用,可以提高程序的运行性能,优化程序的结构 ...

  5. 如何使用.net开发一款小而美的O2O移动应用? ——“家庭小秘”APP介绍及采访记录

    “家庭小秘”是一款“互联网+生活服务”平台,为市民家庭提供优质家庭生活服务和企业后勤服务,包含了用户注册.购买预约.订单查询.充值付款.即时通讯等功能. 这款应用已上线至AppStore和安卓的应用商 ...

  6. [转]How to: Create a Report Server Database (Reporting Services Configuration)

    本文转自:https://docs.microsoft.com/en-us/previous-versions/sql/sql-server-2008-r2/ms157300%28v%3dsql.10 ...

  7. TrieTree

    学习链接:https://blog.csdn.net/lisonglisonglisong/article/details/45584721 前缀树解决字符串前缀匹配问题,查找单词是否存在,统计以如“ ...

  8. Java中1.0 / 0.0 会输出什么?

    蓝桥杯失利后发现算法与数据结构的重要性,开始学习算法,刚刚在看<算法4>,看到了这么个东西,让我对java中的size运算有了新的感悟. 在java中输出1/0会发生什么,毫无疑问会报异常 ...

  9. typescript的函数

    1:默认参数(传入值会覆盖默认参数,不传值也行) function getinfo(name:string,age:number=20):string{ return `${name}---${age ...

  10. Glide的 java.lang.RuntimeException: Expected instanceof GlideModule, but found:X.GlideModule@2e4554f

    问题一 在添加过混淆规则后,App打包的时候,发现报错了 java.lang.RuntimeException: Expected instanceof GlideModule, but found: ...