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

[Feature] Lap(Flag) of TimeInterval added #439

Closed
wants to merge 10 commits into from
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_svg/flutter_svg.dart';
Expand Down Expand Up @@ -48,79 +50,7 @@ class AddOrUpdateAlarmView extends GetView<AddOrUpdateAlarmController> {
if (didPop) {
return;
}

Get.defaultDialog(
titlePadding: const EdgeInsets.symmetric(
vertical: 20,
),
backgroundColor: themeController.isLightMode.value
? kLightSecondaryBackgroundColor
: ksecondaryBackgroundColor,
title: 'Discard Changes?'.tr,
titleStyle: Theme.of(context).textTheme.displaySmall,
content: Column(
children: [
Text(
'unsavedChanges'.tr,
style: Theme.of(context).textTheme.bodyMedium,
textAlign: TextAlign.center,
),
Padding(
padding: const EdgeInsets.only(
top: 20,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
TextButton(
onPressed: () {
Get.back();
},
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all(kprimaryColor),
),
child: Text(
'Cancel'.tr,
style: Theme.of(context)
.textTheme
.displaySmall!
.copyWith(
color: kprimaryBackgroundColor,
),
),
),
OutlinedButton(
onPressed: () {
Get.back(closeOverlays: true);
Get.back();
},
style: OutlinedButton.styleFrom(
side: BorderSide(
color: themeController.isLightMode.value
? Colors.red.withOpacity(0.9)
: Colors.red,
width: 1,
),
),
child: Text(
'Leave'.tr,
style: Theme.of(context)
.textTheme
.displaySmall!
.copyWith(
color: themeController.isLightMode.value
? Colors.red.withOpacity(0.9)
: Colors.red,
),
),
),
],
),
),
],
),
);
controller.checkUnsavedChangesAndNavigate(context);
},
child: Scaffold(
floatingActionButtonLocation:
Expand Down
21 changes: 17 additions & 4 deletions lib/app/modules/stopwatch/controllers/stopwatch_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ class StopwatchController extends GetxController {
final Stopwatch _stopwatch = Stopwatch();
final RxString _result = '00:00:00'.obs;
late Timer timer;

final RxList<String> _flag= <String>[].obs;
String get result => _result.value;
List<String> get flag => _flag;

void toggleTimer() {
if (isTimerPaused.value) {
Expand All @@ -17,6 +18,15 @@ class StopwatchController extends GetxController {
stopTimer();
}
}

void lap_reset(){
if(isTimerPaused.value){
resetTime();
}
else{
recordLap();
}
}

void startTimer() {
timer = Timer.periodic(const Duration(milliseconds: 30), (Timer t) {
Expand All @@ -31,16 +41,19 @@ class StopwatchController extends GetxController {
_stopwatch.stop();
isTimerPaused.value = true;
}

void resetTime() {
stopTimer();
_stopwatch.reset();
_updateResult();
_flag.clear();
}
void recordLap() {
_flag.add('${_stopwatch.elapsed.inMinutes.toString().padLeft(2, '0')}:${(_stopwatch.elapsed.inSeconds % 60).toString().padLeft(2, '0')}:${(_stopwatch.elapsed.inMilliseconds % 100).toString().padLeft(2, '0')}');
}

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

}
Loading