Skip to content

Commit

Permalink
fix global app context
Browse files Browse the repository at this point in the history
  • Loading branch information
salahamassi committed Mar 31, 2024
1 parent 8175efd commit 008e0b4
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 20 deletions.
2 changes: 2 additions & 0 deletions lib/app/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import 'package:bond/features/main/routes.dart';
import 'package:bond/features/notification/routes.dart';
import 'package:bond/features/post/routes.dart';
import 'package:bond/features/update_app/routes.dart';
import 'package:bond_core/bond_core.dart';
import 'package:go_router/go_router.dart';

final goRouter = GoRouter(
debugLogDiagnostics: true,
initialLocation: '/home',
navigatorKey: appKey,
routes: [
...mainRoutes,
...postRoutes,
Expand Down
11 changes: 3 additions & 8 deletions lib/bond_app.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:bond/app/routes.dart';
import 'package:bond_core/bond_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import 'core/app_theme.dart';
Expand All @@ -16,14 +16,9 @@ class BondApp extends ConsumerWidget {
final theme = ref.watch(themeProvider);
return MaterialApp.router(
routerConfig: goRouter,
localizationsDelegates: const [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
AppLocalizations.delegate,
],
localizationsDelegates: AppLocalizations.localizationsDelegates,
locale: locale,
supportedLocales: const [Locale('ar'), Locale('en')],
supportedLocales: AppLocalizations.supportedLocales,
debugShowCheckedModeBanner: true,
theme: appLightThemeData(),
darkTheme: appDarkThemeData(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:developer';

import 'package:bond/core/app_localizations.dart';
import 'package:bond/features/auth/auth.dart';
import 'package:bond/features/auth/data/api.dart';
import 'package:bond_core/bond_core.dart';
Expand All @@ -16,15 +17,15 @@ class LoginFormController extends FormStateNotifier<User, Error> {
Map<String, FormFieldState> fields() => {
'email': TextFieldState(
null,
label: 'Email',
label: appContext.localizations.filed_email_label,
rules: [
Rules.required(),
Rules.email(),
],
),
'password': TextFieldState(
null,
label: 'Password',
label: appContext.localizations.filed_password_label,
rules: [
Rules.required(),
Rules.minLength(6),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:developer';

import 'package:bond/core/app_localizations.dart';
import 'package:bond/features/auth/auth.dart';
import 'package:bond/features/auth/data/api.dart';
import 'package:bond_core/bond_core.dart';
Expand All @@ -16,15 +17,15 @@ class RegisterFormController extends FormStateNotifier<User, Error> {
Map<String, FormFieldState> fields() => {
'email': TextFieldState(
null,
label: 'Email',
label: appContext.localizations.filed_email_label,
rules: [
Rules.required(),
Rules.email(),
],
),
'password': TextFieldState(
null,
label: 'Password',
label: appContext.localizations.filed_password_label,
rules: [
Rules.required(),
Rules.minLength(6),
Expand Down
10 changes: 5 additions & 5 deletions lib/providers/forms_service_provider.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'dart:developer';
import 'dart:ui';

import 'package:bond_cache/bond_cache.dart';
import 'package:bond_core/bond_core.dart';
Expand All @@ -8,10 +8,10 @@ import 'package:get_it/get_it.dart';
class FormsServiceProvider extends ServiceProvider {
@override
Future<void> register(GetIt it) async {
// TODO - local must be a getter constructor in the ValidatorLocalizations class
log('Cache.get('', defaultValue: '') = ${Cache.get<String>('language', defaultValue: 'en')}');
it.registerSingleton(
ValidatorLocalizations(Cache.get('language', defaultValue: 'en')),
//TODO: How to force this to reload when language changes?
final local = Locale(Cache.get<String>('language', defaultValue: 'en'));
it.registerSingletonAsync(
() async => ValidatorLocalizations.load(local),
);
}
}
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ packages:
dependency: "direct main"
description:
name: bond_core
sha256: e91ddf411d9513402c9724f051a0fb7c403a967627ef63230237256cf8f79a20
sha256: "63d7ab60be9c8f161e9c149f332d3fb41f234c79ca2af643fe8809b51b31ed77"
url: "https://pub.dev"
source: hosted
version: "0.0.1+7"
version: "0.0.1+8"
bond_form:
dependency: "direct main"
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies:


# Bond packages
bond_core: ^0.0.1+7
bond_core: ^0.0.1+8
bond_network: ^0.0.3
bond_cache: ^0.0.2
bond_form: ^0.0.1+10
Expand Down

0 comments on commit 008e0b4

Please sign in to comment.