Skip to content
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

ShadInputFormField readOnly Property Not Updating Dynamically #288

Open
DarkHeros09 opened this issue Feb 8, 2025 · 1 comment
Open
Assignees
Labels
accepted A valid and reproducible issue bug Something isn't working

Comments

@DarkHeros09
Copy link

Steps to reproduce

The readOnly property of ShadInputFormField does not update the UI when its value is changed dynamically. When toggling the readOnly boolean (e.g., via a button or state change), the input field does not reflect the new read-only state as expected.

Steps to Reproduce:

  1. Create a ShadInputFormField with a boolean readOnly value tied to a state variable (e.g., _isReadOnly).
  2. Add a button or switch to toggle the _isReadOnly value.
  3. Observe that the input field does not update its read-only state when the boolean changes.

Expected Behavior:
When readOnly is true, the input field should prevent text entry and appear disabled. When readOnly is false, it should allow text entry.

Actual Behavior:
The readOnly state does not update visually or functionally after the initial value is set.

Example Code:

import 'package:flutter/material.dart';
import 'package:shadcn_ui/shadcn_ui.dart';

class FormPage extends StatefulWidget {
  const FormPage({super.key});

  @override
  State<FormPage> createState() => _FormPageState();
}

class _FormPageState extends State<FormPage> {
  final formKey = GlobalKey<ShadFormState>();
  bool _isReadOnly = false; // State for readOnly toggle

  void _toggleReadOnly(bool value) {
    setState(() {
      _isReadOnly = value;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: ShadForm(
          key: formKey,
          child: ConstrainedBox(
            constraints: const BoxConstraints(maxWidth: 350),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisSize: MainAxisSize.min,
              children: [
                ShadInputFormField(
                  initialValue: 'initial text',
                  id: 'username',
                  label: const Text('Username'),
                  placeholder: const Text('Enter your username'),
                  description: const Text('This is your public display name.'),
                  readOnly: _isReadOnly, // Dynamic readOnly property
                  validator: (v) {
                    if (v.length < 2) {
                      return 'Username must be at least 2 characters.';
                    }
                    return null;
                  },
                ),
                const SizedBox(height: 16),
                // Toggle control for readOnly state
                Row(
                  children: [
                    const Text('Read Only:'),
                    Switch(
                      value: _isReadOnly,
                      onChanged: _toggleReadOnly,
                    ),
                  ],
                ),
                const SizedBox(height: 16),
                ShadButton(
                  child: const Text('Submit'),
                  onPressed: () {
                    if (formKey.currentState!.saveAndValidate()) {
                      print(
                          'Validation succeeded with ${formKey.currentState!.value}');
                    } else {
                      print('Validation failed');
                    }
                  },
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

Expected results

i should be able to edit the field.

Actual results

the field is not editable.

shadcn_ui version

0.18.7

Platform

Android

Code sample

Code sample
[Paste your code here]

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.27.3, on Microsoft Windows [Version 10.0.22631.4830], locale en-AE)
    • Flutter version 3.27.3 on channel stable at C:\Users\m_ben\.puro\envs\stable\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision c519ee916e (3 weeks ago), 2025-01-21 10:32:23 -0800
    • Engine revision e672b006cb
    • Dart version 3.6.1
    • DevTools version 2.40.2

[✓] Windows Version (Installed version of Windows is version 10 or higher)

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at C:\Program Files\Android SDK
    • Platform android-35, build-tools 33.0.1
    • ANDROID_SDK_ROOT = C:\Program Files\Android SDK\cmdline-tools\latest\bin
    • Java binary at: C:\Program Files\Zulu\zulu-19\bin\java.exe
    • Java version OpenJDK Runtime Environment Zulu19.30+11-CA (build 19.0.1+10)
    • All Android licenses accepted.

[✗] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.12.4)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.12.35707.178
    • Windows 10 SDK version 10.0.22621.0

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/to/windows-android-setup for detailed instructions).

[✓] VS Code (version 1.96.4)
    • VS Code at C:\Users\m_ben\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.102.0

[✓] Connected device (2 available)
    • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64 • Android 13 (API 33) (emulator)
    • Windows (desktop)            • windows       • windows-x64 • Microsoft Windows [Version 10.0.22631.4830]

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 2 categories.
@DarkHeros09 DarkHeros09 added bug Something isn't working triage Issues that need assessment and prioritization labels Feb 8, 2025
@DarkHeros09 DarkHeros09 changed the title ShadInputFormField readOnly` Property Not Updating Dynamically ShadInputFormField readOnly Property Not Updating Dynamically Feb 8, 2025
@nank1ro
Copy link
Owner

nank1ro commented Feb 8, 2025

Thanks for the detailed report, will fix it soon (Monday)

@nank1ro nank1ro added accepted A valid and reproducible issue and removed triage Issues that need assessment and prioritization labels Feb 8, 2025
@nank1ro nank1ro self-assigned this Feb 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted A valid and reproducible issue bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants