Skip to content

Commit 8e1dde4

Browse files
committed
feat: Support null safety
1 parent f7d58ba commit 8e1dde4

13 files changed

Lines changed: 560 additions & 48 deletions

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ node_modules/
33
.idea/
44
build/
55
/iconfont.json
6-
.DS_Store
6+
.DS_Store
7+
.dart_tool/
8+
.packages

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
...
2020

2121
dependencies:
22-
# 版本号请以官方库的为准:https://github.com/dnfield/flutter_svg/tags
23-
flutter_svg: ^0.18.0
22+
# 版本号请以官方库的为准:https://pub.dev/packages/flutter_svg
23+
flutter_svg: ^0.19.3
2424
...
2525
}
2626
```
@@ -45,7 +45,8 @@ npx iconfont-init
4545
"symbol_url": "请参考README.md,复制官网提供的JS链接",
4646
"save_dir": "./lib/iconfont",
4747
"trim_icon_prefix": "icon",
48-
"default_icon_size": 18
48+
"default_icon_size": 18,
49+
"null_safety": true
4950
}
5051
```
5152
### 配置参数说明:
@@ -66,6 +67,14 @@ npx iconfont-init
6667
### default_icon_size
6768
我们将为每个生成的图标组件加入默认的字体大小,当然,你也可以通过传入props的方式改变这个size值
6869

