Skip to content

Commit

Permalink
Aula 03 | DartWeek 4ª Edição 🔥
Browse files Browse the repository at this point in the history
  • Loading branch information
felipecastrosales authored Sep 16, 2021
2 parents 508e80f + 07dbfa2 commit c1efef5
Show file tree
Hide file tree
Showing 26 changed files with 274 additions and 12 deletions.
Binary file added assets/fonts/FilmesAppIcons.ttf
Binary file not shown.
Binary file added assets/fonts/metropolis/Metropolis-Bold.otf
Binary file not shown.
Binary file added assets/fonts/metropolis/Metropolis-Regular.otf
Binary file not shown.
Binary file added assets/fonts/metropolis/Metropolis-SemiBold.otf
Binary file not shown.
Binary file added assets/images/2x/header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/3x/header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions lib/application/auth/auth_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:get/get.dart';

class AuthService extends GetxService {
User? user;

void init() {
FirebaseAuth.instance.authStateChanges().listen(
(User? user) {
this.user = user;
if (user == null) {
Get.offAllNamed('/login');
} else {
Get.offAllNamed('/home');
}
},
);
}
}
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/auth/auth_service.dart';
import 'package:app_filmes/repositories/login/login_repository_impl.dart';
import 'package:app_filmes/repositories/login/login_repository.dart';
import 'package:app_filmes/services/login/login_service.dart';
Expand All @@ -18,5 +19,8 @@ class ApplicationBindings implements Bindings {
),
fenix: true,
);
Get.put(
AuthService(),
).init();
}
}
32 changes: 32 additions & 0 deletions lib/application/ui/filmes_app_icons_icons.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/// Flutter icons FilmesAppIcons
/// Copyright (C) 2021 by original authors @ fluttericon.com, fontello.com
/// This font was generated by FlutterIcon.com, which is derived from Fontello.
///
/// To use this font, place it in your fonts/ directory and include the
/// following in your pubspec.yaml
///
/// flutter:
/// fonts:
/// - family: FilmesAppIcons
/// fonts:
/// - asset: fonts/FilmesAppIcons.ttf
///
///
/// * Font Awesome 4, Copyright (C) 2016 by Dave Gandy
/// Author: Dave Gandy
/// License: SIL ()
/// Homepage: http://fortawesome.github.com/Font-Awesome/
///
import 'package:flutter/widgets.dart';

class FilmesAppIcons {
FilmesAppIcons._();

static const _kFontFam = 'FilmesAppIcons';
static const String? _kFontPkg = null;

static const IconData heart =
IconData(0xe800, fontFamily: _kFontFam, fontPackage: _kFontPkg);
static const IconData heartEmpty =
IconData(0xe801, fontFamily: _kFontFam, fontPackage: _kFontPkg);
}
21 changes: 21 additions & 0 deletions lib/application/ui/filmes_app_ui_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:flutter/material.dart';

class FilmesAppUiConfig {
FilmesAppUiConfig._();

static String get title => 'Filmes App';

static ThemeData get theme => ThemeData(
scaffoldBackgroundColor: Colors.white,
fontFamily: 'Metropolis',
appBarTheme: const AppBarTheme(
backgroundColor:Colors.white,
iconTheme: IconThemeData(color: Colors.black),
titleTextStyle: TextStyle(
color: Color(0xff222222),
fontSize: 18,
fontWeight: FontWeight.w500,
),
),
);
}
7 changes: 7 additions & 0 deletions lib/application/ui/theme_extension.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import 'package:flutter/material.dart';

extension ThemeExtension on BuildContext {
Color get themeRed => const Color(0xffea4335);
Color get themeOrange => const Color(0xffffba49);
Color get themeGrey => const Color(0xff9b9b9b);
}
9 changes: 5 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import 'package:firebase_remote_config/firebase_remote_config.dart';
import 'package:get/get.dart';

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/splash/splash_module.dart';

Expand All @@ -23,15 +25,14 @@ class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GetMaterialApp(
title: 'App Filmes',
title: FilmesAppUiConfig.title,
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
theme: FilmesAppUiConfig.theme,
initialBinding: ApplicationBindings(),
getPages: [
...SplashModule().routers,
...LoginModule().routers,
...HomeModule().routers,
],
);
}
Expand Down
16 changes: 16 additions & 0 deletions lib/modules/favorites/favorites_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:flutter/material.dart';

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

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Favorites'),
automaticallyImplyLeading: false,
),
body: Container(),
);
}
}
15 changes: 15 additions & 0 deletions lib/modules/home/home_bindings.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:get/get.dart';

import 'home_controller.dart';

class HomeBindings implements Bindings {
@override
void dependencies() {
Get.lazyPut(
() => HomeController(
loginService: Get.find(),
),
fenix: true,
);
}
}
36 changes: 36 additions & 0 deletions lib/modules/home/home_controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import 'package:get/get.dart';

