-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
428 additions
and
179 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
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
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
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,30 @@ | ||
# This file tracks properties of this Flutter project. | ||
# Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
# | ||
# This file should be version controlled and should not be manually edited. | ||
|
||
version: | ||
revision: "67457e669f79e9f8d13d7a68fe09775fefbb79f4" | ||
channel: "stable" | ||
|
||
project_type: app | ||
|
||
# Tracks metadata for the flutter migrate command | ||
migration: | ||
platforms: | ||
- platform: root | ||
create_revision: 67457e669f79e9f8d13d7a68fe09775fefbb79f4 | ||
base_revision: 67457e669f79e9f8d13d7a68fe09775fefbb79f4 | ||
- platform: web | ||
create_revision: 67457e669f79e9f8d13d7a68fe09775fefbb79f4 | ||
base_revision: 67457e669f79e9f8d13d7a68fe09775fefbb79f4 | ||
|
||
# User provided section | ||
|
||
# List of Local paths (relative to this file) that should be | ||
# ignored by the migrate tool. | ||
# | ||
# Files that are not part of the templates will be ignored by default. | ||
unmanaged_files: | ||
- 'lib/main.dart' | ||
- 'ios/Runner.xcodeproj/project.pbxproj' |
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
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,54 +1,180 @@ | ||
import 'package:flutter/cupertino.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
import 'package:go_router/go_router.dart'; | ||
|
||
import 'package:my_quran/models/models.dart'; | ||
import 'package:my_quran/app/app.dart'; | ||
import 'package:my_quran/modules/modules.dart'; | ||
|
||
class AppRouter { | ||
const AppRouter(); | ||
|
||
static const String main = '/'; | ||
static const String home = '/home'; | ||
static const String hatim = '/hatim'; | ||
static const String quran = '/quran'; | ||
static const String read = '/read'; | ||
static const String login = '/login'; | ||
static const String signIn = '/sign-in'; | ||
|
||
static const String settingsPage = '/settings'; | ||
static const String langSettings = '/lang-settings'; | ||
static const String genderSettings = '/gender-settings'; | ||
static const String themeSettings = '/theme-settings'; | ||
static const String aboutUs = '/about-us'; | ||
static const String contactUs = '/contect-us'; | ||
static const String developers = '/developers'; | ||
static const String devModeView = '/dev-mode-view'; | ||
|
||
static Route<void> onGenerateRoute(RouteSettings settings, User? user) { | ||
return switch (settings.name) { | ||
main => CupertinoPageRoute(builder: (_) => user != null ? const MainView() : const LoginView()), | ||
home => CupertinoPageRoute(builder: (_) => const HomeView()), | ||
hatim => CupertinoPageRoute(builder: (_) => const HatimView()), | ||
quran => CupertinoPageRoute(builder: (_) => const QuranView()), | ||
login => CupertinoPageRoute(builder: (_) => const LoginView()), | ||
signIn => CupertinoPageRoute(builder: (_) => const SignInView()), | ||
settingsPage => CupertinoPageRoute(builder: (_) => const SettingsView()), | ||
aboutUs => CupertinoPageRoute(builder: (_) => const AboutUsVuew()), | ||
contactUs => CupertinoPageRoute(builder: (_) => const ContactUsView()), | ||
developers => CupertinoPageRoute(builder: (_) => const DevelopersView()), | ||
genderSettings => CupertinoPageRoute(builder: (_) => const GenderSettingView()), | ||
langSettings => CupertinoPageRoute(builder: (_) => const LangSettingsView()), | ||
themeSettings => CupertinoPageRoute(builder: (_) => const ThemeSettingsView()), | ||
devModeView => CupertinoPageRoute(builder: (_) => const DevModeView()), | ||
read => CupertinoPageRoute<bool>( | ||
builder: (_) { | ||
final args = settings.arguments!; | ||
return ReadView( | ||
(args as Map<String, dynamic>)['pages'] as List<int>, | ||
isHatim: args['isHatim'] as bool, | ||
); | ||
}, | ||
final _rootNavigatorKey = GlobalKey<NavigatorState>(); | ||
final _sectionNavigatorKey1 = GlobalKey<NavigatorState>(debugLabel: 'home'); | ||
final _sectionNavigatorKey2 = GlobalKey<NavigatorState>(debugLabel: 'quran'); | ||
final _sectionNavigatorKey3 = GlobalKey<NavigatorState>(debugLabel: 'quran-audio'); | ||
final _sectionNavigatorKey4 = GlobalKey<NavigatorState>(debugLabel: 'settings'); | ||
|
||
@immutable | ||
final class AppRouter { | ||
const AppRouter._(); | ||
|
||
static const home = 'home'; | ||
static const hatim = 'hatim'; | ||
static const quran = 'quran'; | ||
static const quranAudio = 'quran-audio'; | ||
|
||
static const read = 'read'; | ||
static const hatimRead = 'hatim-read'; | ||
static const login = 'login'; | ||
|
||
static const settingsPage = 'settings'; | ||
static const langSettings = 'lang-settings'; | ||
static const genderSettings = 'gender-settings'; | ||
static const themeSettings = 'theme-settings'; | ||
static const aboutUs = 'about-us'; | ||
static const contactUs = 'contect-us'; | ||
static const developers = 'developers'; | ||
static const devModeView = 'dev-mode-view'; | ||
|
||
static final router = GoRouter( | ||
initialLocation: '/home', | ||
navigatorKey: _rootNavigatorKey, | ||
debugLogDiagnostics: true, | ||
routes: [ | ||
GoRoute( | ||
path: '/', | ||
builder: (context, state) => const Scaffold( | ||
body: Center(child: Text('Init')), | ||
), | ||
_ => throw Exception('no builder specified for route named: [${settings.name}]'), | ||
}; | ||
), | ||
GoRoute( | ||
path: '/$login', | ||
name: login, | ||
builder: (context, state) => const LoginView(), | ||
), | ||
GoRoute( | ||
path: '/$devModeView', | ||
name: devModeView, | ||
builder: (context, state) => const DevModeView(), | ||
), | ||
StatefulShellRoute.indexedStack( | ||
builder: (context, state, navigationShell) => MainView(navigationShell), | ||
branches: [ | ||
StatefulShellBranch( | ||
navigatorKey: _sectionNavigatorKey1, | ||
routes: [ | ||
GoRoute( | ||
path: '/$home', | ||
name: home, | ||
builder: (context, state) => const HomeView(), | ||
routes: homeSubRoutes, | ||
), | ||
], | ||
), | ||
StatefulShellBranch( | ||
navigatorKey: _sectionNavigatorKey2, | ||
routes: [ | ||
GoRoute( | ||
path: '/$quran', | ||
name: quran, | ||
builder: (context, state) => const QuranView(), | ||
routes: quranSubRoutes, | ||
), | ||
], | ||
), | ||
StatefulShellBranch( | ||
navigatorKey: _sectionNavigatorKey3, | ||
routes: [ | ||
GoRoute( | ||
path: '/$quranAudio', | ||
name: quranAudio, | ||
builder: (context, state) => const QuranAudioView(), | ||
), | ||
], | ||
), | ||
StatefulShellBranch( | ||
navigatorKey: _sectionNavigatorKey4, | ||
routes: [ | ||
GoRoute( | ||
path: '/$settingsPage', | ||
name: settingsPage, | ||
builder: (context, state) => const SettingsView(), | ||
routes: settingsSubRoutes, | ||
), | ||
], | ||
), | ||
], | ||
), | ||
], | ||
redirect: (context, state) { | ||
return !context.read<AuthCubit>().isAuthedticated ? '/$login' : null; | ||
}, | ||
); | ||
|
||
static List<RouteBase> get homeSubRoutes { | ||
return [ | ||
GoRoute( | ||
path: hatim, | ||
name: hatim, | ||
builder: (context, state) => const HatimView(), | ||
routes: [ | ||
GoRoute( | ||
path: '$hatimRead/:isHatim/:pages', | ||
name: hatimRead, | ||
parentNavigatorKey: _rootNavigatorKey, | ||
builder: (context, state) { | ||
final args = ParseParams.parseRead(state.pathParameters); | ||
return ReadView(args.$1, isHatim: args.$2); | ||
}, | ||
), | ||
], | ||
), | ||
]; | ||
} | ||
|
||
static List<RouteBase> get quranSubRoutes { | ||
return [ | ||
GoRoute( | ||
path: '$read/:isHatim/:pages', | ||
name: read, | ||
parentNavigatorKey: _rootNavigatorKey, | ||
builder: (context, state) { | ||
final args = ParseParams.parseRead(state.pathParameters); | ||
return ReadView(args.$1, isHatim: args.$2); | ||
}, | ||
), | ||
]; | ||
} | ||
|
||
static List<RouteBase> get settingsSubRoutes { | ||
return [ | ||
GoRoute( | ||
path: genderSettings, | ||
name: genderSettings, | ||
builder: (context, state) => const GenderSettingView(), | ||
), | ||
GoRoute( | ||
path: langSettings, | ||
name: langSettings, | ||
builder: (context, state) => const LangSettingsView(), | ||
), | ||
GoRoute( | ||
path: themeSettings, | ||
name: themeSettings, | ||
builder: (context, state) => const ThemeSettingsView(), | ||
), | ||
GoRoute( | ||
path: aboutUs, | ||
name: aboutUs, | ||
builder: (context, state) => const AboutUsVuew(), | ||
), | ||
GoRoute( | ||
path: contactUs, | ||
name: contactUs, | ||
builder: (context, state) => const ContactUsView(), | ||
), | ||
GoRoute( | ||
path: developers, | ||
name: developers, | ||
builder: (context, state) => const DevelopersView(), | ||
), | ||
]; | ||
} | ||
} |
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,20 @@ | ||
import 'dart:developer'; | ||
|
||
import 'package:meta/meta.dart'; | ||
|
||
@immutable | ||
final class ParseParams { | ||
const ParseParams._(); | ||
|
||
static (List<int>, bool) parseRead(Map<String, String> args) { | ||
try { | ||
final isHatim = args['isHatim'] == 'true'; | ||
final p1 = args['pages'] ?? '[1]'; | ||
final pages = p1.substring(1, p1.length - 1).split(',').map(int.parse).toList(); | ||
return (pages, isHatim); | ||
} catch (e) { | ||
log(e.toString()); | ||
return ([1], false); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.