Skip to content

Commit 9c7787c

Browse files
author
unknown
committed
pdate
1 parent c561bce commit 9c7787c

File tree

6 files changed

+508
-371
lines changed

6 files changed

+508
-371
lines changed

README.md

Lines changed: 5 additions & 371 deletions
Large diffs are not rendered by default.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Flutter相关译文
2+
3+
[在 Google I/O 2018 观看 Flutter 的正确姿势 (wzasd 翻译)](https://juejin.im/post/5aebd7166fb9a07ab4587b3f)
4+
5+
[为什么 Flutter 能最好地改变移动开发 (ALVINYEH 翻译)](https://juejin.im/post/5add65c46fb9a07aa541e97e)
6+
7+
[Flutter 到底有多快?我开发了秒表应用来弄清楚。 (ALVINYEH 翻译)](https://juejin.im/post/5ad861566fb9a045ee01b48d)
8+
9+
[为 JavaScript 程序员准备的 Flutter 指南 (lsvih 翻译)](https://juejin.im/post/5ac43c536fb9a028da7cbd59)
10+
11+
[Flutter — 五个你会爱上它的原因 (rockzhai 翻译)](https://juejin.im/post/5a9e7e89f265da2381552542)
12+
13+
[如何在中国使用 Flutter (mysterytony 翻译)](https://juejin.im/post/5a9f730c6fb9a028d2077ad4)
14+
15+
[[]Flutter for Android Developers - Intents](https://juejin.im/post/5a96cd1f5188257a780de9a0)
16+
17+
[[]Flutter for Android Developers - Async UI](https://juejin.im/post/5a9a21f8518825558b3d5d35)
18+
19+
[[]Flutter for Android Developers - Gesture Detection](https://juejin.im/post/5a9c106151882555872300f2)

pics/线性渐变封装图示.png

54.2 KB
Loading
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import 'package:flutter/material.dart';
2+
3+
/// LinearGradient 线性渐变封装
4+
/// 一共有12种组合方式
5+
/// 用法:在有gradient属性的地方使用:例如:
6+
/// 首先要导包,import 'FractionalOffsetUtil.dart';
7+
/// 然后再去使用
8+
/// gradient: setFractionalOffsets(Type.leftBottomToRightTop, null),
9+
/// 再例如:
10+
/// gradient: setFractionalOffsets(Type.leftToRight, Direction.firstDirection),
11+
12+
LinearGradient setFractionalOffsets(
13+
@required Type type, @required Direction direction) {
14+
LinearGradient linearGradient;
15+
16+
if (type == Type.leftToRight) {
17+
linearGradient =
18+
DirectionStyle2(direction, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0);
19+
} else if (type == Type.rightToLeft) {
20+
linearGradient =
21+
DirectionStyle2(direction, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0);
22+
} else if (type == Type.topToBottom) {
23+
linearGradient =
24+
DirectionStyle2(direction, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0);
25+
} else if (type == Type.bottomToTop) {
26+
linearGradient =
27+
DirectionStyle2(direction, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
28+
} else if (type == Type.leftTopToRightBottom) {
29+
linearGradient = DirectionStyle(0.0, 0.0, 1.0, 1.0);
30+
} else if (type == Type.rightBottomToLeftTop) {
31+
linearGradient = DirectionStyle(1.0, 1.0, 0.0, 0.0);
32+
} else if (type == Type.rightTopToLeftBottom) {
33+
linearGradient = DirectionStyle(0.0, 1.0, 1.0, 0.0);
34+
} else if (type == Type.leftBottomToRightTop) {
35+
linearGradient = DirectionStyle(1.0, 0.0, 0.0, 1.0);
36+
}
37+
return linearGradient;
38+
}
39+
40+
LinearGradient DirectionStyle(
41+
double startX, double startY, double endX, double endY) {
42+
var linearGradient = new LinearGradient(
43+
//线性渐变
44+
begin: FractionalOffset(startX, startY),
45+
end: FractionalOffset(endX, endY),
46+
colors: <Color>[Colors.deepOrange, Colors.deepPurple],
47+
);
48+
return linearGradient;
49+
}
50+
51+
LinearGradient DirectionStyle2(
52+
@required Direction direction,
53+
double startX,
54+
double startY,
55+
double endX,
56+
double endY,
57+
double startX2,
58+
double startY2,
59+
double endX2,
60+
double endY2) {
61+
direction == Direction.firstDirection ? startX = startX : startX2;
62+
direction == Direction.firstDirection ? startY = startY : startY2;
63+
direction == Direction.firstDirection ? endX = endX : endX2;
64+
direction == Direction.firstDirection ? endY = endY : endY2;
65+
66+
var linearGradient = new LinearGradient(
67+
//线性渐变
68+
begin: FractionalOffset(startX, startY),
69+
end: FractionalOffset(endX, endY),
70+
colors: <Color>[Colors.deepOrange, Colors.deepPurple],
71+
);
72+
return linearGradient;
73+
}
74+
75+
// 因为从上到下,或者从左到右 都有两种可能。
76+
// 从上到下 包括: 左上 -> 左下 右上 -> 右下
77+
// 从左到右 包括: 左上 -> 右上 左下 -> 右下
78+
enum Direction {
79+
firstDirection,//如果是从上到下: 左上 -> 左下,如果是从左到右:左上 -> 右上
80+
lastPointDirection,// 如果是从上到下: 右上 -> 右下,如果是从左到右:左下 -> 右下
81+
}
82+
83+
enum Type {
84+
//8个方向
85+
leftToRight, //→
86+
rightToLeft, //←
87+
topToBottom, //↓
88+
bottomToTop, //↑
89+
leftTopToRightBottom, //↘
90+
rightBottomToLeftTop, //↖
91+
rightTopToLeftBottom, //↙
92+
leftBottomToRightTop, //↗
93+
}

0 commit comments

Comments
 (0)