패키지, 저장소 및 앱 카테고리 검색

stop_watch_timer 표지
패키지 상세v3.2.2

stop_watch_timer

간단한 카운트업 타이머 / 카운트다운 타이머. 손쉬워서 스톱워치 앱을 쉽게 만들 수 있습니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
9만
좋아요
340
Pub 점수
160

패키지 설치

flutter pub add stop_watch_timer

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

간단하고 가벼운 Flutter 패키지로 카운트업 또는 카운트다운 타이머를 만들 수 있으며, 스톱워치 기능에 적합합니다. 시작, 정지, 리셋, 랩 등의 타이머 상태를 관리할 수 있는 깔끔한 API를 제공하여 시간 추적 기능이 필요한 앱에 쉽게 통합할 수 있습니다. Android, iOS, Web, macOS, Windows, Linux 등 여러 플랫폼을 지원하며 장치 간 일관된 동작을 보장합니다. 피트니스 앱, 생산성 도구, 또는 정밀한 시간 측정이 필요한 모든 애플리케이션에 적합합니다.

사용 사례

  • 피트니스 트래킹
  • 생산성 앱
  • 공부 타이머
  • 게임 타이밍
  • 이벤트 카운트다운

주요 기능

  • CountUp 및 CountDown 모드
  • 시작/정지/리셋 컨트롤
  • 랩 기능
  • 크로스 플랫폼 지원
  • 간단하고 직관적인 API

적합한 대상

  • 시간 추적 기능을 개발하는 개발자
  • 정지계 기능이 필요한 앱
  • 교육용 또는 게임화된 애플리케이션
  • 타이머 기반의 간단한 UI

고려 사항

  • 기본 타이머 작업에만 제한됨
  • 내장된 UI 컴포넌트 없음
  • 복잡한 사용 사례의 경우 수동 상태 관리가 필요합니다
  • 고주기 업데이트에 최적화되지 않음

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

stop_watch_timer

Never inc

Developed with 💙 by Never inc.


Simple CountUp timer / CountDown timer. It easily create app of stopwatch.

https://pub.dev/packages/stop_watch_timer

./img/countup_timer_demo ./img/countdown_timer_demo

Example code

See the example directory for a complete sample app using stop_watch_timer.

example

Installation

Add this to your package's pubspec.yaml file:

dependencies:
  stop_watch_timer:

Features

This is StopWatchMode.

  • CountUp
  • CountDown
CountUp

This is default mode. If you' d like to set it explicitly, set StopWatchMode.countUp to mode.

final stopWatchTimer = StopWatchTimer(
  mode: StopWatchMode.countUp
);

example code

CountDown

Can be set StopWatchMode.countDown mode and preset millisecond.

final stopWatchTimer = StopWatchTimer(
  mode: StopWatchMode.countDown,
  presetMillisecond: StopWatchTimer.getMilliSecFromMinute(1), // millisecond => minute.
);

example code

This is helper functions for presetTime.

/// Get millisecond from hour
final value = StopWatchTimer.getMilliSecFromHour(1); 

/// Get millisecond from minute
final value = StopWatchTimer.getMilliSecFromMinute(60);

/// Get millisecond from second
final value = StopWatchTimer.getMilliSecFromSecond(60 * 60);

Usage

import 'package:stop_watch_timer/stop_watch_timer.dart';  // Import stop_watch_timer

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  final StopWatchTimer _stopWatchTimer = StopWatchTimer(); // Create instance.

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() async {
    super.dispose();
    await _stopWatchTimer.dispose();  // Need to call dispose function.
  }

  @override
  Widget build(BuildContext context) {
    ...
  }
}

To operation stop watch.

// Start timer.
_stopWatchTimer.onStartTimer();


// Stop timer.
_stopWatchTimer.onStopTimer();


// Reset timer
_stopWatchTimer.onResetTimer();


// Lap time
_stopWatchTimer.onAddLap();

Can be set preset time. This case is "00:01.23".

// Set Millisecond.
_stopWatchTimer.setPresetTime(mSec: 1234);

When timer is idle state, can be set this.

// Set Hours. (ex. 1 hours)
_stopWatchTimer.setPresetHoursTime(1);

// Set Minute. (ex. 30 minute)
_stopWatchTimer.setPresetMinuteTime(30);

// Set Second. (ex. 120 second)
_stopWatchTimer.setPresetSecondTime(120);
Using the stream to get the time

_stopWatchTimer.rawTime.listen((value) => print('rawTime $value'));

_stopWatchTimer.minuteTime.listen((value) => print('minuteTime $value'));

_stopWatchTimer.secondTime.listen((value) => print('secondTime $value'));

_stopWatchTimer.records.listen((value) => print('records $value'));

_stopWatchTimer.fetchStopped.listen((value) => print('stopped from stream'));

