Skip to content

Instantly share code, notes, and snippets.

@felagund18
Last active March 1, 2021 09:28
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felagund18/4ea58e1b4d6646797e866d1c583ca1b0 to your computer and use it in GitHub Desktop.
Save felagund18/4ea58e1b4d6646797e866d1c583ca1b0 to your computer and use it in GitHub Desktop.
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