test_platform_error 0.0.1 copy "test_platform_error: ^0.0.1" to clipboard
test_platform_error: ^0.0.1 copied to clipboard

A Flutter plugin to test Platformdispatcher via third party library. Supports Android and iOS.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:test_platform_error/test_platform_error.dart';
import 'dart:ui';

void main() {
  PlatformDispatcher.instance.onError = (error, stack) {
    debugPrint('Unhandled platform error: $error');
    debugPrint('Stack trace: $stack');
    return true; // Return true to indicate the error has been handled
  };
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Platform Error Example',
      theme: ThemeData(primarySwatch: Colors.blue),
      home: const MyHomePage(),
    );
  }
}

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

  static const MethodChannel _channel = MethodChannel('test_platform_error');

  Future<void> _invokeThrowPlatformError() async {
    // try {
    await _channel.invokeMethod('throwPlatformError');
    // } on PlatformException catch (e) {
    //   // Handle platform error
    //   debugPrint('PlatformException: ${e.code}, ${e.message}');
    // }
  }

  Future<void> _invokeThrowRuntimeError() async {
    // try {
    await _channel.invokeMethod('throwRuntimeError');
    // } on PlatformException catch (e) {
    //   // Handle platform error
    //   debugPrint('PlatformException: ${e.code}, ${e.message}');
    // } on Exception catch (e) {
    //   // Handle runtime error
    //   debugPrint('Exception: $e');
    // }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Platform Error Example')),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            ElevatedButton(
              onPressed: _invokeThrowPlatformError,
              child: const Text('Throw Platform Error'),
            ),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: _invokeThrowRuntimeError,
              child: const Text('Throw Runtime Error'),
            ),
          ],
        ),
      ),
    );
  }
}
3
likes
150
points
121
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin to test Platformdispatcher via third party library. Supports Android and iOS.

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on test_platform_error

Packages that implement test_platform_error