Skip to content

Commit

Permalink
auth feature
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaiasCuvula committed Jun 18, 2023
1 parent d4f94ef commit 46a73ca
Show file tree
Hide file tree
Showing 49 changed files with 560 additions and 52 deletions.
3 changes: 2 additions & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ android {

defaultConfig {
applicationId "com.bersyte.quote_generator"
minSdkVersion flutter.minSdkVersion
minSdkVersion 19
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}

buildTypes {
Expand Down
6 changes: 5 additions & 1 deletion lib/app/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class QuoteGeneratorApp extends ConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
final appLocale = ref.watch(appLocaleProvider);
final theme = ref.watch(themeProvider);
final routeConfig = ref.watch(routerProvider);

return ScreenUtilInit(
designSize: const Size(375, 812),
builder: (context, child) {
Expand All @@ -21,7 +23,9 @@ class QuoteGeneratorApp extends ConsumerWidget {
themeMode: theme,
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
routerConfig: RoutesConfig.routeConfig,
routerDelegate: routeConfig.routerDelegate,
routeInformationParser: routeConfig.routeInformationParser,
routeInformationProvider: routeConfig.routeInformationProvider,
locale: appLocale,
);
},
Expand Down
3 changes: 2 additions & 1 deletion lib/common/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export 'navigation/navigation.dart';
export 'theme/theme.dart';
export 'localization/localization.dart';
export 'shared_prefs/shared_prefs.dart';
export 'settings/settings_screen.dart';
export 'screens/settings_screen.dart';
export 'screens/splash_screen.dart';
18 changes: 18 additions & 0 deletions lib/common/localization/translations/app_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,18 @@ abstract class AppLocalizations {
/// **'Photo Saved on Library'**
String get image_saved;

/// No description provided for @something_went_wrong.
///
/// In en, this message translates to:
/// **'Oops, Something went wrong!'**
String get something_went_wrong;

/// No description provided for @go_to_home.
///
/// In en, this message translates to:
/// **'Go to home screen'**
String get go_to_home;

/// No description provided for @copied_to_clipboard.
///
/// In en, this message translates to:
Expand All @@ -362,6 +374,12 @@ abstract class AppLocalizations {
/// In en, this message translates to:
/// **'Sign In with Google'**
String get sign_in_google;

/// No description provided for @sign_out.
///
/// In en, this message translates to:
/// **'Sign Out'**
String get sign_out;
}

class _AppLocalizationsDelegate extends LocalizationsDelegate<AppLocalizations> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,18 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get image_saved => 'Photo Saved on Library';

@override
String get something_went_wrong => 'Oops, Something went wrong!';

@override
String get go_to_home => 'Go to home screen';

@override
String get copied_to_clipboard => 'quote copied to clipboard';

@override
String get sign_in_google => 'Sign In with Google';

@override
String get sign_out => 'Sign Out';
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,18 @@ class AppLocalizationsPt extends AppLocalizations {
@override
String get image_saved => 'Foto salva na biblioteca';

@override
String get something_went_wrong => 'Oops, algo deu errado!';

@override
String get go_to_home => 'Ir para a tela inicial';

@override
String get copied_to_clipboard => 'citação copiada';

@override
String get sign_in_google => 'Faça login no Google';

@override
String get sign_out => 'Sair';
}
3 changes: 3 additions & 0 deletions lib/common/localization/translations/quote_generator_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@
"dark_mode": "Dark",
"light_mode": "Light",
"image_saved": "Photo Saved on Library",
"something_went_wrong": "Oops, Something went wrong!",
"go_to_home": "Go to home screen",
"@CLIPBOARD": {},
"copied_to_clipboard": "quote copied to clipboard",
"@AUTH": {},
"sign_in_google": "Sign In with Google",
"sign_out": "Sign Out",
"@END_OF_FILE": {}
}
3 changes: 3 additions & 0 deletions lib/common/localization/translations/quote_generator_pt.arb
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@
"dark_mode": "Modo escuro",
"light_mode": "Modo claro ",
"image_saved": "Foto salva na biblioteca",
"something_went_wrong": "Oops, algo deu errado!",
"go_to_home": "Ir para a tela inicial",
"@CLIPBOARD": {},
"copied_to_clipboard": "citação copiada",
"@AUTH": {},
"sign_in_google": "Faça login no Google",
"sign_out": "Sair",
"@END_OF_FILE": {}
}
31 changes: 31 additions & 0 deletions lib/common/navigation/routers/error_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:quote_generator/common/common.dart';

class ErrorScreen extends StatelessWidget {
const ErrorScreen({super.key});

@override
Widget build(BuildContext context) {
final l10n = context.l10n;
final textTheme = context.textTheme;
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: Text(
l10n.something_went_wrong,
style: textTheme.headlineMedium,
),
),
body: Center(
child: ElevatedButton(
onPressed: () => context.go(RouteLocation.createdByYou),
child: Text(
l10n.go_to_home,
style: textTheme.bodyMedium,
),
),
),
);
}
}
4 changes: 2 additions & 2 deletions lib/common/navigation/routers/routers.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export 'routes_config.dart';
export 'routes_provider.dart';
export 'routes.dart';
export 'routes_name.dart';
export 'routes_location.dart';
49 changes: 26 additions & 23 deletions lib/common/navigation/routers/routes.dart
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:quote_generator/common/common.dart';
import 'package:quote_generator/common/navigation/navigation.dart';
import 'package:quote_generator/features/auth/auth.dart';
import 'package:quote_generator/features/discovery/discovery.dart';
import 'package:quote_generator/features/quote/quote.dart';

final _shellNavigatorKey = GlobalKey<NavigatorState>();

