Skip to content

Commit 47e65ec

Browse files
authored
Merge pull request #77 from Onix-Systems/dev
1.1.2+27
2 parents a597416 + 6634089 commit 47e65ec

File tree

43 files changed

+492
-213
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+492
-213
lines changed

bricks/flutter_clean_base/__brick__/{{project_name.snakeCase()}}/analysis_options.yaml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,17 @@ analyzer:
1111
- "**/*.mocks.dart"
1212
- "**/*.tailor.dart"
1313
- "ios/**"
14-
- "lib/core/app/localization/**"
14+
- "lib/app/localization/**"
1515

1616
errors:
1717
prefer_mixin: ignore
1818
flutter_style_todos: ignore
1919
invalid_annotation_target: ignore
2020
always_use_package_imports: warning
21-
avoid_dynamic_calls: info
21+
avoid_dynamic_calls: ignore
2222
avoid_empty_else: error
2323
avoid_print: warning
2424
avoid_relative_lib_imports: warning
25-
avoid_returning_null_for_future: error
2625
avoid_slow_async_io: warning
2726
avoid_type_to_string: error
2827
avoid_types_as_parameter_names: info
@@ -70,7 +69,6 @@ linter:
7069
avoid_empty_else: true
7170
avoid_print: true
7271
avoid_relative_lib_imports: true
73-
avoid_returning_null_for_future: true
7472
avoid_slow_async_io: true
7573
avoid_type_to_string: true
7674
avoid_types_as_parameter_names: true
@@ -100,9 +98,8 @@ linter:
10098
# Style rules.
10199
always_declare_return_types: true
102100
always_put_required_named_parameters_first: true
103-
always_require_non_null_named_parameters: true
104101
annotate_overrides: true
105-
avoid_annotating_with_dynamic: true
102+
avoid_annotating_with_dynamic: false
106103
avoid_bool_literals_in_conditional_expressions: true
107104
avoid_catching_errors: true
108105
avoid_equals_and_hash_code_on_mutable_classes: true
@@ -118,7 +115,6 @@ linter:
118115
avoid_private_typedef_functions: true
119116
avoid_renaming_method_parameters: true
120117
avoid_return_types_on_setters: true
121-
avoid_returning_null: true
122118
avoid_returning_null_for_void: true
123119
avoid_returning_this: true
124120
avoid_setters_without_getters: true
@@ -150,7 +146,7 @@ linter:
150146
non_constant_identifier_names: true
151147
null_closures: true
152148
omit_local_variable_types: true
153-
one_member_abstracts: true
149+
one_member_abstracts: false
154150
only_throw_errors: true
155151
overridden_fields: true
156152
package_api_docs: true

bricks/flutter_clean_base/__brick__/{{project_name.snakeCase()}}/lib/app.gen.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ class _AppState extends BaseState<AppScreenState, AppBloc, AppSR, App> {
5252
);
5353
},
5454
scrollBehavior: const CupertinoScrollBehavior(),
55-
title: '',
5655
theme: createLightTheme(),
5756
darkTheme: createDarkTheme(),
5857
themeMode: state.themeMode,

