03-自己的cocoapod仓库

一:步骤

1,创建库工程,添加源文件到Classess文件夹

2,上传项目到github,并且打好标签

3,配置并上传框架的 PodSpec文件,并使用trunk的方式上传

4,更新本地pod 第三方框架信息数据源(pod setup, 这一步其实也是可是省略的,因为上述的上传,直接更新了本地索引库)

二:具体创建

1,创建库工程,省略(创建工程,实现功能)

Read More

02-cocoapods基本使用

一:pod的基本使用

1,podfile文件的初始化

cd到项目文件所在的目录,使用命令pod init 即可以自动初始化一个podfile文件

2,打开podfile文件,写上需要安装的第三方库,如

3, 在命令行中,使用 pod install 既可自动安装。

4, pod install 和 pod update的区别

  • a, pod install 安装第三方框架的时候是根据Podfile.lock 中的来安装的

  • b, pod update 将本地第三方框架更新到最新版本,并且更新Podfile.lock,并安装

Read More

Hero动画

效果:

代码:

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import 'package:flutter/material.dart';
import 'package:gm_staff_module/demo/example/example_common.dart';

///hero动画
class GMExampleAnimationHeroPage extends StatefulWidget {
GMExampleAnimationHeroPage({Key key}) : super(key: key);

@override
_GMExampleAnimationHeroPageState createState() =>
_GMExampleAnimationHeroPageState();
}

class _GMExampleAnimationHeroPageState
extends State<GMExampleAnimationHeroPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: example_common_appBar(context, "Hero动画"),
body: _buildContent(context),
);
}

Widget _buildContent(ctx) {
return GridView(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
crossAxisSpacing: 8,
mainAxisSpacing: 8,
childAspectRatio: 2),
children: List.generate(20, (index) {
String imageURL = "https://picsum.photos/id/$index/400/200";
return GestureDetector(
onTap: () {
Navigator.of(ctx).push(PageRouteBuilder(pageBuilder:
(BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation) {
return FadeTransition(
opacity: animation,
child: GMExampleAnimationHeroDetailPage(
imageURL: imageURL,
),
);
}));
},
child: Hero(
tag: imageURL,
child: Image.network(imageURL),
),
);
}),
);
}
}

///图片详情页
class GMExampleAnimationHeroDetailPage extends StatelessWidget {
final String imageURL;
GMExampleAnimationHeroDetailPage({Key key, this.imageURL}) : super(key: key);

@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black,
body: Center(
child: GestureDetector(
onTap: () {
Navigator.of(context).pop();
},
child: Hero(
tag: this.imageURL,
child: Image.network(
this.imageURL,
width: double.infinity,
fit: BoxFit.cover,
),
),
),
),
);
}
}

心形跳动

效果:

代码:

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import 'package:flutter/material.dart';
import 'package:gm_staff_module/demo/example/example_common.dart';

//简单动画
class GMExampleAnimationSimplePage extends StatefulWidget {
GMExampleAnimationSimplePage({Key key}) : super(key: key);

@override
_GMExampleAnimationSimplePageState createState() =>
_GMExampleAnimationSimplePageState();
}

class _GMExampleAnimationSimplePageState
extends State<GMExampleAnimationSimplePage> {
final GlobalKey<_AnimationDemo01State> demo01Key = GlobalKey();

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: example_common_appBar(context, "简单动画"),
body: _buildContent(context),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.play_circle_filled),
onPressed: () {
if (!this.demo01Key.currentState.controller.isAnimating) {
demo01Key.currentState.controller.forward();
} else {
demo01Key.currentState.controller.stop();
}
},
),
);
}

Widget _buildContent(ctx) {
return AnimationDemo01(
key: demo01Key,
);
}
}

class AnimationDemo01 extends StatefulWidget {
AnimationDemo01({Key key}) : super(key: key);

@override
_AnimationDemo01State createState() => _AnimationDemo01State();
}

