Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled Exception: Bad state: No element #47040

Closed
Papirosnik opened this issue Dec 14, 2019 · 6 comments
Closed

Unhandled Exception: Bad state: No element #47040

Papirosnik opened this issue Dec 14, 2019 · 6 comments
Labels
c: regression It was better in the past than it is now framework flutter/packages/flutter repository. See also f: labels.

Comments

@Papirosnik
Copy link

Papirosnik commented Dec 14, 2019

I get this error when start my app on both real android device and emulator as well (ios version seems to be free of this error, at least on simulator).

Launching lib/main.dart on SNE LX1 in debug mode...
Running Gradle task 'assembleDebug'...
✓ Built build/app/outputs/apk/debug/app-debug.apk.
Installing build/app/outputs/apk/app.apk...
Syncing files to device SNE LX1...
E/flutter (28106): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: Bad state: No element
E/flutter (28106): #0      ListMixin.singleWhere (dart:collection/list.dart:185:5)
E/flutter (28106): #1      SettingsLogic._applyTheme (package:flutter_xo/logics/settings_logic.dart:34:41)
E/flutter (28106): #2      SettingsLogic.applyThemeFromPrefs.<anonymous closure> (package:flutter_xo/logics/settings_logic.dart:29:7)
E/flutter (28106): #3      _rootRunUnary (dart:async/zone.dart:1134:38)
E/flutter (28106): #4      _CustomZone.runUnary (dart:async/zone.dart:1031:19)
E/flutter (28106): #5      _FutureListener.handleValue (dart:async/future_impl.dart:140:18)
E/flutter (28106): #6      Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:682:45)
E/flutter (28106): #7      Future._propagateToListeners (dart:async/future_impl.dart:711:32)
E/flutter (28106): #8      Future._completeWithValue (dart:async/future_impl.dart:526:5)
E/flutter (28106): #9      Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:556:7)
E/flutter (28106): #10     _rootRun (dart:async/zone.dart:1126:13)
E/flutter (28106): #11     _CustomZone.run (dart:async/zone.dart:1023:19)
E/flutter (28106): #12     _CustomZone.runGuarded (dart:async/zone.dart:925:7)
E/flutter (28106): #13     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:965:23)
E/flutter (28106): #14     _microtaskLoop (dart:async/schedule_microtask.dart:43:21)
E/flutter (28106): #15     _startMicrotaskLoop (dart:async/schedule_microtask.dart:52:5)
E/flutter (28106): 
D/AwareBitmapCacher(28106): handleInit switch not opened pid=28106
I/ycode.flutterx(28106): Starting profile saver IsSaveProfileNow end.

flutter doctor --v

[✓] Flutter (Channel master, v1.13.1-pre.99, on Mac OS X 10.14.6 18G95, locale en-BY)
    • Flutter version 1.13.1-pre.99 at /Users/user/work/flutter
    • Framework revision 354f80b84a (3 days ago), 2019-12-11 16:36:03 -0800
    • Engine revision 12bf95fd49
    • Dart version 2.7.0 (build 2.7.0-dev.2.1 8b8894648f)
 
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /Users/slavak/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.2
    • ANDROID_HOME = /Users/user/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.3, Build version 11C29
    • CocoaPods version 1.8.4

[✓] Android Studio (version 3.5)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 42.1.1
    • Dart plugin version 191.8593
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[✓] IntelliJ IDEA Ultimate Edition (version 2018.3.6)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin version 39.0.1
    • Dart plugin version 183.6270

[✓] Connected device (1 available)
    • SNE LX1 • HYF0218928082691 • android-arm64 • Android 9 (API 28)

Related custom code is:

@override
  void initState() {
    super.initState();
    GetIt.I.get<SettingsLogic>().applyThemeFromPrefs();
  }

// file: settings_logic.dart

