-
-
Notifications
You must be signed in to change notification settings - Fork 699
/
custom_switch.dart
63 lines (61 loc) 路 1.89 KB
/
custom_switch.dart
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
import 'package:flutter/material.dart';
class CustomSwitch extends StatelessWidget {
const CustomSwitch({
super.key,
required this.onChanged,
required this.value,
});
final ValueChanged<bool> onChanged;
final bool value;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () => onChanged(!value),
child: SizedBox(
height: 25,
width: 50,
child: Stack(
children: <Widget>[
AnimatedContainer(
height: 25,
width: 50,
curve: Curves.ease,
duration: const Duration(milliseconds: 400),
decoration: BoxDecoration(
borderRadius: const BorderRadius.all(
Radius.circular(25.0),
),
color: value
? Theme.of(context).colorScheme.primary
: Theme.of(context).colorScheme.secondary,
),
),
AnimatedAlign(
curve: Curves.ease,
duration: const Duration(milliseconds: 400),
alignment: !value ? Alignment.centerLeft : Alignment.centerRight,
child: Container(
height: 20,
width: 20,
margin: const EdgeInsets.symmetric(horizontal: 3),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: value
? Theme.of(context).colorScheme.primaryContainer
: Theme.of(context).colorScheme.surface,
boxShadow: [
BoxShadow(
color: Colors.black12.withOpacity(0.1),
spreadRadius: 0.5,
blurRadius: 1,
),
],
),
),
),
],
),
),
);
}
}