2022-11-17 21:43:16 +00:00
|
|
|
import 'dart:async';
|
|
|
|
|
2020-07-27 20:43:58 +00:00
|
|
|
import 'package:flutter/cupertino.dart' show CupertinoThemeData, DefaultCupertinoLocalizations;
|
|
|
|
import 'package:flutter/material.dart'
|
2024-09-20 18:19:23 +00:00
|
|
|
show BottomSheetThemeData, Colors, DefaultMaterialLocalizations, ThemeData, ThemeMode, MaterialApp, Scaffold;
|
2020-07-27 20:43:58 +00:00
|
|
|
import 'package:flutter/scheduler.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
|
|
|
import 'package:mobile_nebula/screens/MainScreen.dart';
|
2022-11-17 21:43:16 +00:00
|
|
|
import 'package:mobile_nebula/screens/EnrollmentScreen.dart';
|
2020-07-27 20:43:58 +00:00
|
|
|
import 'package:mobile_nebula/services/settings.dart';
|
2022-11-17 21:43:16 +00:00
|
|
|
import 'package:flutter_web_plugins/url_strategy.dart';
|
2024-10-25 12:53:07 +00:00
|
|
|
import 'package:sentry_flutter/sentry_flutter.dart';
|
2020-07-27 20:43:58 +00:00
|
|
|
|
2024-10-25 12:53:07 +00:00
|
|
|
Future<void> main() async {
|
2022-11-17 21:43:16 +00:00
|
|
|
usePathUrlStrategy();
|
2024-10-25 12:53:07 +00:00
|
|
|
await SentryFlutter.init(
|
|
|
|
(options) {
|
|
|
|
options.dsn = 'https://96106df405ade3f013187dfc8e4200e7@o920269.ingest.us.sentry.io/4508132321001472';
|
|
|
|
// Capture all traces. May need to adjust if overwhelming
|
|
|
|
options.tracesSampleRate = 1.0;
|
|
|
|
// For each trace, capture all profiles
|
|
|
|
options.profilesSampleRate = 1.0;
|
|
|
|
},
|
|
|
|
appRunner: () => runApp(Main()),
|
|
|
|
);
|
|
|
|
|
|
|
|
// or define SENTRY_DSN via Dart environment variable (--dart-define)
|
2022-11-17 21:43:16 +00:00
|
|
|
}
|
2020-07-27 20:43:58 +00:00
|
|
|
|
2024-10-25 12:53:07 +00:00
|
|
|
//TODO: EventChannel might be better than the stream controller we are using now
|
|
|
|
|
2020-07-27 20:43:58 +00:00
|
|
|
class Main extends StatelessWidget {
|
|
|
|
// This widget is the root of your application.
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) => App();
|
|
|
|
}
|
|
|
|
|
|
|
|
class App extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_AppState createState() => _AppState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _AppState extends State<App> {
|
|
|
|
final settings = Settings();
|
2024-09-20 18:19:23 +00:00
|
|
|
Brightness brightness = SchedulerBinding.instance.platformDispatcher.platformBrightness;
|
2022-11-17 21:43:16 +00:00
|
|
|
StreamController dnEnrolled = StreamController.broadcast();
|
2020-07-27 20:43:58 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
//TODO: wait until settings is ready?
|
|
|
|
settings.onChange().listen((_) {
|
|
|
|
setState(() {
|
|
|
|
if (!settings.useSystemColors) {
|
|
|
|
brightness = settings.darkMode ? Brightness.dark : Brightness.light;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
2022-11-17 21:43:16 +00:00
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
dnEnrolled.close();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
2020-07-27 20:43:58 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final ThemeData lightTheme = ThemeData(
|
2024-09-20 18:19:23 +00:00
|
|
|
useMaterial3: false,
|
2020-07-27 20:43:58 +00:00
|
|
|
brightness: Brightness.light,
|
|
|
|
primarySwatch: Colors.blueGrey,
|
|
|
|
primaryColor: Colors.blueGrey[900],
|
|
|
|
fontFamily: 'PublicSans',
|
|
|
|
//scaffoldBackgroundColor: Colors.grey[100],
|
|
|
|
scaffoldBackgroundColor: Colors.white,
|
|
|
|
bottomSheetTheme: BottomSheetThemeData(
|
|
|
|
backgroundColor: Colors.blueGrey[50],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
final ThemeData darkTheme = ThemeData(
|
2024-09-20 18:19:23 +00:00
|
|
|
useMaterial3: false,
|
2020-07-27 20:43:58 +00:00
|
|
|
brightness: Brightness.dark,
|
|
|
|
primarySwatch: Colors.grey,
|
|
|
|
primaryColor: Colors.grey[900],
|
|
|
|
fontFamily: 'PublicSans',
|
|
|
|
scaffoldBackgroundColor: Colors.grey[800],
|
|
|
|
bottomSheetTheme: BottomSheetThemeData(
|
|
|
|
backgroundColor: Colors.grey[850],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2024-09-20 18:19:23 +00:00
|
|
|
return MaterialApp(
|
|
|
|
theme: brightness == Brightness.light ? lightTheme : darkTheme,
|
|
|
|
home: Scaffold(
|
2024-10-07 15:38:00 +00:00
|
|
|
body: PlatformProvider(
|
|
|
|
//initialPlatform: initialPlatform,
|
|
|
|
builder: (context) => PlatformApp(
|
|
|
|
debugShowCheckedModeBanner: false,
|
|
|
|
localizationsDelegates: <LocalizationsDelegate<dynamic>>[
|
|
|
|
DefaultMaterialLocalizations.delegate,
|
|
|
|
DefaultWidgetsLocalizations.delegate,
|
|
|
|
DefaultCupertinoLocalizations.delegate,
|
|
|
|
],
|
|
|
|
title: 'Nebula',
|
|
|
|
material: (_, __) {
|
|
|
|
return new MaterialAppData(
|
|
|
|
themeMode: brightness == Brightness.light ? ThemeMode.light : ThemeMode.dark,
|
2022-11-17 21:43:16 +00:00
|
|
|
);
|
2024-10-07 15:38:00 +00:00
|
|
|
},
|
|
|
|
cupertino: (_, __) => CupertinoAppData(
|
|
|
|
theme: CupertinoThemeData(brightness: brightness),
|
|
|
|
),
|
|
|
|
onGenerateRoute: (settings) {
|
|
|
|
if (settings.name == '/') {
|
|
|
|
return platformPageRoute(context: context, builder: (context) => MainScreen(this.dnEnrolled));
|
|
|
|
}
|
|
|
|
|
|
|
|
final uri = Uri.parse(settings.name!);
|
|
|
|
if (uri.path == EnrollmentScreen.routeName) {
|
|
|
|
// TODO: maybe implement this as a dialog instead of a page, you can stack multiple enrollment screens which is annoying in dev
|
|
|
|
return platformPageRoute(
|
|
|
|
context: context,
|
|
|
|
builder: (context) =>
|
|
|
|
EnrollmentScreen(code: EnrollmentScreen.parseCode(settings.name!), stream: this.dnEnrolled),
|
|
|
|
);
|
|
|
|
}
|
2022-11-17 21:43:16 +00:00
|
|
|
|
2024-10-07 15:38:00 +00:00
|
|
|
return null;
|
|
|
|
},
|
|
|
|
),
|
2020-07-27 20:43:58 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|