Skip to content

Commit

Permalink
added photo functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
favandervlist authored and favandervlist committed Apr 16, 2020
1 parent b3dba91 commit 5772b22
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ApiData{
getCategories() async{
/// Get data using the endpoint
if(!getCategoriesRun){
categories = await wc.getAsync("products/categories?hide_empty=true&per_page=100&order=desc&orderby=count");
categories = await wc.getAsync("products/categories?hide_empty=true&per_page=60&order=desc&orderby=count");
getCategoriesRun = true;
return categories;
} else {
Expand Down
31 changes: 22 additions & 9 deletions lib/holidayinfo.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:ui';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'api.dart';
Expand All @@ -11,6 +10,7 @@ import 'SizeConfig.dart';
class HolidayInfo extends StatelessWidget {
static ApiData api = new ApiData();
int id;
List<Widget> imageWidgetList = new List<Widget>();

//constructor for id
HolidayInfo(id) {
Expand All @@ -22,6 +22,18 @@ class HolidayInfo extends StatelessWidget {
return htmlText.replaceAll(exp, '');
}

void addImages(AsyncSnapshot s){
for(int i = s.data["images"].length - 1; i >= 0; i--){
imageWidgetList.add(Image.network(
s.data["images"][i]["src"],
fit: BoxFit.contain,
height: 100 * SizeConfig.imageSizeMultiplier,
width: 100 * SizeConfig.imageSizeMultiplier,
)
);
}
}

@override
Widget build(BuildContext context) {
return LayoutBuilder(builder: (context, constraints) {
Expand Down Expand Up @@ -61,6 +73,7 @@ class HolidayInfo extends StatelessWidget {
),
);
}
addImages(s);
return Column(
children: <Widget>[
Stack(overflow: Overflow.visible, children: <Widget>[
Expand All @@ -69,19 +82,19 @@ class HolidayInfo extends StatelessWidget {
height: 10 * SizeConfig.heightMultiplier,
decoration: BoxDecoration(color: Colors.white),
),
Positioned(
child: Image.network(
s.data["images"][0]["src"],
fit: BoxFit.contain,
height: 100 * SizeConfig.imageSizeMultiplier,
width: 100 * SizeConfig.imageSizeMultiplier,
Container(
height: 35 * SizeConfig.heightMultiplier,
width: 100 * SizeConfig.widthMultiplier,
child: new ListView(
scrollDirection: Axis.horizontal,
children: imageWidgetList
),
),
Positioned(
top: 35 * SizeConfig.heightMultiplier,
top: 30 * SizeConfig.heightMultiplier,
child: Container(
width: MediaQuery.of(context).size.width,
height: 65 * SizeConfig.heightMultiplier,
height: 70 * SizeConfig.heightMultiplier,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
Expand Down
6 changes: 3 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ class _MyHomePageState extends State<MyHomePage> {
);
},
leading: CircleAvatar(
child: Image.network(s.data[index]["images"][0]["src"]),
child: Image.network(s.data[index]["images"][0]["src"], fit: BoxFit.fill,),
radius: 30,
backgroundColor: themeColor,
),
title: Text(s.data[index]["name"]),
subtitle:
Text("Buy now for \$ " + s.data[index]["price"]),
Text("Boek nu vanaf €" + s.data[index]["sale_price"]),
),
);
});
Expand Down Expand Up @@ -168,7 +168,7 @@ class _MyHomePageState extends State<MyHomePage> {
int categoryId = s.data[index]["id"];
Navigator.push(
context,
MaterialPageRoute(builder: (context) => ResultPage(categoryId)),
MaterialPageRoute(builder: (context) => ResultPage(categoryId, s.data[index]["name"])),
);
},
),
Expand Down
6 changes: 4 additions & 2 deletions lib/resultpage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import 'holidayinfo.dart';
class ResultPage extends StatelessWidget {
static ApiData api = new ApiData();
int id;
String name;

ResultPage(int id){
ResultPage(int id, String name){
this.id = id;
this.name = name;
}

@override
Expand All @@ -30,7 +32,7 @@ class ResultPage extends StatelessWidget {
home: Scaffold(
appBar: AppBar(
title: Text(
'Categoriën',
name,
style:
TextStyle(color: themeColor, fontWeight: FontWeight.bold),
),
Expand Down

0 comments on commit 5772b22

Please sign in to comment.