Skip to content

Commit

Permalink
feat: ThemeBuilder support for dark themes.
Browse files Browse the repository at this point in the history
  • Loading branch information
coire1 committed May 8, 2024
1 parent bfec640 commit f4ad3b5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,30 @@ import 'package:flutter/material.dart';
/// [buildTheme] can be used to obtain the corresponding theme data for the
/// [BrandKey] passed to the method.
///
/// [buildDarkTheme] operates in the same way but picks the dark version of the
/// theme for a specific brand.
///
/// For each brand there is a specific key defined in the [BrandKey] enum
/// and a corresponding [ThemeData] in the `themes` folder.
/// For each brand a light and a dark [ThemeData] should be defined.
///
/// [buildTheme] defaults to the [catalyst] theme.
/// [buildTheme] and [buildDarkTheme] default to the [catalyst] theme.
class ThemeBuilder {
static final Map<BrandKey, ThemeData> lightThemes = {
BrandKey.catalyst: catalyst,
BrandKey.fallback: fallback,
};

static final Map<BrandKey, ThemeData> darkThemes = {
BrandKey.catalyst: darkCatalyst,
BrandKey.fallback: darkFallback,
};

static ThemeData buildTheme(BrandKey? brandKey) {
switch (brandKey) {
case BrandKey.catalyst:
return catalyst;
case BrandKey.fallback:
return fallback;
case null:
return catalyst;
}
return lightThemes[brandKey ?? BrandKey.catalyst]!;
}

static ThemeData buildDarkTheme(BrandKey? brandKey) {
return darkThemes[brandKey ?? BrandKey.catalyst]!;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ final ThemeData catalyst = ThemeData(
primary: VoicesColors.blue,
),
);

final ThemeData darkCatalyst = ThemeData.dark();
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';

/// [ThemeData] for the `fallback` brand.
final ThemeData fallback = ThemeData(useMaterial3: true);
final ThemeData fallback = ThemeData.light();
final ThemeData darkFallback = ThemeData.dark();
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ void main() {
),
),
theme: ThemeBuilder.buildTheme(state.brandKey),
darkTheme: ThemeBuilder.buildTheme(state.brandKey),
);
},
),
Expand Down

0 comments on commit f4ad3b5

Please sign in to comment.