AppFlowy/app_flowy/lib/startup/tasks/application_task.dart

81 lines
2.3 KiB
Dart
Raw Normal View History

2021-06-19 15:41:19 +00:00
import 'package:app_flowy/startup/startup.dart';
2021-07-13 00:47:26 +00:00
import 'package:flowy_infra/theme.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
2021-06-19 15:41:19 +00:00
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:window_size/window_size.dart';
2021-10-11 05:15:41 +00:00
import 'package:app_flowy/startup/launcher.dart';
import 'package:bloc/bloc.dart';
import 'package:flowy_log/flowy_log.dart';
2021-06-19 15:41:19 +00:00
class AppWidgetTask extends LaunchTask {
@override
LaunchTaskType get type => LaunchTaskType.appLauncher;
@override
2021-07-12 15:27:58 +00:00
Future<void> initialize(LaunchContext context) {
2021-09-12 14:19:59 +00:00
final widget = context.getIt<EntryPoint>().create();
final app = ApplicationWidget(child: widget);
Bloc.observer = ApplicationBlocObserver();
2021-06-19 15:41:19 +00:00
runApp(app);
2021-07-12 15:27:58 +00:00
return Future(() => {});
2021-06-19 15:41:19 +00:00
}
}
class ApplicationWidget extends StatelessWidget {
2021-06-19 15:41:19 +00:00
final Widget child;
const ApplicationWidget({
2021-06-19 15:41:19 +00:00
Key? key,
required this.child,
}) : super(key: key);
@override
Widget build(BuildContext context) {
2021-10-11 01:05:53 +00:00
const ratio = 1.73;
2021-10-20 06:56:25 +00:00
const minWidth = 1000.0;
2021-10-11 05:15:41 +00:00
setWindowMinSize(const Size(minWidth, minWidth / ratio));
2021-10-11 14:57:27 +00:00
// const launchWidth = 1310.0;
// setWindowFrame(const Rect.fromLTWH(0, 0, launchWidth, launchWidth / ratio));
2021-06-19 15:41:19 +00:00
final theme = AppTheme.fromType(ThemeType.light);
return Provider.value(
2021-10-13 15:11:45 +00:00
value: theme,
child: MaterialApp(
2021-10-19 14:16:37 +00:00
builder: overlayManagerBuilder(),
2021-10-13 15:11:45 +00:00
debugShowCheckedModeBanner: false,
theme: theme.themeData,
navigatorKey: AppGlobals.rootNavKey,
home: child,
),
);
2021-06-19 15:41:19 +00:00
}
}
class AppGlobals {
static GlobalKey<NavigatorState> rootNavKey = GlobalKey();
static NavigatorState get nav => rootNavKey.currentState!;
}
class ApplicationBlocObserver extends BlocObserver {
@override
// ignore: unnecessary_overrides
void onTransition(Bloc bloc, Transition transition) {
// Log.debug("[current]: ${transition.currentState} \n\n[next]: ${transition.nextState}");
2021-11-04 05:22:35 +00:00
//Log.debug("${transition.nextState}");
super.onTransition(bloc, transition);
}
@override
void onError(BlocBase bloc, Object error, StackTrace stackTrace) {
Log.debug(error);
super.onError(bloc, error, stackTrace);
}
2021-11-04 05:22:35 +00:00
@override
void onEvent(Bloc bloc, Object? event) {
Log.debug("$event");
super.onEvent(bloc, event);
}
}