dart Errors

35 error patterns

dart3 fixes

Flutter RenderFlex overflow

RenderFlex overflowed by .* pixels on the (right|bottom|left|top)

  • Wrap overflowing widget in Expanded or Flexible
  • Use SingleChildScrollView for scrollable content
dart3 fixes

Flutter setState called after widget dispose

setState\(\) called after dispose\(\)

  • Check 'if (mounted)' before calling setState()
  • Cancel async operations in dispose() method
dart3 fixes

Flutter platform channel method not implemented

MissingPluginException.*No implementation found for method.*on channel

  • Ensure native plugin is registered in MainActivity/AppDelegate
  • Run 'flutter clean' and rebuild the app
dart3 fixes

Flutter Riverpod/Provider not found in widget tree

ProviderNotFoundException.*Could not find.*provider.*above this.*Widget

  • Wrap the widget tree with ProviderScope at the top
  • Ensure ConsumerWidget or HookConsumerWidget is used correctly
dart3 fixes

Flutter GoRouter route not found

GoRouter.*GoException.*cannot find route

  • Check route path matches exactly (including leading slash)
  • Ensure the route is defined in GoRouter configuration
dart3 fixes

Flutter build_runner output conflict

build_runner.*Conflicting outputs.*were declared

  • Run 'dart run build_runner clean' then 'dart run build_runner build --delete-conflicting-outputs'
  • Check for duplicate generators targeting the same file
dart3 fixes

Flutter Flex layout constraint error

A RenderFlex overflowed.*This error happens when.*Expanded.*Flexible

  • Use Expanded to fill available space in Row/Column
  • Set mainAxisSize: MainAxisSize.min on Row/Column
dart3 fixes

Flutter late field not initialized

LateInitializationError: Field '.*' has not been initialized

  • Initialize the field before accessing it
  • Use nullable type with null check instead of late
dart3 fixes

Flutter null cast to non-nullable type

type 'Null' is not a subtype of type '.*' in type cast

  • Use 'as Type?' for nullable casts then null check
  • Ensure the value is not null before casting
dart3 fixes

Flutter PlatformException from native code

Unhandled Exception:.*PlatformException.*Error performing.*operation

  • Check platform-specific error code and message for details
  • Verify native permissions are granted (camera, location, etc.)
dart3 fixes

Flutter Bloc/Cubit emit after close

StateError.*Cannot emit new states after calling close

  • Check isClosed before emitting new states
  • Cancel subscriptions and timers in close() method
dart3 fixes

Flutter Riverpod StateNotifier used after disposal

Riverpod.*StateNotifier.*was used after being disposed

  • Check mounted property before state updates
  • Don't store references to notifiers outside provider scope
dart3 fixes

Flutter GoRouter infinite redirect loop

GoRouter.*redirect loop detected

  • Add base case to redirect logic: return null to stop redirecting
  • Check redirect doesn't redirect to a path that also redirects
dart3 fixes

Flutter number parsing format exception

FormatException.*Invalid radix-10 number

  • Use int.tryParse() or double.tryParse() which return null on failure
  • Validate string input before parsing
dart3 fixes

Flutter function return type mismatch

Exception.*type '.*' is not a subtype of type '.*' of 'function result'

  • Check the function's return type annotation matches actual return
  • Ensure generic type parameters are correct
dart3 fixes

Flutter Dio connection refused

Flutter.*DioError.*SocketException.*Connection refused

  • Check server is running and accessible from device
  • For Android emulator, use 10.0.2.2 instead of localhost
dart3 fixes

Flutter Freezed JSON generation failure

Flutter.*freezed.*Could not generate.*fromJson

  • Add @JsonSerializable() annotation on the Freezed class
  • Ensure json_serializable is in dev_dependencies
dart3 fixes

Flutter Android multidex/dex error

Flutter.*gradle.*Execution failed.*transformClassesAndResources.*DexArchive

  • Enable multidex: multiDexEnabled true in app/build.gradle
  • Update minSdkVersion to 21+ which has built-in multidex
dart3 fixes

Flutter iOS pod platform version incompatible

