theme_debug_overlay 1.0.3
theme_debug_overlay: ^1.0.3 copied to clipboard
A draggable, animated Flutter debug overlay for toggling ThemeMode at runtime. Renders only in debug builds — zero overhead in release.
import 'package:flutter/material.dart';
import 'package:theme_debug_overlay/theme_debug_overlay.dart';
void main() => runApp(const ExampleApp());
class ExampleApp extends StatefulWidget {
const ExampleApp({super.key});
@override
State<ExampleApp> createState() => _ExampleAppState();
}
class _ExampleAppState extends State<ExampleApp> {
ThemeMode _themeMode = ThemeMode.system;
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'ThemeDebugOverlay Demo',
themeMode: _themeMode,
theme: ThemeData(
colorSchemeSeed: Colors.deepPurple,
brightness: Brightness.light,
useMaterial3: true,
),
darkTheme: ThemeData(
colorSchemeSeed: Colors.deepPurple,
brightness: Brightness.dark,
useMaterial3: true,
),
// Wrap the home screen with ThemeDebugOverlayScaffold.
// The overlay is automatically hidden in release builds.
home: ThemeDebugOverlayScaffold(
themeMode: _themeMode,
onThemeModeChanged: (mode) => setState(() => _themeMode = mode),
child: const _HomeScreen(),
),
);
}
}
class _HomeScreen extends StatelessWidget {
const _HomeScreen();
@override
Widget build(BuildContext context) {
final cs = Theme.of(context).colorScheme;
return Scaffold(
appBar: AppBar(
title: const Text('Theme Debug Overlay'),
backgroundColor: cs.primaryContainer,
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.palette_outlined, size: 64, color: cs.primary),
const SizedBox(height: 24),
Text(
'Drag the floating button\nto move the overlay.',
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.titleMedium,
),
const SizedBox(height: 12),
Text(
'Tap it to switch themes.',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: cs.onSurfaceVariant,
),
),
const SizedBox(height: 32),
FilledButton.icon(
onPressed: () {},
icon: const Icon(Icons.check_circle_outline),
label: const Text('Works in light & dark'),
),
],
),
),
);
}
}