Skip to content

Commit

Permalink
Merge branch 'main' into chore/timezone_date_time_proposal_card
Browse files Browse the repository at this point in the history
  • Loading branch information
LynxLynxx authored Jan 30, 2025
2 parents b85222a + 520fcca commit fdbee3d
Show file tree
Hide file tree
Showing 29 changed files with 847 additions and 404 deletions.
51 changes: 30 additions & 21 deletions catalyst_voices/apps/voices/lib/app/view/app_content.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import 'package:catalyst_voices/app/view/app_active_state_listener.dart';
import 'package:catalyst_voices/app/view/app_precache_image_assets.dart';
import 'package:catalyst_voices/app/view/app_session_listener.dart';
import 'package:catalyst_voices/common/ext/preferences_ext.dart';
import 'package:catalyst_voices_blocs/catalyst_voices_blocs.dart';
import 'package:catalyst_voices_brands/catalyst_voices_brands.dart';
import 'package:catalyst_voices_localization/catalyst_voices_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_localized_locales/flutter_localized_locales.dart';

const _restorationScopeId = 'rootVoices';

final class AppContent extends StatefulWidget {
class AppContent extends StatelessWidget {
final RouterConfig<Object> routerConfig;

const AppContent({
Expand All @@ -17,21 +20,33 @@ final class AppContent extends StatefulWidget {
});

@override
State<AppContent> createState() => AppContentState();

/// Returns the state associated with the [AppContent].
static AppContentState of(BuildContext context) {
return context.findAncestorStateOfType<AppContentState>()!;
Widget build(BuildContext context) {
return BlocSelector<SessionCubit, SessionState, ThemeMode>(
selector: (state) => state.settings.theme.asThemeMode(),
builder: (context, state) {
return _AppContent(
routerConfig: routerConfig,
themeMode: state,
);
},
);
}
}

class AppContentState extends State<AppContent> {
ThemeMode _themeMode = ThemeMode.light;
final class _AppContent extends StatelessWidget {
final RouterConfig<Object> routerConfig;
final ThemeMode themeMode;

void updateThemeMode(ThemeMode themeMode) {
setState(() {
_themeMode = themeMode;
});
const _AppContent({
required this.routerConfig,
required this.themeMode,
});

List<LocalizationsDelegate<dynamic>> get _localizationsDelegates {
return const [
...VoicesLocalizations.localizationsDelegates,
LocaleNamesLocalizationsDelegate(),
];
}

@override
Expand All @@ -41,8 +56,8 @@ class AppContentState extends State<AppContent> {
localizationsDelegates: _localizationsDelegates,
supportedLocales: VoicesLocalizations.supportedLocales,
localeListResolutionCallback: basicLocaleListResolution,
routerConfig: widget.routerConfig,
themeMode: _themeMode,
routerConfig: routerConfig,
themeMode: themeMode,
theme: ThemeBuilder.buildTheme(
brand: Brand.catalyst,
brightness: Brightness.light,
Expand All @@ -51,6 +66,7 @@ class AppContentState extends State<AppContent> {
brand: Brand.catalyst,
brightness: Brightness.dark,
),
debugShowCheckedModeBanner: false,
builder: (context, child) {
return Scaffold(
primary: false,
Expand All @@ -66,11 +82,4 @@ class AppContentState extends State<AppContent> {
},
);
}

List<LocalizationsDelegate<dynamic>> get _localizationsDelegates {
return const [
...VoicesLocalizations.localizationsDelegates,
LocaleNamesLocalizationsDelegate(),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ abstract class VoicesConstants {
'https://docs.projectcatalyst.io/current-fund/fund-basics/project-catalyst-terms-and-conditions';
static const privacyPolicyUrl =
'https://docs.projectcatalyst.io/current-fund/fund-basics/project-catalyst-terms-and-conditions/catalyst-fc-privacy-policy';
static const supportUrl =
'https://catalystiog.zendesk.com/hc/en-us/requests/new';
static const docsUrl = 'https://docs.projectcatalyst.io/';
}
43 changes: 43 additions & 0 deletions catalyst_voices/apps/voices/lib/common/ext/preferences_ext.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import 'package:catalyst_voices_assets/catalyst_voices_assets.dart';
import 'package:catalyst_voices_localization/catalyst_voices_localization.dart';
import 'package:catalyst_voices_models/catalyst_voices_models.dart';
import 'package:flutter/material.dart';

extension TimezonePreferencesExt on TimezonePreferences {
String localizedName(BuildContext context) {
return switch (this) {
TimezonePreferences.utc => 'UTC',
TimezonePreferences.local => context.l10n.local,
};
}

SvgGenImage icon() {
return switch (this) {
TimezonePreferences.utc => VoicesAssets.icons.globeAlt,
TimezonePreferences.local => VoicesAssets.icons.locationMarker,
};
}
}

extension ThemePreferencesExt on ThemePreferences {
ThemeMode asThemeMode() {
return switch (this) {
ThemePreferences.dark => ThemeMode.dark,
ThemePreferences.light => ThemeMode.light,
};
}

String localizedName(BuildContext context) {
return switch (this) {
ThemePreferences.dark => context.l10n.themeDark,
ThemePreferences.light => context.l10n.themeLight,
};
}

SvgGenImage icon() {
return switch (this) {
ThemePreferences.dark => VoicesAssets.icons.moon,
ThemePreferences.light => VoicesAssets.icons.sun,
};
}
}
Loading

0 comments on commit fdbee3d

Please sign in to comment.