Skip to content

Commit

Permalink
Merge pull request #42 from raxysstudios/v0.7
Browse files Browse the repository at this point in the history
v0.7
  • Loading branch information
alkaitagi authored Jul 2, 2022
2 parents de0c26f + ac30ba6 commit e043b9a
Show file tree
Hide file tree
Showing 80 changed files with 2,169 additions and 1,884 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
.pub-cache/
.pub/
/build/
*.g.dart
*.gr.dart

# Web related
lib/generated_plugin_registrant.dart
Expand Down
4 changes: 3 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:lints/recommended.yaml
include: package:flutter_lints/flutter.yaml

analyzer:
strong-mode:
implicit-casts: false
implicit-dynamic: false
exclude:
- 'lib/**/*.g.dart'
- 'lib/**/*.gr.dart'

linter:
# The lint rules applied to this project can be customized in the
Expand All @@ -32,6 +33,7 @@ linter:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
prefer_single_quotes: true
directives_ordering: true
use_build_context_synchronously: false

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
8 changes: 8 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<meta-data android:name="flutter_deeplinking_enabled" android:value="true" />
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="avzag.raxys.app" />
<data android:scheme="https" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
Expand Down
Binary file added assets/raxys.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 removed assets/raxys_dark.png
Binary file not shown.
Binary file removed assets/raxys_light.png
Binary file not shown.
1,214 changes: 512 additions & 702 deletions functions/package-lock.json

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,20 @@
</array>
</dict>
</array>
<key>FlutterDeepLinkingEnabled</key>
<true/>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>avzag.raxys.app</string>
<key>CFBundleURLSchemes</key>
<array>
<string>customscheme</string>
</array>
</dict>
</array>
</dict>
</plist>
13 changes: 0 additions & 13 deletions lib/config/themes.dart

This file was deleted.

17 changes: 0 additions & 17 deletions lib/config/themes/dark.dart

This file was deleted.

21 changes: 0 additions & 21 deletions lib/config/themes/light.dart

This file was deleted.

44 changes: 22 additions & 22 deletions lib/main.dart
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.
2 changes: 1 addition & 1 deletion lib/models/language.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:avzag/shared/utils/utils.dart';
import 'package:avzag/shared/utils.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

class LanguageStats {
Expand Down
62 changes: 62 additions & 0 deletions lib/modules/account/screens/account.dart
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,
),
],
],
),
);
}
}
50 changes: 50 additions & 0 deletions lib/modules/account/services/credentials.dart
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;
}
18 changes: 18 additions & 0 deletions lib/modules/account/services/crypto.dart
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();
}
27 changes: 27 additions & 0 deletions lib/modules/account/services/signing.dart
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;
}
Loading

0 comments on commit e043b9a

Please sign in to comment.