Skip to content

Commit

Permalink
Aula 04 | DartWeek 4ª Edição 🔥
Browse files Browse the repository at this point in the history
  • Loading branch information
felipecastrosales authored Sep 18, 2021
2 parents c1efef5 + 5474116 commit 08064c8
Show file tree
Hide file tree
Showing 16 changed files with 437 additions and 5 deletions.
4 changes: 4 additions & 0 deletions lib/application/bindings/application_bindings.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:get/get.dart';

import 'package:app_filmes/application/rest_client/rest_client.dart';
import 'package:app_filmes/application/auth/auth_service.dart';
import 'package:app_filmes/repositories/login/login_repository_impl.dart';
import 'package:app_filmes/repositories/login/login_repository.dart';
Expand All @@ -9,6 +10,9 @@ import 'package:app_filmes/services/login/login_service_impl.dart';
class ApplicationBindings implements Bindings {
@override
void dependencies() {
Get.lazyPut(
() => RestClient(),
);
Get.lazyPut<LoginRepository>(
() => LoginRepositoryImpl(),
fenix: true,
Expand Down
7 changes: 7 additions & 0 deletions lib/application/rest_client/rest_client.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import 'package:get/get_connect.dart';

class RestClient extends GetConnect {
RestClient() {
httpClient.baseUrl = 'https://api.themoviedb.org/3';
}
}
81 changes: 81 additions & 0 deletions lib/application/ui/widgets/movie_card.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import 'package:app_filmes/application/ui/filmes_app_icons_icons.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

class MovieCard extends StatelessWidget {
const MovieCard({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return SizedBox(
height: 280,
width: 158,
child: Stack(
children: [
Padding(
padding: const EdgeInsets.all(10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Material(
elevation: 2,
borderRadius: BorderRadius.circular(20),
child: ClipRRect(
clipBehavior: Clip.antiAlias,
borderRadius: BorderRadius.circular(20),
child: Image.network(
'https://br.web.img3.acsta.net/pictures/15/09/29/12/57/543717.jpg',
width: 148,
height: 184,
fit: BoxFit.cover,
),
),
),
const SizedBox(height: 20),
const Text(
'Cristiano Ronaldo',
overflow: TextOverflow.ellipsis,
maxLines: 2,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
),
),
const Text(
'2015',
overflow: TextOverflow.ellipsis,
maxLines: 2,
style: TextStyle(
fontSize: 11,
color: Colors.grey,
fontWeight: FontWeight.bold,
),
),
],
),
),
Positioned(
bottom: 80,
right: -8,
child: Material(
elevation: 5,
shape: const CircleBorder(),
clipBehavior: Clip.antiAlias,
child: SizedBox(
height: 30,
child: IconButton(
iconSize: 13,
icon: const Icon(
FilmesAppIcons.heart,
color: Colors.grey,
),
onPressed: () {},
),
),
),
),
],
),
);
}
}
30 changes: 30 additions & 0 deletions lib/models/genre_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'dart:convert';

class GenreModel {
GenreModel({
required this.id,
required this.name,
});

final int id;
final String name;

Map<String, dynamic> toMap() {
return {
'id': id,
'name': name,
};
}

factory GenreModel.fromMap(Map<String, dynamic> map) {
return GenreModel(
id: map['id'] ?? 0,
name: map['name'] ?? '',
);
}

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

factory GenreModel.fromJson(String source) =>
GenreModel.fromMap(json.decode(source));
}
2 changes: 2 additions & 0 deletions lib/modules/home/home_page.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:app_filmes/modules/movies/movies_bindings.dart';
import 'package:flutter/material.dart';

import 'package:get/get.dart';
Expand Down Expand Up @@ -44,6 +45,7 @@ class HomePage extends GetView<HomeController> {
return GetPageRoute(
settings: settings,
page: () => const MoviesPage(),
binding: MoviesBindings(),
);
}
if (settings.name == '/favorites') {
Expand Down
28 changes: 28 additions & 0 deletions lib/modules/movies/movies_bindings.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'package:app_filmes/modules/movies/movies_controller.dart';
import 'package:get/get.dart';

import 'package:app_filmes/repositories/genres/genres_repository.dart';
import 'package:app_filmes/repositories/genres/genres_repository_impl.dart';
import 'package:app_filmes/services/genres/genres_service.dart';
import 'package:app_filmes/services/genres/genres_service_impl.dart';

class MoviesBindings implements Bindings {
@override
void dependencies() {
Get.lazyPut<GenresRepository>(
() => GenresRepositoryImpl(
restClient: Get.find(),
),
);
Get.lazyPut<GenresService>(
() => GenresServiceImpl(
genreRepository: Get.find(),
),
);
Get.lazyPut(
() => MoviesController(
genresService: Get.find(),
),
);
}
}
37 changes: 37 additions & 0 deletions lib/modules/movies/movies_controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'package:get/get.dart';

import 'package:app_filmes/application/ui/messages/messages_mixin.dart';
import 'package:app_filmes/models/genre_model.dart';
import 'package:app_filmes/services/genres/genres_service.dart';

class MoviesController extends GetxController with MessagesMixin {
final GenresService _genresService;
final _message = Rxn<MessageModel>();
final genres = <GenreModel>[].obs;

MoviesController({
required GenresService genresService,
}) : _genresService = genresService;

@override
void onInit() {
super.onInit();
messageListener(_message);
}

@override
void onReady() async {
super.onReady();
try {
final genres = await _genresService.getGenres();
this.genres.assignAll(genres);
} catch (e) {
_message(
MessageModel.error(
title: 'Erro',
message: 'Erro ao buscar Categorias',
),
);
}
}
}
22 changes: 17 additions & 5 deletions lib/modules/movies/movies_page.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
import 'package:flutter/material.dart';


import 'package:get/get.dart';

import 'widgets/movies_filters.dart';
import 'widgets/movies_group.dart';
import 'widgets/movies_header.dart';

class MoviesPage extends StatelessWidget {

const MoviesPage({ Key? key }) : super(key: key);

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Movies'),
return SizedBox(
width: Get.width,
height: Get.height,
child: ListView(
children: const [
MoviesHeader(),
MoviesFilters(),
MoviesGroup(title: 'Mais Populares'),
MoviesGroup(title: 'Top Filmes'),
],
),
body: Container(),
);
}
}
47 changes: 47 additions & 0 deletions lib/modules/movies/widgets/filter_tag.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import 'package:flutter/material.dart';

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

class FilterTag extends StatelessWidget {
final GenreModel model;
final bool selected;
final VoidCallback onPressed;

const FilterTag({
Key? key,
required this.model,
this.selected = false,
required this.onPressed,
}) : super(key: key);

@override
Widget build(BuildContext context) {
return InkWell(
onTap: onPressed,
child: Container(
margin: const EdgeInsets.all(5),
padding: const EdgeInsets.all(5),
height: 20,
constraints: const BoxConstraints(
minWidth: 100,
minHeight: 30,
),
decoration: BoxDecoration(
color: selected ? context.themeRed : Colors.black,
borderRadius: BorderRadius.circular(30),
),
child: Align(
alignment: Alignment.center,
child: Text(
model.name,
style: const TextStyle(
color: Colors.white,
fontSize: 14,
),
),
),
),
);
}
}
33 changes: 33 additions & 0 deletions lib/modules/movies/widgets/movies_filters.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'package:flutter/material.dart';

import 'package:get/get.dart';

import 'package:app_filmes/modules/movies/movies_controller.dart';
import 'filter_tag.dart';

class MoviesFilters extends GetView<MoviesController> {
const MoviesFilters({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(top: 8),
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Obx(() {
return Row(
children: controller.genres
.map(
(g) => FilterTag(
model: g,
onPressed: () {},
selected: false,
),
)
.toList(),
);
}),
),
);
}
}
39 changes: 39 additions & 0 deletions lib/modules/movies/widgets/movies_group.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import 'package:flutter/material.dart';

import 'package:app_filmes/application/ui/widgets/movie_card.dart';

class MoviesGroup extends StatelessWidget {
const MoviesGroup({Key? key, required this.title}) : super(key: key);
final String title;

@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 20),
Text(
title,
style: const TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
SizedBox(
height: 280,
child: ListView.builder(
shrinkWrap: true,
scrollDirection: Axis.horizontal,
itemCount: 10,
itemBuilder: (context, index) {
return const MovieCard();
}
),
),
],
),
);
}
}
Loading

0 comments on commit 08064c8

Please sign in to comment.