1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] Why there is no DateTime.now() after update flutter SDK to 3.24.1

Discussão em 'Mobile' iniciado por Stack, Setembro 11, 2024 às 05:52.

  1. Stack

    Stack Membro Participativo

    Why did they remove the DateTime.now()? It seems like we can not easily get current date and time in the local/utc time zone from different function. I did not find any release note or blog about it.

    In dart 3.5.1' s doc there is still DateTime.now()

    What happened to me: My code use DateTime.now() before and works well. After I upgrade SDK, there is an error "The method 'now' isn't defined for the type 'DateTime'. Try correcting the name to the name of an existing method, or defining a method named 'now'." And I click into DateTime (Users>me>fvm>versions>3.24.1>bin>cache>pkg>sky_engine>lib>core>date_time.dart), I found the code changed. I cleared the cache and flutter doctor does not show error. If I switch to 3.22.2, the now() is back, and if I switch to 3.24.1, it will disappear.

    fvm flutter doctor -v [✓] Flutter (Channel stable, 3.24.1, on macOS 14.5 23F79 darwin-x64, locale zh-Hans-CN) • Flutter version 3.24.1 on channel stable at /Users/me/fvm/versions/3.24.1 • Upstream repository https://github.com/flutter/flutter.git • Framework revision 5874a72aa4 (3 weeks ago), 2024-08-20 16:46:00 -0500 • Engine revision c9b9d5780d • Dart version 3.5.1 • DevTools version 2.37.2

    core/date_time.dart:

    Before(3.22.2 dart 3.4.3)

    /// Constructs a [DateTime] instance with current date and time in the
    /// local time zone.
    ///
    /// ```dart
    /// final now = DateTime.now();
    /// ```
    DateTime.now() : this._now();

    /// Constructs a [DateTime] with the current UTC date and time.
    ///
    ///
    /// ```dart
    /// final mark = DateTime.timestamp();
    /// ```
    @Since("3.0")
    DateTime.timestamp() : this._nowUtc();


    After(3.24.1 dart 3.5.1)

    /// Constructs a [DateTime] instance with current date and time in the
    /// local time zone.
    ///
    /// ```dart
    /// final now = DateTime.timestamp();
    /// ```
    DateTime.timestamp() : this._now();

    /// Constructs a [DateTime] with the current UTC date and time.
    ///
    ///
    /// ```dart
    /// final mark = DateTime.timestamp();
    /// ```
    @Since("3.0")
    DateTime.timestamp() : this._nowUtc();

    Continue reading...

Compartilhe esta Página