Skip to content

Commit

Permalink
feat: introduce description page
Browse files Browse the repository at this point in the history
  • Loading branch information
Ascenio committed May 6, 2024
1 parent 4d835fd commit 58fb087
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class PictureModel extends PictureEntity {
const PictureModel({
required super.url,
required super.title,
required super.explanation,
required super.date,
required super.isVideo,
});
Expand All @@ -14,6 +15,7 @@ class PictureModel extends PictureEntity {
return PictureModel(
url: url,
title: json['title'],
explanation: json['explanation'],
date: DateTime.parse(json['date']),
isVideo: url.host == 'www.youtube.com',
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
class PictureEntity {
const PictureEntity({
required this.url,
required this.explanation,
required this.title,
required this.date,
required this.isVideo,
});

final Uri url;
final String title;
final String explanation;
final DateTime date;
final bool isVideo;

Expand All @@ -18,13 +20,18 @@ class PictureEntity {
}
return other is PictureEntity &&
other.url == url &&
other.explanation == explanation &&
other.title == title &&
other.date == date &&
other.isVideo == isVideo;
}

@override
int get hashCode {
return url.hashCode ^ title.hashCode ^ date.hashCode ^ isVideo.hashCode;
return url.hashCode ^
title.hashCode ^
explanation.hashCode ^
date.hashCode ^
isVideo.hashCode;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import 'package:flutter/material.dart';
import 'package:nasa_potday/features/picture_of_the_day/domain/entities/picture_entity.dart';
import 'package:nasa_potday/features/picture_of_the_day/presentation/widgets/date_widget.dart';

class DetailsPage extends StatelessWidget {
const DetailsPage({
required this.picture,
super.key,
});

final PictureEntity picture;

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: CustomScrollView(
slivers: [
SliverToBoxAdapter(
child: Hero(
tag: picture.url,
child: Image.network(
picture.url.toString(),
),
),
),
const SliverPadding(
padding: EdgeInsets.only(top: 16),
),
SliverPadding(
padding: const EdgeInsets.symmetric(horizontal: 16),
sliver: SliverToBoxAdapter(
child: Text(picture.title),
),
),
const SliverPadding(
padding: EdgeInsets.only(top: 16),
),
SliverPadding(
padding: const EdgeInsets.symmetric(horizontal: 16),
sliver: SliverToBoxAdapter(
child: DateWidget(date: picture.date),
),
),
const SliverPadding(
padding: EdgeInsets.only(top: 16),
),
SliverPadding(
padding: const EdgeInsets.symmetric(horizontal: 16),
sliver: SliverToBoxAdapter(
child: Text(picture.explanation),
),
),
const SliverPadding(
padding: EdgeInsets.only(top: 32),
),
],
),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';

class DateWidget extends StatelessWidget {
const DateWidget({
required this.date,
super.key,
});

final DateTime date;

@override
Widget build(BuildContext context) {
return Row(
children: [
const Icon(Icons.calendar_month_outlined),
const SizedBox(width: 8),
Text(DateFormat('dd/MM/yyyy').format(date)),
],
);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:nasa_potday/features/picture_of_the_day/domain/entities/picture_entity.dart';
import 'package:nasa_potday/features/picture_of_the_day/presentation/pages/details_page.dart';

class PictureWidget extends StatelessWidget {
const PictureWidget({
Expand All @@ -11,15 +12,25 @@ class PictureWidget extends StatelessWidget {

@override
Widget build(BuildContext context) {
return switch (picture.isVideo) {
true => const Placeholder(
child: SizedBox.expand(
child: Center(child: Text('Video is not implemented yet')),
),
),
false => Image.network(
picture.url.toString(),
),
};
return GestureDetector(
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(builder: (_) => DetailsPage(picture: picture)),
);
},
child: Hero(
tag: picture.url,
child: switch (picture.isVideo) {
true => const Placeholder(
child: SizedBox.expand(
child: Center(child: Text('Video is not implemented yet')),
),
),
false => Image.network(
picture.url.toString(),
),
},
),
);
}
}
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.0.2"
intl:
dependency: "direct main"
description:
name: intl
sha256: d6f56758b7d3014a48af9701c085700aac781a92a87a62b1333b46d8879661cf
url: "https://pub.dev"
source: hosted
version: "0.19.0"
leak_tracker:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies:
sdk: flutter
flutter_bloc: ^8.1.5
http: ^1.2.1
intl: ^0.19.0

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 58fb087

Please sign in to comment.