2022-08-21 14:52:17 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
class CustomSwitch extends StatelessWidget {
|
|
|
|
final ValueChanged<bool> onChanged;
|
|
|
|
final bool value;
|
2022-09-01 12:16:14 +02:00
|
|
|
|
2022-08-21 14:52:17 +02:00
|
|
|
const CustomSwitch({
|
|
|
|
Key? key,
|
|
|
|
required this.onChanged,
|
|
|
|
required this.value,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return GestureDetector(
|
2022-08-21 15:06:28 +02:00
|
|
|
onTap: () => onChanged(!value),
|
2022-08-21 14:52:17 +02:00
|
|
|
child: SizedBox(
|
|
|
|
height: 25,
|
|
|
|
width: 50,
|
|
|
|
child: Stack(
|
2022-09-02 15:35:25 +02:00
|
|
|
children: <Widget>[
|
2022-08-21 14:52:17 +02:00
|
|
|
AnimatedContainer(
|
|
|
|
height: 25,
|
|
|
|
width: 50,
|
|
|
|
curve: Curves.ease,
|
2022-09-02 15:35:25 +02:00
|
|
|
duration: const Duration(milliseconds: 400),
|
2022-08-21 14:52:17 +02:00
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: const BorderRadius.all(
|
|
|
|
Radius.circular(25.0),
|
|
|
|
),
|
2022-09-05 04:32:36 +02:00
|
|
|
color: value
|
|
|
|
? Theme.of(context).colorScheme.primary
|
|
|
|
: Theme.of(context).colorScheme.secondary,
|
2022-08-21 14:52:17 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
AnimatedAlign(
|
|
|
|
curve: Curves.ease,
|
2022-09-02 15:35:25 +02:00
|
|
|
duration: const Duration(milliseconds: 400),
|
2022-08-21 14:52:17 +02:00
|
|
|
alignment: !value ? Alignment.centerLeft : Alignment.centerRight,
|
|
|
|
child: Container(
|
|
|
|
height: 20,
|
|
|
|
width: 20,
|
|
|
|
margin: const EdgeInsets.symmetric(horizontal: 3),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
shape: BoxShape.circle,
|
2022-09-07 03:38:07 +02:00
|
|
|
color: value
|
|
|
|
? Theme.of(context).colorScheme.primaryContainer
|
|
|
|
: Colors.white,
|
2022-08-21 14:52:17 +02:00
|
|
|
boxShadow: [
|
|
|
|
BoxShadow(
|
|
|
|
color: Colors.black12.withOpacity(0.1),
|
|
|
|
spreadRadius: 0.5,
|
|
|
|
blurRadius: 1,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|