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

_CastError (type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'List<dynamic>?' in type cast) #16

Closed
Cengizhan00 opened this issue Jun 24, 2022 · 9 comments

Comments

@Cengizhan00
Copy link

Cengizhan00 commented Jun 24, 2022

Stories _$StoriesFromJson(Map<String, dynamic> json) {
return Stories(
storyId: json['storyId'] as String?,
date: json['date'] == null ? null : DateTime.parse(json['date'] as String),
file: (json['file'] as List<dynamic>?)?.map((e) => StoryData.fromJson(e as Map<String, dynamic>)).toList(),
previewImage: json['previewImage'] as String?,
previewTitle: (json['previewTitle'] as Map<String, dynamic>?)?.map(
(k, e) => MapEntry(k, e as String),
),
);
}

@Cengizhan00
Copy link
Author

@awaik

@Cengizhan00
Copy link
Author

I solved the above problem, this time it gives this error

_TypeError (type '() => Null' is not a subtype of type '(() => StoryItem)?' of 'orElse')

@shukill
Copy link

shukill commented Jul 7, 2022

@awaik this issue is still persesting _TypeError (type '() => Null' is not a subtype of type '(() => StoryItem)?' of 'orElse')

@awaik
Copy link
Owner

awaik commented Jul 8, 2022

Can you please provide full error log?

@shukill
Copy link

shukill commented Jul 8, 2022

`[GETX] OPEN BOTTOMSHEET 71736793
[GETX] GOING TO ROUTE /StoriesSection

════════ Exception caught by widgets library ═══════════════════════════════════
The following _TypeError was thrown building RawGestureDetector(state: RawGestureDetectorState#6fcd5(gestures: [vertical drag])):
type '() => Null' is not a subtype of type '(() => StoryItem)?' of 'orElse'

The relevant error-causing widget was
GetMaterialApp
lib/main.dart:44
When the exception was thrown, this was the stack
#0 ListMixin.firstWhere (dart:collection/list.dart)
#1 StoryViewState.initState
package:flutter_instagram_stories/story_view.dart:322
#2 StatefulElement._firstBuild
package:flutter/…/widgets/framework.dart:4942
#3 ComponentElement.mount
package:flutter/…/widgets/framework.dart:4781
... Normal element mounting (32 frames)
#35 Element.inflateWidget
package:flutter/…/widgets/framework.dart:3817
#36 MultiChildRenderObjectElement.inflateWidget
package:flutter/…/widgets/framework.dart:6350
#37 MultiChildRenderObjectElement.mount
package:flutter/…/widgets/framework.dart:6362
... Normal element mounting (29 frames)
#66 Element.inflateWidget
package:flutter/…/widgets/framework.dart:3817
#67 Element.updateChild
package:flutter/…/widgets/framework.dart:3545
#68 ComponentElement.performRebuild
package:flutter/…/widgets/framework.dart:4832
#69 StatefulElement.performRebuild
package:flutter/…/widgets/framework.dart:4977
#70 Element.rebuild
package:flutter/…/widgets/framework.dart:4529
#71 BuildOwner.buildScope
package:flutter/…/widgets/framework.dart:2659
#72 WidgetsBinding.drawFrame
package:flutter/…/widgets/binding.dart:891
#73 RendererBinding._handlePersistentFrameCallback
package:flutter/…/rendering/binding.dart:370
#74 SchedulerBinding._invokeFrameCallback
package:flutter/…/scheduler/binding.dart:1146
#75 SchedulerBinding.handleDrawFrame
package:flutter/…/scheduler/binding.dart:1083
#76 SchedulerBinding._handleDrawFrame
package:flutter/…/scheduler/binding.dart:997
#80 _invoke (dart:ui/hooks.dart:151:10)
#81 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:308:5)
#82 _drawFrame (dart:ui/hooks.dart:115:31)
Screenshot 2022-07-08 at 12 40 04 PM

(elided 3 frames from dart:async)
════════════════════════════════════════════════════════════════════════════════`

@awaik

@Akperhe
Copy link

Akperhe commented Oct 3, 2022

am having same issue. I have done automatically, that is by generating the data class by vs code pluggin.

@awaik
Copy link
Owner

awaik commented Oct 18, 2022

Hi,
Somehow, I couldn't repeat it with an example project.
If you have open-source repo - can you please give me a link to it and I'll try to catch this bug.

@mapkbalaji
Copy link

I too am getting the same bug

@Cengizhan00
Copy link
Author

I solved the problem. You can solve it by following the steps below.

error: _TypeError (type '() => Null' is not a subtype of type '(() => StoryItem)?' of 'orElse')

solution: I used firstWhereOrNull instead of 'firstWhere' everywhere in 'story_view.dart', function from 'collection' package and it solved my problem.

Below is an example usage.

Replace firstWhere with firstWhereOrNull

story_view dart - bulak_hukuk_akademisi - Visual Studio Code 18 01 2023 14_30_12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants