Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Frezyx
Copy link
Owner

@Frezyx Frezyx commented Jun 7, 2025

Summary by Sourcery

Simplify the Talker API by replacing the enum-based log keys with a unified TalkerKey string API and updating all key lookups, settings methods, UI theming, and tests to use the new string-based keys.

Enhancements:

  • Replace the TalkerLogType enum with a static TalkerKey class of string constants for log keys
  • Simplify key lookup by replacing fromKey on the enum with TalkerKey.fromLogLevel returning a string
  • Rename settings methods to getTitleByKey and getPenByKey and update all usages accordingly
  • Update all packages, examples, and tests to reference TalkerKey instead of TalkerLogType.x.key

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jun 7, 2025

Reviewer's Guide

This PR replaces the enum-based TalkerLogType API with a simpler TalkerKey static string constants, updates the settings and core Talker logic to use the new key-based methods, and refactors all related UI components, log classes, tests, and examples accordingly.

Sequence Diagram: Interaction in Talker._createLog with TalkerKey

sequenceDiagram
    actor Caller
    participant T as Talker
    participant TK as TalkerKey
    participant TS as TalkerSettings
    participant TL as TalkerLog

    Caller->>+T: log(message, logLevel, exception, stackTrace, pen)
    T->>+TK: TalkerKey.fromLogLevel(logLevel)
    TK-->>-T: key: String
    T->>+TS: settings.getTitleByKey(key)
    TS-->>-T: title
    T->>+TS: settings.getPenByKey(key)
    TS-->>-T: resolvedPen
    T->>+TL: new TalkerLog(message, key, title, exception, stackTrace, resolvedPen, logLevel)
    TL-->>-T: logData: TalkerLog
    T->>T: _handleLog(logData)
    T-->>-Caller: (void or Future)
Loading

Sequence Diagram: Interaction in Talker._handleLog with TalkerKey

sequenceDiagram
    participant TalkerLogic as "Talker (Internal Logic)"
    participant Data as "data: TalkerData"
    participant Settings as TalkerSettings

    TalkerLogic->>TalkerLogic: _handleLog(data) called
    alt data.key is not null
        TalkerLogic->>+Settings: settings.getTitleByKey(data.key)
        Settings-->>-TalkerLogic: newTitle
        TalkerLogic->>Data: data.title = newTitle

        TalkerLogic->>+Settings: settings.getPenByKey(data.key, data.pen)
        Settings-->>-TalkerLogic: newPen
        TalkerLogic->>Data: data.pen = newPen
    end
    TalkerLogic->>TalkerLogic: (Proceeds to broadcast and observe log)
Loading

Class Diagram: Introduction of TalkerKey and Removal of TalkerLogType

classDiagram
    direction LR

    class TalkerLogType {
        <<Enumeration>>
        +error
        +critical
        +info
        +debug
        +verbose
        +warning
        +exception
        +httpError
        +httpRequest
        +httpResponse
        +blocEvent
        +blocTransition
        +blocClose
        +blocCreate
        +riverpodAdd
        +riverpodUpdate
        +riverpodDispose
        +riverpodFail
        +route
        +key: String
        +fromLogLevel(LogLevel) TalkerLogType
        +fromKey(String) TalkerLogType?
    }

    class TalkerKey {
        <<Abstract>>
        +String error$
        +String critical$
        +String info$
        +String debug$
        +String verbose$
        +String warning$
        +String exception$
        +String httpError$
        +String httpRequest$
        +String httpResponse$
        +String blocEvent$
        +String blocTransition$
        +String blocClose$
        +String blocCreate$
        +String riverpodAdd$
        +String riverpodUpdate$
        +String riverpodDispose$
        +String riverpodFail$
        +String route$
        +fromLogLevel(LogLevel) String$
        -_logLevels: Map~LogLevel, String~$
    }
    class LogLevel {
        <<Enumeration>>
    }
    TalkerKey ..> LogLevel : uses
Loading

Class Diagram: TalkerSettings Update for TalkerKey

