AhmedLSayed9 / dropdown_button2

Flutter's core Dropdown Button widget with steady dropdown menu and many other features.
https://pub.dev/packages/dropdown_button2
MIT License
268 stars 122 forks source link

`DropdownButtonFormField2` doesn't hide its underline. #241

Open rirjkl19 opened 7 months ago

rirjkl19 commented 7 months ago

Consider the code below:

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

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

  @override
  Widget build(BuildContext context) {
    return DropdownButtonHideUnderline(
      child: DropdownButtonFormField2(
        hint: const Text('Items'),
        value: null,
        items: const [
          DropdownMenuItem(
            value: 'item1',
            child: Text('item1'),
          ),
          DropdownMenuItem(
            value: 'item2',
            child: Text('item2'),
          ),
          DropdownMenuItem(
            value: 'item2',
            child: Text('item2'),
          ),

        ],
        onChanged: (val) {},
      ),
    );
  }
}

Was expecting that the Underline inside the DropdownButtonFormField2 would be hidden just like in the DropdownButtonField2.

I also noticed that DropdownButton2 has an option to have underline widget which I could just put SizedBox() inside which solves the problem without having a parent of DropdownButtonHideUnderline eliminating unnecessary widget nesting.

Can someone help me on this?

jaydip-pawar commented 6 months ago

As you are using DropdownButtonFormField2 you can simply hide the underline by adding InputDecoration,.

DropdownButtonFormField2<String>(
    decoration: InputDecoration(
        border: OutlineInputBorder(
            borderSide: BorderSide.none,
        ),
    ),
)

just add above code in your DropdownButtonFormField2