Skip to content

Add DateTime.copyWith to class instead of extension method #60085

Open
@lrampazzo

Description

@lrampazzo

Hello everyone,

Currently DateTime.copyWith is implemented via extension method:

https://api.flutter.dev/flutter/dart-core/DateTimeCopyWith/copyWith.html

Unfortunately this approach may lead to subtle bugs, because any other implementation of the DateTime class can call copyWith and be copied as the core lib implementation.

In our case, we are using timezone package, which provides an implementation of DateTime (TZDateTime). By using copyWith, we lose implicit information about the timezone.

Instead of having an extension method, is it viable to add copyWith as virtual method which can be overridden by subclasses?

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.library-corestatus-blockedBlocked from making progress by another (referenced) issuetype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions