Skip to content

Commit

Permalink
Merge pull request #77 from Onix-Systems/dev
Browse files Browse the repository at this point in the history
1.1.2+27
  • Loading branch information
cozvtieg9 authored Jun 14, 2024
2 parents a597416 + 6634089 commit 47e65ec
Show file tree
Hide file tree
Showing 43 changed files with 492 additions and 213 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,17 @@ analyzer:
- "**/*.mocks.dart"
- "**/*.tailor.dart"
- "ios/**"
- "lib/core/app/localization/**"
- "lib/app/localization/**"

errors:
prefer_mixin: ignore
flutter_style_todos: ignore
invalid_annotation_target: ignore
always_use_package_imports: warning
avoid_dynamic_calls: info
avoid_dynamic_calls: ignore
avoid_empty_else: error
avoid_print: warning
avoid_relative_lib_imports: warning
avoid_returning_null_for_future: error
avoid_slow_async_io: warning
avoid_type_to_string: error
avoid_types_as_parameter_names: info
Expand Down Expand Up @@ -70,7 +69,6 @@ linter:
avoid_empty_else: true
avoid_print: true
avoid_relative_lib_imports: true
avoid_returning_null_for_future: true
avoid_slow_async_io: true
avoid_type_to_string: true
avoid_types_as_parameter_names: true
Expand Down Expand Up @@ -100,9 +98,8 @@ linter:
# Style rules.
always_declare_return_types: true
always_put_required_named_parameters_first: true
always_require_non_null_named_parameters: true
annotate_overrides: true
avoid_annotating_with_dynamic: true
avoid_annotating_with_dynamic: false
avoid_bool_literals_in_conditional_expressions: true
avoid_catching_errors: true
avoid_equals_and_hash_code_on_mutable_classes: true
Expand All @@ -118,7 +115,6 @@ linter:
avoid_private_typedef_functions: true
avoid_renaming_method_parameters: true
avoid_return_types_on_setters: true
avoid_returning_null: true
avoid_returning_null_for_void: true
avoid_returning_this: true
avoid_setters_without_getters: true
Expand Down Expand Up @@ -150,7 +146,7 @@ linter:
non_constant_identifier_names: true
null_closures: true
omit_local_variable_types: true
one_member_abstracts: true
one_member_abstracts: false
only_throw_errors: true
overridden_fields: true
package_api_docs: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class _AppState extends BaseState<AppScreenState, AppBloc, AppSR, App> {
);
},
scrollBehavior: const CupertinoScrollBehavior(),
title: '',
theme: createLightTheme(),
darkTheme: createDarkTheme(),
themeMode: state.themeMode,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//@formatter:off
{{^isGoRouter}}import 'package:auto_route/auto_route.dart';{{/isGoRouter}}
{{#isGoRouter}}import 'package:{{project_name}}/app/router/app_route.dart';{{/isGoRouter}}
{{#isGoRouter}}import 'package:flutter_bloc/flutter_bloc.dart';{{/isGoRouter}}
import 'package:flutter/material.dart';
{{#isGoRouter}}import 'package:go_router/go_router.dart';{{/isGoRouter}}
{{#isGoRouter}}import 'package:{{project_name}}/core/di/services.dart';{{/isGoRouter}}
{{^isGoRouter}}import 'package:{{project_name}}/app/router/guard/init_guard.dart';{{/isGoRouter}}

//{imports end}
Expand All @@ -14,13 +16,9 @@ part 'app_router.gr.dart';
class AppRouter {{^isGoRouter}}extends _$AppRouter{{/isGoRouter}}{
{{#isGoRouter}}static const _initialLocation = '/';

//{consts end}

static final AppRouter _instance = AppRouter._privateConstructor();
static late GoRouter router;

//{getters end}

AppRouter._privateConstructor() {
_initialize();
}
Expand All @@ -32,6 +30,10 @@ class AppRouter {{^isGoRouter}}extends _$AppRouter{{/isGoRouter}}{
void _initialize({String initialLocation = _initialLocation}) {
router = GoRouter(
initialLocation: initialLocation,
refreshListenable: sessionService(),
redirect: (context,state){
return null;
},
routes: <GoRoute>[
//{routes end}
],
Expand All @@ -40,7 +42,7 @@ class AppRouter {{^isGoRouter}}extends _$AppRouter{{/isGoRouter}}{

{{^isGoRouter}}@override
final List<AutoRoute> routes = [
//{routes end}
//{routes end}
];

final InitGuard init;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'package:{{project_name}}/app/router/app_route_location.dart';

enum AppRoute {

//{routes declaration end}

final String routePath;
final AppRouteLocation location;

const AppRoute(
this.routePath, {
this.location = AppRouteLocation.securedApp,
});

static AppRoute? fromName(String? value) {
if (value == null || value.isEmpty) {
return null;
}
return AppRoute.values.firstWhere((e) => e.name == value);
}

static AppRoute? fromRoutePath(String? value) {
if (value == null || value.isEmpty) {
return null;
}
return AppRoute.values.firstWhere((e) => e.routePath == value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

enum AppRouteLocation {
auth,
securedApp,
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:{{project_name}}/app/router/app_route.dart';


///[ReusableRouteFlow] designed to build nested flow with few screens
///with functionality to return to flow begin point.
///Usage: Extend yor Flow class with [ReusableRouteFlow]
///Example
///class KycFlow extends ReusableRouteFlow {
///
/// KycFlow(super.rootNavigatorKey);
///
/// @override
/// List<GoRoute> routes({
/// bool useRootNavigator = true,
/// }) =>
/// [
/// //flow routes here
/// ];
/// }
///
/// Declare Flow in AppRouter and
/// add to GoRouter top level routes from Flow also
/// ...yourFlow.routes()
///
abstract class ReusableRouteFlow {
final GlobalKey<NavigatorState> rootNavigatorKey;
String? _flowRedirect;
Map<String, String>? _redirectParameters;
Object? _redirectExtra;
int _flowIndex = 0;

ReusableRouteFlow(this.rootNavigatorKey);

///Starts Flow rom first screen in flow
///AppRouter.myFlow.startFlow(context)
void startFlow(
BuildContext context, {
AppRoute? flowRedirect,
Map<String, String>? redirectParameters,
Object? redirectExtra,
}) {
if (flowRedirect != null) {
_flowRedirect = flowRedirect.routePath;
_redirectParameters = redirectParameters;
_redirectExtra = redirectExtra;
} else {
_flowRedirect = _getRedirectToCurrentPath(context);
_redirectParameters = _getRedirectToCurrentParameters(context);
_redirectExtra = _getRedirectToCurrentExtra(context);
}
_flowIndex = 0;
final flowEntry = routes().first.name;
if (flowEntry == null) {
throw Exception('Flow entry invalid');
}
context.pushNamed(flowEntry);
}

///Navigates to next screen in Flow
void next(
BuildContext context, {
Map<String, String>? parameters,
Object? extra,
}) {
_flowIndex++;
if (_flowIndex >= routes().length) {
finishFlow(context);
return;
}
final flowStep = routes()[_flowIndex].name;
if (flowStep == null) {
throw Exception('Next flow step invalid');
}
context.pushNamed(
flowStep,
pathParameters: parameters ?? {},
extra: extra,
);
}

///Navigates to Previous screen in flow
void previous(
BuildContext context, {
Object? result,
}) {
_flowIndex--;
if (_flowIndex <= 0) {
finishFlow(context);
return;
}
context.pop(result);
}

///Finish flow and go back to declared redirect location
///AppRouter.myFlow.finishFlow(context)
///
void finishFlow(BuildContext context) {
final flowRedirect = _flowRedirect;
if (flowRedirect == null) {
throw Exception('Flow entry invalid');
}
if (flowRedirect.contains('/')) {
context.go(
flowRedirect,
extra: _redirectExtra,
);
} else {
context.goNamed(
flowRedirect,
pathParameters: _redirectParameters ?? {},
extra: _redirectExtra,
);
}
_flowRedirect = null;
_redirectParameters = null;
_redirectExtra = null;
_flowIndex = 0;
}

@protected
List<GoRoute> routes({
bool useRootNavigator = true,
});

String _getRedirectToCurrentPath(BuildContext context) {
final router = GoRouter.maybeOf(context);
if (router == null) {
throw Exception('GoRouter not found');
}
return router.routerDelegate.currentConfiguration.fullPath;
}

Map<String, String> _getRedirectToCurrentParameters(BuildContext context) {
final router = GoRouter.maybeOf(context);
if (router == null) {
throw Exception('GoRouter not found');
}
return router.routerDelegate.currentConfiguration.pathParameters;
}

Object? _getRedirectToCurrentExtra(BuildContext context) {
final router = GoRouter.maybeOf(context);
if (router == null) {
throw Exception('GoRouter not found');
}
return router.routerDelegate.currentConfiguration.extra;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'dart:typed_data';

import 'package:{{project_name}}/data/source/local/secure_storage/secure_storage_keys.dart';
import 'package:{{project_name}}/data/source/local/secure_storage/secure_storage_source.dart';
import 'package:hive/hive.dart';
import 'package:hive_flutter/hive_flutter.dart';

class HiveCipherKeyService {
final SecureStorageSource _storage;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,61 @@
import 'dart:async';

import 'package:{{project_name}}/core/di/remote.dart';
{{#isGoRouter}}import 'package:flutter/foundation.dart';{{/isGoRouter}}
import 'package:{{project_name}}/core/di/repository.dart';
import 'package:{{project_name}}/domain/entity/authentication/authentication.dart';
import 'package:{{project_name}}/app/service/session_service/session_status.dart';

class SessionService {
class SessionService {{#isGoRouter}}extends ChangeNotifier{{/isGoRouter}} {

{{^isGoRouter}}
final StreamController<SessionStatus> _sessionObserver =
StreamController<SessionStatus>();
StreamController<SessionStatus>();
{{/isGoRouter}}

SessionStatus _sessionStatus = SessionStatus.closed;

{{^isGoRouter}}
Stream<SessionStatus> get sessionObserver => _sessionObserver.stream;
{{/isGoRouter}}

SessionStatus get sessionStatus => _sessionStatus;

Future<void> renewSession() async {
final authData = await tokenRepository.getAuthData();
if (authData == null) {
return;
}
if (authData.accessToken.isEmpty) {
return;
}
_sessionStatus = SessionStatus.open;
{{#isGoRouter}}
notifyListeners();
{{/isGoRouter}}
{{^isGoRouter}}
_sessionObserver.add(_sessionStatus);
{{/isGoRouter}}
}

Future<void> openSession(Authentication authEntity) async {
await tokenRepository.update(authEntity);
_sessionStatus = SessionStatus.open;
{{#isGoRouter}}
notifyListeners();
{{/isGoRouter}}
{{^isGoRouter}}
_sessionObserver.add(_sessionStatus);
{{/isGoRouter}}
}

Future<void> closeSession() async {
await tokenRepository.clear();
_sessionStatus = SessionStatus.closed;
_sessionObserver.add(_sessionStatus);
{{#isGoRouter}}
notifyListeners();
{{/isGoRouter}}
{{^isGoRouter}}
_sessionObserver.add(_sessionStatus);
{{/isGoRouter}}
}
}
Loading

0 comments on commit 47e65ec

Please sign in to comment.