Skip to content

Commit

Permalink
clean main
Browse files Browse the repository at this point in the history
  • Loading branch information
mocodesmo committed May 3, 2024
1 parent 7507c0a commit 6a53fa9
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 84 deletions.
42 changes: 42 additions & 0 deletions lib/_pkg/i18n.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import 'package:bb_mobile/settings/bloc/settings_cubit.dart';
import 'package:bb_mobile/settings/bloc/settings_state.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_translate/flutter_translate.dart';

class Localise {
Expand All @@ -10,3 +14,41 @@ class Localise {
return delegate;
}
}

class LocaliseApp extends StatelessWidget {
const LocaliseApp({super.key, required this.child});

final Widget child;

@override
Widget build(BuildContext context) {
return FutureBuilder(
future: Localise.getDelegate(),
builder: (context, snapshot) {
if (!snapshot.hasData) return child;

final delegate = snapshot.data!;

return LocalizedApp(
delegate,
Builder(
builder: (context) {
return BlocListener<SettingsCubit, SettingsState>(
listenWhen: (previous, current) =>
previous.language != current.language,
listener: (context, state) {
if (state.language != delegate.currentLocale.languageCode)
delegate.changeLocale(Locale(state.language ?? 'en'));
},
child: LocalizationProvider(
state: LocalizationProvider.of(context).state,
child: child,
),
);
},
),
);
},
);
}
}
141 changes: 57 additions & 84 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import 'dart:async';
import 'dart:developer';

