The whole code is pasted below please help.
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
void main(){
runApp(
new MaterialApp(
title: 'app',
home: new Home(),
)
);
}
class Home extends StatefulWidget {
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
String _mySelection;
List<Map> _myJson = [{"id":0,"name":"<New>"},{"id":1,"name":"Test Practice"}];
Future<List<Map>> getData() async{
http.Response response = await http.get('http://192.168.0.6/php/mssql_connection/get_username.php');
print(response.body.toString());
return json.decode(response.body);
}
@override
Widget build(BuildContext context) {
return new Scaffold(
body: new Center(
child: new FutureBuilder<List<Map>>(
future: getData(),
builder: (context,snapshot){
if(snapshot.hasError) print(snapshot.error);
if(snapshot.hasData){
return new DropdownButton<String>(
isDense: true,
hint: new Text("Select"),
value: _mySelection,
onChanged: (String newValue) {
setState(() {
_mySelection = newValue;
});
print (_mySelection);
},
items: snapshot.data.map((Map map) {
return new DropdownMenuItem<String>(
value: map["cunm"].toString(),
child: new Text(
map["cunm"],
),
);
}).toList(),
);
}else{
return new CircularProgressIndicator();
}
},
),
),
);
}
}