-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
282 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:theme_provider/theme_provider.dart'; | ||
|
||
import '/themes/base_theme_config.dart'; | ||
import '/helpers/extensions.dart'; | ||
import 'helper.dart'; | ||
|
||
/// Helper to find correct color from the [context]. | ||
class NyColor { | ||
final Color? light; | ||
final Color? dark; | ||
|
||
NyColor({this.light, this.dark}); | ||
|
||
/// Get the color based on the device mode | ||
Color? toColor(BuildContext context) { | ||
return resolveColor(context, light: light, dark: dark); | ||
} | ||
|
||
/// Get the color based on the device mode | ||
static Color? resolveColor(BuildContext context, | ||
{Color? light, Color? dark}) { | ||
bool isDarkModeEnabled = false; | ||
ThemeController themeController = ThemeProvider.controllerOf(context); | ||
|
||
if (themeController.currentThemeId == getEnv('DARK_THEME_ID')) { | ||
isDarkModeEnabled = true; | ||
} | ||
|
||
if ((themeController.theme.options as NyThemeOptions).meta is Map && | ||
(themeController.theme.options as NyThemeOptions).meta['type'] == | ||
NyThemeType.dark) { | ||
isDarkModeEnabled = true; | ||
} | ||
|
||
if (context.isDeviceInDarkMode) { | ||
isDarkModeEnabled = true; | ||
} | ||
|
||
if (isDarkModeEnabled) { | ||
return dark; | ||
} | ||
|
||
return light; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:nylo_support/helpers/ny_color.dart'; | ||
|
||
/// Helper to define text styles | ||
class NyTextStyle { | ||
final bool inherit; | ||
final NyColor? color; | ||
final NyColor? backgroundColor; | ||
final double? fontSize; | ||
final FontWeight? fontWeight; | ||
final FontStyle? fontStyle; | ||
final double? letterSpacing; | ||
final double? wordSpacing; | ||
final TextBaseline? textBaseline; | ||
final double? height; | ||
final TextLeadingDistribution? leadingDistribution; | ||
final Locale? locale; | ||
final Paint? foreground; | ||
final Paint? background; | ||
final List<Shadow>? shadows; | ||
final List<FontFeature>? fontFeatures; | ||
final List<FontVariation>? fontVariations; | ||
final TextDecoration? decoration; | ||
final NyColor? decorationColor; | ||
final TextDecorationStyle? decorationStyle; | ||
final double? decorationThickness; | ||
final String? debugLabel; | ||
final TextOverflow? overflow; | ||
final String? fontFamily; | ||
final List<String>? fontFamilyFallback; | ||
final String? package; | ||
|
||
NyTextStyle( | ||
{this.inherit = true, | ||
this.color, | ||
this.backgroundColor, | ||
this.fontSize, | ||
this.fontWeight, | ||
this.fontStyle, | ||
this.letterSpacing, | ||
this.wordSpacing, | ||
this.textBaseline, | ||
this.height, | ||
this.leadingDistribution, | ||
this.locale, | ||
this.foreground, | ||
this.background, | ||
this.shadows, | ||
this.fontFeatures, | ||
this.fontVariations, | ||
this.decoration, | ||
this.decorationColor, | ||
this.decorationStyle, | ||
this.decorationThickness, | ||
this.debugLabel, | ||
this.fontFamily, | ||
this.fontFamilyFallback, | ||
this.package, | ||
this.overflow}); | ||
|
||
TextStyle toTextStyle(BuildContext context) { | ||
return TextStyle( | ||
inherit: inherit, | ||
color: color?.toColor(context), | ||
backgroundColor: backgroundColor?.toColor(context), | ||
fontSize: fontSize, | ||
fontWeight: fontWeight, | ||
fontStyle: fontStyle, | ||
letterSpacing: letterSpacing, | ||
wordSpacing: wordSpacing, | ||
textBaseline: textBaseline, | ||
height: height, | ||
leadingDistribution: leadingDistribution, | ||
locale: locale, | ||
foreground: foreground, | ||
background: background, | ||
shadows: shadows, | ||
fontFeatures: fontFeatures, | ||
fontVariations: fontVariations, | ||
decoration: decoration, | ||
decorationColor: decorationColor?.toColor(context), | ||
decorationStyle: decorationStyle, | ||
decorationThickness: decorationThickness, | ||
debugLabel: debugLabel, | ||
fontFamily: fontFamily, | ||
fontFamilyFallback: fontFamilyFallback, | ||
package: package, | ||
overflow: overflow, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.