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 'config/theme.dart';
import 'data/models/app_cubit.dart';
import 'data/models/app_state.dart';
import 'data/models/node_list_cubit.dart';
import 'data/models/payment_cubit.dart';
import 'ui/screens/skeleton_screen.dart';
defaultLevel: LevelMessages.debug,
enableBuildModes: <BuildMode>[
BuildMode.debug,
BuildMode.profile,
BuildMode.release
],
enableLevels: <LevelMessages>[
LevelMessages.debug,
LevelMessages.info,
LevelMessages.error,
LevelMessages.warning
],
);
void main() async {
/// Initialize packages
WidgetsFlutterBinding.ensureInitialized();
await EasyLocalization.ensureInitialized();
final SharedPreferencesHelper shared = SharedPreferencesHelper();
await shared.init();
await shared.getWallet();
assert(shared.getPubKey() != null);
await dotenv.load(
fileName: kReleaseMode
? 'assets/env.production.txt'
: 'assets/.env.development');
if (kIsWeb) {
await Hive.initFlutter();
HydratedBloc.storage = await HydratedStorage.build(
storageDirectory: HydratedStorage.webStorageDirectory);
} else {
final Directory tmpDir = await getTemporaryDirectory();
Hive.init(tmpDir.toString());
HydratedBloc.storage =
await HydratedStorage.build(storageDirectory: tmpDir);
runApp(
EasyLocalization(
path: 'assets/translations',
supportedLocales: const <Locale>[
Locale('en'),
],
fallbackLocale: const Locale('en'),
useFallbackTranslations: true,
child: MultiBlocProvider(providers: <BlocProvider<dynamic>>[
BlocProvider<AppCubit>(create: (BuildContext context) => AppCubit()),
BlocProvider<PaymentCubit>(
create: (BuildContext context) => PaymentCubit()),
BlocProvider<NodeListCubit>(
create: (BuildContext context) => NodeListCubit()),
// Add other BlocProviders here if needed
], child: const MyApp()),
class AppIntro extends StatefulWidget {
const AppIntro({super.key});
@override
State<AppIntro> createState() => _AppIntro();
}
class _AppIntro extends State<AppIntro> {
final GlobalKey<IntroductionScreenState> introKey =
GlobalKey<IntroductionScreenState>();
void _onIntroEnd(BuildContext context) {
MaterialPageRoute<void>(
builder: (BuildContext _) => const SkeletonScreen()),
);
}
@override
Widget build(BuildContext context) {
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
return BlocBuilder<AppCubit, AppState>(
builder: (BuildContext buildContext, AppState state) =>
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'),
],
onDone: () => _onIntroEnd(buildContext),
showSkipButton: true,
skipOrBackFlex: 0,
onSkip: () => _onIntroEnd(buildContext),
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)),
),
),
));
}
}
PageViewModel createPageViewModel(
String title, String body, String imageAsset) {
return PageViewModel(
title: tr(title),
body: tr(body),
image: Image.asset(imageAsset),
decoration: const PageDecoration(
pageColor: Colors.white,
bodyTextStyle: TextStyle(fontSize: 18),
titleTextStyle: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
),
);
}
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
return ConnectivityAppWrapper(
app: 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: MediaQuery(
data: const MediaQueryData(),
child: BlocProvider.of<AppCubit>(context).isIntroViewed
? const SkeletonScreen()
: const AppIntro(),
),
builder: (BuildContext buildContext, Widget? widget) {
final NodeListCubit nodeListCubit =
BlocProvider.of<NodeListCubit>(buildContext);
final int nDuniterNodes = nodeListCubit.duniterNodes.length;
final int nCesiumPlusNodes = nodeListCubit.cesiumPlusNodes.length;
// Load nodes from /network/peers
fetchDuniterNodes(nodeListCubit);
logger(
'Starting with $nDuniterNodes duniter nodes and $nCesiumPlusNodes c+ nodes');
final Cron cron = Cron();
cron.schedule(Schedule.parse('*/45 * * * *'), () async {
// Every 45m check for faster node (maybe it something costly in terms of
// bandwidth
fetchDuniterNodes(nodeListCubit);
});
cron.schedule(Schedule.parse('*/90 * * * *'), () async {
nodeListCubit.cleanDuniterErrorStats();
});
return ResponsiveWrapper.builder(
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(480, name: DESKTOP),
],
background: Container(color: const Color(0xFFF5F5F5)),
);
},
));