void applyThemeFromPrefs() {
    SharedPreferences.getInstance().then((prefs) {
      var themeName = prefs.getString("theme");
      _applyTheme(themeName);
    });
  }

  void _applyTheme(String themeName) {
    AppTheme appTheme = AppTheme.values.singleWhere((v) => describeEnum(v) == themeName);
    _currentTheme = appTheme;
    _streamController.sink.add(AppThemeChangedEvent(appTheme));
  }

...
// listener to theme changing

class FxoApp extends StatelessWidget {
  final SettingsLogic settings = GetIt.I.get<SettingsLogic>();

  @override
  Widget build(BuildContext context) {
    return StreamBuilder<AppThemeChangedEvent>(
      stream: settings.themeStream,
      initialData: AppThemeChangedEvent(AppTheme.Light),
      builder: (context, snapshot) {
        return MaterialApp(
          title: AppName,
          theme: appThemeData[snapshot.data.appTheme],
...

Everything seems working correctly,
just want to understand what is the reason and how to fix this.

@iapicca iapicca added framework flutter/packages/flutter repository. See also f: labels. c: regression It was better in the past than it is now labels Dec 16, 2019
@goderbauer
Copy link
Member

Can you post a runnable code sample that we can just copy and run to see the problem? The code you posted is incomplete.

@goderbauer goderbauer added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Dec 18, 2019
@VladyslavBondarenko
Copy link

Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now. Please don't hesitate to comment on the bug if you have any more information for us; we will reopen it right away!
Thanks for your contribution.
Could everyone who still has this problem please file a new issue with the exact descriptions what happens, logs and the output of 'flutter doctor -v' please.
All system setups can be slightly different so its always better to open new issues and reference related issues.

@NikolaArsenovic
Copy link

It might be that you have some ".firstWhere" that never matches and it is never true.. Just add optional parameter to all .firstWhere((a) => a == b, , orElse: () => null) this will allow your function to return null, instead of throwing errors like this.

@Papirosnik
Copy link
Author

It might be that you have some ".firstWhere" that never matches and it is never true.. Just add optional parameter to all .firstWhere((a) => a == b, , orElse: () => null) this will allow your function to return null, instead of throwing errors like this.

Yes, you're right.
Sorry for my fault, indeed there is hidden singleWhere clause...

@no-response no-response bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jan 28, 2020
@no-response no-response bot reopened this Jan 28, 2020
@sanda0
Copy link

sanda0 commented Aug 14, 2020

how to fix this error. need help

I/flutter ( 1548): https://youtu.be/_2xZ71BodIk
V/AudioManager( 1548): playSoundEffect effectType: 0
E/flutter ( 1548): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: Bad state: No element
E/flutter ( 1548): #0 List.first (dart:core-patch/growable_array.dart:250:5)
E/flutter ( 1548): #1 _HomeState._getLinks (package:y2v/screens/home.dart:95:60)
E/flutter ( 1548):
E/flutter ( 1548): #2 _HomeState.build. (package:y2v/screens/home.dart:47:19)
E/flutter ( 1548): #3 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:992:19)
E/flutter ( 1548): #4 _InkResponseState.build. (package:flutter/src/material/ink_well.dart:1098:38)
E/flutter ( 1548): #5 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:184:24)
E/flutter ( 1548): #6 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:524:11)
E/flutter ( 1548): #7 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:284:5)
E/flutter ( 1548): #8 BaseTapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:256:7)
E/flutter ( 1548): #9 GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:158:27)
E/flutter ( 1548): #10 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:224:20)
E/flutter ( 1548): #11 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:200:22)
E/flutter ( 1548): #12 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:158:7)
E/flutter ( 1548): #13 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:104:7)
E/flutter ( 1548): #14 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:88:7)
E/flutter ( 1548): #15 _rootRunUnary (dart:async/zone.dart:1206:13)
E/flutter ( 1548): #16 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter ( 1548): #17 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter ( 1548): #18 _invoke1 (dart:ui/hooks.dart:267:10)
E/flutter ( 1548): #19 _dispatchPointerDataPacket (dart:ui/hooks.dart:176:5)
E/flutter ( 1548):

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
c: regression It was better in the past than it is now framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

No branches or pull requests

6 participants