2024-11-08 13:59:22 +01:00
|
|
|
import 'dart:async';
|
2024-07-05 09:24:40 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2024-11-08 13:59:22 +01:00
|
|
|
import 'package:flutter/services.dart';
|
2024-07-05 09:24:40 +02:00
|
|
|
import 'package:go_router/go_router.dart';
|
2024-11-08 13:59:22 +01:00
|
|
|
import 'package:localstorage/localstorage.dart';
|
2024-08-27 15:38:21 +02:00
|
|
|
import 'package:oc_front/core/models/shared_workspace_local.dart';
|
2024-07-17 13:28:02 +02:00
|
|
|
import 'package:oc_front/core/models/workspace_local.dart';
|
2024-11-08 13:59:22 +01:00
|
|
|
import 'package:oc_front/core/sections/header/header.dart';
|
|
|
|
import 'package:oc_front/core/sections/header/menu.dart';
|
|
|
|
import 'package:oc_front/core/sections/left_menu.dart';
|
|
|
|
import 'package:oc_front/core/services/auth.service.dart';
|
2024-07-05 09:24:40 +02:00
|
|
|
import 'package:oc_front/core/services/router.dart';
|
|
|
|
import 'package:oc_front/core/sections/end_drawer.dart';
|
2024-11-08 13:59:22 +01:00
|
|
|
import 'package:oc_front/widgets/dialog/login.dart';
|
|
|
|
void main() async {
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
2024-07-05 09:24:40 +02:00
|
|
|
|
2024-11-08 13:59:22 +01:00
|
|
|
// Run `LinuxWebViewPlugin.initialize()` first before creating a WebView.
|
|
|
|
await initLocalStorage();
|
2024-07-05 09:24:40 +02:00
|
|
|
runApp(const MyApp());
|
|
|
|
}
|
2024-11-08 13:59:22 +01:00
|
|
|
GlobalKey<MainPageState>? mainKey;
|
2024-07-05 09:24:40 +02:00
|
|
|
GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
|
|
|
|
class MyApp extends StatelessWidget {
|
|
|
|
const MyApp({super.key});
|
|
|
|
// This widget is the root of your application.
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-11-08 13:59:22 +01:00
|
|
|
AuthService.init();
|
|
|
|
return MaterialApp.router( routerConfig: GoRouter( routes: AppRouter.routes ) );
|
2024-07-05 09:24:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// ignore: must_be_immutable
|
|
|
|
class MainPage extends StatefulWidget {
|
2024-11-08 13:59:22 +01:00
|
|
|
Widget? page;
|
|
|
|
MainPage({Key? key, required this.page}) : super(key: GlobalKey<MainPageState>());
|
2024-07-05 09:24:40 +02:00
|
|
|
|
|
|
|
// This widget is the home page of your application. It is stateful, meaning
|
|
|
|
// that it has a State object (defined below) that contains fields that affect
|
|
|
|
// how it looks.
|
|
|
|
|
|
|
|
// This class is the configuration for the state. It holds the values (in this
|
|
|
|
// case the title) provided by the parent (in this case the App widget) and
|
|
|
|
// used by the build method of the State. Fields in a Widget subclass are
|
|
|
|
// always marked "final".
|
|
|
|
|
|
|
|
@override
|
2024-11-08 13:59:22 +01:00
|
|
|
State<MainPage> createState() => MainPageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
var darkColor = Color.fromRGBO(26, 83, 92, 1);
|
|
|
|
var lightColor = Color.fromRGBO(78, 205, 196, 1);
|
|
|
|
var darkMidColor = Color.fromRGBO(44, 83, 100, 1);
|
|
|
|
var midColor = Colors.grey.shade300;
|
|
|
|
var redColor = Color.fromRGBO(255, 107, 107, 1);
|
|
|
|
|
|
|
|
double getWidth(BuildContext context) {
|
|
|
|
return MediaQuery.of(context).size.width <= 800 ? 800 : MediaQuery.of(context).size.width;
|
|
|
|
}
|
|
|
|
|
|
|
|
double getHeight(BuildContext context) {
|
|
|
|
return MediaQuery.of(context).size.height <= 400 ? 400 : MediaQuery.of(context).size.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
double getMainHeight(BuildContext context) {
|
|
|
|
return getHeight(context) - HeaderConstants.height;
|
|
|
|
}
|
|
|
|
double getMainWidth(BuildContext context) {
|
|
|
|
return getWidth(context) - 50;
|
2024-07-05 09:24:40 +02:00
|
|
|
}
|
|
|
|
|
2024-11-08 13:59:22 +01:00
|
|
|
class MainPageState extends State<MainPage> {
|
|
|
|
bool isCtrl = false;
|
|
|
|
final FocusNode node = FocusNode();
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
mainKey = widget.key as GlobalKey<MainPageState>?;
|
|
|
|
node.requestFocus();
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
2024-07-05 09:24:40 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
// This method is rerun every time setState is called, for instance as done
|
|
|
|
// by the _incrementCounter method above.
|
|
|
|
//
|
|
|
|
// The Flutter framework has been optimized to make rerunning build methods
|
|
|
|
// fast, so that you can just rebuild anything that needs updating rather
|
2024-11-27 10:54:10 +01:00
|
|
|
// than having to individually change instances of widgets.i
|
2024-07-05 09:24:40 +02:00
|
|
|
scaffoldKey = GlobalKey<ScaffoldState>();
|
2024-11-08 13:59:22 +01:00
|
|
|
isCtrl = false;
|
2024-11-27 10:54:10 +01:00
|
|
|
if (!AuthService.isConnected()) {
|
|
|
|
print("isConnected: ${AuthService.isConnected()}");
|
2024-11-08 13:59:22 +01:00
|
|
|
Future.delayed(const Duration(milliseconds: 500), () {
|
|
|
|
showDialog(
|
|
|
|
barrierDismissible: false,
|
|
|
|
context: context, builder: (context) {
|
|
|
|
return AlertDialog(
|
|
|
|
insetPadding: EdgeInsets.zero,
|
|
|
|
backgroundColor: Colors.white,
|
|
|
|
shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(0)),
|
|
|
|
title: LoginWidget());
|
|
|
|
});
|
|
|
|
});
|
2024-11-27 10:54:10 +01:00
|
|
|
}
|
|
|
|
return FutureBuilder(future: AuthService.init(),
|
|
|
|
builder: (e, s) {
|
|
|
|
WorkspaceLocal.init(context, false);
|
|
|
|
CollaborativeAreaLocal.init(context, false);
|
|
|
|
|
2024-11-08 13:59:22 +01:00
|
|
|
HeaderConstants.height = HeaderConstants.isNoHeader(AppRouter.currentRoute.route) || AppRouter.currentRoute.factory.searchFill() ? 50 : 100;
|
|
|
|
return Scaffold( key: scaffoldKey, endDrawer: EndDrawerWidget(), body:
|
|
|
|
SingleChildScrollView(
|
|
|
|
controller: ScrollController(),
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
child: Column( children: [
|
|
|
|
HeaderMenuWidget(),
|
|
|
|
Row( children : [
|
|
|
|
Container( padding: const EdgeInsets.symmetric(vertical: 30),
|
|
|
|
decoration: BoxDecoration( color: darkColor),
|
|
|
|
width: 50, height: getHeight(context) - 50,
|
|
|
|
child: SingleChildScrollView( child: LeftMenuWidget() )),
|
|
|
|
SizedBox( width: getMainWidth(context), height: getHeight(context) - 50,
|
|
|
|
child: KeyboardListener(
|
|
|
|
focusNode: node,
|
|
|
|
onKeyEvent: (event) async {
|
|
|
|
if ( event.logicalKey == LogicalKeyboardKey.controlLeft ) {
|
|
|
|
isCtrl = (event is KeyDownEvent);
|
|
|
|
node.requestFocus();
|
|
|
|
} else if( (event is KeyDownEvent) && event.logicalKey == LogicalKeyboardKey.enter) {
|
|
|
|
AppRouter.currentRoute.factory.search(context, isCtrl);
|
|
|
|
node.requestFocus();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
HeaderWidget(),
|
|
|
|
widget.page ?? Container() // CatalogPageWidget(),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)),
|
|
|
|
])
|
|
|
|
])
|
|
|
|
)
|
|
|
|
));
|
|
|
|
});
|
2024-07-05 09:24:40 +02:00
|
|
|
}
|
|
|
|
}
|