final routes = [
GoRoute(
path: RoutesName.createQuote,
parentNavigatorKey: RoutesConfig.navigationKey,
pageBuilder: (context, state) {
return NoTransitionPage(
child: CreateQuoteScreen.builder(context, state),
);
},
path: RouteLocation.splash,
parentNavigatorKey: navigationKey,
builder: SplashScreen.builder,
),
GoRoute(
name: RoutesName.detailScreen,
path: '${RoutesName.detailScreen}/:id',
parentNavigatorKey: RoutesConfig.navigationKey,
path: RouteLocation.createQuote,
parentNavigatorKey: navigationKey,
builder: CreateQuoteScreen.builder,
),
GoRoute(
name: RouteLocation.detailScreen,
path: '${RouteLocation.detailScreen}/:id',
parentNavigatorKey: navigationKey,
pageBuilder: (context, state) {
return NoTransitionPage(
child: QuoteCardDetails.builder(
Expand All @@ -32,14 +33,16 @@ final routes = [
},
),
GoRoute(
path: RoutesName.settings,
parentNavigatorKey: RoutesConfig.navigationKey,
pageBuilder: (context, state) {
return NoTransitionPage(
child: SettingsScreen.builder(context, state),
);
},
path: RouteLocation.settings,
parentNavigatorKey: navigationKey,
builder: SettingsScreen.builder,
),
GoRoute(
path: RouteLocation.auth,
parentNavigatorKey: navigationKey,
builder: AuthScreen.builder,
),

//Bottom Nav bar shell
ShellRoute(
navigatorKey: _shellNavigatorKey,
Expand All @@ -54,16 +57,16 @@ final routes = [
},
routes: [
GoRoute(
path: RoutesName.createByYou,
path: RouteLocation.createdByYou,
parentNavigatorKey: _shellNavigatorKey,
pageBuilder: (context, state) {
return NoTransitionPage(
child: CreateByYouScreen.builder(context, state),
child: CreatedByYouScreen.builder(context, state),
);
},
),
GoRoute(
path: RoutesName.discovery,
path: RouteLocation.discovery,
parentNavigatorKey: _shellNavigatorKey,
pageBuilder: (context, state) {
return NoTransitionPage(
Expand All @@ -72,7 +75,7 @@ final routes = [
},
),
GoRoute(
path: RoutesName.search,
path: RouteLocation.search,
parentNavigatorKey: _shellNavigatorKey,
pageBuilder: (context, state) {
return NoTransitionPage(
Expand All @@ -81,7 +84,7 @@ final routes = [
},
),
GoRoute(
path: RoutesName.favorites,
path: RouteLocation.favorites,
parentNavigatorKey: _shellNavigatorKey,
pageBuilder: (context, state) {
return NoTransitionPage(
Expand Down
13 changes: 0 additions & 13 deletions lib/common/navigation/routers/routes_config.dart

This file was deleted.

16 changes: 16 additions & 0 deletions lib/common/navigation/routers/routes_location.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:flutter/foundation.dart' show immutable;

@immutable
class RouteLocation {
const RouteLocation._();
//routeLocation
static String get splash => '/splash';
static String get detailScreen => '/quoteDetails';
static String get discovery => '/discovery';
static String get createQuote => '/createQuote';
static String get settings => '/settings';
static String get createdByYou => '/createdByYou';
static String get search => '/search';
static String get favorites => '/favorites';
static String get auth => '/auth';
}
9 changes: 0 additions & 9 deletions lib/common/navigation/routers/routes_name.dart

This file was deleted.

32 changes: 32 additions & 0 deletions lib/common/navigation/routers/routes_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:quote_generator/common/common.dart';
import 'package:quote_generator/common/navigation/routers/error_screen.dart';
import 'package:quote_generator/features/auth/auth.dart';

final navigationKey = GlobalKey<NavigatorState>();

final routerProvider = Provider<GoRouter>(
(ref) {
final authState = ref.watch(authStateChangesProvider);

return GoRouter(
initialLocation: RouteLocation.splash,
navigatorKey: navigationKey,
routes: routes,
errorBuilder: (context, state) => const ErrorScreen(),
redirect: (context, state) {
if (authState.isLoading || authState.hasError) return null;
final isAuth = authState.valueOrNull != null;
final isSplash = state.location == RouteLocation.splash;
if (isSplash) {
return isAuth ? RouteLocation.createdByYou : RouteLocation.auth;
}
final isLoggedIn = state.location == RouteLocation.auth;
if (isLoggedIn) return isAuth ? RouteLocation.createdByYou : null;
return isAuth ? null : RouteLocation.splash;
},
);
},
);
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:go_router/go_router.dart';
import 'package:quote_generator/common/common.dart';
import 'package:quote_generator/features/auth/auth.dart';
import 'package:quote_generator/features/shared/shared.dart';

class SettingsScreen extends ConsumerWidget {
Expand All @@ -16,8 +18,9 @@ class SettingsScreen extends ConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
final l10n = context.l10n;
final textTheme = context.textTheme;
final colorScheme = context.colorScheme;
final themeState = ref.watch(themeProvider);
final switchColor = context.colorScheme.primary;
final switchColor = colorScheme.primary;
final themeLabelDisplay =
themeState == ThemeMode.dark ? l10n.dark_mode : l10n.light_mode;
return Scaffold(
Expand Down Expand Up @@ -52,6 +55,21 @@ class SettingsScreen extends ConsumerWidget {
},
),
),
ListTile(
leading: Text(
l10n.sign_out,
style: textTheme.bodyMedium,
),
trailing: IconButton(
onPressed: () async {
await ref.read(authProvider.notifier).signOut();
},
icon: FaIcon(
FontAwesomeIcons.arrowRightFromBracket,
color: colorScheme.primary,
),
),
),
],
),
),
Expand Down
Loading

0 comments on commit 46a73ca

Please sign in to comment.