Skip to content

Commit

Permalink
Merge pull request #9 from Frezyx/dev
Browse files Browse the repository at this point in the history
Implement filter and FlutterTalkerData models
  • Loading branch information
Frezyx authored Jan 29, 2022
2 parents 8b8d7bf + 3f57020 commit 05b032b
Show file tree
Hide file tree
Showing 33 changed files with 556 additions and 133 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Follow these steps to use this package
### Add dependency
```yaml
dependencies:
talker: ^0.5.0
talker: ^0.6.0
```
### Easy to use
Expand Down Expand Up @@ -86,8 +86,8 @@ Often you need to check what happening in the application when there is no conso
### Add dependency
```yaml
dependencies:
talker: ^0.5.0
talker_flutter: ^0.4.0
talker: ^0.6.0
talker_flutter: ^0.5.0
```
### Easy to use
Expand Down
6 changes: 6 additions & 0 deletions talker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.6.0
- Implement filter for logs

## 0.5.2
- Add title for default models

## 0.5.1
- Fix README images urls

Expand Down
6 changes: 3 additions & 3 deletions talker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Follow these steps to use this package
### Add dependency
```yaml
dependencies:
talker: ^0.5.0
talker: ^0.6.0
```
### Easy to use
Expand Down Expand Up @@ -86,8 +86,8 @@ Often you need to check what happening in the application when there is no conso
### Add dependency
```yaml
dependencies:
talker: ^0.5.0
talker_flutter: ^0.4.0
talker: ^0.6.0
talker_flutter: ^0.5.0
```
### Easy to use
Expand Down
1 change: 1 addition & 0 deletions talker/lib/src/models/filter/filter.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'talker_filter.dart';
67 changes: 67 additions & 0 deletions talker/lib/src/models/filter/talker_filter.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import 'package:talker/src/src.dart';

abstract class Filter<T> {
bool filter(T item);
}

