How To Implement Flutter Dropdown Remove Underline

flutter dropdown remove underline

Flutter dropdown remove underline implementation. In this post, I will be implementing Flutter dropdown remove underline using an easy example so you can also implement and remove the underline from your Flutter dropdown easily. I will be using a proper Flutter example code for demonstration. Let’s jump directly into implementing Flutter dropdown remove underline.

What is Flutter Dropdown Remove Underline?

Flutter dropdown remove underline, as the names suggests, it is removing the underline border from the Flutter dropdown button. Flutter dropdown is used to select from a list of items like we have a list of categories in our Flutter dropdown and we can select anyone of those categories. Let’s now implement Flutter dropdown remove underline using a proper Flutter example.

Simple Flutter Dropdown

Let’s see the default style of Flutter dropdown button. For that we have to define our simple Flutter dropdown. See the below steps:

DropdownButton(
            isExpanded: true,
            hint: Text('Select sports category',
                style: TextStyle(fontSize: 15, color: Colors.black45)),
            value: categoryValue,
            items: [
              DropdownMenuItem(
                  value: 'Football',
                  child: Text('Football',
                      style: TextStyle(fontSize: 15, color: Colors.black45))),
              DropdownMenuItem(
                  value: 'Volleyball',
                  child: Text('Volleyball',
                      style: TextStyle(fontSize: 15, color: Colors.black45))),
              DropdownMenuItem(
                  value: 'Basketball',
                  child: Text('Basketball',
                      style: TextStyle(fontSize: 15, color: Colors.black45))),
            ],
            onChanged: (val) {
              setState(() {
                categoryValue = val.toString();
              });
            }),
flutter dropdown style
In the above code, you can see that I have used a simple Flutter dropdown. I have used hint text to show a default text when no option is selected. I have used a string variable to store the value of selected option using the on changed constructor. I have used three Flutter dropdown menu items and have given them above mentioned values. The value constructor will show the selected option value in Flutter dropdown so I have passed the string variable to that constructor in which the selected option value will be stored.
Now as you can see that the default Flutter dropdown underline is shown. Let’s now see how to remove that underline from our dropdown.

Removing Flutter Dropdown Underline

To remove the underline from Flutter dropdown, we have to wrap the Flutter dropdown widget with drop down button hide underline widget class. Let’s see the below code:

DropdownButtonHideUnderline(
          child: DropdownButton()
                           )
flutter dropdown remove underline
I have just used the drop down button class name and wrap it with drop down hide underline class to avoid bulkiness of code. In the image above, you can see that the Flutter dropdown remove underline is implemented successfully. We can’t see any underline under our Flutter dropdown button which satisfies the reason for which you are reading this post.
So in this way, we can remove the underline from our Flutter dropdown button. Hope you now have complete practical understanding of how to implement Flutter dropdown remove underline. If you have any queries regarding the removal of underline from Flutter dropdown then you can comment it down. I would love to answer it.
Now as a treat, I have designed a beautiful custom Flutter dropdown design for you in which Flutter dropdown remove underline is also implemented. The complete source code is available in the next section.

Custom Flutter Dropdown Design Source Code

flutter dropdown remove underline

import 'package:flutter/material.dart';
void main() {
  runApp(MyApp());
}
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Homepage(),
    );
  }
}
class Homepage extends StatefulWidget {
  @override
  State<Homepage> createState() => _HomepageState();
}
class _HomepageState extends State<Homepage> {
  String? categoryValue;
  @override
  Widget build(BuildContext context) {
    return SafeArea(
        child: Scaffold(
      body: Center(
          child: Padding(
        padding: EdgeInsets.symmetric(horizontal: 40),
        child: Container(
          width: double.infinity,
          height: 55,
          padding: EdgeInsets.symmetric(horizontal: 10),
          decoration: BoxDecoration(
              color: Colors.blue.shade100,
              borderRadius: BorderRadius.only(
                  topLeft: Radius.circular(30),
                  bottomRight: Radius.circular(30))),
          child: DropdownButtonHideUnderline(
            child: DropdownButton(
                isExpanded: true,
                hint: Text('Select sports category',
                    style: TextStyle(fontSize: 15, color: Colors.white)),
                value: categoryValue,
                items: [
                  DropdownMenuItem(
                      value: 'Football',
                      child: Text('Football',
                          style:
                              TextStyle(fontSize: 15, color: Colors.black45))),
                  DropdownMenuItem(
                      value: 'Volleyball',
                      child: Text('Volleyball',
                          style:
                              TextStyle(fontSize: 15, color: Colors.black45))),
                  DropdownMenuItem(
                      value: 'Basketball',
                      child: Text('Basketball',
                          style:
                              TextStyle(fontSize: 15, color: Colors.black45))),
                ],
                onChanged: (val) {
                  setState(() {
                    categoryValue = val.toString();
                  });
                }),
          ),
        ),
      )),
    ));
  }
}

Conclusion

In conclusion, now you have a detailed understanding of how to implemented Flutter dropdown remove underline. I would love to hear your thoughts on this post. I would also encourage you to visit my other amazing posts on Flutter app development, Flutter widgets, Flutter animations, beautiful Flutter templates and many more, links to some of these posts are listed below. Thanks for reading this post.

Leave a Comment

Your email address will not be published.