Skip to content

Commit

Permalink
Aula 06 | DartWeek 4ª Edição 🔥
Browse files Browse the repository at this point in the history
  • Loading branch information
felipecastrosales authored Sep 22, 2021
2 parents 26e8918 + 02ce518 commit 19b2d91
Show file tree
Hide file tree
Showing 30 changed files with 887 additions and 70 deletions.
5 changes: 4 additions & 1 deletion lib/application/bindings/application_bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ApplicationBindings implements Bindings {
void dependencies() {
Get.lazyPut(
() => RestClient(),
fenix: true,
);
Get.lazyPut<LoginRepository>(
() => LoginRepositoryImpl(),
Expand All @@ -26,19 +27,21 @@ class ApplicationBindings implements Bindings {
loginRepository: Get.find(),
),
fenix: true,
);
);
Get.put(
AuthService(),
).init();
Get.lazyPut<MoviesRepository>(
() => MoviesRepositoryImpl(
restClient: Get.find(),
),
fenix: true,
);
Get.lazyPut<MoviesService>(
() => MoviesServiceImpl(
moviesRepository: Get.find(),
),
fenix: true,
);
}
}
133 changes: 77 additions & 56 deletions lib/application/ui/widgets/movie_card.dart
Original file line number Diff line number Diff line change
@@ -1,77 +1,98 @@
import 'package:app_filmes/application/ui/filmes_app_icons_icons.dart';
import 'package:app_filmes/models/movie_model.dart';
import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:intl/intl.dart';

import 'package:app_filmes/application/ui/filmes_app_icons_icons.dart';
import 'package:app_filmes/application/ui/theme_extension.dart';
import 'package:app_filmes/models/movie_model.dart';

class MovieCard extends StatelessWidget {
MovieCard({
Key? key,
required this.movie,
required this.favoriteCallback,
}) : super(key: key);

final MovieModel movie;
final dateFormat = DateFormat('dd/MM/y');
MovieCard({Key? key, required this.movie}) : super(key: key);
final VoidCallback favoriteCallback;

@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(10),
height: 305,
width: 170,
child: Stack(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Material(
elevation: 2,
borderRadius: BorderRadius.circular(15),
child: ClipRRect(
return InkWell(
onTap: () {
Get.toNamed(
'/movie/detail',
arguments: movie.id,
);
},
child: Container(
padding: const EdgeInsets.all(10),
height: 305,
width: 170,
child: Stack(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Material(
elevation: 2,
borderRadius: BorderRadius.circular(15),
clipBehavior: Clip.antiAlias,
child: Image.network(
movie.posterPath,
height: 190,
width: 165,
fit: BoxFit.cover,
child: ClipRRect(
borderRadius: BorderRadius.circular(15),
clipBehavior: Clip.antiAlias,
child: Image.network(
'https://image.tmdb.org/t/p/w200${movie.posterPath}',
height: 190,
width: 165,
fit: BoxFit.cover,
),
),
),
),
SizedBox(height: 20),
Text(
movie.title,
style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600),
overflow: TextOverflow.ellipsis,
maxLines: 2,
),
Text(
dateFormat.format(DateTime.parse(movie.releaseDate)),
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.w300,
color: Colors.grey,
const SizedBox(height: 20),
Text(
movie.title,
style: const TextStyle(
fontSize: 12, fontWeight: FontWeight.w600),
overflow: TextOverflow.ellipsis,
maxLines: 2,
),
),
],
),
Positioned(
bottom: 65,
right: -4,
child: Material(
elevation: 5,
shape: CircleBorder(),
clipBehavior: Clip.antiAlias,
child: SizedBox(
height: 40,
child: IconButton(
iconSize: 18,
icon: Icon(
FilmesAppIcons.heartEmpty,
Text(
dateFormat.format(DateTime.parse(movie.releaseDate)),
style: const TextStyle(
fontSize: 11,
fontWeight: FontWeight.w300,
color: Colors.grey,
),
onPressed: () {},
),
],
),
Positioned(
bottom: 65,
right: -4,
child: Material(
elevation: 5,
shape: const CircleBorder(),
clipBehavior: Clip.antiAlias,
child: SizedBox(
height: 40,
child: IconButton(
iconSize: 18,
icon: Icon(
movie.favorite
? FilmesAppIcons.heart
: FilmesAppIcons.heartEmpty,
color: movie.favorite ? context.themeRed : Colors.grey,
),
onPressed: favoriteCallback,
),
),
),
),
),
],
],
),
),
);
}
}
}
2 changes: 2 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'application/bindings/application_bindings.dart';
import 'application/ui/filmes_app_ui_config.dart';
import 'modules/home/home_module.dart';
import 'modules/login/login_module.dart';
import 'modules/movie_detail/movie_detail_module.dart';
import 'modules/splash/splash_module.dart';

