feat: добавить страницу настроек с сохранением темы
This commit is contained in:
@@ -11,6 +11,7 @@ import '/utils/transaction_utils.dart';
|
||||
final _logger = Logger();
|
||||
|
||||
class HiveService {
|
||||
static const String _settingsBox = 'settings';
|
||||
static const String _categoryBox = 'categories';
|
||||
static const String _tagBox = 'tags';
|
||||
static const String _transactionBox = 'transactions';
|
||||
@@ -35,6 +36,7 @@ class HiveService {
|
||||
|
||||
// Открытие всех Box'ов
|
||||
await Future.wait([
|
||||
Hive.openBox(_settingsBox),
|
||||
Hive.openBox<Category>(_categoryBox),
|
||||
Hive.openBox<Tag>(_tagBox),
|
||||
Hive.openBox<TransactionRecord>(_transactionBox),
|
||||
|
||||
+10
-5
@@ -24,13 +24,18 @@ class MyApp extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MyAppState extends State<MyApp> {
|
||||
bool _isDarkMode = false;
|
||||
late final Box _settingsBox;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_settingsBox = Hive.box('settings');
|
||||
}
|
||||
|
||||
bool get _isDarkMode => _settingsBox.get('darkMode', defaultValue: false);
|
||||
|
||||
/// Переключает тему между светлой и темной
|
||||
void toggleTheme() {
|
||||
setState(() {
|
||||
_isDarkMode = !_isDarkMode;
|
||||
});
|
||||
_settingsBox.put('darkMode', !_isDarkMode);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'settings_page.dart';
|
||||
|
||||
/**
|
||||
* Главная страница приложения для управления бюджетом.
|
||||
@@ -51,6 +52,17 @@ class HomePage extends StatelessWidget {
|
||||
|
||||
// Кнопки в правой части AppBar
|
||||
actions: [
|
||||
// Кнопка настроек
|
||||
IconButton(
|
||||
icon: const Icon(Icons.settings),
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => const SettingsPage()),
|
||||
);
|
||||
},
|
||||
tooltip: 'Настройки',
|
||||
),
|
||||
// Кнопка переключения темы
|
||||
IconButton(
|
||||
// Динамическая иконка - меняется в зависимости от темы
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
|
||||
class SettingsPage extends StatelessWidget {
|
||||
const SettingsPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Настройки'),
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ValueListenableBuilder(
|
||||
valueListenable: Hive.box('settings').listenable(),
|
||||
builder: (context, box, _) {
|
||||
return SwitchListTile(
|
||||
title: const Text('Темная тема'),
|
||||
value: box.get('darkMode', defaultValue: false),
|
||||
onChanged: (value) {
|
||||
box.put('darkMode', value);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user