Skip to content

Commit

Permalink
Add log screen
Browse files Browse the repository at this point in the history
  • Loading branch information
AhsanSarwar45 committed Sep 10, 2024
1 parent 120ee4c commit b305b81
Show file tree
Hide file tree
Showing 20 changed files with 516 additions and 100 deletions.
27 changes: 27 additions & 0 deletions lib/alarm/data/alarm_events_sort_options.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:clock_app/alarm/types/alarm.dart';
import 'package:clock_app/alarm/types/alarm_event.dart';
import 'package:clock_app/common/types/list_filter.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

final List<ListSortOption<AlarmEvent>> alarmEventSortOptions = [
ListSortOption((context) => "Earlies start date", sortStartDateAscending),
ListSortOption((context) => "Latest start date", sortStartDateDescending),
ListSortOption((context) => "Earlies event date", sortEventDateAscending),
ListSortOption((context) => "Latest event date", sortEventDateDescending),
];

int sortStartDateAscending(AlarmEvent a, AlarmEvent b) {
return a.startDate.compareTo(b.startDate);
}

int sortStartDateDescending(AlarmEvent a, AlarmEvent b) {
return b.startDate.compareTo(a.startDate);
}

int sortEventDateAscending(AlarmEvent a, AlarmEvent b) {
return a.eventTime.compareTo(b.eventTime);
}

