mirror of
https://bitbucket.org/FransoletThomas/tablet-app.git
synced 2025-12-06 16:41:19 +00:00
126 lines
4.6 KiB
Dart
126 lines
4.6 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:firebase_core/firebase_core.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:manager_api/api.dart';
|
|
import 'package:path_provider/path_provider.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:tablet_app/client.dart';
|
|
import 'Helpers/DatabaseHelper.dart';
|
|
import 'Models/tabletContext.dart';
|
|
import 'Screens/Configuration/config_view.dart';
|
|
import 'Screens/MainView/main_view.dart';
|
|
import 'Screens/Previous/previous_view.dart';
|
|
import 'app_context.dart';
|
|
import 'constants.dart';
|
|
|
|
void main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
String initialRoute;
|
|
TabletAppContext? localContext;
|
|
bool isConfig = false;
|
|
|
|
if(!kIsWeb) {
|
|
localContext = await DatabaseHelper.instance.getData();
|
|
}
|
|
|
|
Directory? appDocumentsDirectory = Platform.isIOS ? await getApplicationDocumentsDirectory() : await getDownloadsDirectory();
|
|
String localPath = appDocumentsDirectory!.path;
|
|
|
|
if(localContext != null && localContext.host != null) {
|
|
print("we've got an local db !");
|
|
print(localContext);
|
|
localContext.clientAPI = new Client(localContext.host!); // retrieve instanceId from local DB
|
|
isConfig = localContext.configuration != null;
|
|
print(localContext);
|
|
print("localContext.deviceId");
|
|
print(localContext.deviceId!);
|
|
print("localContext.instanceId");
|
|
print(localContext.instanceId);
|
|
// Get config from manager
|
|
DeviceDetailDTO? device = await localContext.clientAPI!.deviceApi!.deviceGetDetail(localContext.deviceId!);
|
|
localContext.configuration!.id = device!.configurationId;
|
|
localContext.instanceId = device.instanceId;
|
|
localContext.localPath = localPath;
|
|
|
|
if (device.configurationId == null) {
|
|
print("device.configurationId == null");
|
|
localContext.configuration = null;
|
|
isConfig = false;
|
|
}
|
|
} else {
|
|
print("NO LOCAL DB !");
|
|
localContext = TabletAppContext(host: "https://api.myinfomate.be");
|
|
|
|
localContext.localPath = localPath;
|
|
}
|
|
|
|
if(kIsWeb) {
|
|
localContext = TabletAppContext(host: "https://api.mymuseum.be", instanceId: "63514fd67ed8c735aaa4b8f1"); // mymuseum : 63514fd67ed8c735aaa4b8f1
|
|
print(localContext);
|
|
} else {
|
|
/*print("MOBILE - set host");
|
|
localContext = TabletAppContext(host: "https://api.mymuseum.be"); // mymuseum : 63514fd67ed8c735aaa4b8f1 //https://localhost:5001/ // https://api.mymuseum.be*/
|
|
}
|
|
|
|
initialRoute = isConfig ? '/main' : '/config';
|
|
|
|
final MyApp myApp = MyApp(
|
|
initialRoute: initialRoute,
|
|
tabletAppContext: localContext,
|
|
);
|
|
|
|
await Firebase.initializeApp();
|
|
|
|
runApp(myApp);
|
|
}
|
|
|
|
class MyApp extends StatefulWidget {
|
|
final String? initialRoute;
|
|
final TabletAppContext? tabletAppContext;
|
|
MyApp({this.initialRoute, this.tabletAppContext});
|
|
|
|
@override
|
|
_MyAppState createState() => _MyAppState();
|
|
}
|
|
|
|
class _MyAppState extends State<MyApp> {
|
|
TabletAppContext? tabletAppContext;
|
|
|
|
@override
|
|
void initState() {
|
|
//tabletAppContext = widget.tabletAppContext;
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ChangeNotifierProvider<AppContext>(
|
|
create: (_) => AppContext(widget.tabletAppContext),
|
|
child: MaterialApp(
|
|
debugShowCheckedModeBanner: false,
|
|
title: 'Tablet App Demo',
|
|
initialRoute: widget.initialRoute,
|
|
/*supportedLocales: [
|
|
const Locale('en', 'US'),
|
|
const Locale('fr', 'FR'),
|
|
],*/
|
|
theme: ThemeData(
|
|
primaryColor: widget.tabletAppContext != null ? widget.tabletAppContext!.configuration != null ? widget.tabletAppContext!.configuration!.primaryColor != null ? new Color(int.parse(widget.tabletAppContext!.configuration!.secondaryColor!.split('(0x')[1].split(')')[0], radix: 16)): kTestSecondColor : kTestSecondColor : kTestSecondColor,
|
|
primarySwatch: Colors.grey,
|
|
scaffoldBackgroundColor: widget.tabletAppContext != null ? widget.tabletAppContext!.configuration != null ? widget.tabletAppContext!.configuration!.secondaryColor != null ? new Color(int.parse(widget.tabletAppContext!.configuration!.secondaryColor!.split('(0x')[1].split(')')[0], radix: 16)): kBackgroundGrey : kBackgroundGrey : kBackgroundGrey,
|
|
//fontFamily: "Vollkorn",
|
|
textTheme: TextTheme(bodyLarge: TextStyle(color: kMainRed)),
|
|
visualDensity: VisualDensity.adaptivePlatformDensity,
|
|
),
|
|
routes: {
|
|
'/previous': (context) => PreviousViewWidget(title: 'Tablet App Demo Home Page'),
|
|
'/main': (context) => MainViewWidget(),
|
|
'/config': (context) => ConfigViewWidget(),
|
|
}
|
|
),
|
|
);
|
|
}
|
|
}
|