Flutter FAQ - splimter/Flutter GitHub Wiki

Flutter FAQ

MediaQuery.of()

Q

Flutter Error: MediaQuery.of() called with a context that does not contain a MediaQuery

A

You need a MaterialApp or a WidgetsApp arround your widget. They provide the MediaQuery.

source

Q

* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: <...>
  The number of method references in a .dex file cannot exceed 64K.
  Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html

A

Add multidex library to android app depedency (/android/app/build.gradle):

android {
  ...
  defaultConfig {
    ...
    multiDexEnabled true
  }
  ...
}
...
dependencies {
  implementation 'com.android.support:multidex:1.0.3' // use latest version
  ...
}

Q

*******************************************************************************************
The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app.
See https://goo.gl/CP92wY for more information on the problem and how to fix it.
*******************************************************************************************

A

  • android\gradle.properties:
android.useAndroidX=true
android.enableJetifier=true
  • android\build.gradle:
subprojects {
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.android.support'
                    && !details.requested.name.contains('multidex') ) {
                details.useVersion "26.1.0"
            }
        }
    }
}

AndroidX migration.

Q

[SEVERE] Failed to snapshot build script .dart_tool/build/entrypoint/build.dart.
This is likely caused by a misconfigured builder definition.

A

Use a correct build_runner version:

dev_dependencies:
  build_runner: ^1.0.0
  json_serializable: ^2.0.0

Q

When Keyboard go up it show Overflow error

A

Under Scaffold Add resizeToAvoidBottomPadding: false,.

Q

Unhandled Exception: ServicesBinding.defaultBinaryMessenger was accessed before the binding was initialized.

A

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(Delta(
    model: ProductDataModel(),
  ));
}
⚠️ **GitHub.com Fallback** ⚠️