Skip to content

Instantly share code, notes, and snippets.

@felagund18 felagund18/item.dart
Last active Jul 23, 2018

Embed
What would you like to do?
Pass data to StatelessWidget
import 'package:flutter/material.dart';
class Item extends StatelessWidget {
Item({Key key, this.param}) : super(key: key);
final Map param;
@override
Widget build(BuildContext context) {
return Container(
child: new Column(
children: [
new Text(param['name']),
new Text(param['email']),
],
),
);
}
}
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
List data = [];
@override
initState() {
super.initState();
http.get('https://api.androidhive.info/contacts/').then((response) {
setState(() {
data = json.decode(response.body);
});
});
}
@override
Widget build(BuildContext context) {
return new MaterialApp(
theme: new ThemeData(
primarySwatch: Colors.blueGrey,
),
home: new Scaffold(
body: new Column(
children: [
new Item(param: data[0]),
new Item(param: data[1]),
new Item(param: data[2]),
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.