reactive_dropdown_button2 0.0.3-beta.10 copy "reactive_dropdown_button2: ^0.0.3-beta.10" to clipboard
reactive_dropdown_button2: ^0.0.3-beta.10 copied to clipboard

Wrapper around dropdown_button2 to use with reactive_forms.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:reactive_dropdown_button2/reactive_dropdown_button2.dart';
import 'package:reactive_forms/reactive_forms.dart';

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

final List<String> items = [
  'Item1',
  'Item2',
  'Item3',
  'Item4',
  'Item5',
  'Item6',
  'Item7',
  'Item8',
];

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  FormGroup buildForm() => fb.group({
        'input': FormControl<String>(
          value: null,
          validators: [
            const RequiredValidator(),
          ],
        ),
      });

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: Scaffold(
        appBar: AppBar(),
        body: SafeArea(
          child: SingleChildScrollView(
            physics: const BouncingScrollPhysics(),
            padding: const EdgeInsets.symmetric(
              horizontal: 20.0,
              vertical: 20.0,
            ),
            child: ReactiveFormBuilder(
              form: buildForm,
              builder: (context, form, child) {
                return Column(
                  children: [
                    const Text('Test'),
                    const SizedBox(height: 16),
                    DropdownButtonHideUnderline(
                      child: ReactiveDropdownButton2<String, String>(
                        formControlName: 'input',
                        isExpanded: true,
                        items: items
                            .map(
                              (String item) => DropdownItem<String>(
                                value: item,
                                child: Text(item),
                              ),
                            )
                            .toList(),
                        buttonStyleData: ButtonStyleData(
                          height: 50,
                          width: 160,
                          padding: const EdgeInsets.only(left: 14, right: 14),
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(14),
                            border: Border.all(
                              color: Colors.black26,
                            ),
                            color: Colors.redAccent,
                          ),
                          elevation: 2,
                        ),

                        iconStyleData: const IconStyleData(
                          icon: Icon(
                            Icons.arrow_forward_ios_outlined,
                          ),
                          iconSize: 14,
                          iconEnabledColor: Colors.yellow,
                          iconDisabledColor: Colors.grey,
                        ),
                        dropdownStyleData: DropdownStyleData(
                          maxHeight: 200,
                          width: 200,
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(14),
                            color: Colors.redAccent,
                          ),
                          offset: const Offset(-20, 0),
                          scrollbarTheme: ScrollbarThemeData(
                            radius: const Radius.circular(40),
                            thickness: MaterialStateProperty.all(6),
                            thumbVisibility: MaterialStateProperty.all(true),
                          ),
                        ),
                        menuItemStyleData: const MenuItemStyleData(
                          padding: EdgeInsets.only(left: 14, right: 14),
                        ),
                      ),
                    ),
                    ElevatedButton(
                      child: const Text('Submit'),
                      onPressed: () {
                        if (form.valid) {
                          debugPrint(form.value.toString());
                        }
                      },
                    ),
                  ],
                );
              },
            ),
          ),
        ),
      ),
    );
  }
}
1
likes
0
pub points
58%
popularity

Publisher

unverified uploader

Wrapper around dropdown_button2 to use with reactive_forms.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

dropdown_button2, flutter, reactive_forms

More

Packages that depend on reactive_dropdown_button2