class _AnimationDemo01State extends State<AnimationDemo01>
with SingleTickerProviderStateMixin {
AnimationController controller;
Animation<double> animation;

@override
void initState() {
super.initState();

//1.创建AnimationController
controller =
AnimationController(duration: Duration(seconds: 1), vsync: this);

//2.动画添加Curve效果
animation = CurvedAnimation(
parent: controller,
curve: Curves.elasticInOut,
reverseCurve: Curves.easeOut);

// //3.监听动画
// animation.addListener(() {
// print("addListener ...");
// setState(() {});
// });

//4.控制动画的翻转
animation.addStatusListener((status) {
print("addStatusListener -- $status");
if (status == AnimationStatus.completed) {
controller.reverse();
} else if (status == AnimationStatus.dismissed) {
controller.forward();
}
});

//5.设置值的范围
animation = Tween(begin: 50.0, end: 120.0).animate(controller);
}

@override
Widget build(BuildContext context) {
return Center(
child: AnimatedBuilder(
animation: animation,
builder: (ctx, child) {
return Icon(
Icons.favorite,
color: Colors.red,
size: animation.value,
);
},
// child: Container(),
),
);
}

@override
void dispose() {
controller.dispose();
super.dispose();
}
}

class IconAnimation extends AnimatedWidget {
IconAnimation(Animation animation) : super(listenable: animation);
@override
Widget build(BuildContext context) {
Animation animation = listenable;
print("IconAnimation -- ${animation.value}");
return Icon(
Icons.favorite,
color: Colors.red,
size: animation.value,
);
}
}

图片动画

效果:

代码:

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import 'package:flutter/material.dart';

import '../example_common.dart';

///一组图片动画
class GMExampleAnimationGroupImagePage extends StatefulWidget {
GMExampleAnimationGroupImagePage({Key key}) : super(key: key);

@override
_GMExampleAnimationGroupImagePageState createState() => _GMExampleAnimationGroupImagePageState();
}

class _GMExampleAnimationGroupImagePageState extends State<GMExampleAnimationGroupImagePage> {
@override
Widget build(BuildContext context) {
debugPrint("build ---------");
return Scaffold(
appBar: example_common_appBar(context, "一组图片动画"),
body: Center(
child: Container(
child: _buildContent(context),
height: 200,
width: 200,
color: Colors.orangeAccent,
padding: EdgeInsets.all(30.0),
),
),
);
}

Widget _buildContent(ctx) {
return GMExampleImagesAnimation(
w: 100,
h: 100,
entry: ImagesAnimationEntry(1, 7, "assets/images/example_ani_0"),
);
}
}

class GMExampleImagesAnimation extends StatefulWidget {
final double w;
final double h;
final ImagesAnimationEntry entry;
final int durationMilliseconds;

GMExampleImagesAnimation(
{Key key, this.w: 80, this.h: 80, this.entry, this.durationMilliseconds: 700})
: super(key: key);

@override
_GMExampleImagesAnimationState createState() =>
_GMExampleImagesAnimationState();
}

class _GMExampleImagesAnimationState extends State<GMExampleImagesAnimation>
with TickerProviderStateMixin {
AnimationController _controller;
Animation<int> _animation;

@override
void initState() {
super.initState();

_controller = AnimationController(
vsync: this, duration: Duration(milliseconds: this.widget.durationMilliseconds))
..repeat();

_animation =
new IntTween(begin: widget.entry.lowIndex, end: widget.entry.highIndex)
.animate(_controller);
}

@override
void dispose() {
_controller.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return AnimatedBuilder(
animation: _animation,
builder: (BuildContext ctx, Widget child) {
String frame = _animation.value.toString();
return Image.asset(
this.widget.entry.basePath + frame + ".png",
gaplessPlayback: true, //避免图片闪烁
width: widget.w,
height: widget.h,
);
},
);
}
}


class ImagesAnimationEntry {
int lowIndex = 0;
int highIndex = 0;
String basePath;

ImagesAnimationEntry(this.lowIndex, this.highIndex, this.basePath);
}

交织动画

效果:

代码:

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:gm_staff_module/demo/example/example_common.dart';

//交织动画
class GMExampleAnimationMixedPage extends StatefulWidget {
GMExampleAnimationMixedPage({Key key}) : super(key: key);

@override
_GMExampleAnimationMixedPageState createState() =>
_GMExampleAnimationMixedPageState();
}

class _GMExampleAnimationMixedPageState
extends State<GMExampleAnimationMixedPage> {
final GlobalKey<_AnimationDemo02State> demo02Key = GlobalKey();

@override
Widget build(BuildContext context) {
debugPrint("GMExampleAnimationMixedPage build ---- ");
return Scaffold(
appBar: example_common_appBar(context, "交织动画"),
body: _buildContent(context),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.play_circle_filled),
onPressed: () {
if (!this.demo02Key.currentState.controller.isAnimating) {
demo02Key.currentState.controller.forward();
} else {
demo02Key.currentState.controller.stop();
}
},
),
);
}

