flutter个别圆角切割

取用圆角类的only属性,左上,右上,左下,右下,此处圆角半径也是一个类

1
2
3
4
BorderRadius.only(
topLeft: Radius.circular(8.w),
topRight: Radius.circular(8.w),
)

全部圆角则取all

1
2
3
BorderRadius.all(
Radius.circular(8.w)
)

flutter模型生成

首先自己写好模型类模板代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import 'package:json_annotation/json_annotation.dart';
part 'buy_record_data.g.dart';

///标志class需要实现json序列化功能
@JsonSerializable()
class BuyRecordData {
///属性
List<BuyRecordEntity> entities;
/// 构造函数
BuyRecordData(this.entities);
/// 这个函数在.g.dart中,命名就是类名+FromJson
/// 直接写就行 报错也没关系 生成.g.dart文件之后就好了
factory BuyRecordData.fromJson(Map<String, dynamic> json) =>
_$BuyRecordDataFromJson(json);
Map<String, dynamic> toJson() => _$BuyRecordDataToJson(this);
}

然后在终端运行,生成.g.dart文件

1
2
flutter packages pub run build_runner build --delete-conflicting-outputs

参考:1. https://blog.csdn.net/YoYo_Newbie/article/details/90634878?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromBaidu-1.control&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromBaidu-1.control

  1. https://my.oschina.net/u/4326108/blog/3675231

flutter渲染原理要点

  • 渲染过程会生成三棵树

    • widget树

    • element树

    • render object树

  • 提高buid效率,在build方法中尽量少做事,层级越简单越好
  • setState方法尽量下放到底层节点
  • 尽量减少重绘区域,使用repaint boundry
  • 减少离屏渲染 比如save layer,clip path,
  • 减少透明度使用,因为每一帧都会重建widget
  • 建立缓存池
  • 提升layout效率

参考:https://www.freesion.com/article/8834628331/

dart枚举

1
2
3
4
5
6
7
8
9
enum MediaType {
movie, //0
shortVideo, //1
other, //2
}

var videoType = MediaType.values[0];
// videoType == movie

定义枚举和OC差别不大,取值的时候不可以直接和int比较,需要从枚举数组中根据index拿出来,比OC多了一步

什么是bitCode

The process of compiling consists of three different steps:

1.The compilier front-end converts the source code into some kind of intermediate representation.

2.The optimizer performs a sequence of optimizing transformations on the IR to render it smaller and more performant:redundant code is removed,results are pretaculated,code is inlined, etc.This crucial step of the compilation process makes use of IR,rather than cource code or machine code,because it can more easily be interreted by the optimizer.

  1. The compilier back-end generates machine code based on the optimized IR.

When we are talking about bitcode,we are actually talking about the IR used by the Clang Compilier.

image

With the bitcode embedded in the executable,Apple is able to recompile applications without interacting with the developer.This has a lot of advantages.

source:https://www.guardsquare.com/en/blog/enable-bitcode

flutter组件

sliverList

A sliver that places multiple box children in a linear array along the main axis.

Each child is forced to have the SliverConstraints.crossAxisExtent in the cross axis but determines its own main axis extent.

SliverList determines its scroll offset by “dead reckoning“ because children outside the visible part of the sliver are not materialized, which means SliverList cannot learn their main axis extent.Instead,newly materialized children are placed adjacent to existing children.

flutter actionSheet使用方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//函数
_showCupertinoActionSheet() async{
var result = await showCupertinoModalPopup(
context: context,
builder: (context) {
return CupertinoActionSheet(

title: Text('标题'),
message: Text('内容'),
actions: <Widget>[
CupertinoActionSheetAction(
child: Text(
'标题一',
style: TextStyle(
color: Color(0xFF00C599)
),
),
onPressed: () {
Navigator.of(context).pop('delete');
},
isDefaultAction: true,
),

CupertinoActionSheetAction(
child: Text('标题二'),
onPressed: () {
Navigator.of(context).pop('not delete');
},
isDestructiveAction: true,
),
],
cancelButton: CupertinoActionSheetAction(
child: Text(
'取消',
style: TextStyle(
color: Colors.white
),
),
onPressed: () {
Navigator.of(context).pop('cancel');
},
),
);
});
print('$result');
}

总结:在showCupertinoModalPopup方法里返回CupertinoActionSheet,里面的元素由CupertinoActionSheetAction组成,有default和destructive类型可选,用法和UI和苹果大致一样

image