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

A BlueScreen widget replaces the default ErrorWidget used for Flutter apps.

example/lib/main.dart

import 'package:blue_screen/blue_screen.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

/// Flutter code sample for [BlueScreenWidget].
void main() {
  // Put the app in a safe mode.
  runSafeMode(() {
    // Start the app.
    runApp(const BlueScreenExampleApp());
  });
}

class BlueScreenExampleApp extends StatefulWidget {
  const BlueScreenExampleApp({super.key});

  @override
  State<BlueScreenExampleApp> createState() => _BlueScreenExampleAppState();
}

class _BlueScreenExampleAppState extends State<BlueScreenExampleApp> {
  var throwError = false;

  @override
  Widget build(BuildContext context) {
    // Set the BlueScreen's builder before the app is started.
    return BlueScreenBuilder(
      builder: (exception) {
        // If we're in debug mode,
        // use the blue screen on Windows 10 to shows the error.
        if (kDebugMode) {
          return BlueScreenWidget.withWindows10(
            exception,
            rebuild: true,
            repeatable: true,
            stopCode: StopCode.ABNORMAL_RESET_DETECTED,
          );
        } else {
          // In release builds, show a blue screen on Windows 11 instead:
          return BlueScreenWidget.withWindows11(exception);
        }
      },
      child: MaterialApp(
        theme: ThemeData(
          fontFamily: FontFamily.segoe,
        ),
        title: 'blue_screen_example',
        debugShowCheckedModeBanner: false,
        home: SafeModeBuilder(
          enable: false,
          builder: (context) {
            if (throwError) {
              // Since the error widget is only used during a build, in this contrived example,
              // we purposely throw an exception in a build function.
              throw Exception('oh no, an error');
            } else {
              return Scaffold(
                appBar: AppBar(
                  title: const Text('BlueScreen Sample'),
                ),
                body: Center(
                  child: TextButton(
                    onPressed: () {
                      setState(() {
                        throwError = true;
                      });
                    },
                    child: const Text('Error Prone'),
                  ),
                ),
              );
            }
          },
          // Show a default BlueScreenWidget when app throws an error.
          creator: (exception) => BlueScreenWidget(exception),
        ),
      ),
    );
  }
}
6
likes
150
pub points
0%
popularity
screenshot

Publisher

unverified uploader

A BlueScreen widget replaces the default ErrorWidget used for Flutter apps.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on blue_screen