yubioath-flutter/lib/main.dart

54 lines
1.4 KiB
Dart
Raw Normal View History

2021-11-19 15:02:25 +03:00
import 'dart:developer' as developer;
import 'package:flutter/material.dart';
2021-11-19 15:02:25 +03:00
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:logging/logging.dart';
2022-03-03 19:24:26 +03:00
import 'package:shared_preferences/shared_preferences.dart';
2021-11-19 15:02:25 +03:00
2022-03-03 19:24:26 +03:00
import 'android/init.dart' as android;
import 'app/app.dart';
2021-11-19 15:02:25 +03:00
import 'core/state.dart';
import 'desktop/init.dart' as desktop;
2021-11-19 17:05:57 +03:00
import 'error_page.dart';
final _log = Logger('main');
void main(List<String> argv) async {
2021-11-19 15:02:25 +03:00
WidgetsFlutterBinding.ensureInitialized();
try {
final Widget initializedApp;
if (isDesktop) {
initializedApp = await desktop.initialize(argv);
2022-03-03 19:24:26 +03:00
} else if (isAndroid) {
initializedApp = await android.initialize();
} else {
_initializeDebugLogging();
throw UnimplementedError('Platform not supported');
}
runApp(initializedApp);
2021-11-19 15:02:25 +03:00
} catch (e) {
_log.warning('Platform initialization failed: $e');
runApp(
ProviderScope(
overrides: [
prefProvider.overrideWithValue(await SharedPreferences.getInstance())
],
2022-05-12 09:34:51 +03:00
child: YubicoAuthenticatorApp(page: ErrorPage(error: e.toString())),
),
);
2021-11-19 15:02:25 +03:00
}
}
void _initializeDebugLogging() {
Logger.root.onRecord.listen((record) {
developer.log(
2021-11-24 13:36:59 +03:00
'${record.level}: ${record.message}',
error: record.error,
name: record.loggerName,
time: record.time,
level: record.level.value,
);
});
}