Skip to content

Code File (Custom Classes) Docs #363

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 12 commits into from
May 30, 2025
Merged

Code File (Custom Classes) Docs #363

merged 12 commits into from
May 30, 2025

Conversation

pinkeshmars
Copy link
Collaborator

Description

Code File (Custom Classes) Docs

Linear ticket and magic word Fixes DEVR-914

Type of change

  • Typo fix
  • New feature
  • Enhancement to current docs
  • Removed outdated references
  • Update assets

Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link
Collaborator

@PoojaB26 PoojaB26 left a comment

Choose a reason for hiding this comment

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

Requested some fixes, but overall LGTM!


## Create Class Instance

You need to create an instance of a class so you can work with actual data and use the class’s properties and methods in your app. Here’s a simple explanation:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Mention how it is similar to datatype instance and point to that doc?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Did you mean point to here or here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess we don't have any docs in custom data type about creating a datatype instance?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, we don't have it yet.

Copy link
Collaborator

Choose a reason for hiding this comment

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

can you create a linear ticket for the same and reference this PR comment?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

- An **instance** (or “object”) is a real, usable item made from that blueprint. See the code snippet below:

```jsx
Review review1 = Review(
Copy link
Collaborator

Choose a reason for hiding this comment

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

THis may be incomplete if we don't show the code for the Review class first. I know its added to the Arcade but its not enough since the rest of the explanations is so tied to the Review class, but we dont show the class definition in code here. I'd suggest add the Review class snippet after the Create Custom Class Arcade

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agree! added.


- Store actual review details.
- Access and update the fields (e.g., `review1.rating` or `review1.comment`).
- Call methods that do something with that data (e.g., `review1.markHelpful()` or `review1.shortComment()`).
Copy link
Collaborator

Choose a reason for hiding this comment

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

another point where these methods are confusing because we dont have the code for Review class somewhere here where we can reference it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ya, now worries. added the code snippet for the Review class.

</div>
<p></p>

:::tip[When You Don't Need an Instance]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wouldnt call it a tip rather its a feature. Im afraid this entire section with the description (for e.g "skip instance creation" language) can make non coders feel like this is the easiest approach so lets go with it, and they will have static methods everywhere and more bugs because the logic will not work the way a non static class is expected to work.

We should treat it as its own section and talk about when its useful with more examples

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, in that case, let's remove (comment out) this part and revisit with more detail!

Copy link
Collaborator

Choose a reason for hiding this comment

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

because it will take more time to rewrite this part?

Copy link
Collaborator

Choose a reason for hiding this comment

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

i see a bunch of new actions under custom class, see here: https://linear.app/flutterflow/issue/SUP-2529/custom-class-method-is-not-appearing-in-actions-list#comment-34cd1a72
also some related to static fields. I think it should be covered in the v1 version of the docs (as a separate section)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

When you say this 'should be covered in the v1 version of the docs' you mean in this PR only right? yes, we can do it. Could you please help with that ticket? it is is not opening for me.
Screenshot 2025-05-27 at 5 18 17 PM

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes in this PR, can you check the linear ticket again?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done! Added a new 'Using Static Classes' section.


![access-fields-methods.avif](imgs/access-fields-methods.avif)

### Call In Action Flows
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think this is more important to show with an Arcade. and if I remember correctly this is not the name of the action. we must have the action name the way we do it for other features.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, you're right. However, there's currently an issue where custom class methods aren't showing up in the actions list, so I’m unable to see any details or record the arcade.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added now!


You can also add your custom class’s methods directly within an Action Flow. For example, you can trigger the `markHelpful()` method when a user taps a “Mark as Helpful” button to update a field or increment the helpful count of a review.

## Enums
Copy link
Collaborator

Choose a reason for hiding this comment

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

its ###?

Copy link
Collaborator

Choose a reason for hiding this comment

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

definitely the name shouldnt be just Enums, same reason as Data Types comment. Custom Enums?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed the name to "Custom Enums" but kept the heading as ## only to avoid nesting it under "Using Custom Classes." Since enums are different from classes, I think they deserve their section.

@pinkeshmars
Copy link
Collaborator Author

Hi @PoojaB26, Most of the review comments are addressed. For some, I left the reply. You can take a look.

@pinkeshmars
Copy link
Collaborator Author

Hi @PoojaB26 all review comments are addressed now!

@@ -194,7 +194,67 @@ You can use custom class fields to display values directly in the UI, and call i

### Call In Action Flows
Copy link
Collaborator

Choose a reason for hiding this comment

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

I dont think we need this, lets just have all actions in h3 and remove this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done!

@pinkeshmars pinkeshmars requested a review from PoojaB26 May 30, 2025 08:18
Copy link
Collaborator

@PoojaB26 PoojaB26 left a comment

Choose a reason for hiding this comment

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

Some examples & explanations need fixing


### Set Field [Action]

Use the **Set Field** action to update a specific property of a custom class instance. For example, you can set `order.status = 'shipped'` when a user confirms an order, allowing the UI to reflect the change immediately.
Copy link
Collaborator

Choose a reason for hiding this comment

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

The example is different from the text here. May be confusing to users.

Copy link
Collaborator

Choose a reason for hiding this comment

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

  • not matching the Review class above

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done!


## Using Static Classes

Sometimes, you just want to run a small piece of logic like formatting text or doing a calculation, without needing to set up anything extra. That’s when `static` data members are helpful. You can access static fields and methods without creating an instance of a class. You can think of them like tools that are always ready to use.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is incorrect actually. We don't use static classes because its minor logic, but rather when there is "shared logic across app" where calculator / utility functions fit that definition.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Sometimes, you just want to run a small piece of logic like formatting text or doing a calculation, without needing to set up anything extra. That’s when `static` data members are helpful. You can access static fields and methods without creating an instance of a class. You can think of them like tools that are always ready to use.
Sometimes, you just want to run a small piece of logic like formatting text or doing a calculation, without needing to set up anything extra. That’s when `static` data members are helpful. You can access static fields and methods without creating an instance of a class. Because they're tied to the class rather than an instance, static members are accessible globally.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok, updated it.

- This `StringFormatter` class below provides reusable static methods to capitalize text, convert it to lowercase, or format it in snake_case.

```jsx
class StringFormatter {
Copy link
Collaborator

Choose a reason for hiding this comment

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

indentation is off on this one

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated!

</div>
<p></p>

## Using Static Classes
Copy link
Collaborator

@PoojaB26 PoojaB26 May 30, 2025

Choose a reason for hiding this comment

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

I'm confused on this one. technically Dart doesnt allow a "static class" per se. What people often do instead is create a class that contains only static members or mix static and instance members in the same class. So the title might be a bit misleading in this context? Maybe just call it Using Static Members or just Static Members if you agree?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok updated to 'Using Static Members'


:::warning

Static classes are powerful, but they should be used carefully. Overusing static methods can lead to less flexible code and potential issues, especially when the logic requires access to state or needs to evolve over time. Stick to static methods only when the logic is truly independent and doesn’t rely on instance-specific data.
Copy link
Collaborator

Choose a reason for hiding this comment

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

can fix the first line based on the feedback about "static classes"

Copy link
Collaborator

Choose a reason for hiding this comment

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

also mention somewhere that static and instance fields can be mixed in a class as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Addressed both of comments!

</div>
<p></p>

### Call Static Method [Action]
Copy link
Collaborator

Choose a reason for hiding this comment

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

The example in the text not matching the example in the Arcade. You can add multiple examples, but the main one should reflect the Arcade

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done!

@pinkeshmars
Copy link
Collaborator Author

@PoojaB26 you can take a look again.

@PoojaB26 PoojaB26 merged commit 4164e3c into main May 30, 2025
1 check passed
@PoojaB26 PoojaB26 deleted the feature/custom-classes branch May 30, 2025 12:07
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