Skip to content

Commit

Permalink
Merge pull request #9 from AmarjitM13/add_button
Browse files Browse the repository at this point in the history
added set as wallpaper button #2
  • Loading branch information
shibam-naskar committed Feb 1, 2022
2 parents 50dc00b + f28372a commit 079f97a
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 109 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -44,3 +44,6 @@ app.*.map.json
/android/app/debug
/android/app/profile
/android/app/release

#API-Key
lib/api_key.dart
154 changes: 73 additions & 81 deletions lib/pages/home.dart
Expand Up @@ -4,6 +4,8 @@ import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:wally/pages/singleImage.dart';

import '../api_key.dart';

class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);

Expand All @@ -13,103 +15,93 @@ class HomePage extends StatefulWidget {

class _HomePageState extends State<HomePage> {
var photos = [];
TextEditingController query =TextEditingController();
TextEditingController query = TextEditingController();

@override
void initState() {
// TODO: implement initState
super.initState();
getPhotos("");
}

void getPhotos(searchQuery) async {
var head = {"Authorization": apiKey}; //TODO: replace apiKey with your own API key
var url = Uri.parse(searchQuery == ""
? 'https://api.pexels.com/v1/curated?per_page=30'
: "https://api.pexels.com/v1/search?query=$searchQuery&per_page=40");
var response = await http.get(url, headers: head);
var data = jsonDecode(response.body);
setState(() {
photos = data['photos'];
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
alignment: Alignment.topCenter,
children: <Widget>[



//body images
SingleChildScrollView(
child: Column(children: [
SizedBox(height: 10,),
Padding(
padding: const EdgeInsets.only(right: 5, left: 5),
child: Container(
height: MediaQuery.of(context).size.height * 1,
child: GridView.count(
crossAxisCount: 2,
crossAxisSpacing: 5.0,
mainAxisSpacing: 5.0,
childAspectRatio: (200 / 400),
children: List.generate(photos.length, (index) {
return InkWell(
onTap: (){
Navigator.of(context).push(MaterialPageRoute(builder: (context)=>SingleImageView(data: photos[index])));
},
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Image.network(
photos[index]['src']['medium'],
fit: BoxFit.cover,
body: Stack(
alignment: Alignment.topCenter,
children: <Widget>[
//body images
SingleChildScrollView(
child: Column(children: [
const SizedBox(
height: 10,
),
Padding(
padding: const EdgeInsets.only(right: 5, left: 5),
child: SizedBox(
height: MediaQuery.of(context).size.height * 1,
child: GridView.count(
crossAxisCount: 2,
crossAxisSpacing: 5.0,
mainAxisSpacing: 5.0,
childAspectRatio: (200 / 400),
children: List.generate(photos.length, (index) {
return InkWell(
onTap: () {
Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => SingleImageView(data: photos[index])));
},
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Image.network(
photos[index]['src']['medium'],
fit: BoxFit.cover,
),
),
),
);
}),
);
}),
),
),
),
)
]),
),
)
]),
),


Padding(
padding: const EdgeInsets.only(right: 15, left: 15, bottom: 5,top: 45),
child: TextField(
controller: query,
onChanged: ((e)=>{
print(e)
}),
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
prefixIcon: Icon(
Icons.search_rounded,
color: Colors.grey,
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(15.0),
borderSide: BorderSide(
width: 0,
style: BorderStyle.none,
),
Padding(
padding: const EdgeInsets.only(right: 15, left: 15, bottom: 5, top: 45),
child: TextField(
controller: query,
onChanged: ((e) => {debugPrint(e)}),
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
prefixIcon: const Icon(
Icons.search_rounded,
color: Colors.grey,
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(15.0),
borderSide: const BorderSide(
width: 0,
style: BorderStyle.none,
),
hintText: 'Search Wallpapers here',
),
hintText: 'Search Wallpapers here',
),
),
],
));
}

void getPhotos(searchQuery) async {
var head = {
"Authorization":
"YOUR PIXELS API KEY"
};
var url = Uri.parse(searchQuery==""?
'https://api.pexels.com/v1/curated?per_page=30'
:"https://api.pexels.com/v1/search?query=${searchQuery}&per_page=40");
var response = await http.get(url, headers: head);
var data = jsonDecode(response.body);
setState(() {
photos = data['photos'];
});
print(data);
),
],
),
);
}
}



124 changes: 97 additions & 27 deletions lib/pages/singleImage.dart
@@ -1,10 +1,8 @@
// ignore_for_file: file_names

import 'package:flutter/material.dart';

class SingleImageView extends StatefulWidget {
final data;
const SingleImageView({ Key? key,required this.data }) : super(key: key);
const SingleImageView({Key? key, required this.data}) : super(key: key);

@override
_SingleImageViewState createState() => _SingleImageViewState();
Expand All @@ -14,32 +12,104 @@ class _SingleImageViewState extends State<SingleImageView> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: Image.network(
widget.data['src']['original'],
fit: BoxFit.cover,
loadingBuilder: (BuildContext context, Widget child,
ImageChunkEvent? loadingProgress) {
if (loadingProgress == null) return child;
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircularProgressIndicator(
value: loadingProgress.expectedTotalBytes != null
? loadingProgress.cumulativeBytesLoaded /
loadingProgress.expectedTotalBytes!
: null,
body: Stack(
alignment: Alignment.bottomCenter,
children: [
SizedBox(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: Image.network(
widget.data['src']['original'],
fit: BoxFit.cover,
loadingBuilder: (BuildContext context, Widget child, ImageChunkEvent? loadingProgress) {
if (loadingProgress == null) return child;
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircularProgressIndicator(
value: loadingProgress.expectedTotalBytes != null
? loadingProgress.cumulativeBytesLoaded / loadingProgress.expectedTotalBytes!
: null,
),
const SizedBox(
height: 10,
),
const Text("Loading wallpaper..."),
],
),
);
},
),
),
SizedBox(
width: double.infinity,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 10),
child: TextButton(
style: TextButton.styleFrom(
backgroundColor: Colors.white,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(5)),
),
),
child: const Padding(
padding: EdgeInsets.symmetric(vertical: 8),
child: Text(
'Set as Wallpaper',
style: TextStyle(
fontSize: 16,
color: Colors.blue,
fontWeight: FontWeight.bold,
),
),
),
onPressed: () async {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('Set As Home Screen'),
actions: [
TextButton(
style: TextButton.styleFrom(
backgroundColor: Colors.white,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(5)),
),
),
onPressed: () {
Navigator.pop(context);
},
child: const Text('CANCEL'),
),
TextButton(
style: TextButton.styleFrom(
backgroundColor: Colors.blue,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(5)),
),
),
onPressed: () {
Navigator.pop(context);
},
child: const Text(
'OK',
style: TextStyle(
color: Colors.white,
),
),
),
SizedBox(height: 10,),
Text("Loading wallpaper...")
],
)
);}
),
);
},
);
},
),
),
)
],
),
);
}
}
}
2 changes: 1 addition & 1 deletion pubspec.lock
Expand Up @@ -176,6 +176,6 @@ packages:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
version: "2.1.1"
sdks:
dart: ">=2.15.0-116.0.dev <3.0.0"

0 comments on commit 079f97a

Please sign in to comment.