Skip to content

Conversation

@richardshiue
Copy link
Collaborator

@richardshiue richardshiue commented Jun 13, 2025

Feature Preview


PR Checklist

  • My code adheres to AppFlowy's Conventions
  • I've listed at least one issue that this PR fixes in the description above.
  • I've added a test(s) to validate changes in this PR, or this PR only contains semantic changes.
  • All existing tests are passing.

Summary by Sourcery

Adjust the desktop toast component to use the new AppFlowyTheme for styling and add an optional close button.

Enhancements:

  • Import the unified appflowy_ui package and remove legacy theme_extension dependency
  • Add a showCloseButton parameter to enable or disable the close icon
  • Apply theme-driven spacing, colors, border radius, and shadows for consistent toast styling
  • Replace direct FlowyText usage with standard Text components styled via the theme

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jun 13, 2025

Reviewer's Guide

This PR refactors the toast component to leverage AppFlowyTheme for all styling (spacing, colors, borders, shadows, and text) and introduces an optional close button toggle in DesktopToast.

Sequence Diagram for Displaying a Toast with a Close Button

sequenceDiagram
    participant C as Client Code
    participant S as showToastNotification()
    participant T as Toastification
    participant D as DesktopToast

    C->>S: call(message, showCloseButton: true)
    S->>T: show(builder: (context, item) -> ...)
    T-->>S: item
    S-->>C: item
    T->>D: new DesktopToast(showCloseButton: true)
Loading

Updated Class Diagram for Toast Components

classDiagram
    direction LR
    class showToastNotification {
        +showToastNotification(description, type, callbacks, showCloseButton, bottomPadding) ToastificationItem
    }
    class DesktopToast {
        +String? message
        +TextSpan? richMessage
        +ToastificationType type
        +void Function()? onDismiss
        +bool showCloseButton
        +build(BuildContext context) Widget
    }

    showToastNotification --|> DesktopToast : creates
Loading

File-Level Changes

Change Details Files
Migrate toast styling to AppFlowyTheme
  • Replaced util/theme_extension import with appflowy_ui and injected theme via AppFlowyTheme.of(context)
  • Replaced hardcoded padding with theme.spacing values
  • Swapped background color, borderRadius, and shadow for theme.surfaceColorScheme.inverse, theme.borderRadius, and theme.shadow.small
  • Updated text rendering to use theme.textStyle.body.standard and theme.textColorScheme.onFill
frontend/appflowy_flutter/lib/workspace/presentation/widgets/dialogs.dart
Add optional close button toggle
  • Added showCloseButton parameter to showToastNotification function and DesktopToast constructor
  • Wrapped close icon widget in an if(showCloseButton) block
  • Added extra spacing before the close icon and increased its size from 16 to 20
frontend/appflowy_flutter/lib/workspace/presentation/widgets/dialogs.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

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @richardshiue - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `frontend/appflowy_flutter/lib/workspace/presentation/widgets/dialogs.dart:498` </location>
<code_context>
     this.richMessage,
     required this.type,
     this.onDismiss,
+    this.showCloseButton = false,
   });

</code_context>

<issue_to_address>
Assert that onDismiss is provided when showCloseButton is true

Add an assertion in the constructor to ensure that if showCloseButton is true, onDismiss is not null: `assert(!showCloseButton || onDismiss != null);`. This will prevent the close button from being non-functional.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
    this.richMessage,
    required this.type,
    this.onDismiss,
    this.showCloseButton = false,
  });
=======
    this.richMessage,
    required this.type,
    this.onDismiss,
    this.showCloseButton = false,
  }) : assert(!showCloseButton || onDismiss != null, 'onDismiss must be provided if showCloseButton is true');
>>>>>>> REPLACE

</suggested_fix>

### Comment 2
<location> `frontend/appflowy_flutter/lib/workspace/presentation/widgets/dialogs.dart:561` </location>
<code_context>
-                    child: FlowySvg(
-                      FlowySvgs.toast_close_s,
-                      size: Size.square(16.0),
-                      color: Color(0xFFBDBDBD),
+            if (showCloseButton) ...[
+              HSpace(
</code_context>

<issue_to_address>
Avoid hard-coded icon color; use theme colors instead

Use a theme-based color (e.g., `theme.iconColorScheme.onSurfaceVariant`) to ensure the icon adapts to different themes and modes.

Suggested implementation:

```
            if (showCloseButton) ...[
              HSpace(

```

```
            // Close button
            if (showCloseButton) ...[
              HSpace(
                theme.spacing.s,
              ),
              FlowySvg(
                FlowySvgs.toast_close_s,
                size: Size.square(16.0),
                color: theme.iconColorScheme.onSurfaceVariant,
              ),
            ],
            // text
            Flexible(
              child: message != null
                  ? Text(
                      message!,
                      maxLines: 2,

```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines 495 to 398
this.richMessage,
required this.type,
this.onDismiss,
this.showCloseButton = false,
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): Assert that onDismiss is provided when showCloseButton is true

Add an assertion in the constructor to ensure that if showCloseButton is true, onDismiss is not null: assert(!showCloseButton || onDismiss != null);. This will prevent the close button from being non-functional.

Suggested change
this.richMessage,
required this.type,
this.onDismiss,
this.showCloseButton = false,
});
this.richMessage,
required this.type,
this.onDismiss,
this.showCloseButton = false,
}) : assert(!showCloseButton || onDismiss != null, 'onDismiss must be provided if showCloseButton is true');

color: Color(0xFFBDBDBD),
if (showCloseButton) ...[
HSpace(
theme.spacing.xl,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Avoid hard-coded icon color; use theme colors instead

Use a theme-based color (e.g., theme.iconColorScheme.onSurfaceVariant) to ensure the icon adapts to different themes and modes.

Suggested implementation:

            if (showCloseButton) ...[
              HSpace(

            // Close button
            if (showCloseButton) ...[
              HSpace(
                theme.spacing.s,
              ),
              FlowySvg(
                FlowySvgs.toast_close_s,
                size: Size.square(16.0),
                color: theme.iconColorScheme.onSurfaceVariant,
              ),
            ],
            // text
            Flexible(
              child: message != null
                  ? Text(
                      message!,
                      maxLines: 2,

@richardshiue richardshiue merged commit 460fd54 into AppFlowy-IO:main Jun 16, 2025
19 checks passed
@richardshiue richardshiue deleted the chore/adjust-toast branch June 16, 2025 04:43
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.

1 participant