import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { const channel = MethodChannel('easy_settings_screen'); testWidgets('mock platform channel', (WidgetTester tester) async { // 1️⃣ Initialize the test binding TestWidgetsFlutterBinding.ensureInitialized(); // 2️⃣ Set up the mock directly on the defaultBinaryMessenger tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(channel, ( MethodCall call, ) async { return '42'; }); // Perform widget actions that trigger the method call... // e.g., pump your widget or call the method manually. // ✅ Verify behavior, e.g.: final result = await channel.invokeMethod('anyMethod'); expect(result, '42'); // 3️⃣ Clean up after test tester.binding.defaultBinaryMessenger.setMockMethodCallHandler( channel, null, ); }); }