Drop Down In Flutter

Drop Down In Flutter :

Flutter DropDown Single Select

Screenshot :

Drop Down In Flutter

Program :

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() {
   runApp(new MaterialApp(
     debugShowCheckedModeBanner: false,
     home: new SignUpPage(),
   ));
 }
class SignUpPage extends StatefulWidget {
   @override
   _SignUpPageState createState() => _SignUpPageState();
 }
class _SignUpPageState extends State {
   final GlobalKey _key = new GlobalKey();

Gender selectedUser;
List genders = [
     const Gender(1, 'Male'),
     const Gender(2, 'Female')
   ];
BuildContext context;
   @override
   void initState() {
     super.initState();
     //selectedUser = genders[0];
   }
@override
   Widget build(BuildContext context) {
     this.context = context;
     return new Scaffold(
       body: new Form(
         child: ListView(
             physics: BouncingScrollPhysics(), children: [formUI()]),
       ),
     );
   }
@override
   void dispose() {
     if (this.mounted) super.dispose();
   }
Widget formUI() {
     return new Container(
       child: Stack(
         children: [
           Container(
             padding: EdgeInsets.symmetric(vertical: 5.0, horizontal: 30.0),
             child: DropdownButtonHideUnderline(
               child: new DropdownButton(
                 hint: new Text("Select gender"),
                 isDense: true,
                 value: selectedUser == null ? null : selectedUser,
                 onChanged: (Gender newValue) {
                   setState(() {
                     selectedUser = newValue;
                   });
                 },
                 items: genders.map((Gender user) {
                   return new DropdownMenuItem(
                     value: user,
                     child: selectedUser == null
                         ? new Text(
                             user.name,
                             style: new TextStyle(color: Colors.grey),
                           )
                         : selectedUser.name == user.name
                             ? new Text(
                                 user.name,
                                 style: new TextStyle(color: Colors.black),
                               )
                             : new Text(
                                 user.name,
                                 style: new TextStyle(color: Colors.grey),
                               ),
                   );
                 }).toList(),
               ),
             ),
           ),
         ],
       ),
     );
   }
 }

class Gender {
   const Gender(this.id, this.name);
final String name;
   final int id;
 }