int sortEventDateDescending(AlarmEvent a, AlarmEvent b) {
return b.eventTime.compareTo(a.eventTime);
}
2 changes: 1 addition & 1 deletion lib/alarm/logic/alarm_isolate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const String setAlarmVolumePortName = "setAlarmVolumePort";
@pragma('vm:entry-point')
void triggerScheduledNotification(int scheduleId, Json params) async {
FlutterError.onError = (FlutterErrorDetails details) {
logger.f(details.exception.toString());
logger.f("Error in triggerScheduledNotification isolate: ${details.exception.toString()}");
};

logger.i(
Expand Down
2 changes: 2 additions & 0 deletions lib/alarm/screens/alarm_events_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:io';
import 'dart:typed_data';

import 'package:clock_app/alarm/data/alarm_events_list_filters.dart';
import 'package:clock_app/alarm/data/alarm_events_sort_options.dart';
import 'package:clock_app/alarm/types/alarm_event.dart';
import 'package:clock_app/alarm/widgets/alarm_event_card.dart';
import 'package:clock_app/common/utils/json_serialize.dart';
Expand Down Expand Up @@ -73,6 +74,7 @@ class _AlarmEventsScreenState extends State<AlarmEventsScreen> {
placeholderText: "No alarm events",
reloadOnPop: true,
listFilters: alarmEventsListFilters,
sortOptions: alarmEventSortOptions,
),
),
],
Expand Down
59 changes: 28 additions & 31 deletions lib/alarm/widgets/alarm_event_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,35 @@ class AlarmEventCard extends StatelessWidget {

Color textColor = colorScheme.onSurface.withOpacity(0.8);

return Column(
children: [
Padding(
padding: const EdgeInsets.only(
left: 16.0, right: 16.0, top: 8.0, bottom: 8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(event.isActive ? "Active" : "Inactive",
style: textTheme.labelMedium?.copyWith(
color: event.isActive
? colorScheme.primary
: colorScheme.onSurface)),
Text('Scheduled for: ${event.startDate}',
style: textTheme.labelMedium?.copyWith(color: textColor)),
Text(
'Type: ${event.notificationType == ScheduledNotificationType.alarm ? "Alarm" : "Timer"}',
style: textTheme.labelMedium?.copyWith(color: textColor)),
Text('Created at: ${event.eventTime}',
style: textTheme.labelMedium?.copyWith(color: textColor)),
Text(
'Description: ${event.description}',
style: textTheme.labelMedium?.copyWith(color: textColor),
maxLines: 5,
),
Text('Schedule Id: ${event.scheduleId}',
style: textTheme.labelMedium?.copyWith(color: textColor)),
],
return Padding(
padding: const EdgeInsets.only(
left: 16.0, right: 16.0, top: 8.0, bottom: 8.0),
child: Column(

crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(event.isActive ? "Active" : "Inactive",
style: textTheme.labelMedium?.copyWith(
color: event.isActive
? colorScheme.primary
: colorScheme.onSurface)),
Text('Scheduled for: ${event.startDate}',
style: textTheme.labelMedium?.copyWith(color: textColor)),
Text(
'Type: ${event.notificationType == ScheduledNotificationType.alarm ? "Alarm" : "Timer"}',
style: textTheme.labelMedium?.copyWith(color: textColor)),
Text('Created at: ${event.eventTime}',
style: textTheme.labelMedium?.copyWith(color: textColor)),
Text(
'Description: ${event.description}',
style: textTheme.labelMedium?.copyWith(color: textColor),
maxLines: 5,
),
),
],
Text('Schedule Id: ${event.scheduleId}',
style: textTheme.labelMedium?.copyWith(color: textColor)),
],
),
);
}
}
4 changes: 4 additions & 0 deletions lib/common/data/paths.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ Future<String> getTimezonesDatabasePath() async {
Future<String> getLogsFilePath() async {
return path.join(await getAppDataDirectoryPath(), "logs.txt");
}

String getLogsFilePathSync(){
return path.join(getAppDataDirectoryPathSync(), "logs.txt");
}
14 changes: 10 additions & 4 deletions lib/common/utils/snackbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ void showSnackBar(BuildContext context, String text,
ThemeData theme = Theme.of(context);
ColorScheme colorScheme = theme.colorScheme;
Color? color = error ? colorScheme.error : null;
Duration duration =
error ? const Duration(hours: 999) : const Duration(seconds: 4);
ScaffoldMessenger.of(context).removeCurrentSnackBar();
ScaffoldMessenger.of(context)
.showSnackBar(getSnackbar(text, fab: fab, navBar: navBar, color: color));
ScaffoldMessenger.of(context).showSnackBar(getSnackbar(text,
fab: fab, navBar: navBar, color: color, duration: duration));
}

SnackBar getSnackbar(String text,
{bool fab = false, bool navBar = false, Color? color}) {
{bool fab = false,
bool navBar = false,
Color? color,
Duration duration = const Duration(seconds: 4)}) {
double left = 20;
double right = 20;
double bottom = 12;
Expand Down Expand Up @@ -57,8 +62,9 @@ SnackBar getSnackbar(String text,
right: right,
bottom: bottom,
),
padding: EdgeInsets.zero,
padding: EdgeInsets.zero,
elevation: 2,
dismissDirection: DismissDirection.vertical,
duration: duration,
);
}
32 changes: 18 additions & 14 deletions lib/common/widgets/list/custom_list_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,10 @@ class _CustomListViewState<Item extends ListItem>

void _handleCustomAction(ListFilterCustomAction<Item> action) {
final list = _getActionableItems();
List<Item> items = list.where((item) =>
widget.listFilters.every((filter) => filter.filterFunction(item))).toList();
List<Item> items = list
.where((item) =>
widget.listFilters.every((filter) => filter.filterFunction(item)))
.toList();

action.action(items);
_endSelection();
Expand Down Expand Up @@ -350,18 +352,20 @@ class _CustomListViewState<Item extends ListItem>
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ListFilterBar(
listFilters: widget.listFilters,
customActions: widget.customActions,
sortOptions: widget.sortOptions,
isSelecting: _isSelecting,
handleCustomAction: _handleCustomAction,
handleEndSelection: _endSelection,
handleDeleteAction: _handleDeleteAction,
handleSelectAll: _handleSelectAll,
selectedIds: _selectedIds,
handleFilterChange: _handleFilterChange,
selectedSortIndex: _selectedSortIndex,
handleSortChange: _handleSortChange),
listFilters: widget.listFilters,
customActions: widget.customActions,
sortOptions: widget.sortOptions,
isSelecting: _isSelecting,
handleCustomAction: _handleCustomAction,
handleEndSelection: _endSelection,
handleDeleteAction: _handleDeleteAction,
handleSelectAll: _handleSelectAll,
selectedIds: _selectedIds,
handleFilterChange: _handleFilterChange,
selectedSortIndex: _selectedSortIndex,
handleSortChange: _handleSortChange,
isDeleteEnabled: widget.isDeleteEnabled,
),
if (widget.header != null) widget.header!,
Expanded(
flex: 1,
Expand Down
17 changes: 10 additions & 7 deletions lib/common/widgets/list/list_filter_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ class ListFilterBar<Item extends ListItem> extends StatelessWidget {
required this.selectedIds,
required this.handleFilterChange,
required this.selectedSortIndex,
required this.handleSortChange});
required this.handleSortChange,
required this.isDeleteEnabled});

