51 lines
1.2 KiB
Dart
51 lines
1.2 KiB
Dart
import 'package:didvan/config/design_config.dart';
|
|
import 'package:didvan/pages/home/profile/widgets/menu_item.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class DidvanSwitch extends StatefulWidget {
|
|
final bool value;
|
|
final String title;
|
|
final IconData? icon;
|
|
final void Function(bool value) onChanged;
|
|
const DidvanSwitch({
|
|
Key? key,
|
|
required this.value,
|
|
required this.title,
|
|
this.icon,
|
|
required this.onChanged,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
_DidvanSwitchState createState() => _DidvanSwitchState();
|
|
}
|
|
|
|
class _DidvanSwitchState extends State<DidvanSwitch> {
|
|
bool _value = false;
|
|
|
|
@override
|
|
void initState() {
|
|
_value = widget.value;
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MenuItem(
|
|
title: widget.title,
|
|
onTap: () => widget.onChanged(_value),
|
|
icon: widget.icon,
|
|
trailing: CupertinoSwitch(
|
|
activeColor: Theme.of(context).colorScheme.primary,
|
|
value: _value,
|
|
onChanged: (value) {
|
|
setState(() {
|
|
_value = value;
|
|
});
|
|
widget.onChanged(value);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|