Skip to content

Instantly share code, notes, and snippets.

@ngtrphuong
Created August 23, 2021 23:56
Show Gist options
  • Save ngtrphuong/03483c08ef16cf6347c37e6a7a53d4f1 to your computer and use it in GitHub Desktop.
Save ngtrphuong/03483c08ef16cf6347c37e6a7a53d4f1 to your computer and use it in GitHub Desktop.
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