import 'package:flutter/services.dart'; /// Native file picker that shows hidden files/folders on macOS. /// Uses a custom method channel to NSOpenPanel with showsHiddenFiles = true, /// which the file_picker package hardcodes to false. class NativePicker { static const _channel = MethodChannel('com.svrnty.native_picker'); /// Opens a folder picker that shows hidden directories. /// Returns the selected folder path, or null if cancelled. static Future getDirectoryPath({String? initialDirectory}) async { try { return _channel.invokeMethod('getDirectoryPath', { 'initialDirectory': initialDirectory, }); } on PlatformException catch (e) { throw Exception('Native picker error: ${e.message}'); } } /// Opens a file picker that shows hidden files, filtered to specific extensions. /// Returns the selected file path, or null if cancelled. static Future pickFile({ List allowedExtensions = const [], String? initialDirectory, }) async { try { final result = await _channel.invokeMethod('pickFiles', { 'allowMultiple': false, 'allowedExtensions': allowedExtensions, 'initialDirectory': initialDirectory, }); if (result != null && result.isNotEmpty) { return result.first as String; } return null; } on PlatformException catch (e) { throw Exception('Native picker error: ${e.message}'); } } }