/// Moon / sun control for switching light and dark themes. library; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import '../providers/theme_provider.dart'; class ThemeToggleButton extends StatelessWidget { const ThemeToggleButton({super.key}); @override Widget build(BuildContext context) { final theme = context.watch(); final colors = Theme.of(context).colorScheme; final dark = theme.isDark; return IconButton( tooltip: dark ? 'Switch to light mode' : 'Switch to dark mode', onPressed: theme.toggleLightDark, visualDensity: VisualDensity.compact, padding: EdgeInsets.zero, constraints: const BoxConstraints(minWidth: 32, minHeight: 32), style: IconButton.styleFrom( backgroundColor: colors.surfaceContainer, foregroundColor: colors.onSurfaceVariant, tapTargetSize: MaterialTapTargetSize.shrinkWrap, ), icon: Icon( dark ? Icons.light_mode_outlined : Icons.dark_mode_outlined, size: 16, ), ); } }