From a024b7e70af60887a6775f72fe406ab4f61122ab Mon Sep 17 00:00:00 2001 From: Hugo Pointcheval Date: Fri, 28 Apr 2023 14:04:15 +0200 Subject: [PATCH] feat(ui_kit): update example by removing adaptative theme --- .../information_card/information_cards.dart | 50 ++++++++++----- .../cards/portfolio_card/portfolio_cards.dart | 41 +++++++----- .../lib/cards/skill_card/skill_cards.dart | 4 +- .../example/lib/cubit/app_mode_cubit.dart | 24 +++++++ .../example/lib/cubit/app_mode_state.dart | 32 ++++++++++ packages/wyatt_ui_kit/example/lib/home.dart | 49 ++++++++------- packages/wyatt_ui_kit/example/lib/main.dart | 62 ++++++++++++------- .../example/lib/theme/themes.dart | 13 ++-- .../Flutter/GeneratedPluginRegistrant.swift | 2 - .../wyatt_ui_kit/example/macos/Podfile.lock | 7 --- packages/wyatt_ui_kit/example/pubspec.yaml | 1 - 11 files changed, 184 insertions(+), 101 deletions(-) create mode 100644 packages/wyatt_ui_kit/example/lib/cubit/app_mode_cubit.dart create mode 100644 packages/wyatt_ui_kit/example/lib/cubit/app_mode_state.dart diff --git a/packages/wyatt_ui_kit/example/lib/cards/information_card/information_cards.dart b/packages/wyatt_ui_kit/example/lib/cards/information_card/information_cards.dart index 13e18f01..838f8535 100644 --- a/packages/wyatt_ui_kit/example/lib/cards/information_card/information_cards.dart +++ b/packages/wyatt_ui_kit/example/lib/cards/information_card/information_cards.dart @@ -1,7 +1,9 @@ import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:gap/gap.dart'; import 'package:wyatt_ui_components/wyatt_ui_components.dart'; import 'package:wyatt_ui_kit/wyatt_ui_kit.dart'; +import 'package:wyatt_ui_kit_example/cubit/app_mode_cubit.dart'; class InformationCards extends StatelessWidget { const InformationCards({super.key}); @@ -43,12 +45,21 @@ class InformationCards extends StatelessWidget { const Gap(20), InformationCard( background: Center( - child: Container( - decoration: const BoxDecoration( - image: DecorationImage( - image: AssetImage('assets/images/asset_1.png'), - fit: BoxFit.fitHeight, - alignment: Alignment.centerRight, + child: ColorFiltered( + colorFilter: ColorFilter.mode( + context.watch().state.brightness == + Brightness.light + ? Colors.grey.withOpacity(0.2) + : Colors.white.withOpacity(0.2), + BlendMode.srcIn, + ), + child: Container( + decoration: const BoxDecoration( + image: DecorationImage( + image: AssetImage('assets/images/asset_1.png'), + fit: BoxFit.fitHeight, + alignment: Alignment.centerRight, + ), ), ), ), @@ -110,12 +121,21 @@ class InformationCards extends StatelessWidget { const Gap(20), InformationCard( background: Center( - child: Container( - decoration: const BoxDecoration( - image: DecorationImage( - image: AssetImage('assets/images/asset_1.png'), - fit: BoxFit.fitHeight, - alignment: Alignment.centerRight, + child: ColorFiltered( + colorFilter: ColorFilter.mode( + context.watch().state.brightness == + Brightness.light + ? Colors.grey.withOpacity(0.2) + : Colors.white.withOpacity(0.2), + BlendMode.srcIn, + ), + child: Container( + decoration: const BoxDecoration( + image: DecorationImage( + image: AssetImage('assets/images/asset_1.png'), + fit: BoxFit.fitHeight, + alignment: Alignment.centerRight, + ), ), ), ), @@ -128,9 +148,9 @@ class InformationCards extends StatelessWidget { subtitle: TextWrapper( 'One single code base.', style: Theme.of(context).textTheme.titleMedium?.copyWith( - fontSize: 15, - fontWeight: FontWeight.bold, - ), + fontSize: 15, + fontWeight: FontWeight.bold, + ), ), body: const TextWrapper( 'Cupidatat reprehenderit aliqua eiusmod Lorem. ' diff --git a/packages/wyatt_ui_kit/example/lib/cards/portfolio_card/portfolio_cards.dart b/packages/wyatt_ui_kit/example/lib/cards/portfolio_card/portfolio_cards.dart index cbb30eed..f467143a 100644 --- a/packages/wyatt_ui_kit/example/lib/cards/portfolio_card/portfolio_cards.dart +++ b/packages/wyatt_ui_kit/example/lib/cards/portfolio_card/portfolio_cards.dart @@ -1,4 +1,3 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:gap/gap.dart'; import 'package:wyatt_ui_components/wyatt_ui_components.dart'; @@ -31,10 +30,12 @@ class PortfolioCards extends StatelessWidget { 'quis elit ut amet velit. Incididunt fugiat proident ' 'proident deserunt tempor Lorem cillum qui do '), ctas: [ - CupertinoButton( - color: Theme.of(context).primaryColor, - onPressed: () {}, - child: const Text('En savoir plus >'), + context.components.flatButtonComponent.call( + label: const TextWrapper('En savoir plus'), + suffix: const Icon( + Icons.arrow_forward_ios, + size: 15, + ), ), ], assets: [ @@ -64,10 +65,12 @@ class PortfolioCards extends StatelessWidget { 'quis elit ut amet velit. Incididunt fugiat proident ' 'proident deserunt tempor Lorem cillum qui do '), ctas: [ - CupertinoButton( - color: Theme.of(context).primaryColor, - onPressed: () {}, - child: const Text('En savoir plus >'), + context.components.flatButtonComponent.call( + label: const TextWrapper('En savoir plus'), + suffix: const Icon( + Icons.arrow_forward_ios, + size: 15, + ), ), ], assets: [ @@ -97,10 +100,12 @@ class PortfolioCards extends StatelessWidget { 'quis elit ut amet velit. Incididunt fugiat proident ' 'proident deserunt tempor Lorem cillum qui do '), ctas: [ - CupertinoButton( - color: Theme.of(context).primaryColor, - onPressed: () {}, - child: const Text('En savoir plus >'), + context.components.flatButtonComponent.call( + label: const TextWrapper('En savoir plus'), + suffix: const Icon( + Icons.arrow_forward_ios, + size: 15, + ), ), ], assets: [ @@ -140,10 +145,12 @@ class PortfolioCards extends StatelessWidget { 'quis elit ut amet velit. Incididunt fugiat proident ' 'proident deserunt tempor Lorem cillum qui do '), ctas: [ - CupertinoButton( - color: Theme.of(context).primaryColor, - onPressed: () {}, - child: const Text('En savoir plus >'), + context.components.flatButtonComponent.call( + label: const TextWrapper('En savoir plus'), + suffix: const Icon( + Icons.arrow_forward_ios, + size: 15, + ), ), ], assets: [ diff --git a/packages/wyatt_ui_kit/example/lib/cards/skill_card/skill_cards.dart b/packages/wyatt_ui_kit/example/lib/cards/skill_card/skill_cards.dart index 0775cab6..2bcb72d2 100644 --- a/packages/wyatt_ui_kit/example/lib/cards/skill_card/skill_cards.dart +++ b/packages/wyatt_ui_kit/example/lib/cards/skill_card/skill_cards.dart @@ -40,7 +40,7 @@ class SkillCards extends StatelessWidget { padding: const EdgeInsets.all(15), decoration: BoxDecoration( shape: BoxShape.circle, - color: Colors.white.withOpacity(0.04), + color: Colors.grey.withOpacity(0.1), ), child: GradientIcon( icon: Icons.ac_unit_sharp, @@ -71,7 +71,7 @@ class SkillCards extends StatelessWidget { padding: const EdgeInsets.all(15), decoration: BoxDecoration( shape: BoxShape.circle, - color: Colors.white.withOpacity(0.04), + color: Colors.grey.withOpacity(0.1), ), child: GradientIcon( icon: Icons.ac_unit_sharp, diff --git a/packages/wyatt_ui_kit/example/lib/cubit/app_mode_cubit.dart b/packages/wyatt_ui_kit/example/lib/cubit/app_mode_cubit.dart new file mode 100644 index 00000000..633ca873 --- /dev/null +++ b/packages/wyatt_ui_kit/example/lib/cubit/app_mode_cubit.dart @@ -0,0 +1,24 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; + +part 'app_mode_state.dart'; + +class AppModeCubit extends Cubit { + AppModeCubit({ + required int theme, + required Brightness brightness, + }) : super( + AppModeState( + theme: theme, + brightness: brightness, + ), + ); + + void changeTheme(int theme) { + emit(state.copyWith(theme: theme)); + } + + void changeBrightness(Brightness brightness) { + emit(state.copyWith(brightness: brightness)); + } +} diff --git a/packages/wyatt_ui_kit/example/lib/cubit/app_mode_state.dart b/packages/wyatt_ui_kit/example/lib/cubit/app_mode_state.dart new file mode 100644 index 00000000..6d99c069 --- /dev/null +++ b/packages/wyatt_ui_kit/example/lib/cubit/app_mode_state.dart @@ -0,0 +1,32 @@ +// ignore_for_file: avoid_equals_and_hash_code_on_mutable_classes + +part of 'app_mode_cubit.dart'; + +class AppModeState { + const AppModeState({ + required this.theme, + required this.brightness, + }); + final int theme; + final Brightness brightness; + + AppModeState copyWith({ + int? theme, + Brightness? brightness, + }) => + AppModeState( + theme: theme ?? this.theme, + brightness: brightness ?? this.brightness, + ); + + @override + bool operator ==(Object other) => + identical(this, other) || + other is AppModeState && + runtimeType == other.runtimeType && + theme == other.theme && + brightness == other.brightness; + + @override + int get hashCode => theme.hashCode ^ brightness.hashCode; +} diff --git a/packages/wyatt_ui_kit/example/lib/home.dart b/packages/wyatt_ui_kit/example/lib/home.dart index 70a20107..ec5d362e 100644 --- a/packages/wyatt_ui_kit/example/lib/home.dart +++ b/packages/wyatt_ui_kit/example/lib/home.dart @@ -1,16 +1,17 @@ -import 'package:adaptive_theme/adaptive_theme.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:gap/gap.dart'; import 'package:wyatt_ui_kit_example/bars/bars.dart'; import 'package:wyatt_ui_kit_example/buttons/buttons.dart'; import 'package:wyatt_ui_kit_example/cards/cards.dart'; +import 'package:wyatt_ui_kit_example/cubit/app_mode_cubit.dart'; import 'package:wyatt_ui_kit_example/demo_page.dart'; import 'package:wyatt_ui_kit_example/loaders/loaders.dart'; import 'package:wyatt_ui_kit_example/rich_text_builders/rich_text_builders.dart'; import 'package:wyatt_ui_kit_example/text_input/text_inputs.dart'; -import 'package:wyatt_ui_kit_example/theme/themes.dart'; const String title = 'Wyatt UIKit Example'; +const List themes = ['Material', 'Studio']; class Home extends StatefulWidget { const Home({super.key, this.forceIndex = 0}); @@ -75,34 +76,34 @@ class _HomeState extends State { actions: [ Row( children: [ - const Text('Mode'), + const Text('Dark'), Switch.adaptive( - value: - AdaptiveTheme.of(context).brightness == Brightness.dark, - onChanged: (_) { - AdaptiveTheme.of(context).brightness == Brightness.light - ? AdaptiveTheme.of(context).setDark() - : AdaptiveTheme.of(context).setLight(); + value: context.watch().state.brightness == + Brightness.dark, + onChanged: (value) { + context.read().changeBrightness( + value ? Brightness.dark : Brightness.light, + ); }, ), ], ), const Gap(30), - Row( - children: [ - const Text('Studio'), - Switch.adaptive( - value: Themes.currentThemeIndex == 1, - onChanged: (_) { - setState(() { - Themes.currentThemeIndex = - (Themes.currentThemeIndex == 1) ? 0 : 1; - }); - Themes.auto(context); - }, - ), - ], - ) + DropdownButton( + items: themes + .map( + (e) => DropdownMenuItem( + value: themes.indexOf(e), + child: Text(e), + ), + ) + .toList(), + value: context.watch().state.theme, + onChanged: (value) { + context.read().changeTheme(value ?? 0); + }, + hint: const Text('Theme'), + ), ], ), body: Padding( diff --git a/packages/wyatt_ui_kit/example/lib/main.dart b/packages/wyatt_ui_kit/example/lib/main.dart index a9de8a29..25896e74 100644 --- a/packages/wyatt_ui_kit/example/lib/main.dart +++ b/packages/wyatt_ui_kit/example/lib/main.dart @@ -14,11 +14,12 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -import 'package:adaptive_theme/adaptive_theme.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:wyatt_ui_components/wyatt_ui_components.dart'; import 'package:wyatt_ui_kit/wyatt_ui_kit.dart'; +import 'package:wyatt_ui_kit_example/cubit/app_mode_cubit.dart'; import 'package:wyatt_ui_kit_example/home.dart'; import 'package:wyatt_ui_kit_example/theme/themes.dart'; @@ -41,28 +42,41 @@ class App extends StatelessWidget { final int defaultTheme; @override - Widget build(BuildContext context) => AdaptiveTheme( - initial: AdaptiveThemeMode.light, - light: Themes.lightFromTheme(defaultTheme), - dark: Themes.darkFromTheme(defaultTheme), - builder: (light, dark) => ComponentTheme( - data: WyattComponentThemeData.wyattComponentThemeData, - child: MaterialApp( - localizationsDelegates: const [ - GlobalMaterialLocalizations.delegate, - GlobalWidgetsLocalizations.delegate, - GlobalCupertinoLocalizations.delegate, - ], - theme: light, - darkTheme: dark, - supportedLocales: const [ - Locale('fr', ''), - ], - title: title, - home: Home( - forceIndex: defaultPage, - ), - ), + Widget build(BuildContext context) { + final brightness = WidgetsBinding.instance.window.platformBrightness; + return BlocProvider( + create: (context) => AppModeCubit( + theme: defaultTheme, + brightness: brightness, + ), + child: Builder( + builder: (context) => BlocBuilder( + builder: (context, state) { + final light = Themes.lightFromTheme(state.theme); + final dark = Themes.darkFromTheme(state.theme); + final theme = state.brightness == Brightness.light ? light : dark; + return ComponentTheme( + data: WyattComponentThemeData.wyattComponentThemeData, + child: MaterialApp( + debugShowCheckedModeBanner: false, + localizationsDelegates: const [ + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + GlobalCupertinoLocalizations.delegate, + ], + theme: theme, + supportedLocales: const [ + Locale('fr', ''), + ], + title: title, + home: Home( + forceIndex: defaultPage, + ), + ), + ); + }, ), - ); + ), + ); + } } diff --git a/packages/wyatt_ui_kit/example/lib/theme/themes.dart b/packages/wyatt_ui_kit/example/lib/theme/themes.dart index 4a8ad422..d5583573 100644 --- a/packages/wyatt_ui_kit/example/lib/theme/themes.dart +++ b/packages/wyatt_ui_kit/example/lib/theme/themes.dart @@ -14,10 +14,11 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -import 'package:adaptive_theme/adaptive_theme.dart'; import 'package:flutter/material.dart' hide CardTheme; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:wyatt_ui_kit/wyatt_ui_kit.dart'; +import 'package:wyatt_ui_kit_example/cubit/app_mode_cubit.dart'; /// Easely switch between Material and Studio themes. abstract class Themes { @@ -46,17 +47,11 @@ abstract class Themes { } static void material(BuildContext context) { - AdaptiveTheme.of(context).setTheme( - light: materialLight, - dark: materialDark, - ); + context.read().changeTheme(0); } static void studio(BuildContext context) { - AdaptiveTheme.of(context).setTheme( - light: studioLight, - dark: studioDark, - ); + context.read().changeTheme(1); } static ThemeData get materialLight => ThemeData.light().copyWith( diff --git a/packages/wyatt_ui_kit/example/macos/Flutter/GeneratedPluginRegistrant.swift b/packages/wyatt_ui_kit/example/macos/Flutter/GeneratedPluginRegistrant.swift index b8e2b22f..e777c67d 100644 --- a/packages/wyatt_ui_kit/example/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/packages/wyatt_ui_kit/example/macos/Flutter/GeneratedPluginRegistrant.swift @@ -6,9 +6,7 @@ import FlutterMacOS import Foundation import path_provider_foundation -import shared_preferences_foundation func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) - SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) } diff --git a/packages/wyatt_ui_kit/example/macos/Podfile.lock b/packages/wyatt_ui_kit/example/macos/Podfile.lock index 9af1d710..bd839d4b 100644 --- a/packages/wyatt_ui_kit/example/macos/Podfile.lock +++ b/packages/wyatt_ui_kit/example/macos/Podfile.lock @@ -3,27 +3,20 @@ PODS: - path_provider_foundation (0.0.1): - Flutter - FlutterMacOS - - shared_preferences_foundation (0.0.1): - - Flutter - - FlutterMacOS DEPENDENCIES: - FlutterMacOS (from `Flutter/ephemeral`) - path_provider_foundation (from `Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/macos`) - - shared_preferences_foundation (from `Flutter/ephemeral/.symlinks/plugins/shared_preferences_foundation/macos`) EXTERNAL SOURCES: FlutterMacOS: :path: Flutter/ephemeral path_provider_foundation: :path: Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/macos - shared_preferences_foundation: - :path: Flutter/ephemeral/.symlinks/plugins/shared_preferences_foundation/macos SPEC CHECKSUMS: FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24 path_provider_foundation: c68054786f1b4f3343858c1e1d0caaded73f0be9 - shared_preferences_foundation: 986fc17f3d3251412d18b0265f9c64113a8c2472 PODFILE CHECKSUM: 353c8bcc5d5b0994e508d035b5431cfe18c1dea7 diff --git a/packages/wyatt_ui_kit/example/pubspec.yaml b/packages/wyatt_ui_kit/example/pubspec.yaml index 30cfec77..203d19cf 100644 --- a/packages/wyatt_ui_kit/example/pubspec.yaml +++ b/packages/wyatt_ui_kit/example/pubspec.yaml @@ -17,7 +17,6 @@ dependencies: flutter_localizations: { sdk: flutter } gap: ^2.0.1 google_fonts: ^4.0.3 - adaptive_theme: ^3.2.0 wyatt_ui_components: hosted: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub