79753055

Date: 2025-09-02 04:03:04
Score: 4
Natty:
Report link

Hope I got you correct.
if this wouldn't help please let me know.

import 'package:clock/clock.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  //prepare a clock in setup and use it inside each test via withClock.
  // Note: code under test should read time from clock.now() not DateTime.now().
  late Clock fixedClock;

  setUp(() {
    fixedClock = Clock.fixed(DateTime(2000, 1, 1));
  });

  test('uses fixed year 2000 inside withClock', () {
    withClock(fixedClock, () {
      expect(clock.now().year, equals(2000));
    });
  });

  test('outside withClock, time falls back to system clock', () {
    //clock.now() defaults to the system clock when not overridden.
    expect(clock.now().year, equals(DateTime.now().year));
  });
}
Reasons:
  • RegEx Blacklisted phrase (2.5): please let me know
  • RegEx Blacklisted phrase (1.5): help please
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Levon Julfikyan