bricks/flutter_clean_base/__brick__/{{project_name.snakeCase()}}/lib/app/router/app_router.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
//@formatter:off
22
{{^isGoRouter}}import 'package:auto_route/auto_route.dart';{{/isGoRouter}}
3+
{{#isGoRouter}}import 'package:{{project_name}}/app/router/app_route.dart';{{/isGoRouter}}
34
{{#isGoRouter}}import 'package:flutter_bloc/flutter_bloc.dart';{{/isGoRouter}}
45
import 'package:flutter/material.dart';
56
{{#isGoRouter}}import 'package:go_router/go_router.dart';{{/isGoRouter}}
7+
{{#isGoRouter}}import 'package:{{project_name}}/core/di/services.dart';{{/isGoRouter}}
68
{{^isGoRouter}}import 'package:{{project_name}}/app/router/guard/init_guard.dart';{{/isGoRouter}}
79

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

17-
//{consts end}
18-
1919
static final AppRouter _instance = AppRouter._privateConstructor();
2020
static late GoRouter router;
2121

22-
//{getters end}
23-
2422
AppRouter._privateConstructor() {
2523
_initialize();
2624
}
@@ -32,6 +30,10 @@ class AppRouter {{^isGoRouter}}extends _$AppRouter{{/isGoRouter}}{
3230
void _initialize({String initialLocation = _initialLocation}) {
3331
router = GoRouter(
3432
initialLocation: initialLocation,
33+
refreshListenable: sessionService(),
34+
redirect: (context,state){
35+
return null;
36+
},
3537
routes: <GoRoute>[
3638
//{routes end}
3739
],
@@ -40,7 +42,7 @@ class AppRouter {{^isGoRouter}}extends _$AppRouter{{/isGoRouter}}{
4042

4143
{{^isGoRouter}}@override
4244
final List<AutoRoute> routes = [
43-
//{routes end}
45+
//{routes end}
4446
];
4547

4648
final InitGuard init;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import 'package:{{project_name}}/app/router/app_route_location.dart';
2+
3+
enum AppRoute {
4+
5+
//{routes declaration end}
6+
7+
final String routePath;
8+
final AppRouteLocation location;
9+
10+
const AppRoute(
11+
this.routePath, {
12+
this.location = AppRouteLocation.securedApp,
13+
});
14+
15+
static AppRoute? fromName(String? value) {
16+
if (value == null || value.isEmpty) {
17+
return null;
18+
}
19+
return AppRoute.values.firstWhere((e) => e.name == value);
20+
}
21+
22+
static AppRoute? fromRoutePath(String? value) {
23+
if (value == null || value.isEmpty) {
24+
return null;
25+
}
26+
return AppRoute.values.firstWhere((e) => e.routePath == value);
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
enum AppRouteLocation {
3+
auth,
4+
securedApp,
5+
}
6+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:go_router/go_router.dart';
3+
import 'package:{{project_name}}/app/router/app_route.dart';
4+
5+
6+
///[ReusableRouteFlow] designed to build nested flow with few screens
7+
///with functionality to return to flow begin point.
8+
///Usage: Extend yor Flow class with [ReusableRouteFlow]
9+
///Example
10+
///class KycFlow extends ReusableRouteFlow {
11+
///
12+
/// KycFlow(super.rootNavigatorKey);
13+
///
14+
/// @override
15+
/// List<GoRoute> routes({
16+
/// bool useRootNavigator = true,
17+
/// }) =>
18+
/// [
19+
/// //flow routes here
20+
/// ];
21+
/// }
22+
///
23+
/// Declare Flow in AppRouter and
24+
/// add to GoRouter top level routes from Flow also
25+
/// ...yourFlow.routes()
26+
///
27+
abstract class ReusableRouteFlow {
28+
final GlobalKey<NavigatorState> rootNavigatorKey;
29+
String? _flowRedirect;
30+
Map<String, String>? _redirectParameters;
31+
Object? _redirectExtra;
32+
int _flowIndex = 0;
33+
34+
ReusableRouteFlow(this.rootNavigatorKey);
35+
36+
///Starts Flow rom first screen in flow
37+
///AppRouter.myFlow.startFlow(context)
38+
void startFlow(
39+
BuildContext context, {
40+
AppRoute? flowRedirect,
41+
Map<String, String>? redirectParameters,
42+
Object? redirectExtra,
43+
}) {
44+
if (flowRedirect != null) {
45+
_flowRedirect = flowRedirect.routePath;
46+
_redirectParameters = redirectParameters;
47+
_redirectExtra = redirectExtra;
48+
} else {
49+
_flowRedirect = _getRedirectToCurrentPath(context);
50+
_redirectParameters = _getRedirectToCurrentParameters(context);
51+
_redirectExtra = _getRedirectToCurrentExtra(context);
52+
}
53+
_flowIndex = 0;
54+
final flowEntry = routes().first.name;
55+
if (flowEntry == null) {
56+
throw Exception('Flow entry invalid');
57+
}
58+
context.pushNamed(flowEntry);
59+
}
60+
61+
///Navigates to next screen in Flow
62+
void next(
63+
BuildContext context, {
64+
Map<String, String>? parameters,
65+
Object? extra,
66+
}) {
67+
_flowIndex++;
68+
if (_flowIndex >= routes().length) {
69+
finishFlow(context);
70+
return;
71+
}
72+
final flowStep = routes()[_flowIndex].name;
73+
if (flowStep == null) {
74+
throw Exception('Next flow step invalid');
75+
}
76+
context.pushNamed(
77+
flowStep,
78+
pathParameters: parameters ?? {},
79+
extra: extra,
80+
);
81+
}
82+
83+
///Navigates to Previous screen in flow
84+
void previous(
85+
BuildContext context, {
86+
Object? result,
87+
}) {
88+
_flowIndex--;
89+
if (_flowIndex <= 0) {
90+
finishFlow(context);
91+
return;
92+
}
93+
context.pop(result);
94+
}
95+
96+
///Finish flow and go back to declared redirect location
97+
///AppRouter.myFlow.finishFlow(context)
98+
///
99+
void finishFlow(BuildContext context) {
100+
final flowRedirect = _flowRedirect;
101+
if (flowRedirect == null) {
102+
throw Exception('Flow entry invalid');
103+
}
104+
if (flowRedirect.contains('/')) {
105+
context.go(
106+
flowRedirect,
107+
extra: _redirectExtra,
108+
);
109+
} else {
110+
context.goNamed(
111+
flowRedirect,
112+
pathParameters: _redirectParameters ?? {},
113+
extra: _redirectExtra,
114+
);
115+
}
116+
_flowRedirect = null;
117+
_redirectParameters = null;
118+
_redirectExtra = null;
119+
_flowIndex = 0;
120+
}
121+
122+
@protected
123+
List<GoRoute> routes({
124+
bool useRootNavigator = true,
125+
});
126+
127+
String _getRedirectToCurrentPath(BuildContext context) {
128+
final router = GoRouter.maybeOf(context);
129+
if (router == null) {
130+
throw Exception('GoRouter not found');
131+
}
132+
return router.routerDelegate.currentConfiguration.fullPath;
133+
}
134+
135+
Map<String, String> _getRedirectToCurrentParameters(BuildContext context) {
136+
final router = GoRouter.maybeOf(context);
137+
if (router == null) {
138+
throw Exception('GoRouter not found');
139+
}
140+
return router.routerDelegate.currentConfiguration.pathParameters;
141+
}
142+
143+
Object? _getRedirectToCurrentExtra(BuildContext context) {
144+
final router = GoRouter.maybeOf(context);
145+
if (router == null) {
146+
throw Exception('GoRouter not found');
147+
}
148+
return router.routerDelegate.currentConfiguration.extra;
149+
}
150+
}

bricks/flutter_clean_base/__brick__/{{project_name.snakeCase()}}/lib/app/service/hive_cipher_key_service.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import 'dart:typed_data';
33

44
import 'package:{{project_name}}/data/source/local/secure_storage/secure_storage_keys.dart';
55
import 'package:{{project_name}}/data/source/local/secure_storage/secure_storage_source.dart';
6-
import 'package:hive/hive.dart';
6+
import 'package:hive_flutter/hive_flutter.dart';
77

88
class HiveCipherKeyService {
99
final SecureStorageSource _storage;
Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,61 @@
11
import 'dart:async';
22

3-
import 'package:{{project_name}}/core/di/remote.dart';
3+
{{#isGoRouter}}import 'package:flutter/foundation.dart';{{/isGoRouter}}
44
import 'package:{{project_name}}/core/di/repository.dart';
55
import 'package:{{project_name}}/domain/entity/authentication/authentication.dart';
66
import 'package:{{project_name}}/app/service/session_service/session_status.dart';
77

8-
class SessionService {
8+
class SessionService {{#isGoRouter}}extends ChangeNotifier{{/isGoRouter}} {
9+
10+
{{^isGoRouter}}
911
final StreamController<SessionStatus> _sessionObserver =
10-
StreamController<SessionStatus>();
12+
StreamController<SessionStatus>();
13+
{{/isGoRouter}}
1114

1215
SessionStatus _sessionStatus = SessionStatus.closed;
1316

17+
{{^isGoRouter}}
1418
Stream<SessionStatus> get sessionObserver => _sessionObserver.stream;
19+
{{/isGoRouter}}
1520

1621
SessionStatus get sessionStatus => _sessionStatus;
1722

23+
Future<void> renewSession() async {
24+
final authData = await tokenRepository.getAuthData();
25+
if (authData == null) {
26+
return;
27+
}
28+
if (authData.accessToken.isEmpty) {
29+
return;
30+
}
31+
_sessionStatus = SessionStatus.open;
32+
{{#isGoRouter}}
33+
notifyListeners();
34+
{{/isGoRouter}}
35+
{{^isGoRouter}}
36+
_sessionObserver.add(_sessionStatus);
37+
{{/isGoRouter}}
38+
}
39+
1840
Future<void> openSession(Authentication authEntity) async {
1941
await tokenRepository.update(authEntity);
2042
_sessionStatus = SessionStatus.open;
43+
{{#isGoRouter}}
44+
notifyListeners();
45+
{{/isGoRouter}}
46+
{{^isGoRouter}}
2147
_sessionObserver.add(_sessionStatus);
48+
{{/isGoRouter}}
2249
}
2350

2451
Future<void> closeSession() async {
2552
await tokenRepository.clear();
2653
_sessionStatus = SessionStatus.closed;
27-
_sessionObserver.add(_sessionStatus);
54+
{{#isGoRouter}}
55+
notifyListeners();
56+
{{/isGoRouter}}
57+
{{^isGoRouter}}
58+
_sessionObserver.add(_sessionStatus);
59+
{{/isGoRouter}}
2860
}
2961
}

0 commit comments

Comments
 (0)