mirror of
https://github.com/smmarty/friflex_flutter_starter.git
synced 2025-12-22 09:30:45 +00:00
Compare commits
4 Commits
3.38.1
...
feat/add-t
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ead44f1b1a | ||
|
|
f64f63641e | ||
|
|
3895b9a7fc | ||
|
|
f7d4c02623 |
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:friflex_starter/app/theme/app_colors_scheme.dart';
|
||||
import 'package:friflex_starter/app/theme/theme_notifier.dart';
|
||||
import 'package:friflex_starter/di/di_container.dart';
|
||||
import 'package:friflex_starter/l10n/gen/app_localizations.dart';
|
||||
@@ -11,7 +12,7 @@ extension AppContextExt on BuildContext {
|
||||
DiContainer get di => read<DiContainer>();
|
||||
|
||||
/// Геттер для получения цветовой схемы
|
||||
ColorScheme get colors => Theme.of(this).colorScheme;
|
||||
AppColors get colors => Theme.of(this).extension<AppColors>()!;
|
||||
|
||||
/// Геттер для получения темы
|
||||
ThemeNotifier get theme => read<ThemeNotifier>();
|
||||
|
||||
@@ -1,18 +1,103 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// {@template app_colors}
|
||||
/// Класс, реализующий расширение для добавления токенов в цветовую схему
|
||||
extension AppColorsScheme on ColorScheme {
|
||||
bool get _isDark => brightness == Brightness.dark;
|
||||
/// {@endtemplate}
|
||||
class AppColors extends ThemeExtension<AppColors> with DiagnosticableTreeMixin {
|
||||
/// {@macro app_colors}
|
||||
///
|
||||
/// Принимает:
|
||||
///
|
||||
/// * [testColor] - цвет тестового текста
|
||||
/// * [errorSnackbarBackground] - цвет фона снекбара ошибки
|
||||
/// * [successSnackbarBackground] - цвет фона снекбара успеха
|
||||
/// * [infoSnackbarBackground] - цвет фона снекбара информации
|
||||
/// * [itemTextColor] - цвет элемента текста
|
||||
const AppColors({
|
||||
required this.testColor,
|
||||
required this.itemTextColor,
|
||||
required this.errorSnackbarBackground,
|
||||
required this.successSnackbarBackground,
|
||||
required this.infoSnackbarBackground,
|
||||
});
|
||||
|
||||
// Тестовый цвет
|
||||
Color get testColor => _isDark ? Colors.green : Colors.red;
|
||||
/// Цвет тестовый
|
||||
final Color testColor;
|
||||
|
||||
/// Цвет заднего фона снекбара с ошибкой
|
||||
Color get errorSnackbarBackground => const Color(0xFFD24720);
|
||||
/// Цвет элемента текста
|
||||
final Color itemTextColor;
|
||||
|
||||
/// Цвет заднего фона снекбара с успехом
|
||||
Color get successSnackbarBackground => const Color(0xFF6FB62C);
|
||||
/// Цвет фона снекбара ошибки
|
||||
final Color errorSnackbarBackground;
|
||||
|
||||
/// Цвет заднего фона снекбара с информацией
|
||||
Color get infoSnackbarBackground => const Color.fromARGB(255, 220, 108, 77);
|
||||
/// Цвет фона снекбара успеха
|
||||
final Color successSnackbarBackground;
|
||||
|
||||
/// Цвет фона снекбара информации
|
||||
final Color infoSnackbarBackground;
|
||||
|
||||
/// Цвета светлой темы
|
||||
static final AppColors light = AppColors(
|
||||
testColor: Colors.red,
|
||||
errorSnackbarBackground: const Color(0xFFD24720),
|
||||
successSnackbarBackground: const Color(0xFF6FB62C),
|
||||
infoSnackbarBackground: const Color.fromARGB(255, 220, 108, 77),
|
||||
itemTextColor: const Color(0xFFFAF3EB),
|
||||
);
|
||||
|
||||
/// Цвета тёмной темы
|
||||
static final AppColors dark = AppColors(
|
||||
testColor: Colors.green,
|
||||
errorSnackbarBackground: const Color(0xFF638B8B),
|
||||
successSnackbarBackground: const Color(0xFF93C499),
|
||||
infoSnackbarBackground: const Color.fromARGB(255, 35, 147, 178),
|
||||
itemTextColor: Colors.white,
|
||||
);
|
||||
|
||||
@override
|
||||
ThemeExtension<AppColors> copyWith({
|
||||
Color? testColor,
|
||||
Color? errorSnackbarBackground,
|
||||
Color? successSnackbarBackground,
|
||||
Color? infoSnackbarBackground,
|
||||
Color? itemTextColor,
|
||||
}) => AppColors(
|
||||
testColor: testColor ?? this.testColor,
|
||||
errorSnackbarBackground:
|
||||
errorSnackbarBackground ?? this.errorSnackbarBackground,
|
||||
successSnackbarBackground:
|
||||
successSnackbarBackground ?? this.successSnackbarBackground,
|
||||
infoSnackbarBackground:
|
||||
infoSnackbarBackground ?? this.infoSnackbarBackground,
|
||||
itemTextColor: itemTextColor ?? this.itemTextColor,
|
||||
);
|
||||
|
||||
@override
|
||||
ThemeExtension<AppColors> lerp(
|
||||
covariant ThemeExtension<AppColors>? other,
|
||||
double t,
|
||||
) {
|
||||
if (other is! AppColors) return this;
|
||||
|
||||
return AppColors(
|
||||
testColor: Color.lerp(testColor, other.testColor, t)!,
|
||||
errorSnackbarBackground: Color.lerp(
|
||||
errorSnackbarBackground,
|
||||
other.errorSnackbarBackground,
|
||||
t,
|
||||
)!,
|
||||
successSnackbarBackground: Color.lerp(
|
||||
successSnackbarBackground,
|
||||
other.successSnackbarBackground,
|
||||
t,
|
||||
)!,
|
||||
infoSnackbarBackground: Color.lerp(
|
||||
infoSnackbarBackground,
|
||||
other.infoSnackbarBackground,
|
||||
t,
|
||||
)!,
|
||||
itemTextColor: Color.lerp(itemTextColor, other.itemTextColor, t)!,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:friflex_starter/app/theme/app_colors_scheme.dart';
|
||||
|
||||
/// Класс для конфигурации светлой/темной темы приложения
|
||||
abstract class AppTheme {
|
||||
/// Геттер для получения светлой темы
|
||||
static ThemeData get light => ThemeData.light();
|
||||
static ThemeData get light => ThemeData.light().copyWith(
|
||||
extensions: <ThemeExtension<Object?>>[AppColors.light],
|
||||
);
|
||||
|
||||
/// Геттер для получения темной темы
|
||||
static ThemeData get dark => ThemeData.dark();
|
||||
static ThemeData get dark => ThemeData.dark().copyWith(
|
||||
extensions: <ThemeExtension<Object?>>[AppColors.dark],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:friflex_starter/app/app_context_ext.dart';
|
||||
import 'package:friflex_starter/app/theme/app_colors_scheme.dart';
|
||||
import 'package:friflex_starter/app/ui_kit/app_box.dart';
|
||||
|
||||
/// {@template app_snackbar}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:friflex_starter/app/app_context_ext.dart';
|
||||
import 'package:friflex_starter/app/theme/app_colors_scheme.dart';
|
||||
import 'package:friflex_starter/gen/assets.gen.dart';
|
||||
import 'package:friflex_starter/gen/fonts.gen.dart';
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:friflex_starter/app/app_context_ext.dart';
|
||||
import 'package:friflex_starter/app/theme/app_colors_scheme.dart';
|
||||
|
||||
/// {@template ThemeScreen}
|
||||
/// Экран для отладки темы приложения
|
||||
@@ -11,6 +10,7 @@ class ThemeScreen extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colors = context.colors;
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Theme')),
|
||||
body: Center(
|
||||
@@ -29,7 +29,25 @@ class ThemeScreen extends StatelessWidget {
|
||||
child: const SizedBox(height: 100, width: 100),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text('Текущая тема: ${context.theme.themeMode}'),
|
||||
Card(
|
||||
elevation: 4,
|
||||
shadowColor: colors.infoSnackbarBackground,
|
||||
margin: const EdgeInsets.symmetric(vertical: 10),
|
||||
color: colors.infoSnackbarBackground,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: ListTile(
|
||||
title: Text(
|
||||
'Текущая тема: ${context.theme.themeMode}',
|
||||
style: TextStyle(
|
||||
color: colors.itemTextColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
trailing: Icon(Icons.color_lens, color: colors.itemTextColor),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user