From c0edb90896f54e91e0223c4a0eb17b247c2cc6da Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Sat, 24 Jun 2023 13:06:37 +0600 Subject: [PATCH] refactor: show devtools only in debug mode --- .../fl_query_devtools/lib/src/devtools.dart | 127 +++++++++--------- 1 file changed, 63 insertions(+), 64 deletions(-) diff --git a/packages/fl_query_devtools/lib/src/devtools.dart b/packages/fl_query_devtools/lib/src/devtools.dart index 84fe500..872f80a 100644 --- a/packages/fl_query_devtools/lib/src/devtools.dart +++ b/packages/fl_query_devtools/lib/src/devtools.dart @@ -18,78 +18,77 @@ class _FlQueryDevtoolsState extends State { @override Widget build(BuildContext context) { - if (kReleaseMode) { - return SizedBox.shrink(child: widget.child); - } - - return Navigator( - onPopPage: (route, result) { - return true; - }, - pages: [ - MaterialPage( - child: Scaffold( - body: Stack( - children: [ - if (widget.child != null) widget.child!, - if (_showDevtools) ...[ - Positioned( - child: GestureDetector( - onTap: () { - setState(() { - _showDevtools = false; - }); - }, - child: const SizedBox.expand( - child: ColoredBox( - color: Colors.black38, + if (kDebugMode) { + return Navigator( + onPopPage: (route, result) { + return true; + }, + pages: [ + MaterialPage( + child: Scaffold( + body: Stack( + children: [ + if (widget.child != null) widget.child!, + if (_showDevtools) ...[ + Positioned( + child: GestureDetector( + onTap: () { + setState(() { + _showDevtools = false; + }); + }, + child: const SizedBox.expand( + child: ColoredBox( + color: Colors.black38, + ), ), ), ), - ), - Positioned( - child: Align( - alignment: Alignment.bottomCenter, - child: Container( - height: MediaQuery.of(context).size.height * 0.7, - width: double.infinity, - margin: const EdgeInsets.all(8.0), - padding: const EdgeInsets.all(8.0), - decoration: BoxDecoration( - color: Theme.of(context).colorScheme.surface, - borderRadius: BorderRadius.circular(8.0), - ), - child: DevtoolsRoot( - onClose: () { - setState(() { - _showDevtools = false; - }); - }, + Positioned( + child: Align( + alignment: Alignment.bottomCenter, + child: Container( + height: MediaQuery.of(context).size.height * 0.7, + width: double.infinity, + margin: const EdgeInsets.all(8.0), + padding: const EdgeInsets.all(8.0), + decoration: BoxDecoration( + color: Theme.of(context).colorScheme.surface, + borderRadius: BorderRadius.circular(8.0), + ), + child: DevtoolsRoot( + onClose: () { + setState(() { + _showDevtools = false; + }); + }, + ), ), ), ), - ), - ] - ], - ), - floatingActionButtonLocation: - FloatingActionButtonLocation.startFloat, - floatingActionButton: AnimatedScale( - duration: const Duration(milliseconds: 100), - scale: _showDevtools ? 0 : 1, - child: FloatingActionButton.extended( - onPressed: () { - setState(() { - _showDevtools = !_showDevtools; - }); - }, - label: const Text("Fl-Query Devtools"), - icon: const Icon(Icons.search_rounded), + ] + ], + ), + floatingActionButtonLocation: + FloatingActionButtonLocation.startFloat, + floatingActionButton: AnimatedScale( + duration: const Duration(milliseconds: 100), + scale: _showDevtools ? 0 : 1, + child: FloatingActionButton.extended( + onPressed: () { + setState(() { + _showDevtools = !_showDevtools; + }); + }, + label: const Text("Fl-Query Devtools"), + icon: const Icon(Icons.search_rounded), + ), ), ), ), - ), - ], - ); + ], + ); + } + return SizedBox.shrink(child: widget.child); } }