cake_wallet/lib/src/widgets/standard_switch.dart

45 lines
1.3 KiB
Dart
Raw Normal View History

import 'package:flutter/cupertino.dart';
2020-01-04 19:31:52 +00:00
import 'package:flutter/material.dart';
2022-12-12 12:28:53 +00:00
class StandardSwitch extends StatefulWidget {
const StandardSwitch({required this.value, required this.onTaped});
2020-01-04 19:31:52 +00:00
final bool value;
final VoidCallback onTaped;
@override
2022-12-12 12:28:53 +00:00
StandardSwitchState createState() => StandardSwitchState();
2020-01-04 19:31:52 +00:00
}
2022-12-12 12:28:53 +00:00
class StandardSwitchState extends State<StandardSwitch> {
2020-01-04 19:31:52 +00:00
@override
Widget build(BuildContext context) {
2023-12-13 15:27:30 +00:00
return Semantics(
toggled: widget.value,
child: GestureDetector(
onTap: widget.onTaped,
child: AnimatedContainer(
padding: EdgeInsets.only(left: 2.0, right: 2.0),
alignment: widget.value ? Alignment.centerRight : Alignment.centerLeft,
duration: Duration(milliseconds: 250),
width: 50,
height: 28,
2020-01-04 19:31:52 +00:00
decoration: BoxDecoration(
2023-12-13 15:27:30 +00:00
color: widget.value
? Theme.of(context).primaryColor
: Theme.of(context).disabledColor,
borderRadius: BorderRadius.all(Radius.circular(14.0))),
child: Container(
width: 24.0,
height: 24.0,
decoration: BoxDecoration(
color: Colors.white,
shape: BoxShape.circle),
),
2020-01-04 19:31:52 +00:00
),
),
);
}
2020-01-08 12:26:34 +00:00
}