final List<ListFilterItem<Item>> listFilters;
final List<ListFilterCustomAction<Item>> customActions;
final List<ListSortOption<Item>> sortOptions;
final bool isSelecting;
final bool isDeleteEnabled;
final Function(ListFilterCustomAction<Item>) handleCustomAction;
final Function handleEndSelection;
final void Function() handleFilterChange;
Expand Down Expand Up @@ -67,12 +69,13 @@ class ListFilterBar<Item extends ListItem> extends StatelessWidget {
action: () => handleCustomAction(action),
),
),
ListFilterAction(
name: AppLocalizations.of(context)!.deleteAllFilteredAction,
icon: Icons.delete_rounded,
color: colorScheme.error,
action: handleDeleteAction,
)
if (isDeleteEnabled)
ListFilterAction(
name: AppLocalizations.of(context)!.deleteAllFilteredAction,
icon: Icons.delete_rounded,
color: colorScheme.error,
action: handleDeleteAction,
)
],
activeFilterCount: activeFilterCount + (isSelecting ? 1 : 0),
),
Expand Down
24 changes: 24 additions & 0 deletions lib/debug/data/log_list_filters.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:clock_app/alarm/types/alarm_event.dart';
import 'package:clock_app/common/types/list_filter.dart';
import 'package:clock_app/common/utils/date_time.dart';
import 'package:clock_app/debug/types/log.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:logger/logger.dart';

final List<ListFilterItem<Log>> logListFilters = [
ListFilterSelect((context) => AppLocalizations.of(context)!.dateFilterGroup, [
ListFilter((context) => AppLocalizations.of(context)!.todayFilter,
(log) => log.dateTime.isToday()),
ListFilter((context) => AppLocalizations.of(context)!.tomorrowFilter,
(log) => log.dateTime.isTomorrow()),
]),
ListFilterMultiSelect(
(context) => AppLocalizations.of(context)!.logTypeFilterGroup, [
ListFilter((context) => "Debug", (log) => log.level == Level.debug),
ListFilter((context) => "Trace", (log) => log.level == Level.trace),
ListFilter((context) => "Info", (log) => log.level == Level.info),
ListFilter((context) => "Warning", (log) => log.level == Level.warning),
ListFilter((context) => "Error", (log) => log.level == Level.error),
ListFilter((context) => "Fatal", (log) => log.level == Level.fatal),
]),
];
17 changes: 17 additions & 0 deletions lib/debug/data/log_sort_options.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:clock_app/common/types/list_filter.dart';
import 'package:clock_app/debug/types/log.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

final List<ListSortOption<Log>> logSortOptions = [
ListSortOption((context) => "Earlies first", sortDateAscending),
ListSortOption((context) => "Latest first", sortDateDescending),
];

int sortDateAscending(Log a, Log b) {
return a.id.compareTo(b.id);
}

int sortDateDescending(Log a, Log b) {
return b.id.compareTo(a.id);
}

3 changes: 2 additions & 1 deletion lib/debug/logic/logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ var logger = Logger(
filter: FileLogFilter(),
output: FileLoggerOutput(),
printer: PrettyPrinter(
methodCount: 0, // Number of method calls to be displayed
methodCount: 100, // Number of method calls to be displayed

errorMethodCount: 8, // Number of method calls if stacktrace is provided
lineLength: 80, // Width of the output
colors: true, // Colorful log messages
Expand Down
Loading

0 comments on commit b305b81

Please sign in to comment.