Widget _buildContent(ctx) {
print("_buildContent ----------");
return AnimationDemo02(key: demo02Key);
}
}

class AnimationDemo02 extends StatefulWidget {
AnimationDemo02({Key key}) : super(key: key);

@override
_AnimationDemo02State createState() => _AnimationDemo02State();
}

class _AnimationDemo02State extends State<AnimationDemo02>
with SingleTickerProviderStateMixin {
AnimationController controller;
Animation<double> animation;
Animation<Color> colorAnim;
Animation<double> sizeAnim;
Animation<double> rotationAnim;

@override
void initState() {
super.initState();

//1.创建AnimationController
controller =
AnimationController(duration: Duration(seconds: 2), vsync: this);

//2.动画添加Curve效果
animation = CurvedAnimation(parent: controller, curve: Curves.easeIn);

//3.监听动画
animation.addListener(() {
setState(() {});
});

animation.addStatusListener((AnimationStatus status) {
if (status == AnimationStatus.completed) {
controller.reverse();
} else if (status == AnimationStatus.dismissed) {
controller.forward();
}
});

//4.设置值的变化
colorAnim =
ColorTween(begin: Colors.blue, end: Colors.red).animate(controller);
sizeAnim = Tween(begin: 0.0, end: 200.0).animate(controller);
rotationAnim = Tween(begin: 0.0, end: 2 * pi).animate(controller);
}

@override
Widget build(BuildContext context) {
debugPrint("_AnimationDemo02State build ---- ");
return Center(
child: AnimatedBuilder(
animation: animation,
builder: (BuildContext context, Widget child) {
return Opacity(
opacity: animation.value,
child: Transform(
alignment: Alignment.center,
transform: Matrix4.rotationZ(rotationAnim.value),
child: Container(
width: sizeAnim.value,
height: sizeAnim.value,
color: colorAnim.value,
alignment: Alignment.center,
),
),
);
},
),
);
}

@override
void dispose() {
controller.dispose();
super.dispose();
}
}

环形动画

效果:

代码:

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import 'package:flutter/material.dart';
import 'dart:math' as math;

import '../example_common.dart';

class GMExampleAnimationRingPage extends StatefulWidget {
GMExampleAnimationRingPage({Key key}) : super(key: key);

@override
_GMExampleAnimationRingPageState createState() => _GMExampleAnimationRingPageState();
}

class _GMExampleAnimationRingPageState extends State<GMExampleAnimationRingPage> with SingleTickerProviderStateMixin{
AnimationController _controller;

Animation<double> angleAnim;

@override
void initState() {
// _controller = AnimationController(duration: Duration(milliseconds: 1500), vsync: this)..repeat();
_controller =
AnimationController(duration: Duration(milliseconds: 1500), vsync: this)
..repeat();

angleAnim = Tween(begin: math.pi * 1.5, end: math.pi * 3.5)
.chain(CurveTween(curve: Interval(0.5, 1.0)))
.animate(_controller);

super.initState();
}

@override
void dispose() {
_controller.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
debugPrint("build ---------");
return Scaffold(
appBar: example_common_appBar(context, "环形动画"),
body: Center(
child: Container(
child: _buildContent(context),
height: 200,
width: 200,
color: Colors.orangeAccent,
padding: EdgeInsets.all(30.0),
),
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.account_balance),
onPressed: () {
debugPrint("status: ${_controller.status}");
if (_controller.status == AnimationStatus.forward) {
_controller.fling();
} else {
_controller.reset();
_controller..forward()..repeat();
}
},
),
);
}

Widget _buildContent(ctx) {
return AnimatedBuilder(
animation: _controller,
builder: (context, child) {
return CustomPaint(
painter: GMExampleRingDemoPainter(angleAnim.value, math.sin(_controller.value * math.pi) * math.pi),
);
},
);
}
}

//自定义绘画
class GMExampleRingDemoPainter extends CustomPainter {
final double _arcStart;
final double _arcSweep;

GMExampleRingDemoPainter(this._arcStart, this._arcSweep);

@override
void paint(Canvas canvas, Size size) {
// debugPrint("_arcStart: $_arcStart, _arcSweep:$_arcSweep");
//找到最小的一边
double side = math.min(size.width, size.height);

Paint paint = Paint()
..color = Colors.red
..strokeCap = StrokeCap.round
..strokeWidth = 4.0
..style = PaintingStyle.stroke;

canvas.drawArc(
Offset.zero & Size(side, side), _arcStart, _arcSweep, false, paint);

}

@override
bool shouldRepaint(GMExampleRingDemoPainter other) {
return _arcStart != other._arcStart || _arcSweep != other._arcSweep;
}
}

