import 'package:flutter/material.dart';
class SettingsToggleScreen extends StatefulWidget {
@override
State<SettingsToggleScreen> createState() => _SettingsToggleScreenState();
}
class _SettingsToggleScreenState extends State<SettingsToggleScreen> {
bool notificationsEnabled = false;
bool darkModeEnabled = false;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Settings Toggle Screen')),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
CheckboxListTile(
title: Text('Enable Notifications'),
value: notificationsEnabled,
onChanged: (bool? value) {
setState(() {
notificationsEnabled = value ?? false;
});
},
),
SwitchListTile(
title: Text('Dark Mode'),
value: darkModeEnabled,
onChanged: (bool value) {
setState(() {
darkModeEnabled = value;
});
},
),
SizedBox(height: 20),
ElevatedButton(
onPressed: () {
final snackBar = SnackBar(
content: Text('Notifications: ${notificationsEnabled ? 'On' : 'Off'}, Dark Mode: ${darkModeEnabled ? 'On' : 'Off'}'),
);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
},
child: Text('Save'),
),
],
),
),
);
}
}
We use CheckboxListTile and SwitchListTile widgets because they combine the toggle control with a label, making the UI clear and accessible.
Each toggle updates its own boolean state variable inside setState() to refresh the UI.
The Save button shows a SnackBar that confirms the current toggle states, giving immediate feedback to the user.