1
0
mirror of https://github.com/flutter/samples.git synced 2026-08-25 01:21:59 +00:00
Files
samples/cupertino_gallery/lib/settings_page.dart
Eric Windmill 0c5ca75d29 Release 3.47 (#2879)
Minor updates for release 3.47

## Pre-launch Checklist

- [x] I read the [Flutter Style Guide] _recently_, and have followed its
advice.
- [x] I signed the [CLA].
- [x] I read the [Contributors Guide].
- [x] I have added sample code updates to the [changelog].
- [x] I updated/added relevant documentation (doc comments with `///`).


If you need help, consider asking for advice on the #hackers-devrel
channel on [Discord].

<!-- Links -->
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Style-guide-for-Flutter-repo.md
[CLA]: https://cla.developers.google.com/
[Discord]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Chat.md
[Contributors Guide]:
https://github.com/flutter/samples/blob/main/CONTRIBUTING.md
[changelog]: ../CHANGELOG.md

---------

Co-authored-by: Parker Lougheed <parlough@gmail.com>
2026-08-12 12:21:23 -07:00

143 lines
4.5 KiB
Dart

import 'package:flutter/cupertino.dart';
class SettingsPage extends StatefulWidget {
const SettingsPage({
super.key,
required this.onThemeChange,
required this.isDarkMode,
required this.onTextSizeChange,
required this.textSize,
});
final ValueChanged<bool> onThemeChange;
final bool isDarkMode;
final ValueChanged<double> onTextSizeChange;
final double textSize;
@override
State<SettingsPage> createState() => _SettingsPageState();
}
class _SettingsPageState extends State<SettingsPage> {
late bool isDarkMode;
late double _textSize;
@override
void initState() {
super.initState();
isDarkMode = widget.isDarkMode;
_textSize = widget.textSize;
}
@override
void didUpdateWidget(SettingsPage oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.isDarkMode != oldWidget.isDarkMode) {
isDarkMode = widget.isDarkMode;
}
if (widget.textSize != oldWidget.textSize) {
_textSize = widget.textSize;
}
}
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(middle: Text('Settings')),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
CupertinoListSection(
header: const Text('Appearance'),
children: [
CupertinoListTile(
title: const Text('Dark Mode'),
trailing: CupertinoSwitch(
value: isDarkMode,
onChanged: (isActive) {
setState(() {
isDarkMode = isActive;
widget.onThemeChange(isActive);
});
},
),
),
CupertinoListTile(
title: const Text('Text Size'),
trailing: Text('${(_textSize * 100).toStringAsFixed(0)}%'),
),
CupertinoSlider(
value: _textSize,
min: 0.5,
max: 1.5,
onChanged: (value) {
setState(() {
_textSize = value;
});
widget.onTextSizeChange(value);
},
),
],
),
CupertinoListSection(
header: const Text('General'),
children: [
CupertinoListTile(
title: const Text('About'),
trailing: const Icon(CupertinoIcons.forward),
onTap: () {},
),
CupertinoListTile(
title: const Text('Privacy'),
trailing: const Icon(CupertinoIcons.forward),
onTap: () {},
),
CupertinoListTile(
title: const Text('Help'),
trailing: const Icon(CupertinoIcons.forward),
onTap: () {},
),
CupertinoListTile(
title: const Text('Reset Settings'),
trailing: const Icon(CupertinoIcons.forward),
onTap: () {
showCupertinoDialog<void>(
context: context,
builder: (context) => CupertinoAlertDialog(
title: const Text('Reset Settings'),
content: const Text(
'Are you sure you want to reset all settings?',
),
actions: <CupertinoDialogAction>[
CupertinoDialogAction(
child: const Text('Cancel'),
onPressed: () {
Navigator.pop(context);
},
),
CupertinoDialogAction(
isDestructiveAction: true,
child: const Text('Reset'),
onPressed: () {
setState(() {
isDarkMode = false;
_textSize = 1.0;
widget.onThemeChange(false);
widget.onTextSizeChange(1.0);
});
Navigator.pop(context);
},
),
],
),
);
},
),
],
),
],
),
);
}
}