Skip to main content

in_app_debug_console 1.0.1 copy "in_app_debug_console: ^1.0.1" to clipboard
in_app_debug_console: ^1.0.1 copied to clipboard

An in-app debug console for Flutter. Logs, network requests, device info, performance and debug tools inside your running app.

example/lib/main.dart

import 'dart:convert';

import 'package:http/http.dart' as http;
import 'package:in_app_debug_console/in_app_debug_console.dart';
import 'package:material_ui/material_ui.dart';

void main() {
  // Captures print(), Flutter errors, uncaught errors and HTTP requests.
  DebugConsole.runGuarded(() => runApp(const ExampleApp()));
}

class ExampleApp extends StatelessWidget {
  const ExampleApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Debug console example',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(colorSchemeSeed: Colors.indigo),
      darkTheme: ThemeData(
        colorSchemeSeed: Colors.indigo,
        brightness: Brightness.dark,
      ),
      // Follows the device setting. The console matches it automatically.
      themeMode: ThemeMode.system,
      // Logs screen changes in the console.
      navigatorObservers: [DebugConsole.instance.navigatorObserver],
      builder: (context, child) => DebugConsoleOverlay(child: child!),
      home: const HomePage(),
    );
  }
}

const _api = 'https://jsonplaceholder.typicode.com';

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    final console = DebugConsole.instance;

    return Scaffold(
      appBar: AppBar(title: const Text('Debug console example')),
      body: ListView(
        padding: const EdgeInsets.all(16),
        children: [
          _Section(
            title: 'Logs',
            children: [
              FilledButton.tonal(
                // ignore: avoid_print
                onPressed: () => print('Hello from print()'),
                child: const Text('print()'),
              ),
              FilledButton.tonal(
                onPressed: () => console.i('User tapped the info button'),
                child: const Text('Info'),
              ),
              FilledButton.tonal(
                onPressed: () => console.w('Cache is almost full'),
                child: const Text('Warning'),
              ),
              FilledButton.tonal(
                onPressed: () => throw StateError('Something broke'),
                child: const Text('Throw error'),
              ),
            ],
          ),
          _Section(
            title: 'Network',
            children: [
              FilledButton.tonal(
                onPressed: () => http.get(Uri.parse('$_api/posts/1')),
                child: const Text('GET 200'),
              ),
              FilledButton.tonal(
                onPressed: () => http.post(
                  Uri.parse('$_api/posts'),
                  headers: {'content-type': 'application/json'},
                  body: jsonEncode({'title': 'Hello', 'userId': 1}),
                ),
                child: const Text('POST 201'),
              ),
              FilledButton.tonal(
                onPressed: () => http.get(Uri.parse('$_api/does-not-exist')),
                child: const Text('GET 404'),
              ),
              FilledButton.tonal(
                onPressed: () async {
                  try {
                    await http.get(Uri.parse('https://no-such-host.invalid'));
                  } catch (e) {
                    console.e('Request failed', e);
                  }
                },
                child: const Text('Failed request'),
              ),
            ],
          ),
          _Section(
            title: 'Navigation',
            children: [
              FilledButton.tonal(
                onPressed: () => Navigator.of(context).push(
                  MaterialPageRoute<void>(
                    settings: const RouteSettings(name: '/details'),
                    builder: (_) => const DetailsPage(),
                  ),
                ),
                child: const Text('Open another screen'),
              ),
            ],
          ),
          const SizedBox(height: 8),
          Text(
            'Tap the console button to see everything.',
            textAlign: TextAlign.center,
            style: Theme.of(context).textTheme.bodySmall,
          ),
        ],
      ),
    );
  }
}

class DetailsPage extends StatelessWidget {
  const DetailsPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Details')),
      body: const Center(
        child: Text(
            'Open the console and check the Logs tab:\n'
            'this screen change was logged.',
            textAlign: TextAlign.center),
      ),
    );
  }
}

class _Section extends StatelessWidget {
  const _Section({required this.title, required this.children});

  final String title;
  final List<Widget> children;

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.only(bottom: 24),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(title, style: Theme.of(context).textTheme.titleMedium),
          const SizedBox(height: 10),
          Wrap(spacing: 10, runSpacing: 10, children: children),
        ],
      ),
    );
  }
}
2
likes
160
points
--
downloads
screenshot

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

An in-app debug console for Flutter. Logs, network requests, device info, performance and debug tools inside your running app.

Repository (GitHub)
View/report issues

Topics

#debugging #logging #network #devtools #console

License

MIT (license)

Dependencies

flutter, material_ui

More

Packages that depend on in_app_debug_console