How To Set Up Dropdown Menu With Flutter Android App

admin_img Posted By Bajarangi soft , Posted On 23-09-2020

DropdownButton widget has a property named as value which is used to hold current drop down button list selected item.

Dropdown menu item in flutter app

Get Selected Item Value from Drop Down Menu Button in Flutter 

YOu can add This Dropdown Menu Code:
 DropdownButton(
  items: _dropdownValues
      .map((value) => DropdownMenuItem(
    child: Text(value),
    value: value,
  ))
      .toList(),
  onChanged: (String value) {},
  isExpanded: false,
  hint: Text('Select Item',style: TextStyle(
    fontSize: 30,
        color: Colors.black
  ),),
),

Complete Code For Dropdown Menu Widget:
Main.dart
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: DropDown()
    );
  }
}

class DropDown extends StatefulWidget {
  @override
  DropDownWidget createState() => DropDownWidget();
}

class DropDownWidget extends State {

  final List<String> _dropdownValues = [
    "Apple",
    "LG",
    "NOkic",
    "Samsung",
    "Moto"
  ]; //

  @override

  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        backgroundColor: Colors.black,
        title: Text('Select Item From DropDown'),
      ),
      body: Center(
        child: DropdownButton(
          items: _dropdownValues
              .map((value) => DropdownMenuItem(
            child: Text(value),
            value: value,
          ))
              .toList(),
          onChanged: (String value) {},
          isExpanded: false,
          hint: Text('Select Item',style: TextStyle(
            fontSize: 20,
                color: Colors.black
          ),),
        ),
      ),
    );
  }
}

Related Post