70+
### null_safety
71+
dart 2.12.0 开始支持的空安全特性,开启该参数后,生成的语法会有所变化,所以需要变更sdk以保证语法能被识别。
72+
```diff
73+
environment:
74+
- sdk: ">=2.7.0 <3.0.0"
75+
+ sdk: ">=2.12.0 <3.0.0"
76+
```
77+
6978
# Step 3
7079
开始生成React标准组件
7180
```bash

pubspec.lock

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
# Generated by pub
2+
# See https://dart.dev/tools/pub/glossary#lockfile
3+
packages:
4+
async:
5+
dependency: transitive
6+
description:
7+
name: async
8+
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub"
9+
source: hosted
10+
version: "2.5.0"
11+
boolean_selector:
12+
dependency: transitive
13+
description:
14+
name: boolean_selector
15+
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub"
16+
source: hosted
17+
version: "2.1.0"
18+
characters:
19+
dependency: transitive
20+
description:
21+
name: characters
22+
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub"
23+
source: hosted
24+
version: "1.1.0"
25+
charcode:
26+
dependency: transitive
27+
description:
28+
name: charcode
29+
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub"
30+
source: hosted
31+
version: "1.2.0"
32+
clock:
33+
dependency: transitive
34+
description:
35+
name: clock
36+
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub"
37+
source: hosted
38+
version: "1.1.0"
39+
collection:
40+
dependency: transitive
41+
description:
42+
name: collection
43+
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub"
44+
source: hosted
45+
version: "1.15.0"
46+
cupertino_icons:
47+
dependency: "direct main"
48+
description:
49+
name: cupertino_icons
50+
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub"
51+
source: hosted
52+
version: "1.0.2"
53+
fake_async:
54+
dependency: transitive
55+
description:
56+
name: fake_async
57+
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub"
58+
source: hosted
59+
version: "1.2.0"
60+
flutter:
61+
dependency: "direct main"
62+
description: flutter
63+
source: sdk
64+
version: "0.0.0"
65+
flutter_svg:
66+
dependency: "direct main"
67+
description:
68+
name: flutter_svg
69+
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub"
70+
source: hosted
71+
version: "0.21.0-nullsafety.0"
72+
flutter_test:
73+
dependency: "direct dev"
74+
description: flutter
75+
source: sdk
76+
version: "0.0.0"
77+
matcher:
78+
dependency: transitive
79+
description:
80+
name: matcher
81+
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub"
82+
source: hosted
83+
version: "0.12.10"
84+
meta:
85+
dependency: transitive
86+
description:
87+
name: meta
88+
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub"
89+
source: hosted
90+
version: "1.3.0"
91+
path:
92+
dependency: transitive
93+
description:
94+
name: path
95+
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub"
96+
source: hosted
97+
version: "1.8.0"
98+
path_drawing:
99+
dependency: transitive
100+
description:
101+
name: path_drawing
102+
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub"
103+
source: hosted
104+
version: "0.5.0-nullsafety.0"
105+
path_parsing:
106+
dependency: transitive
107+
description:
108+
name: path_parsing
109+
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub"
110+
source: hosted
111+
version: "0.2.0-nullsafety.0"
112+
petitparser:
113+
dependency: transitive
114+
description:
115+
name: petitparser
116+
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub"
117+
source: hosted
118+
version: "4.0.2"
119+
sky_engine:
120+
dependency: transitive
121+
description: flutter
122+
source: sdk
123+
version: "0.0.99"
124+
source_span:
125+
dependency: transitive
126+
description:
127+
name: source_span
128+
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub"
129+
source: hosted
130+
version: "1.8.0"
131+
stack_trace:
132+
dependency: transitive
133+
description:
134+
name: stack_trace
135+
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub"
136+
source: hosted
137+
version: "1.10.0"
138+
stream_channel:
139+
dependency: transitive
140+
description:
141+
name: stream_channel
142+
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub"
143+
source: hosted
144+
version: "2.1.0"
145+
string_scanner:
146+
dependency: transitive
147+
description:
148+
name: string_scanner
149+
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub"
150+
source: hosted
151+
version: "1.1.0"
152+
term_glyph:
153+
dependency: transitive
154+
description:
155+
name: term_glyph
156+
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub"
157+
source: hosted
158+
version: "1.2.0"
159+
test_api:
160+
dependency: transitive
161+
description:
162+
name: test_api
163+
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub"
164+
source: hosted
165+
version: "0.2.19"
166+
typed_data:
167+
dependency: transitive
168+
description:
169+
name: typed_data
170+
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub"
171+
source: hosted
172+
version: "1.3.0"
173+
vector_math:
174+
dependency: transitive
175+
description:
176+
name: vector_math
177+
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub"
178+
source: hosted
179+
version: "2.1.0"
180+
xml:
181+
dependency: transitive
182+
description:
183+
name: xml
184+
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub"
185+
source: hosted
186+
version: "5.0.2"
187+
sdks:
188+
dart: ">=2.12.0 <3.0.0"
189+
flutter: ">=1.24.0-7.0"

pubspec.yaml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: flutter_demo
2+
description: A new Flutter project.
3+
4+
# The following line prevents the package from being accidentally published to
5+
# pub.dev using `pub publish`. This is preferred for private packages.
6+
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
7+
8+
# The following defines the version and build number for your application.
9+
# A version number is three numbers separated by dots, like 1.2.43
10+
# followed by an optional build number separated by a +.
11+
# Both the version and the builder number may be overridden in flutter
12+
# build by specifying --build-name and --build-number, respectively.
13+
# In Android, build-name is used as versionName while build-number used as versionCode.
14+
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
15+
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
16+
# Read more about iOS versioning at
17+
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
18+
version: 1.0.0+1
19+
20+
environment:
21+
sdk: ">=2.12.0 <3.0.0"
22+
23+
dependencies:
24+
flutter:
25+
sdk: flutter
26+
flutter_svg: ^0.21.0-nullsafety.0
27+
28+
# The following adds the Cupertino Icons font to your application.
29+
# Use with the CupertinoIcons class for iOS style icons.
30+
cupertino_icons: ^1.0.0
31+
32+
dev_dependencies:
33+
flutter_test:
34+
sdk: flutter
35+
36+
# For information on the generic Dart part of this file, see the
37+
# following page: https://dart.dev/tools/pub/pubspec
38+
39+
# The following section is specific to Flutter.
40+
flutter:
41+
42+
# The following line ensures that the Material Icons font is
43+
# included with your application, so that you can use the icons in
44+
# the material Icons class.
45+
uses-material-design: true
46+
47+
# To add assets to your application, add an assets section, like this:
48+
# assets:
49+
# - images/a_dot_burr.jpeg
50+
# - images/a_dot_ham.jpeg
51+
52+
# An image asset can refer to one or more resolution-specific "variants", see
53+
# https://flutter.dev/assets-and-images/#resolution-aware.
54+
55+
# For details regarding adding assets from package dependencies, see
56+
# https://flutter.dev/assets-and-images/#from-packages
57+
58+
# To add custom fonts to your application, add a fonts section here,
59+
# in this "flutter" section. Each entry in this list should have a
60+
# "family" key with the font family name, and a "fonts" key with a
61+
# list giving the asset and other descriptors for the font. For
62+
# example:
63+
# fonts:
64+
# - family: Schyler
65+
# fonts:
66+
# - asset: fonts/Schyler-Regular.ttf
67+
# - asset: fonts/Schyler-Italic.ttf
68+
# style: italic
69+
# - family: Trajan Pro
70+
# fonts:
71+
# - asset: fonts/TrajanPro.ttf
72+
# - asset: fonts/TrajanPro_Bold.ttf
73+
# weight: 700
74+
#
75+
# For details regarding fonts from package dependencies,
76+
# see https://flutter.dev/custom-fonts/#from-packages

scripts/config/nullsafety.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"symbol_url": "http://at.alicdn.com/t/font_1373348_do9g97fppkg.js",
3+
"save_dir": "./snapshots-1",
4+
"trim_icon_prefix": "icon",
5+
"default_icon_size": 14,
6+
"null_safety": true
7+
}

scripts/update-snapshot.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@
22

33
cp -f ./scripts/config/normal.json ./iconfont.json
44
npx ts-node src/commands/createIcon.ts
5+
6+
cp -f ./scripts/config/nullsafety.json ./iconfont.json
7+
npx ts-node src/commands/createIcon.ts
8+
mv ./snapshots-1/icon_font.dart ./snapshots/null_safety.dart
9+
rmdir ./snapshots-1

snapshots/icon_font.dart

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,21 @@ enum IconNames {
55
_123, setup, user, alipay
66
}
77

8-
/**
9-
* A class includes all icons which you provided from https://iconfont.cn
10-
*
11-
* How to use it:
12-
* ```dart
13-
* IconFont(IconNames.xxx);
14-
* IconFont(IconNames.xxx, color: '#f00');
15-
* IconFont(IconNames.xxx, colors: ['#f00', 'blue']);
16-
* IconFont(IconNames.xxx, size: 30, color: '#000');
17-
* ```
18-
*
19-
* The name is dynamic to against server interface.
20-
* Feel free to input string literal.
21-
* ```dart
22-
* IconFont('xxx');
23-
* ```
24-
*/
8+
/// A class includes all icons which you provided from https://iconfont.cn
9+
///
10+
/// How to use it:
11+
/// ```dart
12+
/// IconFont(IconNames.xxx);
13+
/// IconFont(IconNames.xxx, color: '#f00');
14+
/// IconFont(IconNames.xxx, colors: ['#f00', 'blue']);
15+
/// IconFont(IconNames.xxx, size: 30, color: '#000');
16+
/// ```
17+
///
18+
/// The name is dynamic to against server interface.
19+
/// Feel free to input string literal.
20+
/// ```dart
21+
/// IconFont('xxx');
22+
/// ```
2523
class IconFont extends StatelessWidget {
2624
IconNames name;
2725
final String color;
@@ -168,10 +166,6 @@ class IconFont extends StatelessWidget {
168166

169167
}
170168

171-
if (svgXml == null) {
172-
return new Container(width: 0, height: 0);
173-
}
174-
175169
return SvgPicture.string(svgXml, width: this.size, height: this.size);
176170
}
177171
}

0 commit comments

Comments
 (0)