mirror of
https://github.com/inventree/inventree-app.git
synced 2025-07-01 11:20:41 +00:00
Format Code and Add Format Checks to CI (#643)
* Remove unused lib/generated/i18n.dart * Use `fvm dart format .` * Add contributing guidelines * Enforce dart format * Add `dart format off` directive to generated files
This commit is contained in:
135
lib/main.dart
135
lib/main.dart
@ -18,72 +18,73 @@ import "package:inventree/l10n/collected/app_localizations.dart";
|
||||
import "package:inventree/settings/release.dart";
|
||||
import "package:inventree/widget/home.dart";
|
||||
|
||||
|
||||
Future<void> main() async {
|
||||
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
final savedThemeMode = await AdaptiveTheme.getThemeMode();
|
||||
|
||||
await runZonedGuarded<Future<void>>(() async {
|
||||
await runZonedGuarded<Future<void>>(
|
||||
() async {
|
||||
PackageInfo info = await PackageInfo.fromPlatform();
|
||||
String pkg = info.packageName;
|
||||
String version = info.version;
|
||||
String build = info.buildNumber;
|
||||
|
||||
PackageInfo info = await PackageInfo.fromPlatform();
|
||||
String pkg = info.packageName;
|
||||
String version = info.version;
|
||||
String build = info.buildNumber;
|
||||
String release = "${pkg}@${version}:${build}";
|
||||
|
||||
String release = "${pkg}@${version}:${build}";
|
||||
if (SENTRY_DSN_KEY.isNotEmpty) {
|
||||
await Sentry.init((options) {
|
||||
options.dsn = SENTRY_DSN_KEY;
|
||||
options.release = release;
|
||||
options.environment = isInDebugMode() ? "debug" : "release";
|
||||
options.diagnosticLevel = SentryLevel.debug;
|
||||
options.attachStacktrace = true;
|
||||
});
|
||||
}
|
||||
|
||||
if (SENTRY_DSN_KEY.isNotEmpty) {
|
||||
await Sentry.init((options) {
|
||||
options.dsn = SENTRY_DSN_KEY;
|
||||
options.release = release;
|
||||
options.environment = isInDebugMode() ? "debug" : "release";
|
||||
options.diagnosticLevel = SentryLevel.debug;
|
||||
options.attachStacktrace = true;
|
||||
// Pass any flutter errors off to the Sentry reporting context!
|
||||
FlutterError.onError = (FlutterErrorDetails details) async {
|
||||
// Ensure that the error gets reported to sentry!
|
||||
await sentryReportError(
|
||||
"FlutterError.onError",
|
||||
details.exception,
|
||||
details.stack,
|
||||
context: {
|
||||
"context": details.context.toString(),
|
||||
"summary": details.summary.toString(),
|
||||
"library": details.library ?? "null",
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
final int orientation =
|
||||
await InvenTreeSettingsManager().getValue(
|
||||
INV_SCREEN_ORIENTATION,
|
||||
SCREEN_ORIENTATION_SYSTEM,
|
||||
)
|
||||
as int;
|
||||
|
||||
List<DeviceOrientation> orientations = [];
|
||||
|
||||
switch (orientation) {
|
||||
case SCREEN_ORIENTATION_PORTRAIT:
|
||||
orientations.add(DeviceOrientation.portraitUp);
|
||||
case SCREEN_ORIENTATION_LANDSCAPE:
|
||||
orientations.add(DeviceOrientation.landscapeLeft);
|
||||
default:
|
||||
orientations.add(DeviceOrientation.portraitUp);
|
||||
orientations.add(DeviceOrientation.landscapeLeft);
|
||||
orientations.add(DeviceOrientation.landscapeRight);
|
||||
}
|
||||
|
||||
SystemChrome.setPreferredOrientations(orientations).then((_) {
|
||||
runApp(InvenTreeApp(savedThemeMode));
|
||||
});
|
||||
}
|
||||
|
||||
// Pass any flutter errors off to the Sentry reporting context!
|
||||
FlutterError.onError = (FlutterErrorDetails details) async {
|
||||
|
||||
// Ensure that the error gets reported to sentry!
|
||||
await sentryReportError(
|
||||
"FlutterError.onError",
|
||||
details.exception, details.stack,
|
||||
context: {
|
||||
"context": details.context.toString(),
|
||||
"summary": details.summary.toString(),
|
||||
"library": details.library ?? "null",
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
final int orientation = await InvenTreeSettingsManager().getValue(INV_SCREEN_ORIENTATION, SCREEN_ORIENTATION_SYSTEM) as int;
|
||||
|
||||
List<DeviceOrientation> orientations = [];
|
||||
|
||||
switch (orientation) {
|
||||
case SCREEN_ORIENTATION_PORTRAIT:
|
||||
orientations.add(DeviceOrientation.portraitUp);
|
||||
case SCREEN_ORIENTATION_LANDSCAPE:
|
||||
orientations.add(DeviceOrientation.landscapeLeft);
|
||||
default:
|
||||
orientations.add(DeviceOrientation.portraitUp);
|
||||
orientations.add(DeviceOrientation.landscapeLeft);
|
||||
orientations.add(DeviceOrientation.landscapeRight);
|
||||
}
|
||||
|
||||
SystemChrome.setPreferredOrientations(orientations).then((_) {
|
||||
runApp(
|
||||
InvenTreeApp(savedThemeMode)
|
||||
);
|
||||
});
|
||||
|
||||
}, (Object error, StackTrace stackTrace) async {
|
||||
sentryReportError("main.runZonedGuarded", error, stackTrace);
|
||||
});
|
||||
|
||||
},
|
||||
(Object error, StackTrace stackTrace) async {
|
||||
sentryReportError("main.runZonedGuarded", error, stackTrace);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
class InvenTreeApp extends StatefulWidget {
|
||||
@ -96,13 +97,11 @@ class InvenTreeApp extends StatefulWidget {
|
||||
@override
|
||||
InvenTreeAppState createState() => InvenTreeAppState(savedThemeMode);
|
||||
|
||||
static InvenTreeAppState? of(BuildContext context) => context.findAncestorStateOfType<InvenTreeAppState>();
|
||||
|
||||
static InvenTreeAppState? of(BuildContext context) =>
|
||||
context.findAncestorStateOfType<InvenTreeAppState>();
|
||||
}
|
||||
|
||||
|
||||
class InvenTreeAppState extends State<StatefulWidget> {
|
||||
|
||||
InvenTreeAppState(this.savedThemeMode) : super();
|
||||
|
||||
// Custom _locale (default = null; use system default)
|
||||
@ -120,16 +119,17 @@ class InvenTreeAppState extends State<StatefulWidget> {
|
||||
|
||||
// Run app init routines in the background
|
||||
Future<void> runInitTasks() async {
|
||||
|
||||
// Set the app locale (language)
|
||||
Locale? locale = await InvenTreeSettingsManager().getSelectedLocale();
|
||||
setLocale(locale);
|
||||
|
||||
// Display release notes if this is a new version
|
||||
final String version = await InvenTreeSettingsManager().getValue("recentVersion", "") as String;
|
||||
final String version =
|
||||
await InvenTreeSettingsManager().getValue("recentVersion", "")
|
||||
as String;
|
||||
|
||||
final PackageInfo info = await PackageInfo.fromPlatform();
|
||||
|
||||
|
||||
if (version != info.version) {
|
||||
// Save latest version to the settings database
|
||||
await InvenTreeSettingsManager().setValue("recentVersion", info.version);
|
||||
@ -139,7 +139,7 @@ class InvenTreeAppState extends State<StatefulWidget> {
|
||||
|
||||
// Show the release notes
|
||||
OneContext().push(
|
||||
MaterialPageRoute(builder: (context) => ReleaseNotesWidget(notes))
|
||||
MaterialPageRoute(builder: (context) => ReleaseNotesWidget(notes)),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -155,7 +155,6 @@ class InvenTreeAppState extends State<StatefulWidget> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
return AdaptiveTheme(
|
||||
light: ThemeData(
|
||||
brightness: Brightness.light,
|
||||
@ -168,7 +167,7 @@ class InvenTreeAppState extends State<StatefulWidget> {
|
||||
useMaterial3: true,
|
||||
),
|
||||
initial: savedThemeMode ?? AdaptiveThemeMode.light,
|
||||
builder: (light, dark) => MaterialApp(
|
||||
builder: (light, dark) => MaterialApp(
|
||||
theme: light,
|
||||
darkTheme: dark,
|
||||
debugShowCheckedModeBanner: false,
|
||||
@ -185,7 +184,7 @@ class InvenTreeAppState extends State<StatefulWidget> {
|
||||
],
|
||||
supportedLocales: supported_locales,
|
||||
locale: _locale,
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user