import 'package:app_filmes/services/login/login_service.dart';

class HomeController extends GetxController {
// ignore: constant_identifier_names
static const NAVIGATOR_KEY = 1;
// ignore: constant_identifier_names
static const INDEX_PAGE_EXIT = 2;

final LoginService _loginService;
HomeController({
required LoginService loginService,
}) : _loginService = loginService;

final _pages = [
'/movies',
'/favorites',
];

final _pageIndex = 0.obs;

int get pageIndex => _pageIndex.value;

void goToPage(int page) {
_pageIndex(page);
if (page == INDEX_PAGE_EXIT) {
_loginService.logout();
} else {
Get.offNamed(
_pages[page],
id: NAVIGATOR_KEY,
);
}
}
}
16 changes: 16 additions & 0 deletions lib/modules/home/home_module.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:get/get.dart';

import 'package:app_filmes/application/modules/module.dart';
import 'home_bindings.dart';
import 'home_page.dart';

class HomeModule extends Module {
@override
List<GetPage> routers = [
GetPage(
name: '/home',
page: () => const HomePage(),
binding: HomeBindings(),
),
];
}
60 changes: 60 additions & 0 deletions lib/modules/home/home_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import 'package:flutter/material.dart';

import 'package:get/get.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/modules/favorites/favorites_page.dart';
import 'package:app_filmes/modules/movies/movies_page.dart';
import 'home_controller.dart';

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

@override
Widget build(BuildContext context) {
return Scaffold(
bottomNavigationBar: Obx(() {
return BottomNavigationBar(
selectedItemColor: context.themeRed,
unselectedItemColor: context.themeGrey,
onTap: controller.goToPage,
currentIndex: controller.pageIndex,
items: const [
BottomNavigationBarItem(
icon: Icon(Icons.movie),
label: 'Filmes',
),
BottomNavigationBarItem(
icon: Icon(FilmesAppIcons.heartEmpty),
label: 'Favoritos',
),
BottomNavigationBarItem(
icon: Icon(Icons.logout_outlined),
label: 'Sair',
),
],
);
}),
body: Navigator(
initialRoute: '/movies',
key: Get.nestedKey(HomeController.NAVIGATOR_KEY),
onGenerateRoute: (settings) {
if (settings.name == '/movies') {
return GetPageRoute(
settings: settings,
page: () => const MoviesPage(),
);
}
if (settings.name == '/favorites') {
return GetPageRoute(
settings: settings,
page: () => const FavoritesPage(),
);
}
return null;
},
),
);
}
}
8 changes: 5 additions & 3 deletions lib/modules/login/login_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ class LoginController extends GetxController with LoaderMixin, MessagesMixin {
print(e);
print(s);
loading(false);
MessageModel.error(
title: 'Error',
message: 'Login with Error',
message(
MessageModel.error(
title: 'Error',
message: 'Login with Error',
),
);
}
}
Expand Down
16 changes: 16 additions & 0 deletions lib/modules/movies/movies_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:flutter/material.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'),
),
body: Container(),
);
}
}
6 changes: 1 addition & 5 deletions lib/modules/splash/splash_controller.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import 'package:get/get.dart';

class SplashController extends GetxController {
@override
void onReady() {
super.onReady();
Get.offAllNamed('/login');
}

}
1 change: 1 addition & 0 deletions lib/repositories/login/login_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ import 'package:firebase_auth/firebase_auth.dart';

abstract class LoginRepository {
Future<UserCredential> login();
logout() {}
}
6 changes: 6 additions & 0 deletions lib/repositories/login/login_repository_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@ class LoginRepositoryImpl implements LoginRepository {
}
throw Exception('Erro ao realizar login com Google');
}

@override
Future<void> logout() async {
await GoogleSignIn().signOut();
FirebaseAuth.instance.signOut();
}
}
1 change: 1 addition & 0 deletions lib/services/login/login_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ import 'package:firebase_auth/firebase_auth.dart';

abstract class LoginService {
Future<UserCredential> login();
Future<void> logout();
}
3 changes: 3 additions & 0 deletions lib/services/login/login_service_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ class LoginServiceImpl implements LoginService {

@override
Future<UserCredential> login() => _loginRepository.login();

@override
Future<void> logout() => _loginRepository.logout();
}
10 changes: 10 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,13 @@ flutter:
uses-material-design: true
assets:
- assets/images/
fonts:
- family: FilmesAppIcons
fonts:
- asset: assets/fonts/FilmesAppIcons.ttf
- family: Metropolis
fonts:
- asset: assets/fonts/metropolis/Metropolis-Regular.otf
- asset: assets/fonts/metropolis/Metropolis-Semibold.otf
weight: 600
- asset: assets/fonts/metropolis/Metropolis-Bold.otf

0 comments on commit c1efef5

Please sign in to comment.