Skip to content

Instantly share code, notes, and snippets.

@figengungor
Created January 11, 2019 12:06
Show Gist options
  • Save figengungor/446be330f5d34eb43ce6997feaf3b1ad to your computer and use it in GitHub Desktop.
Save figengungor/446be330f5d34eb43ce6997feaf3b1ad to your computer and use it in GitHub Desktop.
DropdownButtonFormField Empty State Issue
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'DropdownButtonFormField',
theme: ThemeData(
primarySwatch: Colors.blue,
),
routes: {
'/': (context) => HomePage(),
},
);
}
}
class HomePage extends StatefulWidget {
@override
HomePageState createState() {
return new HomePageState();
}
}
class HomePageState extends State<HomePage> {
String _selected;
List<String> items;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Home'),
),
body: Column(
children: <Widget>[
DropdownButtonFormField<String>(
items: items == null
? []
: items
.map(
(String item) => DropdownMenuItem<String>(
child: Text(item),
value: item,
),
)
.toList(),
value: _selected,
onChanged: items == null
? null
: (String value) {
setState(() {
_selected = value;
});
},
),
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment