init
This commit is contained in:
commit
08fe329a7a
15 files changed
+434
No files matched your search
@@ -0,0 +1,105 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
void main() => runApp(const HockeyTimerApp());
|
||||
|
||||
class HockeyTimerApp extends StatelessWidget {
|
||||
const HockeyTimerApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'Hockey Timer',
|
||||
theme: ThemeData(colorSchemeSeed: const Color(0xff087f8c), useMaterial3: true),
|
||||
home: const TimerScreen(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TimerScreen extends StatefulWidget {
|
||||
const TimerScreen({super.key});
|
||||
|
||||
@override
|
||||
State<TimerScreen> createState() => _TimerScreenState();
|
||||
}
|
||||
|
||||
class _TimerScreenState extends State<TimerScreen> {
|
||||
static const _periodLength = 20 * 60;
|
||||
int _secondsRemaining = _periodLength;
|
||||
Timer? _ticker;
|
||||
|
||||
void _toggleTimer() {
|
||||
if (_ticker != null) {
|
||||
_ticker!.cancel();
|
||||
setState(() => _ticker = null);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_secondsRemaining == 0) return;
|
||||
setState(() {
|
||||
_ticker = Timer.periodic(const Duration(seconds: 1), (_) {
|
||||
if (_secondsRemaining <= 1) {
|
||||
_ticker?.cancel();
|
||||
setState(() {
|
||||
_secondsRemaining = 0;
|
||||
_ticker = null;
|
||||
});
|
||||
} else {
|
||||
setState(() => _secondsRemaining--);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void _resetTimer() {
|
||||
_ticker?.cancel();
|
||||
setState(() {
|
||||
_ticker = null;
|
||||
_secondsRemaining = _periodLength;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_ticker?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final minutes = (_secondsRemaining ~/ 60).toString().padLeft(2, '0');
|
||||
final seconds = (_secondsRemaining % 60).toString().padLeft(2, '0');
|
||||
final running = _ticker != null;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Hockey Timer')),
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text('PERIOD 1', style: Theme.of(context).textTheme.titleMedium),
|
||||
const SizedBox(height: 12),
|
||||
Text('$minutes:$seconds', style: Theme.of(context).textTheme.displayLarge),
|
||||
const SizedBox(height: 24),
|
||||
Wrap(
|
||||
spacing: 12,
|
||||
children: [
|
||||
FilledButton.icon(
|
||||
onPressed: _toggleTimer,
|
||||
icon: Icon(running ? Icons.pause : Icons.play_arrow),
|
||||
label: Text(running ? 'Pause' : 'Start'),
|
||||
),
|
||||
OutlinedButton.icon(
|
||||
onPressed: _resetTimer,
|
||||
icon: const Icon(Icons.replay),
|
||||
label: const Text('Reset'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
name: hockey_timer_mobile
|
||||
description: Hockey period timer for iOS and Android.
|
||||
publish_to: "none"
|
||||
version: 1.0.0+1
|
||||
|
||||
environment:
|
||||
sdk: ">=3.4.0 <4.0.0"
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
|
||||
dev_dependencies:
|
||||
Reference in new issue
Block a user