Android and iOS Build Failure ( The getter ‘COINIT’ isn’t defined for the class ‘FilePickerWindows’

Posted by

Error

./../AppData/Local/Pub/Cache/hosted/pub.dev/file_picker-8.0.5/lib/src/windows/file_picker_windows.dart:98:7: Error: The getter 'COINIT' isn't defined for the class 'FilePickerWindows'.
 - 'FilePickerWindows' is from 'package:file_picker/src/windows/file_picker_windows.dart' ('../../AppData/Local/Pub/Cache/hosted/pub.dev/file_picker-8.0.5/lib/src/windows/file_picker_windows.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'COINIT'.
      COINIT.COINIT_APARTMENTTHREADED | COINIT.COINIT_DISABLE_OLE1DDE,
      ^^^^^^
../../AppData/Local/Pub/Cache/hosted/pub.dev/file_picker-8.0.5/lib/src/windows/file_picker_windows.dart:98:41: Error: The getter 'COINIT' isn't defined for the class 'FilePickerWindows'.
 - 'FilePickerWindows' is from 'package:file_picker/src/windows/file_picker_windows.dart' ('../../AppData/Local/Pub/Cache/hosted/pub.dev/file_picker-8.0.5/lib/src/windows/file_picker_windows.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'COINIT'.
      COINIT.COINIT_APARTMENTTHREADED | COINIT.COINIT_DISABLE_OLE1DDE,
                                        ^^^^^^
../../AppData/Local/Pub/Cache/hosted/pub.dev/file_picker-8.0.5/lib/src/windows/file_picker_windows.dart:139:36: Error: The getter 'WIN32_ERROR' isn't defined for the class 'FilePickerWindows'.
 - 'FilePickerWindows' is from 'package:file_picker/src/windows/file_picker_windows.dart' ('../../AppData/Local/Pub/Cache/hosted/pub.dev/file_picker-8.0.5/lib/src/windows/file_picker_windows.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'WIN32_ERROR'.
      if (hr == HRESULT_FROM_WIN32(WIN32_ERROR.ERROR_CANCELLED)) {
                                   ^^^^^^^^^^^
Target kernel_snapshot failed: Exception


FAILURE: Build failed with an exception.

* Where:
Script 'C:\flutter\packages\flutter_tools\gradle\src\main\groovy\flutter.groovy' line: 1419

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\flutter\bin\flutter.bat'' finished with non-zero exit value 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 25s
Error: Gradle task assembleDebug failed with exit code 1

Solution

You’re seeing a compilation error caused by the file_picker package version 8.0.5 using undefined constants like COINIT and WIN32_ERROR. These constants are provided by the win32 package, but your current setup doesn’t support it.


❌ Root Problem

  • file_picker: ^8.0.5 depends on win32 ≥5.3.0, which defines COINIT, WIN32_ERROR, etc.
  • These constants don’t exist if:
    • You have an older version of win32, or
    • You’re not targeting Windows correctly (or trying to build for Android but this code is picked up anyway), or
    • There’s a Flutter/Dart version mismatch.

Recommended Fix: Downgrade file_picker to 6.1.1

Edit your pubspec.yaml:

dependencies:
  file_picker: ^6.1.1

Then run:

flutter clean
flutter pub get
flutter run

✅ Version 6.1.1 doesn’t use those problematic Windows-specific constants and works cross-platform.


✅ Alternative (Advanced): Match Flutter/Dart & win32 versions exactly

If you really need file_picker: ^8.0.5, then you must:

  1. Be using Dart 3.5.0+
  2. Be using Flutter 3.22.0+
  3. Add the compatible win32 version:
dependencies:
  file_picker: ^8.0.5
  win32: ^5.3.0

Then run:

flutter clean
flutter pub get
flutter run

But again: this only works if you’re on Flutter 3.22+ and Dart 3.5+, so check first:

flutter --version

🛑 Avoid This Common Mistake:

Do not mix versions like:

file_picker: ^8.0.5
flutter_inappwebview: ^6.0.0

Because file_picker 8.x expects newer SDK, while flutter_inappwebview: 6.0.0 is made for Dart 3.3 or lower.


✅ Best Setup for Dart 3.3.0

If you’re on Dart 3.3.0 (your earlier message):

dependencies:
  file_picker: ^6.1.1
  flutter_inappwebview: ^6.0.0
  html_editor_enhanced: ^2.4.0

Then:

flutter clean
flutter pub get
flutter run

Let me know if you want me to give you a working full pubspec.yaml file based on your current SDK version.

Leave a Reply

Your email address will not be published. Required fields are marked *

0
Would love your thoughts, please comment.x
()
x