Flutter.*CocoaPods.*pod install.*error.*incompatible.*platform

  • Set platform :ios, '13.0' (or higher) in ios/Podfile
  • Update IPHONEOS_DEPLOYMENT_TARGET in Xcode project
dart3 fixes

Flutter RangeError index on empty collection

Flutter.*RangeError.*index.*valid value range is empty

  • Check collection.isNotEmpty before accessing by index
  • Use collection.firstOrNull (Dart 3) instead of collection.first
dart3 fixes

Flutter null pointer member access

Flutter.*Error:.*The getter '.*' was called on null

  • Use null-aware operator: object?.property
  • Add null check before access: if (object != null)
dart3 fixes

Flutter iterable operation on empty collection

Flutter.*StateError.*Bad state: No element

  • Use firstOrNull/lastOrNull instead of first/last
  • Check iterable.isNotEmpty before accessing elements
dart3 fixes

Flutter hit test on widget not yet laid out

Flutter.*Error:.*Cannot hit test a render box.*needs.*layout

  • Ensure widget has completed layout before gesture detection
  • Use WidgetsBinding.instance.addPostFrameCallback for post-layout logic
dart3 fixes

Flutter ObjectBox schema migration error

Flutter.*ObjectBox.*SchemaException.*incompatible.*change

  • Increment the model version and provide migration steps
  • For development, delete the database and start fresh
dart3 fixes

Flutter network image connection closed

Flutter.*Image\.network.*HttpException.*Connection closed

  • Add errorBuilder to Image.network for graceful fallback
  • Use CachedNetworkImage package for retry and caching
dart3 fixes

Flutter Riverpod ProviderScope disposed error

Flutter.*Riverpod.*ProviderScope.*already disposed

  • Don't access providers after ProviderScope widget is unmounted
  • Use ref.read instead of ref.watch for fire-and-forget operations
dart3 fixes

Flutter GoRouter child route path assertion

Flutter.*GoRouter.*assertion.*child routes.*must start with

  • Child route paths should NOT start with '/' (they're relative)
  • Use path: 'details' not path: '/details' in sub-routes
dart3 fixes

Flutter build_runner invalid source for generation

Flutter.*build_runner.*InvalidGenerationSourceError

  • Check annotations are correctly applied to eligible targets
  • Ensure the generator supports the target element type (class, function, etc.)
dart3 fixes

Flutter Google Sign-In API exception

Flutter.*PlatformException.*sign_in_failed.*ApiException.*10

  • Verify SHA-1/SHA-256 fingerprint in Firebase console matches debug/release key
  • Ensure google-services.json is up to date
dart3 fixes

Flutter MediaQuery not available in widget tree

Flutter.*MediaQuery.*dependOnInheritedWidgetOfExactType.*null

  • Ensure widget is below MaterialApp/CupertinoApp in the tree
  • Wrap test widgets in MediaQuery for unit tests
dart3 fixes

Flutter Firebase not initialized

Flutter.*Firebase.*core.*not initialized.*DefaultFirebaseApp

  • Call await Firebase.initializeApp() in main() before runApp()
  • Ensure WidgetsFlutterBinding.ensureInitialized() is called first
dart3 fixes

Flutter Completer completed more than once

Flutter.*error:.*Future already completed

  • Check completer.isCompleted before calling complete()
  • Use a Completer only once - create new instance for each operation
dart3 fixes

Flutter accessing ancestor of deactivated widget

Flutter.*error:.*looking up a deactivated widget's ancestor

  • Don't access context in callbacks that fire after widget disposal
  • Cache needed values from context before async operations
dart3 fixes

Flutter Riverpod ref used after provider disposed

Flutter.*Riverpod.*Cannot use ref after.*provider.*disposed

  • Use ref.onDispose() to cancel timers and subscriptions
  • Don't capture ref in closures that outlive the provider
dart3 fixes

Flutter Scaffold.of() context doesn't contain Scaffold

Flutter.*Error:.*Scaffold\.of\(\) called with.*context.*does not contain a Scaffold

  • Use ScaffoldMessenger.of(context) for snackbars (Flutter 2.0+)
  • Wrap in Builder widget to get a context below the Scaffold