classDiagram
    class TalkerSettings {
        +Map~String, String~ titles
        +Map~String, AnsiPen~ colors
        +getTitleByKey(String key) String  // Replaces getTitleByLogKey
        +getPenByKey(String key, AnsiPen fallbackPen) AnsiPen // Replaces getAnsiPenByLogType & older getPenByLogKey logic
        --Removed Methods--
        -getTitleByLogKey(String key) String
        -getAnsiPenByLogType(TalkerLogType type, TalkerData logData) AnsiPen
    }
    class AnsiPen
    class TalkerLogType {
      // Details of removed enum, used by removed getAnsiPenByLogType method
    }
    class TalkerData {
      // Used by removed getAnsiPenByLogType method
    }

    TalkerSettings *-- AnsiPen : uses in colors map
    TalkerSettings ..> TalkerLogType : (used by removed method)
    TalkerSettings ..> TalkerData : (used by removed method)
Loading

Class Diagram: TalkerFlutter UI Helper Updates for TalkerKey

classDiagram
    class TalkerKey {
        <<Abstract>>
        +fromLogLevel(LogLevel) String$
        // ... other static keys
    }
    class LogLevel
    class TalkerScreenTheme {
        +LogColors colors // Type alias for Map~String, Color~
    }
    class LogColors {
        <<Type Alias for Map~String, Color~>>
    }
    class MapTalkerFlutterColorsExt {
        <<Extension on LogColors>>
        +getByKey(String key) Color // Replaces getByType(TalkerLogType type)
        --Removed Method--
        -getByType(TalkerLogType type) Color
    }
    LogColors ..> MapTalkerFlutterColorsExt : extended by
    MapTalkerFlutterColorsExt ..> TalkerKey : uses (key parameter is a TalkerKey string)

    class TalkerData {
      +LogLevel? logLevel
      +String? key
    }
    class TalkerDataFlutterExt {
        <<Extension on TalkerData>>
        #_getColorByLogLevel(TalkerScreenTheme theme) Color? // Internals use TalkerKey.fromLogLevel(data.logLevel) or data.key
    }
    TalkerData ..> TalkerDataFlutterExt : extended by
    TalkerDataFlutterExt ..> TalkerKey : uses TalkerKey.fromLogLevel()
    TalkerDataFlutterExt ..> TalkerScreenTheme : uses
Loading

File-Level Changes

Change Details Files
Introduce TalkerKey class and remove TalkerLogType enum
  • Removed the TalkerLogType enum and its extension
  • Added abstract TalkerKey with static const string keys
  • Implemented fromLogLevel mapping to return string keys
packages/talker/lib/src/talker_key.dart
Update settings API to key-based lookups
  • Renamed getTitleByLogKey → getTitleByKey and getPenByLogKey → getPenByKey
  • Switched defaultTitles/defaultColors maps to use TalkerKey constants
packages/talker/lib/src/settings.dart
Adapt Talker core to use new key API
  • Replaced TalkerLogType.fromLogLevel with TalkerKey.fromLogLevel
  • Updated all settings.getPenBy… and getTitleBy… calls to use key-based methods
  • Refactored initial color mapping in Talker.copyWith to use TalkerKey
packages/talker/lib/src/talker.dart
Refactor Flutter UI components to key-based theming
  • Renamed color lookup extension from getByType to getByKey
  • Updated default color maps and data card filters to use TalkerKey
  • Adjusted TalkerMonitor to filter and style logs by string keys
packages/talker_flutter/lib/src/ui/theme/talker_screen_theme.dart
packages/talker_flutter/lib/src/ui/widgets/data_card.dart
packages/talker_flutter/lib/src/ui/talker_monitor/talker_monitor.dart
packages/talker_flutter/lib/src/extensions/talker_data.dart
Update log classes in bloc, dio, http, riverpod to use TalkerKey
  • Replaced all key getters to return TalkerKey constants
  • Removed TalkerLogType.key references across loggers
packages/talker_bloc_logger/lib/bloc_logs.dart
packages/talker_riverpod_logger/lib/riverpod_logs.dart
packages/talker_dio_logger/lib/dio_logs.dart
packages/talker_http_logger/lib/talker_http_logger.dart
Refactor tests and examples to use TalkerKey
  • Replaced TalkerLogType.key checks with TalkerKey constants
  • Updated examples and custom log classes to reference TalkerKey
packages/talker/test/talker_key.dart
packages/talker/test/talker_settings_test.dart
packages/talker_riverpod_logger/test/logs_test.dart
packages/talker_bloc_logger/test/logs_test.dart
examples/shop_app_example/lib/main.dart

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@Frezyx Frezyx merged commit 464c9c9 into 5.0.0-dev Jun 7, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants