Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Detail page #3

Merged
merged 8 commits into from
May 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions flutter_random_images/lib/config.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
const appDisplayName = "Lorem Picsum";
const apiHost = "https://picsum.photos/v2";
const apiBase = "picsum.photos";
const apiHost = "https://$apiBase/v2";
const apiEndpoint = "/list?page=%s&limit=%s";
const pingHost = "https://httpbin.org";
const pingEndpoint = "/ip";
const startPage = 0;
const defaultLimit = 10;
const defaultLimit = 8;
const nullPlaceholder = "n/a";
const nullUri = "http://mock.io";
const placeholderUri = "asserts/images/img_placeholder.png";
const errorUri = "asserts/images/img_error.png";
const lineCount = 2;
const thumbnailSize = 200;
16 changes: 12 additions & 4 deletions flutter_random_images/lib/domain/photo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ import '../config.dart';
//}
//

const thumbnailSize = 200;

class Photo {
final String id;
final String author;
final int width;
final int height;
final String url;
final String downloadUrl;
Uri _thumbnail;
Uri _webLocation;
Uri _downloadLocation;

Photo(this.id, this.author, this.width, this.height, this.url,
this.downloadUrl);
Expand All @@ -34,11 +35,18 @@ class Photo {
map["url"] ?? nullPlaceholder,
map["download_url"] ?? nullPlaceholder);

Uri get webLocation => Uri.parse(url);
Uri get webLocation {
if (_webLocation != null) return _webLocation;
return Uri.parse(url);
}

Uri get downloadLocation => Uri.parse(downloadUrl);
Uri get downloadLocation {
if (_downloadLocation != null) return _downloadLocation;
return Uri.parse(downloadUrl);
}

Uri get thumbnail {
if (_thumbnail != null) return _thumbnail;
//
//Download is "https://picsum.photos/id/121/1600/1067"
//Thumbnail shall be "https://picsum.photos/id/121/$thumbnailSize/$thumbnailSize"
Expand Down
28 changes: 28 additions & 0 deletions flutter_random_images/lib/image_app_detail.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_random_images/domain/photo.dart';

import 'config.dart';

class ImageAppDetail extends StatelessWidget {
final Photo _photo;

ImageAppDetail(this._photo);

@override
Widget build(BuildContext context) {
return Container(
child: CachedNetworkImage(
placeholder: (context, url) => Image.asset(
placeholderUri,
fit: BoxFit.cover,
),
errorWidget: (context, url, error) => Image.asset(
errorUri,
fit: BoxFit.cover,
),
imageUrl: _photo.downloadUrl.toString(),
fit: BoxFit.cover,
));
}
}
7 changes: 6 additions & 1 deletion flutter_random_images/lib/image_app_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:flutter_random_images/domain/photo_list.dart';
import 'package:flutter_random_images/viewmodel/image_app_page_view_model.dart';

import 'domain/photo.dart';
import 'image_app_detail.dart';

class ImageAppPage extends StatefulWidget {
final int index;
Expand Down Expand Up @@ -85,7 +86,11 @@ class _ImageCellState extends State<ImageCell> {
fit: BoxFit.cover,
),
),
onTap: () {},
onTap: () {
Navigator.of(context).push(MaterialPageRoute(builder: (_) {
return ImageAppDetail(widget._photo);
}));
},
),
),
),
Expand Down
2 changes: 1 addition & 1 deletion flutter_random_images/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class MyApp extends StatelessWidget {
),
home: ImageAppSplash(ImageAppSplashViewModel(
Service(HttpClientProvider()),
() => InternetAddress.lookup('google.com'))),
() => InternetAddress.lookup(apiBase))),
);
}
}
2 changes: 1 addition & 1 deletion flutter_random_images/lib/service/gateway.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import 'dart:async';
import 'dart:core';
import 'dart:io';

import 'package:flutter_random_images/domain/ping.dart';
import 'package:flutter_random_images/domain/photo.dart';
import 'package:flutter_random_images/domain/photo_list.dart';
import 'package:flutter_random_images/domain/ping.dart';
import 'package:meta/meta.dart';
import 'package:sprintf/sprintf.dart';

Expand Down
1 change: 1 addition & 0 deletions flutter_random_images/test/thumbnail_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter_random_images/config.dart';
import 'package:flutter_random_images/domain/photo.dart';
import 'package:test_api/test_api.dart';

Expand Down