Future<void> main() async {
Expand All @@ -33,6 +34,7 @@ class MyApp extends StatelessWidget {
...SplashModule().routers,
...LoginModule().routers,
...HomeModule().routers,
...MovieDetailModule().routers,
],
);
}
Expand Down
34 changes: 34 additions & 0 deletions lib/models/cast_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'dart:convert';

class CastModel {
CastModel({
required this.name,
required this.image,
required this.character,
});

final String name;
final String image;
final String character;

Map<String, dynamic> toMap() {
return {
'original_name': name,
'profile_path': image,
'character': character,
};
}

factory CastModel.fromMap(Map<String, dynamic> map) {
return CastModel(
name: map['original_name'] ?? '',
image: 'https://image.tmdb.org/t/p/w200${map['profile_path']}',
character: map['character'] ?? '',
);
}

String toJson() => json.encode(toMap());

factory CastModel.fromJson(String source) =>
CastModel.fromMap(json.decode(source));
}
75 changes: 75 additions & 0 deletions lib/models/movie_detail_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import 'dart:convert';

import 'package:app_filmes/models/genre_model.dart';
import 'cast_model.dart';

class MovieDetailModel {
final String title;
final double stars;
final List<GenreModel> genres;
final List<String> urlImages;
final DateTime releaseDate;
final String overview;
final List<String> productionCompanies;
final String originalLanguage;
final List<CastModel> cast;

MovieDetailModel({
required this.title,
required this.stars,
required this.genres,
required this.urlImages,
required this.releaseDate,
required this.overview,
required this.productionCompanies,
required this.originalLanguage,
required this.cast,
});

Map<String, dynamic> toMap() {
return {
'title': title,
'vote_average': stars,
'genres': genres.map((x) => x.toMap()).toList(),
'urlImages': urlImages,
'release_date': releaseDate.millisecondsSinceEpoch,
'overview': overview,
'production_companies': productionCompanies,
'original_language': originalLanguage,
'cast': cast.map((x) => x.toMap()).toList(),
};
}

factory MovieDetailModel.fromMap(Map<String, dynamic> map) {
var urlImagesPoster = map['images']['posters'];
var urlImages = urlImagesPoster
?.map<String>((images) =>
'https://image.tmdb.org/t/p/w200${images['file_path']}')
.toList() ??
const [];

return MovieDetailModel(
title: map['title'] ?? '',
stars: map['vote_average'] ?? 0.0,
genres: List<GenreModel>.from(map['genres']?.map(
(x) => GenreModel.fromMap(x),
) ??
const []),
urlImages: urlImages,
releaseDate: DateTime.parse(map['release_date']),
overview: map['overview'] ?? '',
productionCompanies: List<dynamic>.from(
map['production_companies'] ?? const [],
).map<String>((production) => production['name']).toList(),
originalLanguage: map['original_language'] ?? '',
cast: List<CastModel>.from(
map['credits']['cast']?.map((x) => CastModel.fromMap(x)) ?? const [],
),
);
}

String toJson() => json.encode(toMap());

factory MovieDetailModel.fromJson(String source) =>
MovieDetailModel.fromMap(json.decode(source));
}
20 changes: 19 additions & 1 deletion lib/models/movie_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MovieModel {
id: map['id'] ?? 0,
title: map['title'] ?? '',
releaseDate: map['release_date'] ?? '',
posterPath: 'https://image.tmdb.org/t/p/w200/${map['poster_path']}',
posterPath: map['poster_path'],
genres: List<int>.from(map['genre_ids'] ?? const []),
favorite: map['favorite'] ?? false,
);
Expand All @@ -42,4 +42,22 @@ class MovieModel {
String toJson() => json.encode(toMap());

factory MovieModel.fromJson(String source) => MovieModel.fromMap(json.decode(source));

MovieModel copyWith({
int? id,
String? title,
String? releaseDate,
String? posterPath,
List<int>? genres,
bool? favorite,
}) {
return MovieModel(
id: id ?? this.id,
title: title ?? this.title,
releaseDate: releaseDate ?? this.releaseDate,
posterPath: posterPath ?? this.posterPath,
genres: genres ?? this.genres,
favorite: favorite ?? this.favorite,
);
}
}
15 changes: 15 additions & 0 deletions lib/modules/favorites/favorites_bindings.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:get/get.dart';

import 'favorites_controller.dart';

class FavoritesBindings implements Bindings {
@override
void dependencies() {
Get.put(
FavoritesController(
authService: Get.find(),
moviesService: Get.find(),
),
);
}
}
Loading

0 comments on commit 19b2d91

Please sign in to comment.