import 'package:bb_mobile/_pkg/i18n.dart';
import 'package:bb_mobile/_pkg/logger.dart';
import 'package:bb_mobile/_ui/security_overlay.dart';
import 'package:bb_mobile/currency/bloc/currency_cubit.dart';
import 'package:bb_mobile/home/bloc/home_cubit.dart';
import 'package:bb_mobile/home/deep_linking.dart';
import 'package:bb_mobile/home/listeners.dart';
import 'package:bb_mobile/locator.dart';
import 'package:bb_mobile/network/bloc/network_cubit.dart';
import 'package:bb_mobile/network_fees/bloc/networkfees_cubit.dart';
import 'package:bb_mobile/routes.dart';
import 'package:bb_mobile/settings/bloc/lighting_cubit.dart';
import 'package:bb_mobile/settings/bloc/settings_cubit.dart';
import 'package:bb_mobile/settings/bloc/settings_state.dart';
import 'package:bb_mobile/styles.dart';
import 'package:bb_mobile/swap/bloc/watchtxs_bloc.dart';
import 'package:bb_mobile/swap/listeners.dart';
Expand All @@ -24,7 +21,6 @@ import 'package:flutter/services.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_translate/flutter_translate.dart';
import 'package:go_router/go_router.dart';
import 'package:lwk_dart/lwk_dart.dart';
import 'package:oktoast/oktoast.dart';
Expand All @@ -41,14 +37,8 @@ Future main({bool fromTest = false}) async {
Bloc.observer = BBlocObserver();
// await FlutterWindowManager.addFlags(FlutterWindowManager.FLAG_SECURE);
await setupLocator(fromTest: fromTest);
final delegate = await Localise.getDelegate();

runApp(
LocalizedApp(
delegate,
const BullBitcoinWalletApp(),
),
);
runApp(const BullBitcoinWalletApp());
}, (error, stack) {
log('\n\nError: $error \nStack: $stack\n\n');
});
Expand All @@ -59,87 +49,70 @@ class BullBitcoinWalletApp extends StatelessWidget {

@override
Widget build(BuildContext context) {
final localizationDelegate = LocalizedApp.of(context).delegate;
return MultiBlocProvider(
providers: [
BlocProvider.value(value: locator<SettingsCubit>()),
BlocProvider.value(value: locator<Logger>()),
BlocProvider.value(value: locator<Lighting>()),
BlocProvider.value(value: locator<NetworkCubit>()),
BlocProvider.value(value: locator<NetworkFeesCubit>()),
BlocProvider.value(value: locator<CurrencyCubit>()),
BlocProvider.value(value: locator<HomeCubit>()),
BlocProvider.value(value: locator<WatchTxsBloc>()),
// BlocProvider.value(value: TestCub()),
BlocProvider.value(value: locator<NavName>()),
],
child: BlocBuilder<Lighting, ThemeLighting>(
builder: (context, lightingState) {
return AnimatedSwitcher(
duration: 600.ms,
switchInCurve: Curves.easeInOutCubic,
child: MaterialApp.router(
theme: Themes.lightTheme,
darkTheme: lightingState.dark(),
themeMode: lightingState.mode(),
routerConfig: locator<GoRouter>(),
debugShowCheckedModeBanner: false,
// localizationsDelegates: [localizationDelegate],
// supportedLocales: localizationDelegate.supportedLocales,
// locale: localizationDelegate.currentLocale,
builder: (context, child) {
scheduleMicrotask(() async {
await Future.delayed(200.ms);
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(
statusBarColor: context.colour.background,
),
);
});

return LocalizationProvider(
state: LocalizationProvider.of(context).state,
child: MultiBlocProvider(
providers: [
BlocProvider.value(value: locator<SettingsCubit>()),
BlocProvider.value(value: locator<Logger>()),
BlocProvider.value(value: locator<Lighting>()),
BlocProvider.value(value: locator<NetworkCubit>()),
BlocProvider.value(value: locator<NetworkFeesCubit>()),
BlocProvider.value(value: locator<CurrencyCubit>()),
BlocProvider.value(value: locator<HomeCubit>()),
BlocProvider.value(value: locator<WatchTxsBloc>()),
// BlocProvider.value(value: TestCub()),
BlocProvider.value(value: locator<NavName>()),
],
child: BlocListener<SettingsCubit, SettingsState>(
listener: (context, state) {
if (state.language !=
localizationDelegate.currentLocale.languageCode)
localizationDelegate.changeLocale(Locale(state.language ?? 'en'));
},
child: DeepLinker(
child: BlocBuilder<Lighting, ThemeLighting>(
builder: (context, lightingState) {
return AnimatedSwitcher(
duration: 600.ms,
switchInCurve: Curves.easeInOutCubic,
child: MaterialApp.router(
theme: Themes.lightTheme,
darkTheme: lightingState.dark(),
themeMode: lightingState.mode(),
routerConfig: locator<GoRouter>(),
debugShowCheckedModeBanner: false,
localizationsDelegates: [
localizationDelegate,
],
supportedLocales: localizationDelegate.supportedLocales,
locale: localizationDelegate.currentLocale,
builder: (context, child) {
scheduleMicrotask(() async {
await Future.delayed(200.ms);
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(
statusBarColor: context.colour.background,
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
]);
if (child == null) return Container();
return OKToast(
child: HomeWalletsSetupListener(
child: SwapAppListener(
child: GestureDetector(
onTap: () {
FocusScope.of(context).requestFocus(FocusNode());
},
child: MediaQuery(
data: MediaQuery.of(context).copyWith(
textScaler: TextScaler.noScaling,
),
);
});

SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
]);
if (child == null) return Container();
return OKToast(
child: HomeWalletsSetupListener(
child: SwapAppListener(
child: GestureDetector(
onTap: () {
FocusScope.of(context)
.requestFocus(FocusNode());
},
child: MediaQuery(
data: MediaQuery.of(context).copyWith(
textScaler: TextScaler.noScaling,
),
child: AppLifecycleOverlay(
child: child,
),
),
),
child: AppLifecycleOverlay(
child: child,
),
),
);
},
),
),
),
);
},
),
),
),
);
},
),
);
}
Expand Down

0 comments on commit 6a53fa9

Please sign in to comment.