Skip to content

Instantly share code, notes, and snippets.

@theindianappguy
Created May 18, 2020 16:41
Show Gist options
  • Save theindianappguy/d2a217b7521444e2c55fee0142d3bc48 to your computer and use it in GitHub Desktop.
Save theindianappguy/d2a217b7521444e2c55fee0142d3bc48 to your computer and use it in GitHub Desktop.
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