Skip to content

Commit 3a77b99

Browse files
authored
Merge branch 'main' into feature/gateway-follower
2 parents 3017b2f + 6181d21 commit 3a77b99

File tree

10 files changed

+173
-64
lines changed

10 files changed

+173
-64
lines changed

catalyst_voices/ios/Podfile.lock

+6
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ PODS:
77
- path_provider_foundation (0.0.1):
88
- Flutter
99
- FlutterMacOS
10+
- url_launcher_ios (0.0.1):
11+
- Flutter
1012

1113
DEPENDENCIES:
1214
- Flutter (from `Flutter`)
1315
- flutter_secure_storage (from `.symlinks/plugins/flutter_secure_storage/ios`)
1416
- integration_test (from `.symlinks/plugins/integration_test/ios`)
1517
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
18+
- url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`)
1619

1720
EXTERNAL SOURCES:
1821
Flutter:
@@ -23,12 +26,15 @@ EXTERNAL SOURCES:
2326
:path: ".symlinks/plugins/integration_test/ios"
2427
path_provider_foundation:
2528
:path: ".symlinks/plugins/path_provider_foundation/darwin"
29+
url_launcher_ios:
30+
:path: ".symlinks/plugins/url_launcher_ios/ios"
2631

2732
SPEC CHECKSUMS:
2833
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
2934
flutter_secure_storage: 23fc622d89d073675f2eaa109381aefbcf5a49be
3035
integration_test: 13825b8a9334a850581300559b8839134b124670
3136
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943
37+
url_launcher_ios: bf5ce03e0e2088bad9cc378ea97fa0ed5b49673b
3238

3339
PODFILE CHECKSUM: ff9ae414ffbc80ad6f9d2058e299051a15f6eca7
3440

catalyst_voices/lib/app/view/app_content.dart

+21-10
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,33 @@ import 'package:catalyst_voices_localization/catalyst_voices_localization.dart';
44
import 'package:flutter/material.dart';
55
import 'package:flutter_bloc/flutter_bloc.dart';
66
import 'package:flutter_localized_locales/flutter_localized_locales.dart';
7+
import 'package:go_router/go_router.dart';
8+
9+
const _restorationScopeId = 'rootVoices';
710

811
final class AppContent extends StatelessWidget {
912
const AppContent({super.key});
1013

14+
List<LocalizationsDelegate<dynamic>> get _localizationsDelegates {
15+
return const [
16+
...VoicesLocalizations.localizationsDelegates,
17+
LocaleNamesLocalizationsDelegate(),
18+
];
19+
}
20+
1121
@override
1222
Widget build(BuildContext context) {
23+
final l10n = context.l10n;
1324
return BlocListener<AuthenticationBloc, AuthenticationState>(
1425
listener: (context, state) {},
1526
child: MaterialApp.router(
16-
restorationScopeId: 'rootVoices',
17-
localizationsDelegates: const [
18-
...VoicesLocalizations.localizationsDelegates,
19-
LocaleNamesLocalizationsDelegate(),
20-
],
27+
restorationScopeId: _restorationScopeId,
28+
localizationsDelegates: _localizationsDelegates,
2129
supportedLocales: VoicesLocalizations.supportedLocales,
2230
localeListResolutionCallback: basicLocaleListResolution,
23-
routerConfig: AppRouter.init(
24-
authenticationBloc: context.read<AuthenticationBloc>(),
25-
),
26-
title: 'Catalyst Voices',
31+
routerConfig: _routeConfig(context),
32+
title: l10n.homeScreenText,
2733
theme: ThemeData(
28-
useMaterial3: true,
2934
brightness: Brightness.dark,
3035
bottomNavigationBarTheme: const BottomNavigationBarThemeData(
3136
type: BottomNavigationBarType.fixed,
@@ -34,4 +39,10 @@ final class AppContent extends StatelessWidget {
3439
),
3540
);
3641
}
42+
43+
GoRouter _routeConfig(BuildContext context) {
44+
return AppRouter.init(
45+
authenticationBloc: context.read<AuthenticationBloc>(),
46+
);
47+
}
3748
}
+24-32
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
// ignore_for_file: discarded_futures
2+
13
import 'package:catalyst_voices/app/view/app_content.dart';
24
import 'package:catalyst_voices_blocs/catalyst_voices_blocs.dart';
3-
import 'package:catalyst_voices_repositories/catalyst_voices_repositories.dart';
4-
import 'package:catalyst_voices_services/catalyst_voices_services.dart';
55
import 'package:flutter/material.dart';
66
import 'package:flutter_bloc/flutter_bloc.dart';
77

@@ -13,47 +13,39 @@ final class App extends StatefulWidget {
1313
}
1414

1515
final class _AppState extends State<App> {
16-
late final AuthenticationRepository _authenticationRepository;
17-
late final CredentialsStorageRepository _credentialsStorageRepository;
16+
late final Future<void> _initFuture;
1817

1918
@override
2019
Widget build(BuildContext context) {
21-
return MultiRepositoryProvider(
22-
providers: [
23-
RepositoryProvider.value(
24-
value: _authenticationRepository,
25-
),
26-
],
27-
child: BlocProvider(
28-
create: (_) => AuthenticationBloc(
29-
authenticationRepository: _authenticationRepository,
30-
),
31-
child: const AppContent(),
32-
),
20+
return FutureBuilder<void>(
21+
future: _initFuture,
22+
builder: (context, snapshot) {
23+
return MultiBlocProvider(
24+
providers: _multiBlocProviders(),
25+
child: const AppContent(),
26+
);
27+
},
3328
);
3429
}
3530

36-
@override
37-
Future<void> dispose() async {
38-
await _authenticationRepository.dispose();
39-
40-
super.dispose();
41-
}
42-
4331
@override
4432
void initState() {
4533
super.initState();
46-
47-
_configureRepositories();
34+
_initFuture = _init();
4835
}
4936

50-
void _configureRepositories() {
51-
_credentialsStorageRepository = CredentialsStorageRepository(
52-
secureStorageService: SecureStorageService(),
53-
);
37+
Future<void> _init() async {
38+
await Dependency.instance.init();
39+
}
5440

55-
_authenticationRepository = AuthenticationRepository(
56-
credentialsStorageRepository: _credentialsStorageRepository,
57-
);
41+
List<BlocProvider> _multiBlocProviders() {
42+
return [
43+
BlocProvider<AuthenticationBloc>(
44+
create: (_) => Dependency.instance.get<AuthenticationBloc>(),
45+
),
46+
BlocProvider<LoginBloc>(
47+
create: (_) => Dependency.instance.get<LoginBloc>(),
48+
),
49+
];
5850
}
5951
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import 'package:catalyst_voices/pages/login/login.dart';
2-
import 'package:catalyst_voices_blocs/catalyst_voices_blocs.dart';
3-
import 'package:catalyst_voices_repositories/catalyst_voices_repositories.dart';
42
import 'package:flutter/material.dart';
5-
import 'package:flutter_bloc/flutter_bloc.dart';
63

74
final class LoginPage extends StatelessWidget {
85
static const loginPage = Key('LoginInPage');
@@ -11,17 +8,6 @@ final class LoginPage extends StatelessWidget {
118

129
@override
1310
Widget build(BuildContext context) {
14-
return BlocProvider(
15-
key: loginPage,
16-
create: (context) {
17-
return LoginBloc(
18-
authenticationRepository:
19-
RepositoryProvider.of<AuthenticationRepository>(
20-
context,
21-
),
22-
);
23-
},
24-
child: const LoginForm(),
25-
);
11+
return const LoginForm();
2612
}
2713
}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export 'authentication/authentication.dart';
2+
export 'dependency/dependency.dart';
23
export 'login/login.dart';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import 'package:catalyst_voices_blocs/catalyst_voices_blocs.dart';
2+
import 'package:catalyst_voices_blocs/src/dependency/dependency_provider.dart';
3+
import 'package:catalyst_voices_repositories/catalyst_voices_repositories.dart';
4+
import 'package:catalyst_voices_services/catalyst_voices_services.dart';
5+
6+
final class Dependency extends DependencyProvider {
7+
static final Dependency instance = Dependency._();
8+
9+
Dependency._();
10+
11+
Future<void> init() async {
12+
_registerServices();
13+
_registerRepositories();
14+
_registerBlocsWithDependencies();
15+
}
16+
17+
void _registerBlocsWithDependencies() {
18+
this
19+
..registerSingleton<AuthenticationBloc>(
20+
AuthenticationBloc(
21+
authenticationRepository: get(),
22+
),
23+
)
24+
..registerLazySingleton<LoginBloc>(
25+
() => LoginBloc(
26+
authenticationRepository: get(),
27+
),
28+
);
29+
}
30+
31+
void _registerRepositories() {
32+
this
33+
..registerSingleton<CredentialsStorageRepository>(
34+
CredentialsStorageRepository(secureStorageService: get()),
35+
)
36+
..registerSingleton<AuthenticationRepository>(
37+
AuthenticationRepository(credentialsStorageRepository: get()),
38+
);
39+
}
40+
41+
void _registerServices() {
42+
registerSingleton<SecureStorageService>(
43+
SecureStorageService(),
44+
);
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import 'package:flutter/foundation.dart';
2+
import 'package:get_it/get_it.dart';
3+
4+
abstract class DependencyProvider {
5+
static final getIt = GetIt.instance;
6+
7+
static Future<void> get reset => getIt.reset();
8+
9+
@protected
10+
Future<void> allReady() {
11+
return getIt.allReady();
12+
}
13+
14+
T get<T extends Object>() => getIt.get<T>();
15+
16+
Future<T> getAsync<T extends Object>() => getIt.getAsync<T>();
17+
18+
T getWithParam<T extends Object, P extends Object>({P? param}) {
19+
return getIt.get<T>(param1: param);
20+
}
21+
22+
@protected
23+
void registerFactory<T extends Object>(ValueGetter<T> factoryFunc) {
24+
getIt.registerFactory(factoryFunc);
25+
}
26+
27+
@protected
28+
void registerLazySingleton<T extends Object>(
29+
ValueGetter<T> factoryFunc, {
30+
DisposingFunc<T>? dispose,
31+
}) {
32+
getIt.registerLazySingleton(
33+
factoryFunc,
34+
dispose: dispose,
35+
);
36+
}
37+
38+
@protected
39+
void registerSingleton<T extends Object>(T instance) {
40+
getIt.registerSingleton(instance);
41+
}
42+
43+
@protected
44+
void registerSingletonAsync<T extends Object>(
45+
ValueGetter<Future<T>> factoryFunc, {
46+
Iterable<Type>? dependsOn,
47+
}) {
48+
getIt.registerSingletonAsync(
49+
factoryFunc,
50+
dependsOn: dependsOn,
51+
);
52+
}
53+
54+
@protected
55+
void registerSingletonWithDependencies<T extends Object>(
56+
FactoryFunc<T> factoryFunc, {
57+
required List<Type> dependsOn,
58+
}) {
59+
getIt.registerSingletonWithDependencies(
60+
factoryFunc,
61+
dependsOn: dependsOn,
62+
);
63+
}
64+
}

catalyst_voices/packages/catalyst_voices_blocs/pubspec.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ dependencies:
1414
path: ../catalyst_voices_models
1515
catalyst_voices_repositories:
1616
path: ../catalyst_voices_repositories
17+
catalyst_voices_services:
18+
path: ../catalyst_voices_services
1719
catalyst_voices_view_models:
1820
path: ../catalyst_voices_view_models
1921
collection: ^1.17.1
2022
equatable: ^2.0.5
2123
flutter:
2224
sdk: flutter
2325
formz: ^0.6.1
26+
get_it: ^7.6.7
2427
meta: ^1.10.0
2528
result_type: ^0.2.0
2629

catalyst_voices/packages/catalyst_voices_repositories/lib/src/authentication_repository.dart

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import 'package:catalyst_voices_repositories/catalyst_voices_repositories.dart';
55

66
final class AuthenticationRepository {
77
final CredentialsStorageRepository credentialsStorageRepository;
8-
final _controller = StreamController<AuthenticationStatus>();
8+
final _streamController = StreamController<AuthenticationStatus>();
99

1010
AuthenticationRepository({required this.credentialsStorageRepository});
1111

@@ -22,10 +22,10 @@ final class AuthenticationRepository {
2222
yield AuthenticationStatus.unknown;
2323
}
2424

25-
yield* _controller.stream;
25+
yield* _streamController.stream;
2626
}
2727

28-
Future<void> dispose() async => _controller.close();
28+
Future<void> dispose() async => _streamController.close();
2929

3030
Future<SessionData?> getSessionData() async {
3131
try {
@@ -43,7 +43,7 @@ final class AuthenticationRepository {
4343

4444
void logOut() {
4545
credentialsStorageRepository.clearSessionData;
46-
_controller.add(AuthenticationStatus.unauthenticated);
46+
_streamController.add(AuthenticationStatus.unauthenticated);
4747
}
4848

4949
Future<void> signIn({
@@ -60,7 +60,7 @@ final class AuthenticationRepository {
6060
// TODO(minikin): remove this delay after implementing real auth flow.
6161
await Future.delayed(
6262
const Duration(milliseconds: 300),
63-
() => _controller.add(AuthenticationStatus.authenticated),
63+
() => _streamController.add(AuthenticationStatus.authenticated),
6464
);
6565
}
6666
}

melos.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ command:
1212
workspaceChangelog: true
1313
bootstrap:
1414
environment:
15-
sdk: '>=3.2.1 <4.0.0'
16-
flutter: 3.16.5
15+
sdk: '>=3.2.5 <4.0.0'
16+
flutter: 3.16.8
1717
dependencies:
1818
bloc_concurrency: ^0.2.2
1919
bloc: ^8.1.2

0 commit comments

Comments
 (0)