Giter Site home page Giter Site logo

Null safety about screwdriver HOT 7 CLOSED

naamapps avatar naamapps commented on July 20, 2024
Null safety

from screwdriver.

Comments (7)

naamapps avatar naamapps commented on July 20, 2024 1

@BirjuVachhani
I think the last one doesn't show an error because the extension is on Iterable? while the others are part of the Dart language and it is not an extension.
I think this is also the case with strings but i'm not sure.

from screwdriver.

BirjuVachhani avatar BirjuVachhani commented on July 20, 2024 1

@naamapps I have added these extensions back for now.

dependencies:
  screwdriver: ^2.1.0

from screwdriver.

naamapps avatar naamapps commented on July 20, 2024 1

@BirjuVachhani Thank you, much appreciated!

from screwdriver.

BirjuVachhani avatar BirjuVachhani commented on July 20, 2024

@naamapps I am working it. Will publish it soon.

from screwdriver.

BirjuVachhani avatar BirjuVachhani commented on July 20, 2024

@naamapps

Null-safe version has been released. Please check CHANGELOG before upgrading.
https://pub.dev/packages/screwdriver

from screwdriver.

naamapps avatar naamapps commented on July 20, 2024

Hi, thanks for the update.
Why did you remove the extensions Iterable.isNullOrEmpty, Iterable.isNotNullOrEmpty, String.isNullOrEmpty, String.isNotNullOrEmpty, String.isNullOrBlank ,String.isNotNullOrBlank?
Even when there is null safety it is still required to do null checks..

for the collections it can be done like so:

extension NullableIterableScrewDriver<E> on Iterable<E>? {
  bool get isNullOrEmpty => this == null || this!.isEmpty;
  bool get isNotNullOrEmpty => this != null && this!.isNotEmpty;
}

What do you think about adding new extensions only for nullable collections or strings?

from screwdriver.

BirjuVachhani avatar BirjuVachhani commented on July 20, 2024

@naamapps

String? testing;
testing.substring(5); // This shows error

List<int>? list2;
print(list2.first); // This also shows error

List<int>? list3;
print(list3.isNullOrEmpty); // But this doesn't :(

I thought it would show error when accessing nullable types and we would need to use ? for null safety but now it seems that extensions doesn't respect whether the receiver is null or not.

Seems that I need to add those extensions back but for Iterable? type.

from screwdriver.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.