Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 63bf8a3

Browse files
WeUIThemeData添加copyWith方法
1 parent cbe0400 commit 63bf8a3

File tree

2 files changed

+186
-0
lines changed

2 files changed

+186
-0
lines changed

‎lib/src/base/theme.dart‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ class WeUIThemeData extends Diagnosticable {
150150
Color textTipsColor,
151151
Color linkDefaultColor,
152152
WeUIButtonThemeData buttonTheme,
153+
Color loadingColor,
153154
}){
154155
brightness ??= Brightness.light;
155156
textTipsColor ??= weuiTextColorTips(brightness);
@@ -166,6 +167,7 @@ class WeUIThemeData extends Diagnosticable {
166167
textDescColor ??= weuiTextColorDesc(brightness);
167168
textWarnColor ??= weuiTextColorWarn(brightness);
168169
buttonTheme ??= WeUIButtonThemeData(brightness: brightness);
170+
loadingColor ??= weuiLoadingColor(brightness);
169171
return WeUIThemeData.raw(
170172
brightness: brightness,
171173
textTipsColor: textTipsColor,
@@ -182,8 +184,48 @@ class WeUIThemeData extends Diagnosticable {
182184
textTitleColor: textTitleColor,
183185
textWarnColor: textWarnColor,
184186
buttonTheme: buttonTheme,
187+
loadingColor: loadingColor,
185188
);
186189
}
190+
191+
WeUIThemeData copyWith({
192+
Color primaryColor,
193+
Color warnColor,
194+
Color activeMaskBlack,
195+
Color bgDefaultColor,
196+
Color bgPrimaryColor,
197+
Color bgActiveColor,
198+
Color lineLightColor,
199+
Color lineDarkColor,
200+
Color textTitleColor,
201+
Color textDescColor,
202+
Color textWarnColor,
203+
Brightness brightness,
204+
Color textTipsColor,
205+
Color linkDefaultColor,
206+
WeUIButtonThemeData buttonTheme,
207+
Color loadingColor,
208+
}){
209+
return WeUIThemeData.raw(
210+
brightness: brightness ?? this.brightness,
211+
textTipsColor: textTipsColor ?? this.textTipsColor,
212+
linkDefaultColor: linkDefaultColor ?? this.linkDefaultColor,
213+
primaryColor: primaryColor ?? primaryColor,
214+
warnColor: warnColor ?? this.warnColor,
215+
activeMaskBlack: activeMaskBlack ?? this.activeMaskBlack,
216+
bgDefaultColor: bgDefaultColor ?? this.bgDefaultColor,
217+
bgPrimaryColor: bgPrimaryColor ?? this.bgPrimaryColor,
218+
bgActiveColor: bgActiveColor ?? this.bgActiveColor,
219+
lineDarkColor: lineDarkColor ?? this.lineDarkColor,
220+
lineLightColor: lineLightColor ?? this.lineLightColor,
221+
textDescColor: textDescColor ?? this.textDescColor,
222+
textTitleColor: textTitleColor ?? this.textTitleColor,
223+
textWarnColor: textWarnColor ?? this.textWarnColor,
224+
buttonTheme: buttonTheme ?? this.buttonTheme,
225+
loadingColor: loadingColor ?? this.loadingColor,
226+
);
227+
}
228+
187229
const WeUIThemeData.raw({
188230
@required this.primaryColor,
189231
@required this.warnColor,
@@ -200,6 +242,7 @@ class WeUIThemeData extends Diagnosticable {
200242
@required this.textTipsColor,
201243
@required this.linkDefaultColor,
202244
@required this.buttonTheme,
245+
@required this.loadingColor,
203246
});
204247
final Color primaryColor;
205248
final Color warnColor;
@@ -216,6 +259,7 @@ class WeUIThemeData extends Diagnosticable {
216259
final Color textDescColor;
217260
final Color textWarnColor;
218261
final WeUIButtonThemeData buttonTheme;
262+
final Color loadingColor;
219263

220264
factory WeUIThemeData.light() => WeUIThemeData(brightness: Brightness.light);
221265

‎lib/src/loading.dart‎

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
// Copyright 2017 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'dart:math' as math;
6+
7+
import 'package:flutter/widgets.dart';
8+
import 'package:flutter/rendering.dart';
9+
import 'base/theme.dart';
10+
11+
const double _kDefaultIndicatorRadius = 10.0;
12+
13+
14+
/// An iOS-style activity indicator that spins clockwise.
15+
///
16+
/// See also:
17+
///
18+
/// * <https://developer.apple.com/ios/human-interface-guidelines/controls/progress-indicators/#activity-indicators>
19+
class Loading extends StatefulWidget {
20+
/// Creates an iOS-style activity indicator that spins clockwise.
21+
const Loading({
22+
Key key,
23+
this.animating = true,
24+
this.radius = _kDefaultIndicatorRadius,
25+
}) : assert(animating != null),
26+
assert(radius != null),
27+
assert(radius > 0),
28+
super(key: key);
29+
30+
/// Whether the activity indicator is running its animation.
31+
///
32+
/// Defaults to true.
33+
final bool animating;
34+
35+
/// Radius of the spinner widget.
36+
///
37+
/// Defaults to 10px. Must be positive and cannot be null.
38+
final double radius;
39+
40+
@override
41+
_LoadingState createState() => _LoadingState();
42+
}
43+
44+
45+
class _LoadingState extends State<Loading> with SingleTickerProviderStateMixin {
46+
AnimationController _controller;
47+
48+
@override
49+
void initState() {
50+
super.initState();
51+
_controller = AnimationController(
52+
duration: const Duration(seconds: 1),
53+
vsync: this,
54+
);
55+
56+
if (widget.animating)
57+
_controller.repeat();
58+
}
59+
60+
@override
61+
void didUpdateWidget(Loading oldWidget) {
62+
super.didUpdateWidget(oldWidget);
63+
if (widget.animating != oldWidget.animating) {
64+
if (widget.animating)
65+
_controller.repeat();
66+
else
67+
_controller.stop();
68+
}
69+
}
70+
71+
@override
72+
void dispose() {
73+
_controller.dispose();
74+
super.dispose();
75+
}
76+
77+
@override
78+
Widget build(BuildContext context) {
79+
return SizedBox(
80+
height: widget.radius * 2,
81+
width: widget.radius * 2,
82+
child: CustomPaint(
83+
painter: _CupertinoActivityIndicatorPainter(
84+
position: _controller,
85+
activeColor: WeUITheme.of(context).loadingColor,
86+
radius: widget.radius,
87+
),
88+
),
89+
);
90+
}
91+
}
92+
93+
const double _kTwoPI = math.pi * 2.0;
94+
const int _kTickCount = 12;
95+
96+
// Alpha values extracted from the native component (for both dark and light mode).
97+
// The list has a length of 12.
98+
const List<int> _alphaValues = <int>[147, 131, 114, 97, 81, 64, 47, 47, 47, 47, 47, 47];
99+
100+
class _CupertinoActivityIndicatorPainter extends CustomPainter {
101+
_CupertinoActivityIndicatorPainter({
102+
@required this.position,
103+
@required this.activeColor,
104+
double radius,
105+
}) : tickFundamentalRRect = RRect.fromLTRBXY(
106+
-radius,
107+
radius / _kDefaultIndicatorRadius,
108+
-radius / 2.0,
109+
-radius / _kDefaultIndicatorRadius,
110+
radius / _kDefaultIndicatorRadius,
111+
radius / _kDefaultIndicatorRadius,
112+
),
113+
super(repaint: position);
114+
115+
final Animation<double> position;
116+
final RRect tickFundamentalRRect;
117+
final Color activeColor;
118+
119+
@override
120+
void paint(Canvas canvas, Size size) {
121+
final Paint paint = Paint();
122+
123+
canvas.save();
124+
canvas.translate(size.width / 2.0, size.height / 2.0);
125+
126+
final int activeTick = (_kTickCount * position.value).floor();
127+
128+
for (int i = 0; i < _kTickCount; ++ i) {
129+
final int t = (i + activeTick) % _kTickCount;
130+
paint.color = activeColor.withAlpha(_alphaValues[t]);
131+
canvas.drawRRect(tickFundamentalRRect, paint);
132+
canvas.rotate(-_kTwoPI / _kTickCount);
133+
}
134+
135+
canvas.restore();
136+
}
137+
138+
@override
139+
bool shouldRepaint(_CupertinoActivityIndicatorPainter oldPainter) {
140+
return oldPainter.position != position || oldPainter.activeColor != activeColor;
141+
}
142+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /