ambito/lib/main.dart

229 lines
8.3 KiB
Dart
Raw Normal View History

import 'package:ambito/src/config/config.dart';
import 'package:ambito/src/consts/consts.dart';
2024-12-13 09:41:26 +01:00
import 'package:ambito/src/entity/cart/cart.dart';
import 'package:ambito/src/entity/cart/cart_element.dart';
import 'package:ambito/src/entity/cart/cart_repository.dart';
2024-12-04 16:21:50 +01:00
import 'package:ambito/src/entity/lists/list_measure.dart';
import 'package:ambito/src/entity/lists/list_repository.dart';
import 'package:ambito/src/packages/ambito_api/base_api.dart';
import 'package:ambito/src/packages/ambito_db/base_db.dart';
2024-11-18 15:19:07 +01:00
import 'package:ambito/src/packages/ambito_notifier/notifier/theme_manager.dart';
2024-11-07 05:52:03 +01:00
import 'package:ambito/src/packages/ambito_sharedprefs/ambito_sharedprefs.dart';
import 'package:ambito/src/pages/calendar/calendar_page.dart';
import 'package:ambito/src/pages/calendar/calendar_page_year.dart';
2024-12-13 09:41:26 +01:00
import 'package:ambito/src/pages/cart/cart_page.dart';
2024-12-07 20:53:13 +01:00
import 'package:ambito/src/pages/dashboard/areas/dashboard_areas_page.dart';
2024-11-09 22:03:03 +01:00
import 'package:ambito/src/pages/dashboard/dashboard_page.dart';
2024-12-04 16:21:50 +01:00
import 'package:ambito/src/pages/error/error_page.dart';
import 'package:ambito/src/pages/measure/categories/measure_categories_page.dart';
import 'package:ambito/src/pages/measure/create/measure_create_page.dart';
import 'package:ambito/src/pages/measure/detail/measure_detail_page.dart';
import 'package:ambito/src/pages/measure/groups/measure_groups_page.dart';
import 'package:ambito/src/pages/measure/measure_page.dart';
2024-09-18 15:07:08 +02:00
import 'package:flutter/foundation.dart';
2024-09-13 21:32:34 +02:00
import 'package:flutter/material.dart';
2024-09-18 15:07:08 +02:00
import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
2024-11-07 05:52:03 +01:00
import 'package:get/get.dart';
2024-11-18 15:19:07 +01:00
import 'package:provider/provider.dart';
2024-11-18 09:15:00 +01:00
import 'package:screen_breakpoints/screen_breakpoints.dart';
import 'package:syncfusion_localizations/syncfusion_localizations.dart';
2024-09-13 21:32:34 +02:00
2024-12-04 16:21:50 +01:00
List<ListMeasure> listMeasures = <ListMeasure>[].toList(growable: true);
2024-09-18 15:07:08 +02:00
void main() async {
WidgetsFlutterBinding.ensureInitialized();
2024-11-07 05:52:03 +01:00
await AmbitoSharedPrefs.start();
await AmbitoIsarDB.init();
await Future.wait([
2024-12-04 16:21:50 +01:00
BaseApi().getContent('measure_types'),
BaseApi().getContent('measure_types_details'),
BaseApi().getContent('measure_general'),
BaseApi().getContent('measure_details'),
BaseApi().getContent('funding_program'),
2024-12-07 20:53:13 +01:00
BaseApi().getContent('business'),
BaseApi().getContent('area'),
2024-09-18 15:07:08 +02:00
]);
2024-12-13 09:41:26 +01:00
List<int> myCartIds = [];
var carts = await BaseApi().getContent('cart', false);
for (final cart in carts) {
CartRepository().put(Cart.fromJson(cart));
}
var cart_elements = await BaseApi().getContent('cart_element', false);
for (final element in cart_elements) {
CartRepository().putElement(CartElement.fromJson(element));
}
/*for (final cart in carts) {
if (cart['field_3106997'].first['id'] ==
(prefs.getInt('currentUser') ?? 100)) {
logger.i('Found my cart!');
Cart cartToSave = Cart.fromJson(cart);
myCartIds.add(cartToSave.id);
CartRepository().put(cartToSave);
}
}*/
2024-12-16 11:15:11 +01:00
MeasureRepository().buildMeasureComplete();
2024-12-13 09:41:26 +01:00
/*BaseApi().getContent('cart', false).then((carts) {
logger.i(carts);
for (final cart in carts) {
logger.e(cart);
if (cart['field_3106997'].first['id'] ==
(prefs.getInt('currentUser') ?? 100)) {
logger.i('Found my cart!');
CartRepository().put(Cart.fromJson(cart));
}
}
logger.e(CartRepository().getAll().length);
});*/
2024-12-04 16:21:50 +01:00
ListRepository().buildTypeGroupCategoryList();
ListRepository().buildListMeasureSingle();
ListRepository().putListMeasure(listMeasures);
await MeasureRepository().getCategoriesGroupsAndTypes();
2024-12-16 11:15:11 +01:00
MeasureRepository().buildMeasureMonths();
2024-09-18 15:07:08 +02:00
runApp(const Ambito());
}
class Ambito extends StatelessWidget {
const Ambito({super.key});
2024-09-13 21:32:34 +02:00
@override
Widget build(BuildContext context) {
2024-11-18 09:15:00 +01:00
return BreakpointConfigurator(
configuration: myBreakpoints,
2024-11-18 15:19:07 +01:00
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: supportedLocales,
locale: ThemeManager().locale,
2024-11-18 15:19:07 +01:00
builder: FlutterI18n.rootAppBuilder(),
theme: ThemeManager().themeData?.lightThemeData,
darkTheme: ThemeManager().themeData?.darkThemeData,
themeMode: ThemeMode.light,
initialRoute: '/massnahmen',
getPages: [
GetPage(
name: '/',
2024-12-04 16:21:50 +01:00
page: () => const MeasureCategoriesPage(),
2024-11-18 15:19:07 +01:00
),
2024-12-13 09:41:26 +01:00
GetPage(
name: '/warenkorb',
page: () => const CartPage(
measure: null,
),
),
2024-11-18 15:19:07 +01:00
GetPage(
name: '/kalender',
page: () => const CalendarPage(),
),
GetPage(
name: '/kalender/jahr',
page: () => const CalendarPageYear(),
),
GetPage(
name: '/massnahmen',
2024-12-04 16:21:50 +01:00
page: () => const MeasureCategoriesPage(),
2024-11-18 15:19:07 +01:00
),
GetPage(
name: '/massnahmendatenbank',
2024-12-04 16:21:50 +01:00
page: () => const MeasureCategoriesPage(),
2024-11-18 15:19:07 +01:00
),
GetPage(
name: '/massnahmendatenbank/:kategorie',
2024-12-04 16:21:50 +01:00
page: () => const MeasureGroupsPage(),
),
GetPage(
name: '/massnahmendatenbank/:kategorie/:group',
page: () => const MeasuresPage(),
),
GetPage(
2024-12-04 16:21:50 +01:00
name: '/massnahmendatenbank/:kategorie/:group/:type',
page: () => const MeasuresPage(),
),
2024-11-18 15:19:07 +01:00
GetPage(
name: '/dashboard',
page: () => DashboardPage(
2024-12-07 20:53:13 +01:00
businessId: prefs.getInt('currentUser') ?? 100,
2024-11-18 15:19:07 +01:00
userId: 0,
),
),
GetPage(
name: '/dashboard/meine-massnahmen',
page: () => DashboardPage(
2024-12-07 20:53:13 +01:00
businessId: prefs.getInt('currentUser') ?? 100,
2024-11-18 15:19:07 +01:00
userId: 0,
),
),
GetPage(
name: '/dashboard/urkunde',
page: () => DashboardPage(
2024-12-07 20:53:13 +01:00
businessId: prefs.getInt('currentUser') ?? 100,
2024-11-18 15:19:07 +01:00
userId: 0,
),
),
GetPage(
name: '/dashboard/flaechen',
2024-12-07 20:53:13 +01:00
page: () => DashboardAreasPage(
businessId: prefs.getInt('currentUser') ?? 100,
userId: 0,
),
),
GetPage(
name: '/dashboard/flaechen/:index',
page: () => DashboardAreasPage(
businessId: prefs.getInt('currentUser') ?? 100,
2024-11-18 15:19:07 +01:00
userId: 0,
),
),
GetPage(
name: '/dashboard/stammdaten',
page: () => DashboardPage(
2024-12-07 20:53:13 +01:00
businessId: prefs.getInt('currentUser') ?? 100,
2024-11-18 15:19:07 +01:00
userId: 0,
),
),
GetPage(
name: '/massnahme/neu',
2024-12-04 16:21:50 +01:00
page: () => const MeasureCreatePage(),
),
GetPage(
2024-12-13 09:41:26 +01:00
name: '/massnahme/:id',
page: () => const MeasureDetailPage(),
2024-11-18 15:19:07 +01:00
),
GetPage(
2024-12-04 16:21:50 +01:00
name: '/error',
page: () => const ErrorPage(),
),
2024-11-18 15:19:07 +01:00
],
);
}),
2024-11-18 09:15:00 +01:00
),
2024-09-13 21:32:34 +02:00
);
}
}