Created
August 23, 2021 23:56
-
-
Save ngtrphuong/03483c08ef16cf6347c37e6a7a53d4f1 to your computer and use it in GitHub Desktop.
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'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: MyHomePage(), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
String dropdownvalue = 'Apple'; | |
var items = ['Apple','Banana','Grapes','Orange','watermelon','Pineapple']; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: const Text("DropDownList Example"), | |
), | |
body: Container( | |
decoration: BoxDecoration( | |
image: DecorationImage( | |
image: const NetworkImage( | |
"https://images.unsplash.com/photo-1579202673506-ca3ce28943ef" | |
), | |
fit: BoxFit.cover, | |
colorFilter: ColorFilter.mode( Colors.black.withOpacity(0.4), BlendMode.dstATop), | |
) | |
), | |
child: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
DropdownButton( | |
value: dropdownvalue, | |
icon: const Icon( | |
Icons.keyboard_arrow_down, | |
color: Colors.amber, | |
), | |
iconSize: 40, | |
underline: Container( | |
height: 1, | |
color: Colors.transparent, | |
), | |
items:items.map((String items) { | |
return DropdownMenuItem( | |
value: items, | |
child: Container( | |
width: double.infinity, | |
alignment: Alignment.center, | |
padding: const EdgeInsets.fromLTRB(0,8.0,0,6.0), | |
child: Text(items), | |
decoration: const BoxDecoration( | |
border: Border(top:BorderSide(color:Colors.grey,width:1)) | |
) | |
) | |
//child: Text(items) | |
); | |
} | |
).toList(), | |
onChanged: (String newValue){ setState(() { dropdownvalue = newValue; }); | |
}, | |
isExpanded: true, | |
isDense: true, | |
), | |
], | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment