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

Lap_added #429

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class AddOrUpdateAlarmView extends GetView<AddOrUpdateAlarmController> {
if (didPop) {
return;
}

Get.defaultDialog(
titlePadding: const EdgeInsets.symmetric(
vertical: 20,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ class BottomNavigationBarController extends GetxController
TimerView(),
];

@override
void onInit() {
super.onInit();
WidgetsBinding.instance.addObserver(this);
_loadSavedState();
}
// @override
// void onInit() {
// super.onInit();
// // WidgetsBinding.instance.addObserver(this);
// // _loadSavedState();
// }

@override
void onClose() {
Expand All @@ -44,9 +44,9 @@ class BottomNavigationBarController extends GetxController
}
}

void _loadSavedState() async {
activeTabIndex.value = await _secureStorageProvider.readTabIndex();
}
// void _loadSavedState() async {
// activeTabIndex.value = await _secureStorageProvider.readTabIndex();
// }

void _saveState() async {
await _secureStorageProvider.writeTabIndex(
Expand Down
22 changes: 22 additions & 0 deletions lib/app/modules/stopwatch/controllers/stopwatch_controller.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// stopwatch_controller.dart
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
Expand All @@ -6,9 +7,12 @@ class StopwatchController extends GetxController {
final RxBool isTimerPaused = true.obs;
final Stopwatch _stopwatch = Stopwatch();
final RxString _result = '00:00:00'.obs;
final RxList<String> _laps = <String>[].obs;
late Timer timer;

bool isLapButtonEnabled = true;
String get result => _result.value;
List<String> get laps => _laps;

void toggleTimer() {
if (isTimerPaused.value) {
Expand Down Expand Up @@ -36,11 +40,29 @@ class StopwatchController extends GetxController {
stopTimer();
_stopwatch.reset();
_updateResult();
_laps.clear();
}

void recordLap() {
if (_stopwatch.isRunning && isLapButtonEnabled) {
isLapButtonEnabled = false; // Disable lap button temporarily
_laps.add(_formattedElapsedTime());
update();
print('Lap recorded:${_formattedElapsedTime()}');

// Allow lap button after a short delay (adjust as needed)
Future.delayed(const Duration(milliseconds: 500), () {
isLapButtonEnabled = true;
});
}
}

void _updateResult() {
_result.value =
'${_stopwatch.elapsed.inMinutes.toString().padLeft(2, '0')}:${(_stopwatch.elapsed.inSeconds % 60).toString().padLeft(2, '0')}:${(_stopwatch.elapsed.inMilliseconds % 100).toString().padLeft(2, '0')}';
}

String _formattedElapsedTime() {
return '${_stopwatch.elapsed.inMinutes.toString().padLeft(2, '0')}:${(_stopwatch.elapsed.inSeconds % 60).toString().padLeft(2, '0')}:${(_stopwatch.elapsed.inMilliseconds % 100).toString().padLeft(2, '0')}';
}
}
158 changes: 50 additions & 108 deletions lib/app/modules/stopwatch/views/stopwatch_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,124 +20,66 @@ class StopwatchView extends GetView<StopwatchController> {
toolbarHeight: height / 7.9,
elevation: 0.0,
centerTitle: true,
actions: [
LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
return IconButton(
onPressed: () {
Utils.hapticFeedback();
Scaffold.of(context).openEndDrawer();
},
icon: const Icon(
Icons.menu,
),
color: themeController.isLightMode.value
? kLightPrimaryTextColor.withOpacity(0.75)
: kprimaryTextColor.withOpacity(0.75),
iconSize: 27,
// splashRadius: 0.000001,
);
},
),
],
),
),
body: Column(
children: [
SizedBox(
height: height * 0.3,
),
Obx(
() => Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Obx(() => Text(
controller.result,
style: const TextStyle(
fontSize: 60.0, fontWeight: FontWeight.bold),
)),
const SizedBox(
height: 20.0,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
SizedBox(
height: 55,
width: 70,
child: Center(
child: Text(
controller.result.split(':')[0],
style: const TextStyle(
fontSize: 50.0,
fontWeight: FontWeight.bold,
),
),
),
),
const Text(
':',
style: TextStyle(
fontSize: 50.0,
fontWeight: FontWeight.bold,
),
),
SizedBox(
height: 55,
width: 70,
child: Center(
child: Text(
controller.result.split(':')[1],
style: const TextStyle(
fontSize: 50.0,
fontWeight: FontWeight.bold,
),
),
),
FloatingActionButton(
heroTag: "start",
onPressed: controller.toggleTimer,
child: Obx(() => Icon(
controller.isTimerPaused.value
? Icons.play_arrow
: Icons.pause,
)),
),
const Text(
':',
style: TextStyle(
fontSize: 50.0,
fontWeight: FontWeight.bold,
),
// Reset button
FloatingActionButton(
heroTag: "stop",
onPressed: controller.resetTime,
child: Icon(Icons.square_rounded),
),
SizedBox(
height: 55,
width: 70,
child: Center(
child: Text(
controller.result.split(':')[2],
style: const TextStyle(
fontSize: 50.0,
fontWeight: FontWeight.bold,
),
),
),

FloatingActionButton(
heroTag: "lap",
onPressed: controller.recordLap,
child: Icon(Icons.flag),
),
],
),
),
const SizedBox(
height: 10.0,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
FloatingActionButton(
heroTag: "start",
onPressed: controller.toggleTimer,
child: Obx(
() => Icon(
controller.isTimerPaused.value
? Icons.play_arrow_rounded
: Icons.pause_rounded,
size: 33,
),
),
),
// Reset button
FloatingActionButton(
heroTag: "stop",
onPressed: controller.resetTime,
child: Icon(
Icons.stop_rounded,
size: 33,
SizedBox(
height: 20,
),
Obx(
() => Expanded(
child: ListView.builder(
itemCount: controller.laps.length,
itemBuilder: (context, index) {
final reversedIndex = controller.laps.length - 1 - index;
return ListTile(
title: Text(
'Lap ${reversedIndex + 1}: ${controller.laps[reversedIndex]}'),
);
},
),
),
],
),
],
),
],
),
),
endDrawer: Obx(
() => Drawer(
Expand Down
4 changes: 4 additions & 0 deletions linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <audioplayers_linux/audioplayers_linux_plugin.h>
#include <flutter_secure_storage_linux/flutter_secure_storage_linux_plugin.h>
#include <flutter_volume_controller/flutter_volume_controller_plugin.h>
#include <isar_flutter_libs/isar_flutter_libs_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>

Expand All @@ -18,6 +19,9 @@ void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) flutter_secure_storage_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterSecureStorageLinuxPlugin");
flutter_secure_storage_linux_plugin_register_with_registrar(flutter_secure_storage_linux_registrar);
g_autoptr(FlPluginRegistrar) flutter_volume_controller_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterVolumeControllerPlugin");
flutter_volume_controller_plugin_register_with_registrar(flutter_volume_controller_registrar);
g_autoptr(FlPluginRegistrar) isar_flutter_libs_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "IsarFlutterLibsPlugin");
isar_flutter_libs_plugin_register_with_registrar(isar_flutter_libs_registrar);
Expand Down
1 change: 1 addition & 0 deletions linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
list(APPEND FLUTTER_PLUGIN_LIST
audioplayers_linux
flutter_secure_storage_linux
flutter_volume_controller
isar_flutter_libs
url_launcher_linux
)
Expand Down
2 changes: 2 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import cloud_firestore
import device_info_plus
import firebase_core
import flutter_secure_storage_macos
import flutter_volume_controller
import google_sign_in_ios
import isar_flutter_libs
import mobile_scanner
Expand All @@ -24,6 +25,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
FLTFirebaseCorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseCorePlugin"))
FlutterSecureStoragePlugin.register(with: registry.registrar(forPlugin: "FlutterSecureStoragePlugin"))
FlutterVolumeControllerPlugin.register(with: registry.registrar(forPlugin: "FlutterVolumeControllerPlugin"))
FLTGoogleSignInPlugin.register(with: registry.registrar(forPlugin: "FLTGoogleSignInPlugin"))
IsarFlutterLibsPlugin.register(with: registry.registrar(forPlugin: "IsarFlutterLibsPlugin"))
MobileScannerPlugin.register(with: registry.registrar(forPlugin: "MobileScannerPlugin"))
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -820,10 +820,10 @@ packages:
dependency: "direct main"
description:
name: mobile_scanner
sha256: "190506c3b0cf8a5a3c11e83de8c4f5ef4b6025a06c67d425a03f08129abf20d0"
sha256: c3e5bba1cb626b6ab4fc46610f72a136803f6854267967e19f4a4a6a31ff9b74
url: "https://pub.dev"
source: hosted
version: "3.5.6"
version: "3.5.5"
numberpicker:
dependency: "direct main"
description:
Expand Down
3 changes: 3 additions & 0 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <cloud_firestore/cloud_firestore_plugin_c_api.h>
#include <firebase_core/firebase_core_plugin_c_api.h>
#include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h>
#include <flutter_volume_controller/flutter_volume_controller_plugin_c_api.h>
#include <isar_flutter_libs/isar_flutter_libs_plugin.h>
#include <permission_handler_windows/permission_handler_windows_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>
Expand All @@ -23,6 +24,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("FirebaseCorePluginCApi"));
FlutterSecureStorageWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin"));
FlutterVolumeControllerPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FlutterVolumeControllerPluginCApi"));
IsarFlutterLibsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("IsarFlutterLibsPlugin"));
PermissionHandlerWindowsPluginRegisterWithRegistrar(
Expand Down
1 change: 1 addition & 0 deletions windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
cloud_firestore
firebase_core
flutter_secure_storage_windows
flutter_volume_controller
isar_flutter_libs
permission_handler_windows
url_launcher_windows
Expand Down