Created
May 18, 2020 16:41
-
-
Save theindianappguy/d2a217b7521444e2c55fee0142d3bc48 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 'dart:convert'; | |
import 'package:flutter/material.dart'; | |
import 'package:http/http.dart' as http; | |
import 'package:wallpaper/data/data.dart'; | |
import 'package:wallpaper/models/photos_model.dart'; | |
import 'package:wallpaper/widget/widget.dart'; | |
class CategorieScreen extends StatefulWidget { | |
final String categorie; | |
CategorieScreen({@required this.categorie}); | |
@override | |
_CategorieScreenState createState() => _CategorieScreenState(); | |
} | |
class _CategorieScreenState extends State<CategorieScreen> { | |
List<PhotosModel> photos = new List(); | |
getCategorieWallpaper() async { | |
await http.get( | |
"https://api.pexels.com/v1/search?query=${widget.categorie}&per_page=30&page=1", | |
headers: {"Authorization": apiKEY}).then((value) { | |
//print(value.body); | |
Map<String, dynamic> jsonData = jsonDecode(value.body); | |
jsonData["photos"].forEach((element) { | |
//print(element); | |
PhotosModel photosModel = new PhotosModel(); | |
photosModel = PhotosModel.fromMap(element); | |
photos.add(photosModel); | |
//print(photosModel.toString()+ " "+ photosModel.src.portrait); | |
}); | |
setState(() {}); | |
}); | |
} | |
@override | |
void initState() { | |
getCategorieWallpaper(); | |
super.initState(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: brandName(), | |
elevation: 0.0, | |
actions: <Widget>[ | |
Container( | |
padding: EdgeInsets.symmetric(horizontal: 16), | |
child: Icon( | |
Icons.add, | |
color: Colors.white, | |
)) | |
], | |
), | |
body: SingleChildScrollView( | |
child: wallPaper(photos, context) | |
, | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment