-
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathload_switch.dart
More file actions
65 lines (60 loc) · 2.1 KB
/
Copy pathload_switch.dart
File metadata and controls
65 lines (60 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// This switch is inspired by https://pub.dev/packages/load_switch
import 'package:animated_toggle_switch/animated_toggle_switch.dart';
import 'package:flutter/material.dart';
class LoadSwitch extends StatefulWidget {
const LoadSwitch({super.key});
@override
State<LoadSwitch> createState() => _LoadSwitchState();
}
class _LoadSwitchState extends State<LoadSwitch> {
bool value = false;
@override
Widget build(BuildContext context) {
const height = 50.0;
const borderWidth = 5.0;
return CustomAnimatedToggleSwitch<bool>(
height: height,
indicatorSize: const Size.square(height),
current: value,
values: const [false, true],
onChanged: (newValue) {
setState(() => value = newValue);
return Future.delayed(const Duration(seconds: 2));
},
animationDuration: const Duration(milliseconds: 350),
iconArrangement: IconArrangement.overlap,
spacing: -16.0,
wrapperBuilder: (context, global, child) => DecoratedBox(
decoration: BoxDecoration(
color: Color.lerp(
Color.lerp(Colors.red, Colors.green, global.position),
Colors.grey,
global.loadingAnimationValue),
borderRadius:
const BorderRadius.all(Radius.circular(height / 2))),
child: child),
foregroundIndicatorBuilder: (context, global) {
return Stack(
fit: StackFit.expand,
children: [
const Padding(
padding: EdgeInsets.all(borderWidth),
child: DecoratedBox(
decoration: BoxDecoration(
shape: BoxShape.circle, color: Colors.white)),
),
Padding(
padding: const EdgeInsets.all(borderWidth / 2),
child: CircularProgressIndicator(
strokeWidth: borderWidth,
color:
Colors.blue.withValues(alpha: global.loadingAnimationValue),
),
),
],
);
},
iconBuilder: (context, local, global) => const SizedBox(),
);
}
}