-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disallow choosing system color palette if not supported by device
Rename `ColorSchemeType.app` -> `.custom` Add `subtitle` and `enabled` params to `ChoiceListTile`
- Loading branch information
Showing
8 changed files
with
131 additions
and
23 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
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,56 @@ | ||
import "package:dynamic_color/dynamic_color.dart"; | ||
import "package:flutter/material.dart"; | ||
import "package:flutter/services.dart"; | ||
import "package:material_color_utilities/material_color_utilities.dart"; | ||
|
||
Future<BrightnessAwareColorScheme> loadColorScheme({required Color fallbackSeedColor}) async { | ||
try { | ||
final corePalette = await DynamicColorPlugin.getCorePalette(); | ||
|
||
if (corePalette != null) { | ||
return BrightnessAwareColorScheme.fromCorePalette(corePalette); | ||
} | ||
} on PlatformException { | ||
// ignore | ||
} | ||
|
||
try { | ||
final accentColor = await DynamicColorPlugin.getAccentColor(); | ||
|
||
if (accentColor != null) { | ||
return BrightnessAwareColorScheme.fromAccentColor(accentColor, isDynamicColorSupported: true); | ||
} | ||
} on PlatformException { | ||
// ignore | ||
} | ||
|
||
return BrightnessAwareColorScheme.fromAccentColor(fallbackSeedColor, isDynamicColorSupported: false); | ||
} | ||
|
||
class BrightnessAwareColorScheme { | ||
final ColorScheme light; | ||
final ColorScheme dark; | ||
final bool isDynamicColorSupported; | ||
|
||
BrightnessAwareColorScheme({ | ||
required this.light, | ||
required this.dark, | ||
required this.isDynamicColorSupported, | ||
}); | ||
|
||
BrightnessAwareColorScheme.fromCorePalette(CorePalette palette) | ||
: this( | ||
light: palette.toColorScheme(brightness: Brightness.light), | ||
dark: palette.toColorScheme(brightness: Brightness.dark), | ||
isDynamicColorSupported: true, | ||
); | ||
|
||
BrightnessAwareColorScheme.fromAccentColor( | ||
Color accentColor, { | ||
required bool isDynamicColorSupported, | ||
}) : this( | ||
light: ColorScheme.fromSeed(seedColor: accentColor, brightness: Brightness.light), | ||
dark: ColorScheme.fromSeed(seedColor: accentColor, brightness: Brightness.dark), | ||
isDynamicColorSupported: isDynamicColorSupported, | ||
); | ||
} |
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,35 @@ | ||
import "package:flutter/material.dart"; | ||
import "package:provider/provider.dart"; | ||
|
||
import "../utils/color_scheme.dart"; | ||
import "../utils/settings.dart"; | ||
|
||
class BrightnessAwareColorSchemeBuilder extends StatelessWidget { | ||
final Widget Function(BrightnessAwareColorScheme colorScheme) builder; | ||
|
||
const BrightnessAwareColorSchemeBuilder({ | ||
super.key, | ||
required this.builder, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final settings = context.watch<SettingsModel>(); | ||
final systemColorScheme = context.read<BrightnessAwareColorScheme>(); | ||
final customColorScheme = BrightnessAwareColorScheme.fromAccentColor( | ||
settings.seedColor, | ||
isDynamicColorSupported: systemColorScheme.isDynamicColorSupported, | ||
); | ||
|
||
if (!systemColorScheme.isDynamicColorSupported) { | ||
return builder(customColorScheme); | ||
} | ||
|
||
switch (settings.colorSchemeType) { | ||
case ColorSchemeType.system: | ||
return builder(systemColorScheme); | ||
case ColorSchemeType.custom: | ||
return builder(customColorScheme); | ||
} | ||
} | ||
} |
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