flutter-form-builder-ecosystem / form_builder_file_picker

File picker field widget for FlutterFormBuilder.
https://pub.dev/packages/form_builder_file_picker
BSD 3-Clause "New" or "Revised" License
15 stars 33 forks source link

General: Creating Multiple Duplicate Fields #66

Open holy-dev opened 1 year ago

holy-dev commented 1 year ago

Is there an existing issue for this?

Package/Plugin version

4.0.0

Platforms

Flutter doctor

Flutter doctor ```bash [✓] Flutter (Channel stable, 3.10.5, on macOS 13.4 22F66 darwin-arm64, locale en-IN) • Flutter version 3.10.5 on channel stable at /Users/bijoy/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 796c8ef792 (4 weeks ago), 2023-06-13 15:51:02 -0700 • Engine revision 45f6e00911 • Dart version 3.0.5 • DevTools version 2.23.1 [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0) • Android SDK at /Users/bijoy/Library/Android/sdk • Platform android-33, build-tools 33.0.0 • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 14.3.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 14E300c • CocoaPods version 1.11.3 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2021.2) • 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 11.0.12+0-b1504.28-7817840) [✓] VS Code (version 1.79.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.68.0 [✓] Connected device (4 available) • SM G990E (mobile) • RZCW118D1XK • android-arm64 • Android 13 (API 33) • iPhone 14 Pro Max (mobile) • FE3A0644-69E3-4FE0-AA3B-A62AEA82C982 • ios • com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator) • macOS (desktop) • macos • darwin-arm64 • macOS 13.4 22F66 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 114.0.5735.198 [✓] Network resources • All expected network resources are available. • No issues found! ```

Minimal code example

Code sample ```dart import 'package:flutter/material.dart'; import 'package:flutter_form_builder/flutter_form_builder.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), useMaterial3: true, ), home: const MyHomePage(), ); } } class MyHomePage extends StatefulWidget { const MyHomePage({super.key}); @override State createState() => _MyHomePageState(); } class _MyHomePageState extends State { final _formKey = GlobalKey(); @override Widget build(BuildContext context) { return Scaffold( body: Center( child: Column( children: [ FormBuilderFilePicker( name: "doc", maxFiles: 2, previewImages: true, onChanged: (val) => print(val), decoration: const InputDecoration( border: InputBorder.none, ), typeSelectors: const [ TypeSelector( type: FileType.media, selector: Row( children: [ Icon( Icons.add_circle, color: Colors.white, ), Padding( padding: EdgeInsets.only(left: 8.0), child: Text( "Add Passport Copy", style: TextStyle( color: Colors.white, ), ), ), ], ), ), ], validator: FormBuilderValidators.compose([ FormBuilderValidators.required(), ]), onFileLoading: (val) { print(val); }, ), ], ), ), ); } } ```

Current Behavior

Automatically creating multiple duplicate fields

Screenshot_20230710_111700

Expected Behavior

Not create duplicate fields

Steps To Reproduce

Just add file picker field in a formbuilder

Aditional information

No response

deandreamatias commented 1 year ago

Hi! Where is the file picker field in example code? Please add a complete example code

holy-dev commented 1 year ago
import 'package:flutter/material.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(),
    );
  }
}

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

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final _formKey = GlobalKey<FormBuilderState>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          children: [
            FormBuilderFilePicker(
              name: "doc",
              maxFiles: 2,
              previewImages: true,
              onChanged: (val) => print(val),
              decoration: const InputDecoration(
                border: InputBorder.none,
              ),
              typeSelectors: const [
                TypeSelector(
                  type: FileType.media,
                  selector: Row(
                    children: <Widget>[
                      Icon(
                        Icons.add_circle,
                        color: Colors.white,
                      ),
                      Padding(
                        padding: EdgeInsets.only(left: 8.0),
                        child: Text(
                          "Add Passport Copy",
                          style: TextStyle(
                            color: Colors.white,
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ],
              validator: FormBuilderValidators.compose([
                FormBuilderValidators.required(),
              ]),
              onFileLoading: (val) {
                print(val);
              },
            ),
          ],
        ),
      ),
    );
  }
}
holy-dev commented 1 year ago

@deandreamatias Please check I've updated