Add yellow to base colour & colour reset button in settings

This commit is contained in:
2025-07-09 20:40:30 +02:00
parent b835603a7c
commit 6957075f46
7 changed files with 89 additions and 71 deletions

View File

@ -1,4 +1,3 @@
// pages/settings_page.dart
import 'package:flutter/material.dart';
import 'package:rtime/l10n/app_localizations.dart';
import 'package:provider/provider.dart';
@ -15,13 +14,11 @@ class SettingsPage extends StatefulWidget {
}
class _SettingsPageState extends State<SettingsPage> {
// Initialize with a default color or the current accent color
late Color _pickerColor; // Use late to initialize in initState
late Color _pickerColor;
@override
void initState() {
super.initState();
// Initialize _pickerColor with the current accent color from the ColorProvider
_pickerColor = Provider.of<ColorProvider>(context, listen: false).accentColor;
}
@ -36,9 +33,6 @@ class _SettingsPageState extends State<SettingsPage> {
final themeProvider = Provider.of<ThemeProvider>(context);
final colorProvider = Provider.of<ColorProvider>(context);
// REMOVE THIS LINE:
// _pickerColor = colorProvider.accentColor;
return Scaffold(
backgroundColor: Theme.of(context).colorScheme.background,
appBar: AppBar(
@ -133,61 +127,72 @@ class _SettingsPageState extends State<SettingsPage> {
const SizedBox(height: 10),
Card(
color: Theme.of(context).cardTheme.color,
child: ListTile(
title: Text(
l10n.selectButtonColor,
style: Theme.of(context).textTheme.titleMedium,
),
trailing: Container(
width: 30,
height: 30,
decoration: BoxDecoration(
// This should always reflect the current accent color from the provider
color: colorProvider.accentColor,
shape: BoxShape.circle,
border: Border.all(color: Theme.of(context).dividerColor),
),
),
onTap: () {
// When the dialog is opened, ensure _pickerColor reflects the *current* accent color
// so that the color picker starts with the color currently in use.
setState(() {
_pickerColor = colorProvider.accentColor;
});
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text(l10n.pickColor),
content: SingleChildScrollView(
child: ColorPicker(
pickerColor: _pickerColor,
onColorChanged: _onColorChanged,
pickerAreaHeightPercent: 0.8,
enableAlpha: false,
displayThumbColor: true,
paletteType: PaletteType.hsv,
),
),
actions: <Widget>[
TextButton(
child: Text(l10n.cancel),
onPressed: () {
Navigator.of(context).pop();
},
),
TextButton(
child: Text(l10n.select),
onPressed: () {
colorProvider.setAccentColor(_pickerColor);
Navigator.of(context).pop();
},
),
],
child: Column(
children: [
ListTile(
title: Text(
l10n.selectButtonColor,
style: Theme.of(context).textTheme.titleMedium,
),
trailing: Container(
width: 30,
height: 30,
decoration: BoxDecoration(
color: colorProvider.accentColor,
shape: BoxShape.circle,
border: Border.all(color: Theme.of(context).dividerColor),
),
),
onTap: () {
setState(() {
_pickerColor = colorProvider.accentColor;
});
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text(l10n.pickColor),
content: SingleChildScrollView(
child: ColorPicker(
pickerColor: _pickerColor,
onColorChanged: _onColorChanged,
pickerAreaHeightPercent: 0.8,
enableAlpha: false,
displayThumbColor: true,
paletteType: PaletteType.hsv,
),
),
actions: <Widget>[
TextButton(
child: Text(l10n.cancel),
onPressed: () {
Navigator.of(context).pop();
},
),
TextButton(
child: Text(l10n.select),
onPressed: () {
colorProvider.setAccentColor(_pickerColor);
Navigator.of(context).pop();
},
),
],
);
},
);
},
);
},
),
ListTile(
title: Text(l10n.resetColor, style: Theme.of(context).textTheme.titleMedium),
trailing: const Icon(Icons.restore),
onTap: () {
colorProvider.setAccentColor(Colors.yellow[700]!);
setState(() {
_pickerColor = Colors.yellow[700]!;
});
},
),
],
),
),
],