Newer
Older
import 'package:connectivity_wrapper/connectivity_wrapper.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_displaymode/flutter_displaymode.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:introduction_screen/introduction_screen.dart';
import 'package:responsive_framework/responsive_wrapper.dart';
import 'package:responsive_framework/utils/scroll_behavior.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'config/theme.dart';
import 'data/models/app_cubit.dart';
import 'data/models/app_state.dart';
import 'data/models/payment_cubit.dart';
import 'ui/screens/skeleton_screen.dart';
/// Initialize packages
WidgetsFlutterBinding.ensureInitialized();
await EasyLocalization.ensureInitialized();
await dotenv.load(
fileName: kReleaseMode
? 'assets/env.production.txt'
: 'assets/.env.development');
final SharedPreferencesHelper shared = SharedPreferencesHelper();
await shared.init();
await shared.getWallet();
assert(shared.getPubKey() != null);
if (kIsWeb) {
HydratedBloc.storage = await HydratedStorage.build(
storageDirectory: HydratedStorage.webStorageDirectory);
} else {
final Directory tmpDir = await getTemporaryDirectory();
Hive.init(tmpDir.toString());
await HydratedStorage.build(storageDirectory: tmpDir);
PWAInstall().setup(installCallback: () {
logger('APP INSTALLED!');
});
EasyLocalization(
path: 'assets/translations',
supportedLocales: const <Locale>[
Locale('en'),
Locale('es'),
Locale('fr'),
],
fallbackLocale: const Locale('en'),
useFallbackTranslations: true,
child: MultiBlocProvider(providers: <BlocProvider<dynamic>>[
BlocProvider<BottomNavCubit>(
create: (BuildContext context) => BottomNavCubit()),
BlocProvider<AppCubit>(
create: (BuildContext context) => AppCubit()),
BlocProvider<PaymentCubit>(
create: (BuildContext context) => PaymentCubit()),
BlocProvider<NodeListCubit>(
create: (BuildContext context) => NodeListCubit()),
BlocProvider<ContactsCubit>(
create: (BuildContext context) => ContactsCubit()),
BlocProvider<TransactionsCubit>(
create: (BuildContext context) => TransactionsCubit()),
// Add other BlocProviders here if needed
], child: const GinkgoApp()),
),
);
if (kReleaseMode) {
// Only use sentry in production
await SentryFlutter.init((
SentryFlutterOptions options,
) {
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
options.tracesSampleRate = 1.0;
options.reportPackages = false;
// options.addInAppInclude('sentry_flutter_example');
options.considerInAppFramesByDefault = false;
// options.attachThreads = true;
// options.enableWindowMetricBreadcrumbs = true;
options.addIntegration(LoggingIntegration());
options.sendDefaultPii = true;
options.reportSilentFlutterErrors = true;
// options.attachScreenshot = true;
// options.screenshotQuality = SentryScreenshotQuality.low;
// This fails:
// options.attachViewHierarchy = true;
// We can enable Sentry debug logging during development. This is likely
// going to log too much for your app, but can be useful when figuring out
// configuration issues, e.g. finding out why your events are not uploaded.
options.debug = false;
options.maxRequestBodySize = MaxRequestBodySize.always;
options.maxResponseBodySize = MaxResponseBodySize.always;
// options.release = version;
// options.environment = 'production';
// options.beforeSend = (SentryEvent event, {dynamic hint}) {
// return event;
//};
options.dsn = "${dotenv.env['SENTRY_DSN']}";
// Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
// We recommend adjusting this value in production.
// options.tracesSampleRate = 1.0;
}, appRunner: appRunner);
} else {
appRunner();
}
class AppIntro extends StatefulWidget {
const AppIntro({super.key});
@override
State<AppIntro> createState() => _AppIntro();
}
class _AppIntro extends State<AppIntro> {
final GlobalKey<IntroductionScreenState> introKey =
void _onIntroEnd(BuildContext context, AppCubit cubit) {
cubit.introViewed();
MaterialPageRoute<void>(
builder: (BuildContext _) => const SkeletonScreen()),
);
}
@override
Widget build(BuildContext context) {
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
builder: (BuildContext buildContext, AppState state) {
final AppCubit cubit = context.read<AppCubit>();
return IntroductionScreen(
key: introKey,
pages: <PageViewModel>[
for (int i = 1; i <= 5; i++)
createPageViewModel('intro_${i}_title', 'intro_${i}_description',
'assets/img/undraw_intro_$i.png', context),
],
onDone: () => _onIntroEnd(buildContext, cubit),
showSkipButton: true,
skipOrBackFlex: 0,
onSkip: () => _onIntroEnd(buildContext, cubit),
nextFlex: 0,
skip: Text(tr('skip')),
next: const Icon(Icons.arrow_forward),
done: Text(tr('start'),
style: const TextStyle(fontWeight: FontWeight.w600)),
dotsDecorator: const DotsDecorator(
size: Size(10.0, 10.0),
color: Color(0xFFBDBDBD),
activeColor: Colors.blueAccent,
activeSize: Size(22.0, 10.0),
activeShape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(25.0)),
),
),
);
});
String title, String body, String imageAsset, BuildContext context) {
final ColorScheme colorScheme = Theme.of(context).colorScheme;
final TextStyle titleStyle = TextStyle(
color: colorScheme.primary,
fontWeight: FontWeight.bold,
fontSize: 24.0,
);
final TextStyle bodyStyle = TextStyle(
color: colorScheme.onSurface,
fontSize: 18.0,
);
return PageViewModel(
title: tr(title),
body: tr(body),
image: Image.asset(imageAsset),
decoration: PageDecoration(
titleTextStyle: titleStyle,
bodyTextStyle: bodyStyle,
pageColor: colorScheme.background,
class GinkgoApp extends StatefulWidget {
const GinkgoApp({super.key});
Future<void> _loadNodes() async {
_printNodeStatus();
_printNodeStatus(prefix: 'Continuing');
}
void _printNodeStatus({String prefix = 'Starting'}) {
final int nDuniterNodes = NodeManager().nodeList(NodeType.duniter).length;
final int nCesiumPlusNodes =
NodeManager().nodeList(NodeType.cesiumPlus).length;
final int nGvaNodes = NodeManager().nodeList(NodeType.gva).length;
'$prefix with $nDuniterNodes duniter nodes, $nCesiumPlusNodes c+ nodes, and $nGvaNodes gva nodes');
if (!kReleaseMode) {
logger('${NodeManager().nodeList(NodeType.cesiumPlus)}');
}
@override
void initState() {
super.initState();
NodeManager().loadFromCubit(context.read<NodeListCubit>());
}
@override
void dispose() {
ContactsCache().dispose();
super.dispose();
}
return BlocBuilder<NodeListCubit, NodeListState>(
builder: (BuildContext nodeContext, NodeListState state) {
Once.runHourly('load_nodes',
_printNodeStatus(prefix: 'After once hourly having');
});
Once.runCustom('clear_errors', callback: () {
NodeManager().cleanErrorStats();
}, duration: const Duration(minutes: 90));
Once.runCustom('fetch_transactions', callback: () {
fetchTransactions(context);
}, duration: const Duration(minutes: 10));
fetchTransactions(context);
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
app: FilesystemPickerDefaultOptions(
fileTileSelectMode: FileTileSelectMode.wholeTile,
theme: FilesystemPickerTheme(
topBar: FilesystemPickerTopBarThemeData(
backgroundColor: Theme.of(context).colorScheme.primary,
),
),
child: MaterialApp(
/// Localization is not available for the title.
title: 'Ğ1nkgo',
theme: ThemeData(
useMaterial3: true, colorScheme: lightColorScheme),
darkTheme:
ThemeData(useMaterial3: true, colorScheme: darkColorScheme),
/// Theme stuff
/// Localization stuff
localizationsDelegates: context.localizationDelegates,
supportedLocales: context.supportedLocales,
locale: context.locale,
debugShowCheckedModeBanner: false,
home: context.read<AppCubit>().isIntroViewed
? const SkeletonScreen()
: const AppIntro(),
builder: (BuildContext buildContext, Widget? widget) {
return ResponsiveWrapper.builder(
BouncingScrollWrapper.builder(
context,
ConnectivityWidgetWrapper(
message: tr('offline'),
height: 20,
child: widget!,
)),
maxWidth: 480,
minWidth: 480,
// defaultScale: true,
breakpoints: <ResponsiveBreakpoint>[
const ResponsiveBreakpoint.resize(200, name: MOBILE),
const ResponsiveBreakpoint.resize(480, name: TABLET),
const ResponsiveBreakpoint.resize(1000, name: DESKTOP),
],
background: Container(color: const Color(0xFFF5F5F5)),
);
},
)));