Skip to content

Commit bd7f47a

Browse files
committed
refoactor: chang the code formatting
1 parent 2595449 commit bd7f47a

20 files changed

+144
-248
lines changed

CHANGELOG.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
## 2.3.0
2-
- The controller now extends the *Animation<double>*.
3-
- New *ClampedAnimation* class for constraining the *IndicatorController* animation value within a specific range using the *clamp* method.
4-
- Drag interaction details are now available, enabling pointer-position-based animations.
5-
- Example app:
1+
## 3.0.0
2+
- **CustomRefreshIndicator**:
3+
- Deprecated *indicatorFinalizeDuration*, *indicatorSettleDuration* and *indicatorCancelDuration* parameters in favor of *finalizeDuration*, *settleDuration* and *cancelDuration*.
4+
- The indicator widget will now be rebuilt every time *state* changes, even if the *autoRebuilt* parameter is set to false. This will make managing the state of the indicator widget simpler.
5+
- **IndicatorController**:
6+
- The controller now extends *Animation<double>*. This allows it to be used directly with *Transition* widgets to further improve animation performance.
7+
- New *ClampedAnimation* class for constraining the *IndicatorController* animation value within a specific range using the *clamp* method.
8+
- Drag interaction details are now available, enabling pointer-position-based animations.
9+
- **Example app**:
610
- The checkmark indicator example has been simplified.
711
- Minor corrections to the envelope indicator.
8-
- Removed unused code.
912
- Added image precaching.
13+
- Removed unused code.
1014
## 2.2.1
1115
- Fixed typos in documentation
1216
## 2.2.0

example/lib/indicators/check_mark_indicator.dart

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ class CheckMarkStyle {
2323

2424
static const defaultStyle = CheckMarkStyle(
2525
loading: CheckMarkColors(content: Colors.white, background: Colors.black),
26-
completed:
27-
CheckMarkColors(content: Colors.white, background: Colors.greenAccent),
26+
completed: CheckMarkColors(content: Colors.white, background: Colors.greenAccent),
2827
);
2928
}
3029

@@ -42,8 +41,7 @@ class CheckMarkIndicator extends StatefulWidget {
4241
State<CheckMarkIndicator> createState() => _CheckMarkIndicatorState();
4342
}
4443

