Skip to content

Add copyWith methods to DefaultStyles, HorizontalSpacing, and VerticalSpacing #2550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 27, 2025

Conversation

md-rifatkhan
Copy link
Contributor

  • Feature: New functionality without breaking existing features.
  • 🛠️ Bug fix: Resolves an issue without altering current behavior.
  • 🧹 Refactor: Code reorganization, no behavior change.
  • Breaking: Alters existing functionality and requires updates.
  • 🧪 Tests: New or modified tests
  • 📝 Documentation: Updates or additions to documentation.
  • 🗑️ Chore: Routine tasks, or maintenance.
  • Build configuration change: Build/configuration changes.

Easily override style:

DefaultStyles _buildDefaults(BuildContext context) {
    // flutter quill
    final base = DefaultStyles.getInstance(context);
    final h1 = base.h1;

    return base.merge(
      DefaultStyles(
        // Before (Copied from default_styles.dart file)
        // h1: DefaultTextBlockStyle(
        //   TextStyle(
        //     fontSize: 34,
        //     color: Colors.white,
        //     letterSpacing: -0.5,
        //     height: 1.083,
        //     fontWeight: FontWeight.bold,
        //     decoration: TextDecoration.none,
        //   ),
        //   HorizontalSpacing(0, 0),
        //   const VerticalSpacing(16, 0),
        //   VerticalSpacing.zero,
        //   null,
        // ),

        // after (Modified)
        // h1: h1?.copyWith(
        //   style: h1.style.copyWith(color: Colors.blue),
        //   verticalSpacing: h1.verticalSpacing.copyWith(bottom: 20),
        // ),


      ),
    );
  }

@EchoEllet
Copy link
Collaborator

EchoEllet commented Apr 26, 2025

A minor issue: copyWith does not allow setting properties to null; attempting to do so will leave the property unchanged. There is a workaround, but before using it, we need to check whether there is a nullable or if there is a need to set it to null.

horizontalSpacing.copyWith(
  left: null // left will not set to null even if `this.left` type is nullable. 
)

The workaround is to wrap left in the copyWith inside a class, but this workaround should be avoided if not needed.

@EchoEllet
Copy link
Collaborator

Could you update CHANGELOG.md? Any modification is enough, so I can update update the file with the changes directly using GitHub web.

@EchoEllet
Copy link
Collaborator

Thank you for your contribution.

@EchoEllet EchoEllet merged commit da4be28 into singerdmx:master Apr 27, 2025
7 checks passed
wangjinshan pushed a commit to wangjinshan/flutter-quill that referenced this pull request Apr 29, 2025
* master: (83 commits)
  Add copyWith methods to DefaultStyles, HorizontalSpacing, and VerticalSpacing (singerdmx#2550)
  docs: update migration guide to relfect singerdmx#2529
  chore(release): prepare to publish 11.4.0
  feat: allow to override link validation check, and accept mailto and other links by default (singerdmx#2525)
  chore(release): prepare to publish 11.3.0
  Fix selection in readOnly mode, Add magnifier via RawMagnifier widget (singerdmx#2529)
  Clarify platform support of QuillEditorConfig.onKeyPressed (singerdmx#2542)
  chore(release): prepare to publish 11.2.0
  feat: cache for toPlainText in Document to avoid unnecessary text computing (singerdmx#2482)
  chore(example): update deps
  chore(release): prepare to publish 11.1.2
  fix: QuillEditor doesn't respect the system keyboard brightness by default on iOS (singerdmx#2522)
  chore(release): prepare to publish flutter_quill_test
  chore(release): prepare to publish 11.1.1
  Chore: general improvements in flutter_quill_tests API (singerdmx#2512)
  Explicitly schedule frame on secondary click. (singerdmx#2507)
  chore(release): prepare to publish 11.1.0
  fix: unpredictable endless loop of '_handleFocusChanged' in the phase of page route changing when editor is set to readonly. (singerdmx#2488)
  feat: Enable BoxDecoration for DefaultTextBlockStyle of header Attribute (singerdmx#2438)
  Expose Rule type so that Document.setCustomRules can be used (singerdmx#2484)
  ...
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