class TalkerFilter implements Filter<TalkerDataInterface> {
TalkerFilter({
required this.titles,
required this.types,
this.searchQuery,
});

final List<String> titles;
final List<Type> types;
final String? searchQuery;

@override
bool filter(TalkerDataInterface item) {
var match = false;

if (titles.isNotEmpty) {
match = match || titles.contains(item.displayTitle);
}

if (types.isNotEmpty) {
match = match || _checkTypeMatch(item);
}

if (searchQuery?.isNotEmpty ?? false) {
final fullMsg = item.generateTextMessage();
final fullUpperMsg = fullMsg.toUpperCase();
final fullLowerMsg = fullMsg.toLowerCase();
final textContain = fullUpperMsg.contains(searchQuery!) ||
fullLowerMsg.contains(searchQuery!);
match = match || textContain;
}

if (titles.isEmpty && types.isEmpty && (searchQuery?.isEmpty ?? true)) {
match = true;
}
return match;
}

bool _checkTypeMatch(TalkerDataInterface item) {
var match = false;
for (final type in types) {
if (item.runtimeType == type) {
match = true;
break;
}
}
return match;
}

TalkerFilter copyWith({
List<String>? titles,
List<Type>? types,
String? searchQuery,
}) {
return TalkerFilter(
titles: titles ?? this.titles,
types: types ?? this.types,
searchQuery: searchQuery ?? this.searchQuery,
);
}
}
1 change: 1 addition & 0 deletions talker/lib/src/models/models.dart
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export 'filter/filter.dart';
export 'talker_data/talker_data.dart';
19 changes: 14 additions & 5 deletions talker/lib/src/models/talker_data/talker_data_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ abstract class TalkerDataInterface {
/// {@endtemplate}
Error? get error;

/// {@template talker_data_title}
/// Title of Talker log
/// {@endtemplate}
String? get title;

/// {@template talker_data_stackTrace}
/// StackTrace?] [stackTrace] - stackTrace if [exception] or [error] happened
/// {@endtemplate}
Expand Down Expand Up @@ -57,20 +62,24 @@ abstract class TalkerDataInterface {
extension FeildsToDisplay on TalkerDataInterface {
/// Displayed title of [TalkerDataInterface]
String get displayTitle {
var title = '';
var t = '';
switch (runtimeType) {
case TalkerError:
title = 'ERROR';
t = 'ERROR';
break;
case TalkerException:
title = 'EXCEPTION';
t = 'EXCEPTION';
break;
case TalkerLog:
default:
title = logLevel.title;
t = title ?? logLevel.title;
break;
}
return '[$title]' + ' | $displayTime | ';
return t;
}

String get displayTitleWithTime {
return '[$displayTitle] | $displayTime | ';
}

/// Displayed stackTrace of [TalkerDataInterface]
Expand Down
7 changes: 6 additions & 1 deletion talker/lib/src/models/talker_data/talker_error.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class TalkerError implements TalkerDataInterface {
this.message,
this.logLevel,
this.stackTrace,
this.title,
DateTime? time,
}) {
_time = time ?? DateTime.now();
Expand All @@ -27,14 +28,18 @@ class TalkerError implements TalkerDataInterface {
@override
final StackTrace? stackTrace;

/// {@macro talker_data_title}
@override
final String? title;

/// {@macro talker_data_loglevel}
@override
final LogLevel? logLevel;

/// {@macro talker_data_generateTextMessage}
@override
String generateTextMessage() {
return '$displayTitle$displayMessage$displayError$displayStackTrace';
return '$displayTitleWithTime$displayMessage$displayError$displayStackTrace';
}

/// {@macro talker_data_time}
Expand Down
7 changes: 6 additions & 1 deletion talker/lib/src/models/talker_data/talker_exception.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class TalkerException implements TalkerDataInterface {
this.message,
this.logLevel,
this.stackTrace,
this.title,
DateTime? time,
}) {
_time = time ?? DateTime.now();
Expand All @@ -27,14 +28,18 @@ class TalkerException implements TalkerDataInterface {
@override
final StackTrace? stackTrace;

/// {@macro talker_data_title}
@override
final String? title;

/// {@macro talker_data_loglevel}
@override
final LogLevel? logLevel;

/// {@macro talker_data_generateTextMessage}
@override
String generateTextMessage() {
return '$displayTitle$displayMessage$displayException$displayStackTrace';
return '$displayTitleWithTime$displayMessage$displayException$displayStackTrace';
}

/// {@macro talker_data_time}
Expand Down
8 changes: 7 additions & 1 deletion talker/lib/src/models/talker_data/talker_log.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class TalkerLog implements TalkerDataInterface {
this.error,
this.stackTrace,
this.additional,
this.title,
DateTime? time,
this.pen,
}) {
Expand All @@ -33,6 +34,11 @@ class TalkerLog implements TalkerDataInterface {
@override
final StackTrace? stackTrace;

/// {@macro talker_data_title}
@override
final String? title;

/// {@macro talker_data_additional}
@override
final Map<String, dynamic>? additional;

Expand All @@ -43,7 +49,7 @@ class TalkerLog implements TalkerDataInterface {
/// {@macro talker_data_generateTextMessage}
@override
String generateTextMessage() {
return '$displayTitle$message$displayAditional';
return '$displayTitleWithTime$message$displayAditional';
}

/// {@macro talker_data_time}
Expand Down
3 changes: 1 addition & 2 deletions talker/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
name: talker
description: Advanced error handler and logger package for flutter and dart apps
version: 0.5.1
version: 0.6.0
homepage: https://github.com/Frezyx/talker

environment:
sdk: '>=2.15.0 <3.0.0'


dependencies:
intl: ^0.17.0
talker_error_handler: ^0.5.0
Expand Down
6 changes: 6 additions & 0 deletions talker_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.5.0
- Implement UI filter for convenient work with the console in the application

## 0.4.1
- Add Flutter Colors extended Talker models <br> to customize colors of your UI logs

## 0.4.0
- Update talker version to 0.5.0

Expand Down
Loading

0 comments on commit 05b032b

Please sign in to comment.