动画容器

效果:

代码:

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import 'package:flutter/material.dart';

import 'package:flutter/material.dart';
import 'package:gm_staff_module/demo/example/example_common.dart';

///动画容器
class GMExampleAnimationContainerPage extends StatefulWidget {
GMExampleAnimationContainerPage({Key key}) : super(key: key);

@override
_GMExampleAnimationContainerPageState createState() =>
_GMExampleAnimationContainerPageState();
}

class _GMExampleAnimationContainerPageState
extends State<GMExampleAnimationContainerPage> {
double leftWidth = 0;
double topHeight1 = 0;
double topHeight2 = 0;

bool isLeftFlag = false;
bool isTopFlag1 = false;
bool isTopFlag2 = false;

@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: <Widget>[
Scaffold(
appBar: example_common_appBar(context, "动画容器"),
body: _buildContent(context),
),
_buildContent_topView1(),
],
),
);
}

Widget _buildContent(ctx) {
return Stack(
children: <Widget>[
_buildContent_dataView(),
_buildContent_leftView(),
_buildContent_topView2(),
],
);
}

//数据视图
Widget _buildContent_dataView() {
return Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
GestureDetector(
child: Container(
width: double.infinity,
height: 40,
color: Colors.red,
alignment: Alignment.center,
child: Text("左侧视图"),
),
onTap: () {
this.isLeftFlag = !this.isLeftFlag;
if (this.isLeftFlag) {
this.leftWidth = 200;
} else {
this.leftWidth = 0;
}
setState(() {});
},
),
SizedBox(
height: 10,
),
GestureDetector(
child: Container(
width: double.infinity,
height: 40,
color: Colors.red,
alignment: Alignment.center,
child: Text("顶部视图1"),
),
onTap: () {
this.isTopFlag1 = !this.isTopFlag1;
if (this.isTopFlag1) {
this.topHeight1 = 200;
} else {
this.topHeight1 = 0;
}
setState(() {});
},
),
SizedBox(
height: 10,
),
GestureDetector(
child: Container(
width: double.infinity,
height: 40,
color: Colors.red,
alignment: Alignment.center,
child: Text("顶部视图2"),
),
onTap: () {
this.isTopFlag2 = !this.isTopFlag2;
if (this.isTopFlag2) {
this.topHeight2 = 200;
} else {
this.topHeight2 = 0;
}
setState(() {});
},
),
],
);
}

//左侧视图
Widget _buildContent_leftView() {
return Positioned(
top: 150,
left: 0,
child: AnimatedContainer(
duration: Duration(milliseconds: 250),
width: leftWidth,
height: 300,
child: Container(
width: 200,
color: Colors.orange,
alignment: Alignment.center,
child: ListView.separated(
itemBuilder: (BuildContext ctx, int index) {
return Text("left -- $index");
},
separatorBuilder: (BuildContext ctx, int index) {
return Divider(color: Colors.grey,);
},
itemCount: 30),
),
),
);
}

//顶部视图1
Widget _buildContent_topView1() {
return Positioned(
top: 0,
left: 0,
child: AnimatedContainer(
duration: Duration(milliseconds: 250),
width: MediaQuery.of(context).size.width,
height: this.topHeight1,
child: Container(
width: 200,
height: 200,
color: Colors.blue,
alignment: Alignment.center,
),
),
);
}
//顶部视图2
Widget _buildContent_topView2() {
return Positioned(
top: 0,
left: 0,
child: AnimatedContainer(
duration: Duration(milliseconds: 250),
width: MediaQuery.of(context).size.width,
height: this.topHeight2,
child: Container(
width: 200,
height: 200,
color: Colors.purple,
alignment: Alignment.center,
),
),
);
}
}

12-sqlite数据处理

问题: 当给XMGStu模型类添加数组型属性和字典型属性,该如何处理?

1,在XMGSqliteModelTool中的saveOrUpdateModel:uid方法中,在保存的时候,将值为字典或者数组的时候,进行处理,先转成data, 然后转成字符串。

2,在查询的时候,将类型为数组或者字典的属性,对值进行处理,先转成data, 然后转成相应的类型值。

Read More