← 返回 openai 的题目列表Android Jetpack Compose rating card with comment validation and submission state
类型:online_judge
Problem: Build a rating card in Android Jetpack Compose (Coding)
Implement a “rating + comment submission” card using Kotlin + Jetpack Compose.
UI & Interaction
The card must include:
A rating control (e.g., 1–5 stars).
A comment input (TextField).
A Submit button.
Validation rules
Submit is enabled only if:
A rating has been selected (e.g., 1–5).
The comment is non-empty after trimming whitespace.
Submission behavior & state
On submit:
Trigger submission logic (you may simulate a network call, e.g., 1s delay).
After success, show “Submitted successfully” inside the card.
Constraints
Must use Compose.
Compose has no built-in rating bar: implement your own rating component (e.g., clickable star icons or custom drawing).
Prefer using a ViewModel for state management.
Code should be clean and easy to read; minimal explanations.
Bounds
Rating range: 1–5 (fixed).
Comment should handle empty/whitespace-only input.
Acceptance examples
Initial: no rating + empty comment => Submit disabled.
Select 4 stars + comment "Great" => Submit enabled.
Comment becomes " " => Submit disabled.
Submit => optional loading => after 1s show success message.
Example
Input
(UI) 初始:rating=0, comment=""
Output
Submit disabled; no success message