Home > Net >  Dart Flutter - The named parameter 'begin' is required, but there's no corresponding
Dart Flutter - The named parameter 'begin' is required, but there's no corresponding

Time:03-04

I have a code like this :

import 'package:custom_timer/custom_timer.dart';
import 'package:fitness/core/service/date_service.dart';
import 'package:flutter/material.dart';

class StartWorkoutTimer extends StatefulWidget {
  final int time;
  final bool isPaused;

  StartWorkoutTimer({
    required this.time,
    required this.isPaused,
  });

  @override
  _StartWorkoutTimerState createState() => _StartWorkoutTimerState();
}

class _StartWorkoutTimerState extends State<StartWorkoutTimer> {
  @override
  Widget build(BuildContext context) {
    return widget.isPaused ? _createPauseText() : _createCountdownTimer();
  }

  Widget _createCountdownTimer() {
    return CustomTimer(
      from: Duration(seconds: widget.time),
      to: Duration(seconds: 0),
      onBuildAction: CustomTimerAction.auto_start,
      builder: (CustomTimerRemainingTime remaining) {
        return Text(
          "${remaining.minutes}:${remaining.seconds}",
          style: TextStyle(fontSize: 17, fontWeight: FontWeight.w600),
        );
      },
    );
  }

  Widget _createPauseText() {
    final minutesSeconds = DateService.convertIntoSeconds(widget.time);
    return Text(
      "${minutesSeconds.minutes.toString().padLeft(2, '0')}:${minutesSeconds.seconds.toString().padLeft(2, '0')}",
      style: TextStyle(
        fontSize: 17,
        fontWeight: FontWeight.w600,
      ),
    );
  }
}

But it's showing an error like this : error

Then it says that: Undefined name 'CustomTimerAction'. and : The named parameter 'onBuildAction' isn't defined.

Can please someone help with this ?

CodePudding user response:

The CustomTimer doesn't have the property from but begin. Like the error said, it is required. So for your case, you have to change from to begin. Also the property onBuildAction doesn't exist.

Widget _createCountdownTimer() {
    return CustomTimer(
      begin: Duration(seconds: widget.time),
      end: Duration(seconds: 0),
      builder: (CustomTimerRemainingTime remaining) {
        return Text(
          "${remaining.minutes}:${remaining.seconds}",
          style: TextStyle(fontSize: 17, fontWeight: FontWeight.w600),
        );
      },
    );
  }
  • Related