Advertisement
fahimkamal63

Drop down menu Flutter - 2

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