Skip to content

Commit 6520f26

Browse files
committed
Address review comment
1 parent 30c9540 commit 6520f26

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

docs/ff-concepts/adding-customization/code-file.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,64 @@ Here’s an example of adding a Review custom class:
5757
</div>
5858
<p></p>
5959

60+
Here's the code snippet of the Review custom class:
61+
62+
```jsx
63+
class Review {
64+
String id;
65+
String productId;
66+
String userId;
67+
String userName;
68+
String comment;
69+
double rating; // out of 5
70+
ReviewStatus reviewStatus;
71+
DateTime date;
72+
int helpfulCount = 0;
73+
74+
Review(
75+
this.id,
76+
this.productId,
77+
this.userId,
78+
this.userName,
79+
this.comment,
80+
this.rating,
81+
this.reviewStatus,
82+
this.date,
83+
);
84+
85+
// Method: Get a short version of the comment
86+
String shortComment() {
87+
if (comment.length <= 50) return comment;
88+
return comment.substring(0, 47) + "...";
89+
}
90+
91+
// Method: Get formatted date as string (e.g., "2024-05-22")
92+
String formattedDate() {
93+
return "${date.year}-${_twoDigits(date.month)}-${_twoDigits(date.day)}";
94+
}
95+
96+
String _twoDigits(int n) {
97+
return n >= 10 ? "$n" : "0$n";
98+
}
99+
100+
// Method: Check if review is positive (4 stars or more)
101+
bool isPositive() {
102+
return rating >= 4.0;
103+
}
104+
105+
// Method: Check if review is recent (within last 30 days)
106+
bool isRecent() {
107+
final now = DateTime.now();
108+
return now.difference(date).inDays <= 30;
109+
}
110+
111+
// Method: Mark this review as helpful
112+
void markHelpful() {
113+
helpfulCount += 1;
114+
}
115+
}
116+
```
117+
60118
## Create Class Instance
61119

62120
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:

0 commit comments

Comments
 (0)