Last active
March 1, 2021 09:28
-
-
Save felagund18/4ea58e1b4d6646797e866d1c583ca1b0 to your computer and use it in GitHub Desktop.
Pass data to StatelessWidget
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']), | |
], | |
), | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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