-
-
Notifications
You must be signed in to change notification settings - Fork 101
Description
My feature request comes from issue #349 where a user was confused about how to use the custom log feature in talker_flutter.
I'd like to see better documentation regarding the custom logs, especially because the example app hosted by the talker team uses a different approach than the documentation. In the team's documentation custom logs types are created by the following code:
Lines 185 to 199 in ab547ee
| class YourCustomLog extends TalkerLog { | |
| YourCustomLog(String message) : super(message); | |
| @override | |
| String get title => 'Custom'; | |
| @override | |
| String? get key => 'custom_log_key'; | |
| @override | |
| AnsiPen get pen => AnsiPen()..xterm(121); | |
| } | |
| final talker = Talker(); | |
| talker.logCustom(YourCustomLog('Something like your own service message')); |
However, in the team's example app, the way they use getters in the custom log type is the following:
talker/examples/shop_app_example/lib/utils/good_log.dart
Lines 4 to 22 in ab547ee
| class GoodLog extends TalkerLog { | |
| GoodLog(String super.message); | |
| /// Log title | |
| @override | |
| String get title => 'good'; | |
| /// Log key | |
| @override | |
| String get key => getKey; | |
| /// Log color | |
| @override | |
| AnsiPen get pen => getPen; | |
| static get getPen => AnsiPen()..xterm(121); | |
| static get getKey => 'good'; | |
| } |
This makes it confusing for people who are first starting to use custom logs with the talker_flutter package's TalkerScreen. If you were to use the code in the documentation, you get errors when trying to get the custom log keys, which I believe has been overlooked.
TalkerScreenTheme(
/// Your custom log colors
logColors: {
TalkerLogType.error.key: Colors.redAccent,
TalkerLogType.info.key: Colors.grey,
RequestLog.getKey: Colors.pink,
// correct implementation with no errors, from the example app
ResponseLog.getKey: Colors.green,
// error right here
YourCustomLog.key: Colors.black
},
)Instead, I believe that documentation should use the approach taken by the designer of the example app, where getters are used, and it is more clear that you should be using the getKey static string. Example of which, from the demo app listed below.
talker/examples/shop_app_example/lib/ui/theme.dart
Lines 22 to 24 in ab547ee
| final talkerTheme = TalkerScreenTheme(logColors: { | |
| GoodLog.getKey: const Color(0xff4CAF50), | |
| }); |