Stacked-Org / stacked

A Flutter application architecture created from real world scenarios
MIT License
935 stars 256 forks source link

[bug]: Generated form with only drop down form fields has missing methods and multiple errors #1099

Open dankhan-helmet opened 2 months ago

dankhan-helmet commented 2 months ago

Describe the bug

When running stacked generate with a form consisting of only dropdown fields, the generated form.dart contains missing methods.

If you add these methods back from another generated form with some text fields, the methods are resolved. I think the current code must expect at least one TEXT form field before it adds the _updateFormData and validateForm methods in them.

FYI: My annotation definitions are:

@FormView(
  fields: [
    FormDropdownField(
      name: 'goal1Priority',
      items: AppGoal.all,
    ),
    FormDropdownField(
      name: 'goal2Priority',
      items: AppGoal.all,
    ),
    FormDropdownField(
      name: 'goal3Priority',
      items: AppGoal.all,
    ),
  ],
  autoTextFieldValidation: false,
)

With an AppGoal defined as:

class AppGoal {
  static const List<StaticDropdownItem> all = [
    StaticDropdownItem(title: '1st', value: '1'),
    StaticDropdownItem(title: '2nd', value: '2'),
    StaticDropdownItem(title: '3rd', value: '3'),
  ];
}

What operating system do you use?

macOS

Information about the installed tooling

[✓] Flutter (Channel stable, 3.19.2, on macOS 13.6.4 22G513 darwin-arm64, locale en-NZ)
    • Flutter version 3.19.2 on channel stable at /Users/dan/Library/CloudStorage/Dropbox/Development/Projects/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 7482962148 (8 weeks ago), 2024-02-27 16:51:22 -0500
    • Engine revision 04817c99c9
    • Dart version 3.3.0
    • DevTools version 2.31.1

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/dan/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /Users/dan/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15C500b
    • CocoaPods version 1.15.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)

[✓] VS Code (version 1.88.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.86.0

[✓] Connected device (3 available)
    • iPhone 15 Pro (mobile) • 5708553D-16CB-425E-852B-D3F752379C47 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-17-2 (simulator)
    • macOS (desktop)        • macos                                • darwin-arm64   • macOS 13.6.4 22G513 darwin-arm64
    • Chrome (web)           • chrome                               • web-javascript • Google Chrome 124.0.6367.61

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

• No issues found!

Steps to reproduce the issue

  1. create a new stacked view with the following annotations:
    
    @FormView(
    fields: [
    FormDropdownField(
      name: 'goal1Priority',
      items: AppGoal.all,
    ),
    FormDropdownField(
      name: 'goal2Priority',
      items: AppGoal.all,
    ),
    FormDropdownField(
      name: 'goal3Priority',
      items: AppGoal.all,
    ),
    ],
    autoTextFieldValidation: false,
    )

With AppGoal defined as:

class AppGoal { static const List all = [ StaticDropdownItem(title: '1st', value: '1'), StaticDropdownItem(title: '2nd', value: '2'), StaticDropdownItem(title: '3rd', value: '3'), ]; }



2. run stacked generate
3. note the generated form.dart contains the missing methods and are marked in the IDE with multiple errors.

### Expected behavior

No errors in generated file and methods present

### Screenshots

![CleanShot 2024-04-22 at 09 59 10](https://github.com/Stacked-Org/stacked/assets/150875245/e8fa4958-7e13-4e8b-bc64-c9f48abb0bb8)

![CleanShot 2024-04-22 at 09 59 27](https://github.com/Stacked-Org/stacked/assets/150875245/163ca1ea-b808-4512-b8a2-3133d9e7db18)

![CleanShot 2024-04-22 at 09 59 44](https://github.com/Stacked-Org/stacked/assets/150875245/751dad42-09ec-4788-845e-d56a121b9e4a)

### Additional Context

_No response_
FilledStacks commented 2 months ago

Hey @dankhan-helmet, thanks for filing this issue.

We kind of half removed the dropdown form functionality but I think this can be fixed for now by adding a FormTextField in there for now even if you don't use it.

Let me know if that workaround works, will add this to the list of fixes to make.