Created
June 26, 2019 03:00
-
-
Save rodrigordgfs/c67f469053757a193649a96b84face5c to your computer and use it in GitHub Desktop.
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
Future<Category> _fetchCategoriesPreview() async { | |
http.Response response = | |
await http.get(Uri.encodeFull(UtilsURL.CATEGORIES_PREVIEW), headers: { | |
"Authorization": 'Token 9dcc473d8e65ccdd6440e03f0622642b11acbbbd', | |
"Accept": "application/json", | |
"Content-Type": "text/html; charset=utf-8" | |
}); | |
if (response.statusCode == 200) { | |
return Category.fromJson(json.decode(response.body)); | |
} else { | |
throw Exception('Erro: ' + response.statusCode.toString()); | |
} | |
} | |
Widget _sliverGridCategory() { | |
return FutureBuilder<Category>( | |
future: _fetchCategoriesPreview(), | |
builder: (BuildContext context, AsyncSnapshot 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.results[index].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[index].titulo, | |
textAlign: TextAlign.center, | |
style: TextStyle( | |
fontWeight: FontWeight.w700, | |
color: Colors.white), | |
), | |
), | |
), | |
], | |
), | |
)), | |
); | |
}, childCount: snapshot.data.results.length), | |
); | |
} | |
}, | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment