React Hooks

React Hooks产生的原因

由于类组件存在一些缺点:

  • 大型组件很难拆分和重构,也很难测试。
  • 业务逻辑分散在组件的各个方法之中,导致重复逻辑或关联逻辑。
  • 组件类引入了复杂的编程模式,比如 render props 和高阶组件。
Read More

声明文件的写法的区别

基本的声明

声明文件

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

var x = 1;
module.exports.x = x; //导出变量

var add = function(a, b){
return a + b;
};

module.exports.add = add; //导出函数


function multiplay(a, b) {}

export {multiplay} // 导出对象

module.exports = {}; //ES5的写法,导出多个文件


export {add as default}; //导出默认值

export default class A {}

export default () => {}

export {Header, Bottom};

export type {TypeA, TypeB}; //导出类型

export default XXX 和 export {XXX} 区别

  • export default XXX:

Read More

打包

下载证书,本地安装到钥匙链中

配置Xcode

打包命令

修改项目的版本号和构建次数

若要使pubspec.yaml文件中的version生效,需要修改Android、iOS项目的配置文件。

Android项目配置文件修改

确认android/app/build.gradle文件中使用了Flutter的versionCode和versionName

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
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new FileNotFoundException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}

android {
compileSdkVersion 31

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
applicationId "com.xiaopeng.scepter"
minSdkVersion 21
targetSdkVersion 31
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
}

Read More