Advertisement
fahimkamal63

Drop down menu Flutter

Dec 9th, 2021
1,145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.53 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:tt/time_and_date_picker.dart';
  3.  
  4. class DropDownBtn extends StatefulWidget {
  5.   const DropDownBtn({Key? key}) : super(key: key);
  6.  
  7.   @override
  8.   _DropDownBtnState createState() => _DropDownBtnState();
  9. }
  10.  
  11. class _DropDownBtnState extends State<DropDownBtn> {
  12.   String dropdownValue = 'One';
  13.   List<String> dropdownItem = ['One', 'Two', 'Three', 'Four'];
  14.  
  15.   @override
  16.   Widget build(BuildContext context) {
  17.     return Scaffold(
  18.       appBar: AppBar(
  19.         title: Text("Dropdown Button"),
  20.         centerTitle: true,
  21.       ),
  22.       body: Container(
  23.         padding: EdgeInsets.all(10),
  24.         margin: EdgeInsets.all(10),
  25.         width: MediaQuery.of(context).size.width,
  26.         color: Colors.white,
  27.         child: DropdownButtonHideUnderline(
  28.           child: DropdownButton<String>(
  29.               value: dropdownValue,
  30.               onChanged: (value){
  31.                 setState(() {
  32.                   dropdownValue = value!;
  33.                 });
  34.               },
  35.               onTap: (){
  36.                 // Navigator.push(context, MaterialPageRoute(builder: (builder) => DateAndTimePicker()));
  37.               },
  38.               items: dropdownItem.map((String selectNumber) {
  39.                 return DropdownMenuItem(
  40.                     value: selectNumber,
  41.                     child: Text(
  42.                       selectNumber,
  43.                       style: TextStyle(color: Colors.amber),
  44.                     ));
  45.               }).toList()),
  46.         ),
  47.       ),
  48.     );
  49.   }
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement