Last active
February 6, 2020 00:16
-
-
Save maheshj01/7818b6ff4109fe3008309fbda7fc1e34 to your computer and use it in GitHub Desktop.
dropdown in flutter
This file contains hidden or 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'; | |
final Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue), | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: Center( | |
child: MyWidget(), | |
), | |
), | |
); | |
} | |
} | |
class MyWidget extends StatefulWidget { | |
@override | |
_MyWidgetState createState() => _MyWidgetState(); | |
} | |
class _MyWidgetState extends State<MyWidget> { | |
var currentSelectedValue; | |
final deviceTypes = ["Mac", "Windows", "Mobile"]; | |
Widget typeFieldWidget() { | |
return Container( | |
padding: EdgeInsets.symmetric(horizontal: 20), | |
child: FormField<String>( | |
builder: (FormFieldState<String> state) { | |
return InputDecorator( | |
decoration: InputDecoration( | |
border: OutlineInputBorder( | |
borderRadius: BorderRadius.circular(5.0))), | |
child: DropdownButtonHideUnderline( | |
child: DropdownButton<String>( | |
hint: Text("Select Device"), | |
value: currentSelectedValue, | |
isDense: true, | |
onChanged: (newValue) { | |
setState(() { | |
currentSelectedValue = newValue; | |
}); | |
print(currentSelectedValue); | |
}, | |
items: deviceTypes.map((String value) { | |
return DropdownMenuItem<String>( | |
value: value, | |
child: Text(value), | |
); | |
}).toList(), | |
), | |
), | |
); | |
}, | |
), | |
); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body:Center( | |
child: typeFieldWidget(), | |
)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment