Map future list flutter

Gopal Jangid

unread,
Jun 25, 2019, 3:12:04 PM6/25/19
to Flutter Development (flutter-dev)
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 {
String _mySelection;
List _myJson = [{"id":0,"name":""},{"id":1,"name":"Test Practice"}];

Future> 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>(
future: getData(),
builder: (context,snapshot){
if(snapshot.hasError) print(snapshot.error);
if(snapshot.hasData){
return new DropdownButton(
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(
value: map["cunm"].toString(),
child: new Text(
map["cunm"],
),
);
}).toList(),
);
}else{
return new CircularProgressIndicator();
}
},
),
),
);
}
}