0Pricing
Jetpack Compose Academy · درس

التحقق المضمّن وحالات الخطأ

قدّم ملاحظات فورية عند الإدخال غير الصحيح

التحقق المضمّن وحالات الخطأ درس مجاني في Jetpack Compose Academy على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Jetpack Compose Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Jetpack Compose Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Catch Mistakes Early

Great forms fix problems as the user types, not after they tap submit. Inline validation means instant, gentle feedback. ✅

Compute Validity from State

Derive an isError flag straight from the current value. When the email looks wrong, the flag turns true.

val isError = email.isNotEmpty() && !email.contains("@")

The isError Parameter

Pass that flag to the field's isError parameter. Compose then tints the border and label red to signal trouble.

OutlinedTextField(
    value = email,
    onValueChange = { email = it },
    isError = isError
)

Explain the Problem

A red border alone is vague. Use supportingText to spell out exactly what went wrong so the user can fix it.

supportingText = {
    if (isError) Text("Enter a valid email.")
}

Show Errors at the Right Time

Do not shout at an empty field. Validate only after the user has typed, so the error appears when it is actually useful.

Add an Error Icon

A trailingIcon reinforces the message. Swap in a warning icon when the field is in an error state.

trailingIcon = {
    if (isError) Icon(Icons.Default.Warning, "Error")
}

Validate Many Fields

Each field gets its own flag. Combine them to know whether the whole form is valid and ready to submit.

val formValid = emailValid && passwordValid

Gate the Submit Button

Tie the button's enabled flag to form validity. Users cannot submit until every field passes its check.

Button(onClick = ::submit, enabled = formValid) {
    Text("Sign Up")
}

Keep Messages Kind

Write error text that helps, not blames. Password too short beats Invalid input every single time.

Validation Is Just State

Notice the pattern: errors are plain values derived from state. No magic, just the same Compose model you already know.

Real Forms Feel Trustworthy

Clear, timely feedback builds trust. Users feel guided rather than tested, and they finish your forms with ease.

Quick Check

How do you turn a text field's border red to signal a problem?

Recap

You built inline validation: derive an error flag, set isError, explain it with supporting text, and gate submit on validity. Forms that feel great. 🌟

الأسئلة الشائعة

هل درس «التحقق المضمّن وحالات الخطأ» مجاني؟

نعم — نص درس «التحقق المضمّن وحالات الخطأ» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Jetpack Compose Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Jetpack Compose Academy 4 دروس في المجموع.

ماذا ستتعلم في «التحقق المضمّن وحالات الخطأ»؟

قدّم ملاحظات فورية عند الإدخال غير الصحيح تتمرن على Jetpack Compose Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Jetpack Compose Academy؟

لا تُشترط خبرة سابقة. Jetpack Compose Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.

كم من الوقت يستغرق درس «التحقق المضمّن وحالات الخطأ»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Jetpack Compose Academy هذا؟

نعم. كل درس في Jetpack Compose Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. ‏TextField وOutlinedTextField
  2. التسميات والعناصر النائبة والأيقونات البادئة
  3. أنواع لوحة المفاتيح وإجراءات IME
  4. التحقق المضمّن وحالات الخطأ
← العودة إلى Jetpack Compose Academy