Newer
Older
import 'package:connectivity_wrapper/connectivity_wrapper.dart';
import 'package:flutter/material.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 'cubit/theme_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);
final Cron cron = Cron();
cron.schedule(Schedule.parse('*/45 * * * *'), () async {
// Every 45m check for faster node (maybe it something costly in terms of
// bandwidth
DuniterNodeManager().loadNodes();
});
runApp(
EasyLocalization(
path: 'assets/translations',
supportedLocales: const <Locale>[
Locale('en'),
],
fallbackLocale: const Locale('en'),
useFallbackTranslations: true,
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) {
Navigator.of(context).pushReplacement(
MaterialPageRoute<void>(
builder: (BuildContext _) => const SkeletonScreen()),
);
}
@override
Widget build(BuildContext context) {
return IntroductionScreen(
key: introKey,
pages: <PageViewModel>[
for (int i = 1; i <= 5; i++)
createPageViewModel('intro_${i}_title', 'intro_${i}_description',
],
onDone: () => _onIntroEnd(context),
showSkipButton: true,
skipOrBackFlex: 0,
done: Text(tr('start'),
style: const TextStyle(fontWeight: FontWeight.w600)),
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
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> {
@override
Widget build(BuildContext context) {
return BlocProvider<ThemeCubit>(
create: (BuildContext context) => ThemeCubit(),
child: BlocBuilder<ThemeCubit, ThemeModeState>(
builder: (BuildContext context, ThemeModeState state) {
return ConnectivityAppWrapper(
app: MaterialApp(
/// Theme stuff
theme: lightTheme,
darkTheme: darkTheme,
themeMode: state.themeMode,
/// Localization stuff
localizationsDelegates: context.localizationDelegates,
supportedLocales: context.supportedLocales,
locale: context.locale,
debugShowCheckedModeBanner: false,
home: MediaQuery(
data: const MediaQueryData(),
child: _skipIntro ? const SkeletonScreen() : const AppIntro(),
),
builder: (BuildContext buildContext, Widget? widget) {
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)),
);
},
));