feat(ui_kit): add theme control in example
This commit is contained in:
@@ -0,0 +1,152 @@
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import 'package:adaptive_theme/adaptive_theme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:wyatt_ui_kit_example/theme/flat_button_theme.dart';
|
||||
import 'package:wyatt_ui_kit_example/theme/symbol_button_theme.dart';
|
||||
import 'package:wyatt_ui_kit_example/theme_extension.dart';
|
||||
|
||||
/// Easely switch between Material and Studio themes.
|
||||
abstract class Themes {
|
||||
static int currentThemeIndex = 0;
|
||||
|
||||
static List<Set<ThemeData>> themes = [
|
||||
{materialLight, materialDark},
|
||||
{studioLight, studioDark},
|
||||
];
|
||||
|
||||
static ThemeData lightFromTheme(int themeId) {
|
||||
currentThemeIndex = themeId;
|
||||
return themes[themeId].first;
|
||||
}
|
||||
static ThemeData darkFromTheme(int themeId) {
|
||||
currentThemeIndex = themeId;
|
||||
return themes[themeId].last;
|
||||
}
|
||||
|
||||
static void auto(BuildContext context) {
|
||||
if (currentThemeIndex == 1) {
|
||||
return studio(context);
|
||||
}
|
||||
return material(context);
|
||||
}
|
||||
|
||||
static void material(BuildContext context) {
|
||||
AdaptiveTheme.of(context).setTheme(
|
||||
light: materialLight,
|
||||
dark: materialDark,
|
||||
);
|
||||
}
|
||||
|
||||
static void studio(BuildContext context) {
|
||||
AdaptiveTheme.of(context).setTheme(
|
||||
light: studioLight,
|
||||
dark: studioDark,
|
||||
);
|
||||
}
|
||||
|
||||
static ThemeData get materialLight => ThemeData.light();
|
||||
|
||||
static ThemeData get studioLight => materialLight.copyWith(
|
||||
appBarTheme: AppBarTheme(
|
||||
foregroundColor: const Color.fromRGBO(36, 38, 42, 1),
|
||||
backgroundColor: Colors.white,
|
||||
titleTextStyle: GoogleFonts.montserrat(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: const Color.fromRGBO(36, 38, 42, 1),
|
||||
),
|
||||
),
|
||||
scaffoldBackgroundColor: Colors.white,
|
||||
extensions: <ThemeExtension<dynamic>>[
|
||||
CustomCardColorExtension(
|
||||
backgroundColors: const [
|
||||
Color.fromRGBO(246, 246, 246, 1),
|
||||
],
|
||||
secondaryBackgroundColors: Colors.white,
|
||||
borderColor: const [
|
||||
Color.fromRGBO(221, 224, 227, 1),
|
||||
Color.fromRGBO(202, 204, 212, 1),
|
||||
],
|
||||
title: GoogleFonts.montserrat(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: const Color.fromRGBO(36, 38, 42, 1),
|
||||
),
|
||||
subtitle: GoogleFonts.montserrat(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w300,
|
||||
color: const Color.fromRGBO(36, 38, 42, 1),
|
||||
),
|
||||
body: GoogleFonts.montserrat(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w300,
|
||||
height: 1.7,
|
||||
color: const Color.fromRGBO(36, 38, 42, 1),
|
||||
),
|
||||
),
|
||||
FlatButtonTheme.light(),
|
||||
SymbolButtonTheme.light(),
|
||||
],
|
||||
);
|
||||
|
||||
static ThemeData get materialDark => ThemeData.dark();
|
||||
|
||||
static ThemeData get studioDark => materialDark.copyWith(
|
||||
appBarTheme: AppBarTheme(
|
||||
foregroundColor: Colors.white,
|
||||
backgroundColor: const Color.fromRGBO(56, 60, 64, 1),
|
||||
titleTextStyle: GoogleFonts.montserrat(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
scaffoldBackgroundColor: const Color.fromRGBO(56, 60, 64, 1),
|
||||
extensions: <ThemeExtension<dynamic>>[
|
||||
CustomCardColorExtension(
|
||||
secondaryBackgroundColors: Colors.white.withOpacity(0.04),
|
||||
backgroundColors: [
|
||||
Colors.white.withOpacity(0.04),
|
||||
],
|
||||
borderColor: const [
|
||||
Color.fromRGBO(96, 101, 106, 1),
|
||||
Color.fromRGBO(56, 60, 64, 1),
|
||||
],
|
||||
title: GoogleFonts.montserrat(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.white,
|
||||
),
|
||||
subtitle: GoogleFonts.montserrat(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w300,
|
||||
color: Colors.white,
|
||||
),
|
||||
body: GoogleFonts.montserrat(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w300,
|
||||
height: 1.7,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
FlatButtonTheme.dark(),
|
||||
SymbolButtonTheme.dark(),
|
||||
],
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user