Skip to content

Commit dfd8a7a

Browse files
committed
优化代码
1 parent 5c2527d commit dfd8a7a

9 files changed

+224
-99
lines changed

README.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,11 @@ class _DanmakuPageState extends State<DanmakuPage> {
3737

3838
[https://www.zhihu.com/question/370464345](https://www.zhihu.com/question/370464345)
3939

40-
[https://github.com/LaoMengFlutter/flutter-do](https://github.com/LaoMengFlutter/flutter-do/tree/master/flutter_barrage_sample)
40+
[https://github.com/LaoMengFlutter/flutter-do](https://github.com/LaoMengFlutter/flutter-do/tree/master/flutter_barrage_sample)
41+
42+
43+
## TODO
44+
45+
1、优化弹幕配置方式
46+
2、应先初始化Controller
47+
3、弹幕边框优化

analysis_options.yaml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# This file configures the analyzer, which statically analyzes Dart code to
2+
# check for errors, warnings, and lints.
3+
#
4+
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
5+
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
6+
# invoked from the command line by running `flutter analyze`.
7+
8+
# The following line activates a set of recommended lints for Flutter apps,
9+
# packages, and plugins designed to encourage good coding practices.
10+
include: package:flutter_lints/flutter.yaml
11+
12+
linter:
13+
# The lint rules applied to this project can be customized in the
14+
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
15+
# included above or to enable additional rules. A list of all available lints
16+
# and their documentation is published at
17+
# https://dart-lang.github.io/linter/lints/index.html.
18+
#
19+
# Instead of disabling a lint rule for the entire project in the
20+
# section below, it can also be suppressed for a single line of code
21+
# or a specific dart file by using the `// ignore: name_of_lint` and
22+
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
23+
# producing the lint.
24+
rules:
25+
# avoid_print: false # Uncomment to disable the `avoid_print` rule
26+
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
27+
28+
# Additional information about this file can be found at
29+
# https://dart.dev/guides/language/analysis-options

example/pubspec.lock

+45-26
Original file line numberDiff line numberDiff line change
@@ -5,58 +5,58 @@ packages:
55
dependency: transitive
66
description:
77
name: async
8+
sha256: bfe67ef28df125b7dddcea62755991f807aa39a2492a23e1550161692950bbe0
89
url: "https://pub.flutter-io.cn"
910
source: hosted
10-
version: "2.8.2"
11+
version: "2.10.0"
1112
boolean_selector:
1213
dependency: transitive
1314
description:
1415
name: boolean_selector
16+
sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66"
1517
url: "https://pub.flutter-io.cn"
1618
source: hosted
17-
version: "2.1.0"
19+
version: "2.1.1"
1820
characters:
1921
dependency: transitive
2022
description:
2123
name: characters
24+
sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c
2225
url: "https://pub.flutter-io.cn"
2326
source: hosted
24-
version: "1.2.0"
25-
charcode:
26-
dependency: transitive
27-
description:
28-
name: charcode
29-
url: "https://pub.flutter-io.cn"
30-
source: hosted
31-
version: "1.3.1"
27+
version: "1.2.1"
3228
clock:
3329
dependency: transitive
3430
description:
3531
name: clock
32+
sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf
3633
url: "https://pub.flutter-io.cn"
3734
source: hosted
38-
version: "1.1.0"
35+
version: "1.1.1"
3936
collection:
4037
dependency: transitive
4138
description:
4239
name: collection
40+
sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0
4341
url: "https://pub.flutter-io.cn"
4442
source: hosted
45-
version: "1.16.0"
43+
version: "1.17.0"
4644
cupertino_icons:
4745
dependency: "direct main"
4846
description:
4947
name: cupertino_icons
48+
sha256: e35129dc44c9118cee2a5603506d823bab99c68393879edb440e0090d07586be
5049
url: "https://pub.flutter-io.cn"
5150
source: hosted
5251
version: "1.0.5"
5352
fake_async:
5453
dependency: transitive
5554
description:
5655
name: fake_async
56+
sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78"
5757
url: "https://pub.flutter-io.cn"
5858
source: hosted
59-
version: "1.3.0"
59+
version: "1.3.1"
6060
flutter:
6161
dependency: "direct main"
6262
description: flutter
@@ -67,41 +67,53 @@ packages:
6767
description: flutter
6868
source: sdk
6969
version: "0.0.0"
70+
js:
71+
dependency: transitive
72+
description:
73+
name: js
74+
sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7"
75+
url: "https://pub.flutter-io.cn"
76+
source: hosted
77+
version: "0.6.5"
7078
matcher:
7179
dependency: transitive
7280
description:
7381
name: matcher
82+
sha256: "16db949ceee371e9b99d22f88fa3a73c4e59fd0afed0bd25fc336eb76c198b72"
7483
url: "https://pub.flutter-io.cn"
7584
source: hosted
76-
version: "0.12.11"
85+
version: "0.12.13"
7786
material_color_utilities:
7887
dependency: transitive
7988
description:
8089
name: material_color_utilities
90+
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
8191
url: "https://pub.flutter-io.cn"
8292
source: hosted
83-
version: "0.1.4"
93+
version: "0.2.0"
8494
meta:
8595
dependency: transitive
8696
description:
8797
name: meta
98+
sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42"
8899
url: "https://pub.flutter-io.cn"
89100
source: hosted
90-
version: "1.7.0"
101+
version: "1.8.0"
91102
ns_danmaku:
92103
dependency: "direct main"
93104
description:
94105
path: ".."
95106
relative: true
96107
source: path
97-
version: "0.0.2"
108+
version: "0.0.3"
98109
path:
99110
dependency: transitive
100111
description:
101112
name: path
113+
sha256: db9d4f58c908a4ba5953fcee2ae317c94889433e5024c27ce74a37f94267945b
102114
url: "https://pub.flutter-io.cn"
103115
source: hosted
104-
version: "1.8.1"
116+
version: "1.8.2"
105117
sky_engine:
106118
dependency: transitive
107119
description: flutter
@@ -111,50 +123,57 @@ packages:
111123
dependency: transitive
112124
description:
113125
name: source_span
126+
sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250
114127
url: "https://pub.flutter-io.cn"
115128
source: hosted
116-
version: "1.8.2"
129+
version: "1.9.1"
117130
stack_trace:
118131
dependency: transitive
119132
description:
120133
name: stack_trace
134+
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
121135
url: "https://pub.flutter-io.cn"
122136
source: hosted
123-
version: "1.10.0"
137+
version: "1.11.0"
124138
stream_channel:
125139
dependency: transitive
126140
description:
127141
name: stream_channel
142+
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
128143
url: "https://pub.flutter-io.cn"
129144
source: hosted
130-
version: "2.1.0"
145+
version: "2.1.1"
131146
string_scanner:
132147
dependency: transitive
133148
description:
134149
name: string_scanner
150+
sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
135151
url: "https://pub.flutter-io.cn"
136152
source: hosted
137-
version: "1.1.0"
153+
version: "1.2.0"
138154
term_glyph:
139155
dependency: transitive
140156
description:
141157
name: term_glyph
158+
sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84
142159
url: "https://pub.flutter-io.cn"
143160
source: hosted
144-
version: "1.2.0"
161+
version: "1.2.1"
145162
test_api:
146163
dependency: transitive
147164
description:
148165
name: test_api
166+
sha256: ad540f65f92caa91bf21dfc8ffb8c589d6e4dc0c2267818b4cc2792857706206
149167
url: "https://pub.flutter-io.cn"
150168
source: hosted
151-
version: "0.4.9"
169+
version: "0.4.16"
152170
vector_math:
153171
dependency: transitive
154172
description:
155173
name: vector_math
174+
sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
156175
url: "https://pub.flutter-io.cn"
157176
source: hosted
158-
version: "2.1.2"
177+
version: "2.1.4"
159178
sdks:
160-
dart: ">=2.17.3 <3.0.0"
179+
dart: ">=2.18.0 <3.0.0"

lib/danmaku_border_text.dart

+14-2
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,34 @@ class DanmakuBorderText extends StatelessWidget {
2323
textAlign: textAlign,
2424
style: TextStyle(
2525
fontSize: fontSize,
26+
letterSpacing: 1,
2627
foreground: Paint()
2728
..style = PaintingStyle.stroke
28-
..strokeWidth = 2
29-
..color = color == Colors.black ? Colors.white : Colors.black,
29+
..strokeWidth = strokeWidth
30+
..strokeCap = StrokeCap.round
31+
..strokeJoin = StrokeJoin.round
32+
..color = getBorderColor(color),
3033
),
3134
),
3235
Text(
3336
text,
3437
softWrap: false,
3538
textAlign: textAlign,
3639
style: TextStyle(
40+
letterSpacing: 1,
3741
fontSize: fontSize,
3842
color: color,
3943
),
4044
),
4145
],
4246
);
4347
}
48+
49+
double get strokeWidth => (fontSize / 20).ceil() * 2;
50+
51+
Color getBorderColor(Color color) {
52+
var brightness =
53+
((color.red * 299) + (color.green * 587) + (color.blue * 114)) / 1000;
54+
return brightness > 70 ? Colors.black : Colors.white;
55+
}
4456
}

0 commit comments

Comments
 (0)