Created
June 6, 2022 06:20
-
-
Save nbnD/a70dfce31a0317472da642a0cef4b22e to your computer and use it in GitHub Desktop.
Alert Dialog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
class AlertItem extends StatefulWidget { | |
const AlertItem({Key? key}) : super(key: key); | |
@override | |
State<AlertItem> createState() => _AlertItemState(); | |
} | |
class _AlertItemState extends State<AlertItem> { | |
// Initial Selected Value | |
String dropdownvalue = 'Item 1'; | |
// List of items in our dropdown menu | |
var items = [ | |
'Item 1', | |
'Item 2', | |
'Item 3', | |
'Item 4', | |
'Item 5', | |
]; | |
@override | |
Widget build(BuildContext context) { | |
return Column( | |
mainAxisSize: MainAxisSize.min, | |
children: [ | |
DropdownButton( | |
// Initial Value | |
value: dropdownvalue, | |
// Down Arrow Icon | |
icon: const Icon(Icons.keyboard_arrow_down), | |
// Array list of items | |
items: items.map((String items) { | |
return DropdownMenuItem( | |
value: items, | |
child: Text(items), | |
); | |
}).toList(), | |
// After selecting the desired option,it will | |
// change button value to selected value | |
onChanged: (String? newValue) { | |
setState(() { | |
dropdownvalue = newValue!; | |
}); | |
}, | |
), | |
TextButton(onPressed: () { | |
Navigator.pop(context,dropdownvalue); | |
}, child: const Text("Ok")) | |
], | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment