Skip to content

Commit

Permalink
updating adding Navigation (2.0), updating the flow between modules-s…
Browse files Browse the repository at this point in the history
…ervices-repositories and fixing assets
  • Loading branch information
felipecastrosales committed Sep 16, 2021
1 parent f742220 commit 07dbfa2
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 28 deletions.
1 change: 1 addition & 0 deletions lib/modules/favorites/favorites_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class FavoritesPage extends StatelessWidget {
return Scaffold(
appBar: AppBar(
title: const Text('Favorites'),
automaticallyImplyLeading: false,
),
body: Container(),
);
Expand Down
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,
);
}
}
}
2 changes: 2 additions & 0 deletions lib/modules/home/home_module.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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 {
Expand All @@ -9,6 +10,7 @@ class HomeModule extends Module {
GetPage(
name: '/home',
page: () => const HomePage(),
binding: HomeBindings(),
),
];
}
64 changes: 46 additions & 18 deletions lib/modules/home/home_page.dart
Original file line number Diff line number Diff line change
@@ -1,31 +1,59 @@
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 StatelessWidget {
class HomePage extends GetView<HomeController> {
const HomePage({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return Scaffold(
bottomNavigationBar: BottomNavigationBar(
selectedItemColor: context.themeRed,
unselectedItemColor: context.themeGrey,
items: const [
BottomNavigationBarItem(
icon: Icon(Icons.movie),
label: 'Filmes',
),
BottomNavigationBarItem(
icon: Icon(FilmesAppIcons.heartEmpty),
label: 'Favoritos',
),
BottomNavigationBarItem(
icon: Icon(Icons.logout_outlined),
label: 'Sair',
),
],
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;
},
),
);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/movies/movies_page.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:flutter/material.dart';

class MoviesPageDart extends StatelessWidget {
class MoviesPage extends StatelessWidget {

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

@override
Widget build(BuildContext context) {
Expand Down
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();
}
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ flutter:
- asset: assets/fonts/FilmesAppIcons.ttf
- family: Metropolis
fonts:
- asset: assets/fonts/Metropolis-Regular.otf/
- asset: assets/fonts/Metropolis-Semibold.otf/
- asset: assets/fonts/metropolis/Metropolis-Regular.otf
- asset: assets/fonts/metropolis/Metropolis-Semibold.otf
weight: 600
- asset: assets/fonts/Metropolis-Bold.otf/
- asset: assets/fonts/metropolis/Metropolis-Bold.otf

0 comments on commit 07dbfa2

Please sign in to comment.