Skip to content

Instantly share code, notes, and snippets.

@rodrigordgfs
Last active June 26, 2019 00:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodrigordgfs/eac60d60ea3eb53d8d1e66476ae4d726 to your computer and use it in GitHub Desktop.
Save rodrigordgfs/eac60d60ea3eb53d8d1e66476ae4d726 to your computer and use it in GitHub Desktop.
Mostrar dados da api
Future<Map<String, dynamic>> _fetchCategoriesPreview() async {
http.Response response =
await http.get(Uri.encodeFull(UtilsURL.CATEGORIES_PREVIEW), headers: {
"Authorization": 'Token 9dcc473d8e65ccdd6440e03f0622642b11acbbbd',
"Accept": "application/json"
});
if (response.statusCode == 200) {
// return json.decode(response.body);
return json.decode(response.body[3]);
} else {
throw Exception('Erro: ' + response.statusCode.toString());
}
}
Widget _sliverGridCategory() {
return FutureBuilder<Map<String, dynamic>>(
future: _fetchCategoriesPreview(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return SliverList(
delegate: SliverChildListDelegate([
Center(
child: CircularProgressIndicator(),
)
]));
} else {
return SliverGrid(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
mainAxisSpacing: 4.0,
childAspectRatio: 1.0,
crossAxisSpacing: 4.0),
delegate:
SliverChildBuilderDelegate((BuildContext context, int index) {
return InkWell(
onTap: () {
//Navigator.of(context).push(MaterialPageRoute(
// builder: (context) => CategoriesActivity(categoryData, snapshot)));
},
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0)),
child: ClipRRect(
borderRadius: BorderRadius.circular(20.0),
child: Stack(
alignment: Alignment.bottomCenter,
children: <Widget>[
AspectRatio(
aspectRatio: 1.0,
child: Image.network(
snapshot.data['imagem'],
fit: BoxFit.cover,
)),
Container(
height: 25.0,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
color: Color.fromARGB(180, 0, 0, 0)),
child: Padding(
padding: EdgeInsets.symmetric(vertical: 4.0),
child: Text(
snapshot.data['results']['titulo'],
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.w700,
color: Colors.white),
),
),
),
],
),
)),
);
}, childCount: snapshot.data.length),
);
}
},
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment