-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from raxysstudios/v0.7
v0.7
- Loading branch information
Showing
80 changed files
with
2,169 additions
and
1,884 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,8 @@ | |
.pub-cache/ | ||
.pub/ | ||
/build/ | ||
*.g.dart | ||
*.gr.dart | ||
|
||
# Web related | ||
lib/generated_plugin_registrant.dart | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,51 @@ | ||
import 'package:algolia/algolia.dart'; | ||
import 'package:avzag/store.dart'; | ||
import 'package:firebase_auth/firebase_auth.dart'; | ||
import 'package:firebase_core/firebase_core.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
import 'config/themes.dart'; | ||
import 'package:url_strategy/url_strategy.dart'; | ||
|
||
import 'firebase_options.dart'; | ||
import 'modules/navigation/nav_drawer.dart'; | ||
import 'modules/navigation/services/root_guard.dart'; | ||
import 'modules/navigation/services/router.gr.dart'; | ||
import 'theme_set.dart'; | ||
|
||
void main() async { | ||
WidgetsFlutterBinding.ensureInitialized(); | ||
SystemChrome.setPreferredOrientations([ | ||
DeviceOrientation.portraitUp, | ||
]); | ||
await Firebase.initializeApp( | ||
options: DefaultFirebaseOptions.currentPlatform, | ||
); | ||
prefs = await SharedPreferences.getInstance(); | ||
algolia = const Algolia.init( | ||
applicationId: 'NYVVAA43NI', | ||
apiKey: 'cf52a68ac340fc555978892202ce37df', | ||
); | ||
await Firebase.initializeApp( | ||
options: DefaultFirebaseOptions.currentPlatform, | ||
); | ||
await FirebaseAuth.instance.authStateChanges().first; | ||
await EditorStore.init(); | ||
await GlobalStore.init(); | ||
runApp(const App()); | ||
GlobalStore.init(); | ||
setPathUrlStrategy(); | ||
runApp(App()); | ||
} | ||
|
||
class App extends StatelessWidget { | ||
const App({Key? key}) : super(key: key); | ||
App({Key? key}) : super(key: key); | ||
|
||
final _appRouter = AppRouter(rootGuard: RootGuard()); | ||
|
||
@override | ||
Widget build(context) { | ||
final themes = Themes(Theme.of(context).colorScheme); | ||
return MaterialApp( | ||
final theme = ThemeSet(Theme.of(context).colorScheme); | ||
return MaterialApp.router( | ||
title: 'Avzag', | ||
theme: themes.light, | ||
darkTheme: themes.dark, | ||
home: FutureBuilder<void>( | ||
future: Future.value(), | ||
builder: (context, snapshot) { | ||
navigate( | ||
context, | ||
prefs.getString('module') ?? 'home', | ||
); | ||
return const Material(); | ||
}, | ||
), | ||
theme: theme.light, | ||
darkTheme: theme.dark, | ||
routerDelegate: _appRouter.delegate(), | ||
routeInformationParser: _appRouter.defaultRouteParser(), | ||
); | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import 'package:auto_route/auto_route.dart'; | ||
import 'package:avzag/models/language.dart'; | ||
import 'package:avzag/modules/account/widgets/account_tile.dart'; | ||
import 'package:avzag/modules/account/widgets/adminable_languages.dart'; | ||
import 'package:avzag/modules/navigation/services/router.gr.dart'; | ||
import 'package:avzag/store.dart'; | ||
import 'package:firebase_auth/firebase_auth.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
import '../widgets/sign_in_buttons.dart'; | ||
|
||
class AccountScreen extends StatefulWidget { | ||
const AccountScreen({Key? key}) : super(key: key); | ||
|
||
@override | ||
State<AccountScreen> createState() => _AccountScreenState(); | ||
} | ||
|
||
class _AccountScreenState extends State<AccountScreen> { | ||
var adminable = <String>[]; | ||
User? get user => FirebaseAuth.instance.currentUser; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
leading: IconButton( | ||
icon: const Icon(Icons.arrow_back_rounded), | ||
onPressed: () => context.pushRoute(const RootRoute()), | ||
), | ||
title: const Text('Account'), | ||
), | ||
body: ListView( | ||
padding: const EdgeInsets.only(bottom: 76), | ||
children: [ | ||
if (user == null) | ||
SignInButtons( | ||
onSingIn: () => EditorStore.getAdminable().then( | ||
(value) => setState(() { | ||
adminable = value; | ||
}), | ||
), | ||
) | ||
else ...[ | ||
AccountTile( | ||
user!, | ||
onSignOut: () => setState(() {}), | ||
), | ||
AdminableLanguages( | ||
GlobalStore.languages.values.whereType<Language>().toList(), | ||
adminable: adminable, | ||
onTap: (l) => setState(() { | ||
EditorStore.language = l == EditorStore.language ? null : l; | ||
}), | ||
selected: EditorStore.language, | ||
), | ||
], | ||
], | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import 'package:firebase_auth/firebase_auth.dart'; | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:google_sign_in/google_sign_in.dart'; | ||
import 'package:sign_in_with_apple/sign_in_with_apple.dart' as apple; | ||
|
||
import 'crypto.dart'; | ||
|
||
Future<AuthCredential?> getGoogleCredentials() async { | ||
final user = await GoogleSignIn().signIn(); | ||
if (user != null) { | ||
final auth = await user.authentication; | ||
return GoogleAuthProvider.credential( | ||
accessToken: auth.accessToken, | ||
idToken: auth.idToken, | ||
); | ||
} | ||
return null; | ||
} | ||
|
||
Future<AuthCredential?> getAppleCredentials() async { | ||
if (kIsWeb) { | ||
final provider = OAuthProvider('apple.com') | ||
..addScope('email') | ||
..addScope('name'); | ||
await FirebaseAuth.instance.signInWithPopup(provider); | ||
} else { | ||
final rawNonce = generateNonce(); | ||
final nonce = sha256ofString(rawNonce); | ||
var redirectURL = 'https://avzagapp.firebaseapp.com/__/auth/handler'; | ||
var clientID = 'avzagapp'; | ||
final appleIdCredential = await apple.SignInWithApple.getAppleIDCredential( | ||
scopes: [ | ||
apple.AppleIDAuthorizationScopes.email, | ||
apple.AppleIDAuthorizationScopes.fullName, | ||
], | ||
webAuthenticationOptions: apple.WebAuthenticationOptions( | ||
clientId: clientID, | ||
redirectUri: Uri.parse(redirectURL), | ||
), | ||
nonce: nonce, | ||
); | ||
// Create an `OAuthCredential` from the credential returned by Apple. | ||
return OAuthProvider('apple.com').credential( | ||
idToken: appleIdCredential.identityToken, | ||
accessToken: appleIdCredential.authorizationCode, | ||
rawNonce: rawNonce, | ||
); | ||
} | ||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import 'dart:convert'; | ||
import 'dart:math'; | ||
|
||
import 'package:crypto/crypto.dart'; | ||
|
||
String generateNonce([int length = 32]) { | ||
const charset = | ||
'0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-._'; | ||
final random = Random.secure(); | ||
return List.generate(length, (_) => charset[random.nextInt(charset.length)]) | ||
.join(); | ||
} | ||
|
||
String sha256ofString(String input) { | ||
final bytes = utf8.encode(input); | ||
final digest = sha256.convert(bytes); | ||
return digest.toString(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import 'package:firebase_auth/firebase_auth.dart'; | ||
import 'package:google_sign_in/google_sign_in.dart'; | ||
|
||
Future<bool> signIn( | ||
Future<AuthCredential?> Function() getCredentials, | ||
) async { | ||
final credentials = await getCredentials(); | ||
if (credentials == null) return false; | ||
await FirebaseAuth.instance.signInWithCredential(credentials); | ||
return true; | ||
} | ||
|
||
Future<bool> signOut([User? user]) async { | ||
final provider = (user ?? FirebaseAuth.instance.currentUser) | ||
?.providerData | ||
.first | ||
.providerId; | ||
if (provider == null) return false; | ||
|
||
await FirebaseAuth.instance.signOut(); | ||
switch (provider) { | ||
case 'google.com': | ||
await GoogleSignIn().signOut(); | ||
break; | ||
} | ||
return true; | ||
} |
Oops, something went wrong.