DEV Community

ThinkDigitalSoftware
ThinkDigitalSoftware

Posted on

4 1

Facepalm moment of the day

I'm developing an app in Flutter and Dart and I come across an issue where an event being added to my BLoC. (A stream-based state management solution for the uninitiated)

The state class is made up of a combination of a few different streams. When one releases an event, the state is updated with the latest updated value using a copyWith() function. This is all going fine and well until I push a null value into one of the streams and the state doesn't change. I know it was pushed successfully, but the old state is still reflected. Hopefully this will help some of you.

If your copyWith functions look like this:

State copyWith({int param1, String param2}){
  return State(
            param1: param1 ?? this.param1, 
            param2: param2 ?? this.param2
         ); 

then passing a null value will cause it to return the existing value even if you intended to set it to null. I doubt this is an issue in languages with an Undefined type, however, Dart does not have one.

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay