ModernMemoires/lib/views/settings_page/widgets/TextSwitchContainer.dart

65 lines
1.9 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class TextSwitchContainer extends StatefulWidget {
final String leftText;
final String? rightText;
final bool hasSwitch;
final Function onTap;
final Function(bool)? onSwitchToggle;
TextSwitchContainer({
required this.leftText,
this.rightText,
this.hasSwitch = false,
required this.onTap,
this.onSwitchToggle,
});
@override
_TextSwitchContainerState createState() => _TextSwitchContainerState();
}
class _TextSwitchContainerState extends State<TextSwitchContainer> {
bool switchValue = false;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () => widget.onTap(),
child: Container(
padding: EdgeInsets.symmetric(horizontal: 0, vertical: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
widget.leftText,
style: TextStyle(fontSize: 18),
),
if (widget.hasSwitch)
CupertinoSwitch(
trackColor: Colors.white,
thumbColor: switchValue ? Colors.lightGreen : Colors.grey,
value: switchValue,
onChanged: (newValue) {
setState(() {
switchValue = newValue;
widget.onSwitchToggle?.call(newValue);
});
},
activeColor: Colors.white, // Active (ON) color
// CupertinoSwitch doesn't allow inactive thumb color customization by default
// Track color changes with the active color
)
else if (widget.rightText != null)
Text(
widget.rightText!,
style: TextStyle(fontSize: 16, color: Colors.grey),
),
],
),
),
);
}
}