45-
class _CheckMarkIndicatorState extends State<CheckMarkIndicator>
46-
with SingleTickerProviderStateMixin {
44+
class _CheckMarkIndicatorState extends State<CheckMarkIndicator> with SingleTickerProviderStateMixin {
4745
/// Whether to render check mark instead of spinner
4846
bool _renderCompleteState = false;
4947

@@ -74,9 +72,7 @@ class _CheckMarkIndicatorState extends State<CheckMarkIndicator>
7472
BuildContext context,
7573
IndicatorController controller,
7674
) {
77-
final style = _renderCompleteState
78-
? widget.style.completed
79-
: widget.style.loading;
75+
final style = _renderCompleteState ? widget.style.completed : widget.style.loading;
8076
return AnimatedContainer(
8177
duration: const Duration(milliseconds: 150),
8278
alignment: Alignment.center,
@@ -95,9 +91,7 @@ class _CheckMarkIndicatorState extends State<CheckMarkIndicator>
9591
child: CircularProgressIndicator(
9692
strokeWidth: 2,
9793
color: style.content,
98-
value: controller.isDragging || controller.isArmed
99-
? controller.value.clamp(0.0, 1.0)
100-
: null,
94+
value: controller.isDragging || controller.isArmed ? controller.value.clamp(0.0, 1.0) : null,
10195
),
10296
),
10397
);

example/lib/indicators/envelope_indicator.dart

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ class EnvelopRefreshIndicator extends StatelessWidget {
1111
static const _circleSize = 70.0;
1212

1313
static const _blurRadius = 10.0;
14-
static const _defaultShadow = [
15-
BoxShadow(blurRadius: _blurRadius, color: Colors.black26)
16-
];
14+
static const _defaultShadow = [BoxShadow(blurRadius: _blurRadius, color: Colors.black26)];
1715

1816
const EnvelopRefreshIndicator({
1917
super.key,
@@ -29,20 +27,16 @@ class EnvelopRefreshIndicator extends StatelessWidget {
2927
return CustomRefreshIndicator(
3028
leadingScrollIndicatorVisible: leadingScrollIndicatorVisible,
3129
trailingScrollIndicatorVisible: trailingScrollIndicatorVisible,
32-
builder: (context, child, controller) =>
33-
LayoutBuilder(builder: (context, constraints) {
30+
builder: (context, child, controller) => LayoutBuilder(builder: (context, constraints) {
3431
final widgetWidth = constraints.maxWidth;
3532
final widgetHeight = constraints.maxHeight;
3633
final letterTopWidth = (widgetWidth / 2) + 50;
3734

38-
final leftValue = (widgetWidth +
39-
_blurRadius -
40-
((letterTopWidth + _blurRadius) * controller.value / 1))
35+
final leftValue = (widgetWidth + _blurRadius - ((letterTopWidth + _blurRadius) * controller.value / 1))
4136
.clamp(letterTopWidth - 100, double.infinity);
4237

4338
final rightShift = widgetWidth + _blurRadius;
44-
final rightValue = (rightShift - (rightShift * controller.value / 1))
45-
.clamp(0.0, double.infinity);
39+
final rightValue = (rightShift - (rightShift * controller.value / 1)).clamp(0.0, double.infinity);
4640

4741
final opacity = (controller.value - 1).clamp(0, 0.5) / 0.5;
4842

@@ -85,27 +79,23 @@ class EnvelopRefreshIndicator extends StatelessWidget {
8579
child: Transform.scale(
8680
scale: controller.value,
8781
child: Opacity(
88-
opacity: controller.isLoading || controller.state.isSettling
89-
? 1
90-
: opacity,
82+
opacity: controller.isLoading || controller.state.isSettling ? 1 : opacity,
9183
child: Align(
9284
alignment: Alignment.center,
9385
child: Container(
9486
width: _circleSize,
9587
height: _circleSize,
9688
decoration: BoxDecoration(
9789
boxShadow: _defaultShadow,
98-
color:
99-
accent ?? Theme.of(context).colorScheme.primary,
90+
color: accent ?? Theme.of(context).colorScheme.primary,
10091
shape: BoxShape.circle,
10192
),
10293
child: Stack(
10394
fit: StackFit.expand,
10495
alignment: Alignment.center,
10596
children: <Widget>[
10697
CircularProgressIndicator(
107-
valueColor:
108-
const AlwaysStoppedAnimation(Colors.black),
98+
valueColor: const AlwaysStoppedAnimation(Colors.black),
10999
value: controller.isLoading ? null : 0,
110100
),
111101
const Icon(
@@ -138,10 +128,7 @@ class TrianglePainter extends CustomPainter {
138128
return radius * 0.57735 + 0.5;
139129
}
140130

141-
TrianglePainter(
142-
{this.strokeColor = Colors.black,
143-
this.strokeWidth = 3,
144-
this.paintingStyle = PaintingStyle.stroke});
131+
TrianglePainter({this.strokeColor = Colors.black, this.strokeWidth = 3, this.paintingStyle = PaintingStyle.stroke});
145132

146133
@override
147134
void paint(Canvas canvas, Size size) {
@@ -152,8 +139,7 @@ class TrianglePainter extends CustomPainter {
152139
final path = getTrianglePath(size.width, size.height);
153140
final shadowPaint = Paint()
154141
..color = Colors.black.withAlpha(50)
155-
..maskFilter =
156-
MaskFilter.blur(BlurStyle.normal, convertRadiusToSigma(10));
142+
..maskFilter = MaskFilter.blur(BlurStyle.normal, convertRadiusToSigma(10));
157143
canvas.drawPath(path, shadowPaint);
158144

159145
canvas.drawPath(path, paint);

example/lib/indicators/swipe_action.dart

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ class FetchMoreIndicator extends StatelessWidget {
2929
return AnimatedBuilder(
3030
animation: controller,
3131
builder: (context, _) {
32-
final dy = controller.value.clamp(0.0, 1.25) *
33-
-(height - (height * 0.25));
32+
final dy = controller.value.clamp(0.0, 1.25) * -(height - (height * 0.25));
3433
return Stack(
3534
children: [
3635
Transform.translate(
@@ -64,9 +63,7 @@ class FetchMoreIndicator extends StatelessWidget {
6463
color: appContentColor,
6564
),
6665
Text(
67-
controller.isLoading
68-
? "Fetching..."
69-
: "Pull to fetch more",
66+
controller.isLoading ? "Fetching..." : "Pull to fetch more",
7067
style: const TextStyle(
7168
color: appContentColor,
7269
),

example/lib/indicators/warp_indicator.dart

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ class WarpIndicator extends StatefulWidget {
4040
State<WarpIndicator> createState() => _WarpIndicatorState();
4141
}
4242

43-
class _WarpIndicatorState extends State<WarpIndicator>
44-
with SingleTickerProviderStateMixin {
43+
class _WarpIndicatorState extends State<WarpIndicator> with SingleTickerProviderStateMixin {
4544
static const _indicatorSize = 150.0;
4645
final _random = Random();
4746
WarpAnimationState _state = WarpAnimationState.stopped;
@@ -145,8 +144,7 @@ class _WarpIndicatorState extends State<WarpIndicator>
145144
animation: shakeController,
146145
builder: (_, __) {
147146
return LayoutBuilder(
148-
builder:
149-
(BuildContext context, BoxConstraints constraints) {
147+
builder: (BuildContext context, BoxConstraints constraints) {
150148
return CustomPaint(
151149
painter: Sky(
152150
stars: stars,
@@ -163,10 +161,8 @@ class _WarpIndicatorState extends State<WarpIndicator>
163161
return Transform.scale(
164162
scale: _scaleTween.transform(controller.value),
165163
child: Builder(builder: (context) {
166-
if (shakeController.value == 1.0 &&
167-
_state == WarpAnimationState.playing) {
168-
SchedulerBinding.instance
169-
.addPostFrameCallback((_) => _resetShakeAnimation());
164+
if (shakeController.value == 1.0 && _state == WarpAnimationState.playing) {
165+
SchedulerBinding.instance.addPostFrameCallback((_) => _resetShakeAnimation());
170166
}
171167
return Transform.rotate(
172168
angle: _angleTween.transform(shakeController.value),
@@ -220,8 +216,7 @@ class Star {
220216
speed = Offset(cos(angle), sin(angle));
221217
const minSpeedScale = 20;
222218
const maxSpeedScale = 35;
223-
final speedScale = minSpeedScale +
224-
random.nextInt(maxSpeedScale - minSpeedScale).toDouble();
219+
final speedScale = minSpeedScale + random.nextInt(maxSpeedScale - minSpeedScale).toDouble();
225220
speed = speed.scale(
226221
speedScale,
227222
speedScale,
@@ -244,8 +239,7 @@ class Star {
244239

245240
final startShiftAngle = angle + (pi / 2);
246241
final startShift = Offset(cos(startShiftAngle), sin(startShiftAngle));
247-
final shiftedStartPosition =
248-
startPosition + (startShift * (0.75 + value * 0.01));
242+
final shiftedStartPosition = startPosition + (startShift * (0.75 + value * 0.01));
249243

250244
final endShiftAngle = angle + (pi / 2);
251245
final endShift = Offset(cos(endShiftAngle), sin(endShiftAngle));

example/lib/main.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ class MyApp extends StatelessWidget {
3838
'/envelope': (context) => const EnvelopIndicatorScreen(),
3939
'/fetch-more': (context) => const FetchMoreScreen(),
4040
'/horizontal': (context) => const HorizontalScreen(),
41-
'/programmatically-controlled': (context) =>
42-
const ProgrammaticallyControlled(),
41+
'/programmatically-controlled': (context) => const ProgrammaticallyControlled(),
4342
},
4443
);
4544
}
@@ -86,8 +85,7 @@ class MainScreen extends StatelessWidget {
8685
child: Container(
8786
height: 50,
8887
alignment: Alignment.center,
89-
child:
90-
const Text("Custom material indicator with list opacity"),
88+
child: const Text("Custom material indicator with list opacity"),
9189
),
9290
onPressed: () => Navigator.pushNamed(
9391
context,

example/lib/screens/check_mark_indicator_screen.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ class CheckMarkIndicatorScreen extends StatefulWidget {
77
const CheckMarkIndicatorScreen({super.key});
88

99
@override
10-
State<CheckMarkIndicatorScreen> createState() =>
11-
_CheckMarkIndicatorScreenState();
10+
State<CheckMarkIndicatorScreen> createState() => _CheckMarkIndicatorScreenState();
1211
}
1312

1413
class _CheckMarkIndicatorScreenState extends State<CheckMarkIndicatorScreen> {

example/lib/screens/horizontal_screen.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ class _HorizontalScreenState extends State<HorizontalScreen> {
2626
_isHorizontal = !_isHorizontal;
2727
});
2828
},
29-
icon: _isHorizontal
30-
? const Icon(Icons.swap_horizontal_circle)
31-
: const Icon(Icons.swap_vert_circle),
29+
icon: _isHorizontal ? const Icon(Icons.swap_horizontal_circle) : const Icon(Icons.swap_vert_circle),
3230
)
3331
],
3432
),

example/lib/screens/ice_cream_indicator_screen.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ class IceCreamIndicatorScreen extends StatefulWidget {
77
const IceCreamIndicatorScreen({super.key});
88

99
@override
10-
State<IceCreamIndicatorScreen> createState() =>
11-
_IceCreamIndicatorScreenState();
10+
State<IceCreamIndicatorScreen> createState() => _IceCreamIndicatorScreenState();
1211
}
1312

1413
class _IceCreamIndicatorScreenState extends State<IceCreamIndicatorScreen> {

example/lib/screens/presentation_screen.dart

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,18 @@ class _PresentationScreenState extends State<PresentationScreen> {
2020
body: SafeArea(
2121
child: CustomRefreshIndicator(
2222
trigger: IndicatorTrigger.bothEdges,
23-
indicatorFinalizeDuration: const Duration(seconds: 1),
24-
indicatorSettleDuration: const Duration(seconds: 1),
25-
indicatorCancelDuration: const Duration(seconds: 1),
23+
finalizeDuration: const Duration(seconds: 1),
24+
settleDuration: const Duration(seconds: 1),
25+
cancelDuration: const Duration(seconds: 1),
2626
leadingScrollIndicatorVisible: false,
2727
trailingScrollIndicatorVisible: false,
2828
offsetToArmed: 100.0,
2929
controller: _controller,
3030
onRefresh: () => Future.delayed(const Duration(seconds: 2)),
3131
child: DecoratedBox(
32-
decoration:
33-
const BoxDecoration(color: appBackgroundColor, boxShadow: [
34-
BoxShadow(color: Colors.black26, blurRadius: 8, spreadRadius: 4)
35-
]),
32+
decoration: const BoxDecoration(
33+
color: appBackgroundColor,
34+
boxShadow: [BoxShadow(color: Colors.black26, blurRadius: 8, spreadRadius: 4)]),
3635
child: CustomScrollView(
3736
physics: const AlwaysScrollableScrollPhysics(
3837
parent: ClampingScrollPhysics(),
@@ -55,8 +54,7 @@ class _PresentationScreenState extends State<PresentationScreen> {
5554
width: double.infinity,
5655
decoration: const BoxDecoration(
5756
color: Colors.white,
58-
borderRadius:
59-
BorderRadius.all(Radius.circular(20)),
57+
borderRadius: BorderRadius.all(Radius.circular(20)),
6058
boxShadow: [
6159
BoxShadow(
6260
color: Colors.black12,
@@ -146,25 +144,19 @@ class _PresentationScreenState extends State<PresentationScreen> {
146144
const Spacer(),
147145
ElevatedButton(
148146
style: ButtonStyle(
149-
backgroundColor:
150-
MaterialStateProperty.all(
151-
_controller.isRefreshEnabled
152-
? Colors.red
153-
: Colors.lightGreen,
147+
backgroundColor: MaterialStateProperty.all(
148+
_controller.isRefreshEnabled ? Colors.red : Colors.lightGreen,
154149
),
155150
),
156151
child: Text(
157-
_controller.isRefreshEnabled
158-
? "DISABLE"
159-
: "ENABLE",
152+
_controller.isRefreshEnabled ? "DISABLE" : "ENABLE",
160153
style: const TextStyle(
161154
color: Colors.white,
162155
),
163156
),
164-
onPressed: () =>
165-
_controller.isRefreshEnabled
166-
? _controller.disableRefresh()
167-
: _controller.enableRefresh(),
157+
onPressed: () => _controller.isRefreshEnabled
158+
? _controller.disableRefresh()
159+
: _controller.enableRefresh(),
168160
),
169161
],
170162
),
@@ -187,9 +179,7 @@ class _PresentationScreenState extends State<PresentationScreen> {
187179
return AnimatedBuilder(
188180
animation: _controller,
189181
builder: (context, _) => Stack(
190-
alignment: _controller.side.isBottom
191-
? AlignmentDirectional.bottomStart
192-
: AlignmentDirectional.topStart,
182+
alignment: _controller.side.isBottom ? AlignmentDirectional.bottomStart : AlignmentDirectional.topStart,
193183
children: <Widget>[
194184
Container(
195185
height: 100,
@@ -206,9 +196,8 @@ class _PresentationScreenState extends State<PresentationScreen> {
206196
),
207197
),
208198
Container(
209-
margin: controller.side.isBottom
210-
? const EdgeInsets.only(bottom: 100)
211-
: const EdgeInsets.only(top: 100),
199+
margin:
200+
controller.side.isBottom ? const EdgeInsets.only(bottom: 100) : const EdgeInsets.only(top: 100),
212201
width: double.infinity,
213202
height: 50,
214203
color: Colors.greenAccent,
@@ -226,8 +215,7 @@ class _PresentationScreenState extends State<PresentationScreen> {
226215
Transform.translate(
227216
offset: Offset(
228217
0.0,
229-
(_controller.side.isBottom ? -100 : 100) *
230-
_controller.value,
218+
(_controller.side.isBottom ? -100 : 100) * _controller.value,
231219
),
232220
child: child,
233221
),

0 commit comments

Comments
 (0)