ambito/lib/main.dart

237 lines
7.7 KiB
Dart

import 'package:ambito/src/packages/ambito_api/base_api.dart';
import 'package:ambito/src/packages/ambito_db/base_db.dart';
import 'package:ambito/src/packages/ambito_notifier/notifier/theme_manager.dart';
import 'package:ambito/src/packages/ambito_sharedprefs/ambito_sharedprefs.dart';
import 'package:ambito/src/packages/ambito_theme/ambito_theme.dart';
import 'package:ambito/src/packages/ambito_theme/ambito_theme_large.dart';
import 'package:ambito/src/packages/ambito_theme/ambito_theme_medium.dart';
import 'package:ambito/src/packages/ambito_theme/ambito_theme_small.dart';
import 'package:ambito/src/pages/actions/actions_page.dart';
import 'package:ambito/src/pages/actions/actions_pre_page.dart';
import 'package:ambito/src/pages/actions/create/action_create_page.dart';
import 'package:ambito/src/pages/actions/detail/action_detail_page.dart';
import 'package:ambito/src/pages/calendar/calendar_page.dart';
import 'package:ambito/src/pages/calendar/calendar_page_year.dart';
import 'package:ambito/src/pages/dashboard/dashboard_page.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:get/get.dart';
import 'package:isar/isar.dart';
import 'package:logger/logger.dart';
import 'package:provider/provider.dart';
import 'package:screen_breakpoints/screen_breakpoints.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:syncfusion_localizations/syncfusion_localizations.dart';
final Logger logger = Logger(
printer: PrettyPrinter(),
);
const BreakpointConfiguration myBreakpoints = BreakpointConfiguration(
xs: Breakpoint(
breakpoint: 0,
width: double.infinity,
margin: 16,
padding: 0,
columns: 4,
),
sm: Breakpoint(
breakpoint: 320,
width: double.infinity,
margin: 32,
padding: 10,
columns: 8,
),
md: Breakpoint(
breakpoint: 905,
width: 840,
margin: null,
padding: 0,
columns: 12,
),
lg: Breakpoint(
breakpoint: 1240,
width: 1152,
margin: 0,
padding: 0,
columns: 12,
),
xl: Breakpoint(
breakpoint: 1440,
width: 1152,
margin: null,
padding: 0,
columns: 12,
),
xxl: null,
);
late Isar isar;
late SharedPreferences prefs;
AmbitoTheme largeTheme = AmbitoThemeLarge();
AmbitoTheme mediumTheme = AmbitoThemeMedium();
AmbitoTheme smallTheme = AmbitoThemeSmall();
const BASEROW_TOKEN = 'TFxO7vzBLVRCu9I3VMoHmTuCvSu8aCDi';
const BASEROW_IDS = {
"measure": 328253,
"measure_combination": 328217,
"organism": 328255,
"funding_program": 328256,
"factsheet": 328273,
"location_requirements": 328188,
"reference_implementation": 328465,
"business": 328472,
"experience_report": 330802,
"approval_requirement": 330806,
"service_provider": 330824,
"service_provider_contact_person": 330832,
"material": 330836,
"source": 334231,
"tree_type": 342622,
"aenderungfactsheet": 330946,
};
void main() async {
WidgetsFlutterBinding.ensureInitialized();
//await dotenv.load(fileName: '.env');
await AmbitoSharedPrefs.start();
await AmbitoIsarDB.init();
await Future.wait([
//BaseApi().getContent('tree_type'),
BaseApi().getContent('measure'),
BaseApi().getContent('measure_combination'),
//BaseApi().getContent('organism'),
//BaseApi().getContent('funding_program'),
//BaseApi().getContent('location_requirements'),
//BaseApi().getContent('reference_implementation'),
//BaseApi().getContent('business'),
//BaseApi().getContent('service_provider'),
//BaseApi().getContent('service_provider_contact_person'),
//BaseApi().getContent('material'),
//BaseApi().getContent('source'),
]);
await MeasureRepository().buildMeasureFilters();
await MeasureRepository().downloadImages();
runApp(const Ambito());
}
class Ambito extends StatelessWidget {
const Ambito({super.key});
@override
Widget build(BuildContext context) {
return BreakpointConfigurator(
configuration: myBreakpoints,
child: ChangeNotifierProvider(
create: (_) => ThemeManager(),
child: Consumer<ThemeManager>(
builder: (context, ThemeManager themeManager, child) {
return GetMaterialApp(
debugShowCheckedModeBanner: false,
localizationsDelegates: [
FlutterI18nDelegate(
translationLoader: FileTranslationLoader(
fallbackFile: 'de',
basePath: 'i18n',
),
missingTranslationHandler: (key, locale) {
if (kDebugMode) {
print("--- Missing Key: $key, languageCode: $locale");
}
},
),
GlobalMaterialLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
SfGlobalLocalizations.delegate,
],
title: 'AmBiTo',
supportedLocales: const [Locale('de')],
locale: const Locale('de'),
builder: FlutterI18n.rootAppBuilder(),
theme: ThemeManager().themeData?.lightThemeData,
darkTheme: ThemeManager().themeData?.darkThemeData,
themeMode: ThemeMode.light,
initialRoute: '/massnahmen',
getPages: [
GetPage(
name: '/',
page: () => const ActionsPrePage(),
),
GetPage(
name: '/kalender',
page: () => const CalendarPage(),
),
GetPage(
name: '/kalender/jahr',
page: () => const CalendarPageYear(),
),
GetPage(
name: '/massnahmen',
page: () => const ActionsPrePage(),
),
GetPage(
name: '/massnahmendatenbank',
page: () => const ActionsPage(),
),
GetPage(
name: '/massnahmendatenbank/:kategorie',
page: () => const ActionsPage(),
),
GetPage(
name: '/massnahmendatenbank/:kategorie/:typ',
page: () => const ActionsPage(),
),
GetPage(
name: '/dashboard',
page: () => DashboardPage(
businessId: prefs.getInt('currentUser') ?? 22,
userId: 0,
),
),
GetPage(
name: '/dashboard/meine-massnahmen',
page: () => DashboardPage(
businessId: prefs.getInt('currentUser') ?? 22,
userId: 0,
),
),
GetPage(
name: '/dashboard/urkunde',
page: () => DashboardPage(
businessId: prefs.getInt('currentUser') ?? 22,
userId: 0,
),
),
GetPage(
name: '/dashboard/flaechen',
page: () => DashboardPage(
businessId: prefs.getInt('currentUser') ?? 22,
userId: 0,
),
),
GetPage(
name: '/dashboard/stammdaten',
page: () => DashboardPage(
businessId: prefs.getInt('currentUser') ?? 22,
userId: 0,
),
),
GetPage(
name: '/massnahme/neu',
page: () => const ActionsCreatePage(),
),
GetPage(
name: '/massnahme/:id', page: () => const ActionDetailPage())
],
);
}),
),
);
}
}