Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Features #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 50 additions & 84 deletions lib/home.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:audioplayers/audioplayers.dart'; // Add this dependency in pubspec.yaml

class Home extends StatefulWidget {
const Home({super.key});
Expand All @@ -13,13 +14,16 @@ class _HomeState extends State<Home> {
Color highlight = Colors.redAccent;

List<Map<String, String>> lapsList = [];

Timer? _timer;
Duration _elapsedTime = Duration.zero;
Duration _countdownTime = Duration(minutes: 1); // Default countdown time
bool isCountdown = false;

bool isStart = false;
bool isPause = false;

AudioPlayer audioPlayer = AudioPlayer();

String timeFormat(Duration duration) {
String twoDigits(int n) => n.toString().padLeft(2, '0');
String hours = twoDigits(duration.inHours);
Expand All @@ -32,6 +36,7 @@ class _HomeState extends State<Home> {
setState(() {
isStart = true;
isPause = false;
isCountdown = false;
});

_timer = Timer.periodic(const Duration(seconds: 1), (timer) {
Expand All @@ -41,6 +46,27 @@ class _HomeState extends State<Home> {
});
}

void startCountdown() {
setState(() {
isCountdown = true;
isStart = true;
isPause = false;
});

_timer = Timer.periodic(const Duration(seconds: 1), (timer) {
setState(() {
if (_countdownTime.inSeconds > 0) {
_countdownTime -= const Duration(seconds: 1);
} else {
audioPlayer.play('alert_sound.mp3'); // Ensure you have this file in assets
_timer?.cancel();
isStart = false;
isCountdown = false;
}
});
});
}

void pauseWatch() {
_timer?.cancel();
setState(() {
Expand All @@ -56,6 +82,8 @@ class _HomeState extends State<Home> {
setState(() {
isStart = false;
isPause = false;
isCountdown = false;
_countdownTime = Duration(minutes: 1); // Reset countdown time
});
}

Expand All @@ -65,6 +93,7 @@ class _HomeState extends State<Home> {
_elapsedTime = Duration.zero;
isStart = false;
isPause = false;
isCountdown = false;
});
}

Expand All @@ -87,53 +116,38 @@ class _HomeState extends State<Home> {
actions: [
IconButton(
icon: const Icon(Icons.refresh),
onPressed: () {
resetWatch();
},
onPressed: resetWatch,
),
],
),
body: Stack(
children: [
// Completely overlapping Timer Display
Positioned(
top: 30,
left: 10,
child: Container(
width: 300,
height: 300,
decoration: BoxDecoration(
color: Colors.green, // Clashing color
color: Colors.green,
borderRadius: BorderRadius.circular(150),
border: Border.all(color: Colors.purple, width: 10), // Inconsistent styling
border: Border.all(color: Colors.purple, width: 10),
),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
timeFormat(_elapsedTime),
style: const TextStyle(
color: Colors.white,
fontSize: 60,
fontWeight: FontWeight.bold,
),
isCountdown ? timeFormat(_countdownTime) : timeFormat(_elapsedTime),
style: const TextStyle(color: Colors.white, fontSize: 60, fontWeight: FontWeight.bold),
),
const SizedBox(height: 10),
const Text(
'Lap Now!',
style: TextStyle(
color: Colors.black,
fontSize: 20,
),
),
const Text('Lap Now!', style: TextStyle(color: Colors.black, fontSize: 20)),
],
),
),
),
),

// Overlapping Laps List in a chaotic way
Positioned(
top: 200,
left: 50,
Expand All @@ -143,7 +157,6 @@ class _HomeState extends State<Home> {
child: ListView.builder(
itemCount: lapsList.length,
padding: const EdgeInsets.only(left: 10, right: 10),
scrollDirection: Axis.vertical,
itemBuilder: (context, index) {
final lapItem = lapsList[index];
return Container(
Expand All @@ -153,41 +166,27 @@ class _HomeState extends State<Home> {
decoration: BoxDecoration(
color: Colors.redAccent,
borderRadius: BorderRadius.circular(15),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.5),
blurRadius: 10,
),
],
boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.5), blurRadius: 10)],
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
lapItem['lap']!,
style: const TextStyle(color: Colors.black, fontSize: 16),
),
Text(
lapItem['time']!,
style: const TextStyle(color: Colors.black, fontSize: 14),
),
Text(lapItem['lap']!, style: const TextStyle(color: Colors.black, fontSize: 16)),
Text(lapItem['time']!, style: const TextStyle(color: Colors.black, fontSize: 14)),
],
),
);
},
),
),
),

// Control Buttons
Positioned(
bottom: 20,
left: 0,
right: 0,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
// Start/Pause Button with exaggerated design
InkWell(
onTap: () {
if (isStart) {
Expand All @@ -204,19 +203,13 @@ class _HomeState extends State<Home> {
decoration: BoxDecoration(
color: Colors.yellow,
borderRadius: BorderRadius.circular(30),
boxShadow: [
BoxShadow(color: Colors.black38, blurRadius: 5),
],
boxShadow: [BoxShadow(color: Colors.black38, blurRadius: 5)],
),
child: Center(
child: Text(
isStart ? 'PAUSE' : isPause ? 'RESUME' : 'START',
style: const TextStyle(color: Colors.black, fontSize: 24),
),
child: Text(isStart ? 'PAUSE' : isPause ? 'RESUME' : 'START', style: const TextStyle(color: Colors.black, fontSize: 24)),
),
),
),
// Stop/Reset Button with chaotic design
InkWell(
onTap: () {
if (isStart || isPause) {
Expand All @@ -231,59 +224,32 @@ class _HomeState extends State<Home> {
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(30),
boxShadow: [
BoxShadow(color: Colors.black38, blurRadius: 5),
],
boxShadow: [BoxShadow(color: Colors.black38, blurRadius: 5)],
),
child: Center(
child: Text(
isStart || isPause ? 'STOP' : 'RESET',
style: const TextStyle(color: Colors.white, fontSize: 24),
),
child: Text(isStart || isPause ? 'STOP' : 'RESET', style: const TextStyle(color: Colors.white, fontSize: 24)),
),
),
),
],
),
),

// Extra chaotic buttons
Positioned(
bottom: 150,
left: 50,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.pink,
elevation: 10,
padding: EdgeInsets.symmetric(horizontal: 30, vertical: 15),
),
style: ElevatedButton.styleFrom(backgroundColor: Colors.pink, elevation: 10, padding: EdgeInsets.symmetric(horizontal: 30, vertical: 15)),
onPressed: addLap,
child: const Text('Add Lap', style: TextStyle(fontSize: 20)),
),
),
Positioned(
top: 450,
right: 10,
child: IconButton(
icon: const Icon(Icons.add),
color: Colors.brown,
iconSize: 50,
onPressed: () {},
),
),
Positioned(
top: 480,
right: 80,
child: Container(
width: 100,
height: 50,
color: Colors.green,
child: Center(
child: const Text(
'Chaos',
style: TextStyle(color: Colors.black, fontSize: 24),
),
),
bottom: 150,
right: 50,
child: ElevatedButton(
style: ElevatedButton.styleFrom(backgroundColor: Colors.green, elevation: 10, padding: EdgeInsets.symmetric(horizontal: 30, vertical: 15)),
onPressed: startCountdown,
child: const Text('Start Countdown', style: TextStyle(fontSize: 20)),
),
),
],
Expand Down