useDark function

Ref<bool> useDark()

A composable that returns a reactive boolean Ref indicating if the current theme is dark.

The value of the Ref will update automatically when the theme changes.

Example:

KaeruWidget((ref) {
  final isDark = useDark();

  return KaeruBuilder(() {
    return Container(
      color: isDark.value ? Colors.black : Colors.white,
      child: Text(
        isDark.value ? 'Dark Mode' : 'Light Mode',
        style: TextStyle(
          color: isDark.value ? Colors.white : Colors.black,
        ),
      ),
    );
  });
});

Implementation

Ref<bool> useDark() {
  final theme = useTheme();
  final dark = UseDark();

  dark.mode ??= ref(theme.brightness == Brightness.dark);

  return dark.mode!;
}