Panic

Panic screenshots

Supported platforms

Current Build Status. Panic is released under the MIT license. Effective Dart PRs welcome!

Content

Features

Panics a Flutter app.

This allows a flutter app to terminate immediately and provide feedback to the caller of the app. Panic should be used when an app reaches an unrecoverable state.

Requirements

  • Dart: 2.14.0+
  • Flutter : 2.5.0+

Install

dependencies:
  panic: ^0.0.1

Example

  1. Add GlobalKey<NavigatorState>() to MaterialApp widget.
// `appKey` should be globally accessible in an app.
final appKey = GlobalKey<NavigatorState>();

class App extends StatelessWidget {
  const App({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      navigatorKey: appKey,
      home: Home(),
    );
  }
}

  1. Initialized Panic.
import 'package:panic/panic.dart';
// `panic` should be globally accessible in an app
final panic = Panic(appKey);
  1. Panic a flutter app when you really need it.
  static Future<Result<DiscoverResponse?, NetworkError>> fetchDiscover() async {
    final response = await _client.get(
      Uri.parse('$baseUrl/discover/movie?api_key=$themoviedbApiKey&page=1'),
    );

    if (response.statusCode == 200) {
      // Panic app if some important parameters are missed e.g.,
      // some field in a Header or in a Body.
      if (!response.headers.containsKey('MY MISSING KEY')) {
        panic.app();
      }
      return Success(DiscoverResponse.fromJson(response.body));
    } else {
      throw NetworkError(response.statusCode);
    }
  }

To see examples of the following package on a device or simulator:

cd example && flutter run

Support

Post issues and feature requests on the GitHub issue tracker.

License

The source code of Panic project is available under the MIT license. See the LICENSE file for more info.

Libraries

panic