Skip to content

Commit

Permalink
Fix stopwatch screen
Browse files Browse the repository at this point in the history
  • Loading branch information
AhsanSarwar45 committed Apr 16, 2024
1 parent 50d86ac commit 205961b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 63 deletions.
2 changes: 2 additions & 0 deletions lib/alarm/screens/alarm_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ class _AlarmScreenState extends State<AlarmScreen> {

_handleCustomizeAlarm(Alarm alarm) async {
await _openCustomizeAlarmScreen(alarm, onSave: (newAlarm) async {
// The alarm id changes for the new alarm, so we have to cancel the old one
await alarm.cancel();
alarm.copyFrom(newAlarm);
await alarm
.update("_handleCustomizeAlarm(): Alarm customized by the user");
Expand Down
55 changes: 2 additions & 53 deletions lib/common/widgets/list/custom_list_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:clock_app/common/logic/get_list_filter_chips.dart';
import 'package:clock_app/common/types/list_controller.dart';
import 'package:clock_app/common/types/list_filter.dart';
import 'package:clock_app/common/types/list_item.dart';
import 'package:clock_app/common/utils/json_serialize.dart';
import 'package:clock_app/common/utils/reorderable_list_decorator.dart';
import 'package:clock_app/common/widgets/list/delete_alert_dialogue.dart';
import 'package:clock_app/common/widgets/list/list_filter_chip.dart';
Expand Down Expand Up @@ -92,14 +91,12 @@ class _CustomListViewState<Item extends ListItem>

updateCurrentList();
});
// TODO: MAN THIS SUCKS, WHY YOU GOTTA DO THIS
// TODO: MAN THIS SUCKS, WHY YOU GOTTA DO THIS
_controller.notifyRemovedRange(
0, widget.items.length - 1, _getChangeListBuilder());
_controller.notifyInsertedRange(0, widget.items.length);
}

// int _getItemIndex(Item item) =>
// widget.items.indexWhere((element) => element.id == item.id);
void updateCurrentList() {
if (selectedSortIndex > widget.sortOptions.length) {
selectedSortIndex = 0;
Expand All @@ -112,7 +109,6 @@ class _CustomListViewState<Item extends ListItem>
} else {
currentList.addAll(widget.items);
}
// = getCurrentList();
}

int _getItemIndex(Item item) =>
Expand Down Expand Up @@ -169,41 +165,6 @@ class _CustomListViewState<Item extends ListItem>

if (callOnModifyList) widget.onModifyList?.call();
}
//
// void _handleChangeItemWithId(
// int id, SingleItemChangerCallback<Item> callback, bool callOnModifyList) {
// Item item = widget.items.firstWhere((element) => element.id == id);
// int index = _getItemIndex(item);
// callback(item);
//
// setState(() {
// updateCurrentList();
// });
// _controller.notifyChangedRange(
// index,
// 1,
// _getChangeListBuilder(),
// );
//
// if (callOnModifyList) widget.onModifyList?.call();
// }

// void _handleChangeItemWithIndex(
// int index, SingleItemChangerCallback<Item> callback, bool callOnModifyList) {
// Item item = widget.items[index];
// callback(item);
//
// setState(() {
// updateCurrentList();
// });
// _controller.notifyChangedRange(
// index,
// 1,
// _getChangeListBuilder(),
// );
//
// if (callOnModifyList) widget.onModifyList?.call();
// }

Future<void> _handleDeleteItem(Item deletedItem,
[bool callOnModifyList = true]) async {
Expand Down Expand Up @@ -246,19 +207,7 @@ class _CustomListViewState<Item extends ListItem>
}

void _handleClear() {
int listLength = widget.items.length;

setState(() {
widget.items.clear();
updateCurrentList();
});

_controller.notifyRemovedRange(
0,
listLength,
_getChangeListBuilder(),
);
widget.onModifyList?.call();
_handleDeleteItemList(List<Item>.from(widget.items));
}

Future<void> _handleAddItem(Item item, {int index = -1}) async {
Expand Down
11 changes: 1 addition & 10 deletions lib/stopwatch/screens/stopwatch_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,6 @@ class _StopwatchScreenState extends State<StopwatchScreen> {

@override
Widget build(BuildContext context) {
ThemeData theme = Theme.of(context);
// ColorScheme colorScheme = theme.colorScheme;
TextTheme textTheme = theme.textTheme;
timeDilation = 0.5;
return Stack(
alignment: Alignment.center,
Expand All @@ -144,13 +141,7 @@ class _StopwatchScreenState extends State<StopwatchScreen> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
StopwatchTicker(stopwatch:_stopwatch),
// TimerBuilder.periodic(const Duration(milliseconds: 33),
// builder: (context) {
// // print(_stopwatch.fastestLap?.lapTime.toTimeString());
// // print(_stopwatch.slowestLap?.lapTime.toTimeString());
// return ;
// }),
const SizedBox(height: 8),
const SizedBox(height: 8),
Expanded(
child: CustomListView<Lap>(
items: _stopwatch.laps,
Expand Down

0 comments on commit 205961b

Please sign in to comment.