I have some problem that I cannot solve, please help me. I want to fetch data from database, and this data is json list... I wrote some code but I could not print on the console... I will add the code below, please help me... I guess I have to use for loop but when I tried I can just fetch 1 data...
codes below here:
class DenemeParca extends StatefulWidget {
final String parcaReferans;
DenemeParca({this.parcaReferans});
@override
_DenemeParcaState createState() => _DenemeParcaState();
}
Future<List<dynamic>> getIhaleData() async {
final url =
'https://www.ekspar.com.tr/onarim/dart.php';
var response = await http.get(url);
return json.decode(response.body);
}
String _parcaReferans(dynamic user) {
for (var i = 8; i < 40; i++) {
return user['parca_adi']['$i'];
}
}
class _DenemeParcaState extends State<DenemeParca> {
Widget _buildBody() {
return FutureBuilder<List<dynamic>>(
future: getIhaleData(),
builder: (context, snapshot) {
return ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (context, index) {
return Container(
child: Column(
children: <Widget>[
RaisedButton(
onPressed: () async {
print(_parcaReferans(snapshot.data[index]));
},
child: Text('Get Data'),
),
],
),
);
},
);
},
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Title'),
),
body: _buildBody(),
);
}
}
void main() {
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Ekspar Demo',
theme: ThemeData(
backgroundColor: Colors.white,
),
home: DenemeParca()
),
);
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return DenemeParca();
}
}
by the way link has the json codes, thank you...