_stopWatchTimer.fetchEnded.listen((value) => print('ended from stream'));

Display time formatted stop watch. Using function of "rawTime" and "getDisplayTime".

final raw = 3000 // 3sec
final displayTime = StopWatchTimer.getDisplayTime(raw); // 00:00:03.00
Using the StreamBuilder to get the time

Example code using stream builder.

StreamBuilder<int>(
  stream: _stopWatchTimer.rawTime,
  initialData: 0,
  builder: (context, snap) {
    final value = snap.data;
    final displayTime = StopWatchTimer.getDisplayTime(value);
    return Column(
      children: <Widget>[
        Padding(
          padding: const EdgeInsets.all(8),
          child: Text(
            displayTime,
            style: TextStyle(
              fontSize: 40,
              fontFamily: 'Helvetica',
              fontWeight: FontWeight.bold
            ),
          ),
        ),
        Padding(
          padding: const EdgeInsets.all(8),
          child: Text(
            value.toString(),
            style: TextStyle(
                fontSize: 16,
                fontFamily: 'Helvetica',
                fontWeight: FontWeight.w400
            ),
          ),
        ),
      ],
    );
  },
),
),

Notify from "secondTime" every second.

_stopWatchTimer.secondTime.listen((value) => print('secondTime $value'));

Example code using stream builder.

StreamBuilder<int>(
  stream: _stopWatchTimer.secondTime,
  initialData: 0,
  builder: (context, snap) {
    final value = snap.data;
    print('Listen every second. $value');
    return Column(
      children: <Widget>[
        Padding(
          padding: const EdgeInsets.all(8),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              const Padding(
                padding: EdgeInsets.symmetric(horizontal: 4),
                child: Text(
                  'second',
                  style: TextStyle(
                      fontSize: 17,
                      fontFamily: 'Helvetica',
                  ),
                ),
              ),
              Padding(
                padding: const EdgeInsets.symmetric(horizontal: 4),
                child: Text(
                  value.toString(),
                  style: TextStyle(
                      fontSize: 30,
                      fontFamily: 'Helvetica',
                      fontWeight: FontWeight.bold
                  ),
                ),
              ),
            ],
          )
        ),
      ],
    );
  },
),

Notify from "minuteTime" every minute.

_stopWatchTimer.minuteTime.listen((value) => print('minuteTime $value'));

Example code using stream builder.

StreamBuilder<int>(
  stream: _stopWatchTimer.minuteTime,
  initialData: 0,
  builder: (context, snap) {
    final value = snap.data;
    print('Listen every minute. $value');
    return Column(
      children: <Widget>[
        Padding(
            padding: const EdgeInsets.all(8),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                const Padding(
                  padding: EdgeInsets.symmetric(horizontal: 4),
                  child: Text(
                    'minute',
                    style: TextStyle(
                      fontSize: 17,
                      fontFamily: 'Helvetica',
                    ),
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.symmetric(horizontal: 4),
                  child: Text(
                    value.toString(),
                    style: TextStyle(
                        fontSize: 30,
                        fontFamily: 'Helvetica',
                        fontWeight: FontWeight.bold
                    ),
                  ),
                ),
              ],
            )
        ),
      ],
    );
  },
),

Notify lap time.

_stopWatchTimer.records.listen((value) => print('records $value'));

Example code using stream builder.

StreamBuilder<List<StopWatchRecord>>(
  stream: _stopWatchTimer.records,
  initialData: const [],
  builder: (context, snap) {
    final value = snap.data;
    return ListView.builder(
      scrollDirection: Axis.vertical,
      itemBuilder: (BuildContext context, int index) {
        final data = value[index];
        return Column(
          children: <Widget>[
            Padding(
              padding: const EdgeInsets.all(8),
              child: Text(
                '${index + 1} ${data.displayTime}',
                style: TextStyle(
                  fontSize: 17,
                  fontFamily: 'Helvetica',
                  fontWeight: FontWeight.bold
                ),
              ),
            ),
            const Divider(height: 1,)
          ],
        );
      },
      itemCount: value.length,
    );
  },
),

Using the Callback to get the time
final _stopWatchTimer = StopWatchTimer(
  onChange: (value) {
    final displayTime = StopWatchTimer.getDisplayTime(value);
    print('displayTime $displayTime');
  },
  onChangeRawSecond: (value) => print('onChangeRawSecond $value'),
  onChangeRawMinute: (value) => print('onChangeRawMinute $value'),
);
Parsing Time

Can be used getDisplayTime func. It display time like a real stopwatch timer.

  • Hours
  • Minute
  • Second
  • Millisecond

For example, 1 hours and 30 minute and 50 second and 20 millisecond => "01:30:50.20"

And can be set enable/disable display time and change split character.

카테고리

의존성

의존성 목록 1 개

소스 저장소

이 패키지를 사용하는 프로젝트

순위