diff --git a/.env b/.env new file mode 100644 index 0000000..08e1ce9 --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +BASEROW_TOKEN="TFxO7vzBLVRCu9I3VMoHmTuCvSu8aCDi" +BASEROW_IDS='{"massnahmen": 328253, "massnahmenkombination": 328217, "organismen": 328255, "foerderprogramme": 328256, "factsheet": 328273, "standortansprueche": 328188, "referenzumsetzung": 328465, "betriebsverzeichnis": 328472, "erfahrungsbericht": 330802, "genehmigungspflicht": 330806, "dienstleister": 330824, "ansprechperson": 330832, "material": 330836, "quellen": 334231, "baumarten": 342622, "aenderungfactsheet": 330946}' \ No newline at end of file diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..232bb44 --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +BASEROWTOKEN='ENTER_THE_TOKEN_HERE' +BASEROW_IDS="{'massnahmen': 1, 'massnahmenkombination': 2, 'organismen': 3, 'foerderprogramme': 4, 'factsheet': 5, 'standortansprueche': 6, 'referenzumsetzung': 7, 'betriebsverzeichnis': 8, 'erfahrungsbericht': 9, 'genehmigungspflicht': 10, 'dienstleister': 11, 'ansprechperson': 12, 'material': 13, 'quellen': 14, 'baumarten': 15, 'aenderungfactsheet': 16,}" \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index 6d2dbc4..ed19b89 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,9 +1,10 @@ import 'package:ambito/src/domain/entity/baumarten/baumarten.dart'; import 'package:ambito/src/domain/entity/massnahme/massnahme.dart'; import 'package:ambito/src/packages/ambito_api/base.dart'; -import 'package:ambito/src/pages/start/start_page.dart'; +import 'package:ambito/src/pages/loading/loading_page.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:flutter_i18n/flutter_i18n.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:get/get_navigation/src/root/get_material_app.dart'; @@ -11,8 +12,6 @@ import 'package:isar/isar.dart'; import 'package:logger/logger.dart'; import 'package:syncfusion_localizations/syncfusion_localizations.dart'; -const String ambitoToken = 'TFxO7vzBLVRCu9I3VMoHmTuCvSu8aCDi'; - final Logger logger = Logger( printer: PrettyPrinter(), ); @@ -22,6 +21,8 @@ late Isar isar; void main() async { WidgetsFlutterBinding.ensureInitialized(); + await dotenv.load(fileName: '.env'); + await Isar.initialize(); const dir = Isar.sqliteInMemory; const engine = kIsWeb ? IsarEngine.sqlite : IsarEngine.isar; @@ -32,7 +33,7 @@ void main() async { inspector: true, ); - Future.wait([ + await Future.wait([ BaseApi().getContent('baumarten'), BaseApi().getContent('massnahmen'), ]); @@ -64,14 +65,14 @@ class Ambito extends StatelessWidget { SfGlobalLocalizations.delegate, ], title: 'Flutter Demo', - supportedLocales: [Locale('de')], + supportedLocales: const [Locale('de')], locale: const Locale('de'), builder: FlutterI18n.rootAppBuilder(), theme: ThemeData( scaffoldBackgroundColor: Colors.white, useMaterial3: true, ), - home: const StartPage(), + home: const LoadingPage(), ); } } diff --git a/lib/src/domain/entity/base_entity.dart b/lib/src/domain/entity/base_entity.dart index b934175..23fd37e 100644 --- a/lib/src/domain/entity/base_entity.dart +++ b/lib/src/domain/entity/base_entity.dart @@ -1 +1,5 @@ class BaseEntity {} + +mixin EntityWithId { + late int id; +} diff --git a/lib/src/domain/entity/baumarten/baumarten.dart b/lib/src/domain/entity/baumarten/baumarten.dart index ae2d709..43aa0b3 100644 --- a/lib/src/domain/entity/baumarten/baumarten.dart +++ b/lib/src/domain/entity/baumarten/baumarten.dart @@ -9,10 +9,9 @@ part 'baumarten.g.dart'; @JsonSerializable(explicitToJson: true) @collection -class Baumarten extends BaseEntity { +class Baumarten extends BaseEntity with EntityWithId { Baumarten(); - late int id; @JsonKey(name: 'order') String? orderString; @JsonKey(name: 'Art') diff --git a/lib/src/domain/entity/baumarten/baumarten.g.dart b/lib/src/domain/entity/baumarten/baumarten.g.dart index 8daea42..3eec6d7 100644 --- a/lib/src/domain/entity/baumarten/baumarten.g.dart +++ b/lib/src/domain/entity/baumarten/baumarten.g.dart @@ -498,7 +498,6 @@ int serializeBaumarten(IsarWriter writer, Baumarten object) { @isarProtected Baumarten deserializeBaumarten(IsarReader reader) { final object = Baumarten(); - object.id = IsarCore.readId(reader); object.orderString = IsarCore.readString(reader, 1); object.art = IsarCore.readString(reader, 2); object.id2 = IsarCore.readString(reader, 3); @@ -731,14 +730,13 @@ Baumarten deserializeBaumarten(IsarReader reader) { object.local = IsarCore.readBool(reader, 32); } } + object.id = IsarCore.readId(reader); return object; } @isarProtected dynamic deserializeBaumartenProp(IsarReader reader, int property) { switch (property) { - case 0: - return IsarCore.readId(reader); case 1: return IsarCore.readString(reader, 1); case 2: @@ -1004,6 +1002,8 @@ dynamic deserializeBaumartenProp(IsarReader reader, int property) { return IsarCore.readBool(reader, 32); } } + case 0: + return IsarCore.readId(reader); default: throw ArgumentError('Unknown property: $property'); } @@ -1344,87 +1344,6 @@ extension BaumartenQueryBuilderUpdate extension BaumartenQueryFilter on QueryBuilder { - QueryBuilder idEqualTo( - int value, - ) { - return QueryBuilder.apply(this, (query) { - return query.addFilterCondition( - EqualCondition( - property: 0, - value: value, - ), - ); - }); - } - - QueryBuilder idGreaterThan( - int value, - ) { - return QueryBuilder.apply(this, (query) { - return query.addFilterCondition( - GreaterCondition( - property: 0, - value: value, - ), - ); - }); - } - - QueryBuilder - idGreaterThanOrEqualTo( - int value, - ) { - return QueryBuilder.apply(this, (query) { - return query.addFilterCondition( - GreaterOrEqualCondition( - property: 0, - value: value, - ), - ); - }); - } - - QueryBuilder idLessThan( - int value, - ) { - return QueryBuilder.apply(this, (query) { - return query.addFilterCondition( - LessCondition( - property: 0, - value: value, - ), - ); - }); - } - - QueryBuilder idLessThanOrEqualTo( - int value, - ) { - return QueryBuilder.apply(this, (query) { - return query.addFilterCondition( - LessOrEqualCondition( - property: 0, - value: value, - ), - ); - }); - } - - QueryBuilder idBetween( - int lower, - int upper, - ) { - return QueryBuilder.apply(this, (query) { - return query.addFilterCondition( - BetweenCondition( - property: 0, - lower: lower, - upper: upper, - ), - ); - }); - } - QueryBuilder orderStringIsNull() { return QueryBuilder.apply(this, (query) { @@ -5461,6 +5380,87 @@ extension BaumartenQueryFilter ); }); } + + QueryBuilder idEqualTo( + int value, + ) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition( + EqualCondition( + property: 0, + value: value, + ), + ); + }); + } + + QueryBuilder idGreaterThan( + int value, + ) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition( + GreaterCondition( + property: 0, + value: value, + ), + ); + }); + } + + QueryBuilder + idGreaterThanOrEqualTo( + int value, + ) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition( + GreaterOrEqualCondition( + property: 0, + value: value, + ), + ); + }); + } + + QueryBuilder idLessThan( + int value, + ) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition( + LessCondition( + property: 0, + value: value, + ), + ); + }); + } + + QueryBuilder idLessThanOrEqualTo( + int value, + ) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition( + LessOrEqualCondition( + property: 0, + value: value, + ), + ); + }); + } + + QueryBuilder idBetween( + int lower, + int upper, + ) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition( + BetweenCondition( + property: 0, + lower: lower, + upper: upper, + ), + ); + }); + } } extension BaumartenQueryObject @@ -5502,18 +5502,6 @@ extension BaumartenQueryObject } extension BaumartenQuerySortBy on QueryBuilder { - QueryBuilder sortById() { - return QueryBuilder.apply(this, (query) { - return query.addSortBy(0); - }); - } - - QueryBuilder sortByIdDesc() { - return QueryBuilder.apply(this, (query) { - return query.addSortBy(0, sort: Sort.desc); - }); - } - QueryBuilder sortByOrderString( {bool caseSensitive = true}) { return QueryBuilder.apply(this, (query) { @@ -5945,22 +5933,22 @@ extension BaumartenQuerySortBy on QueryBuilder { return query.addSortBy(32, sort: Sort.desc); }); } -} -extension BaumartenQuerySortThenBy - on QueryBuilder { - QueryBuilder thenById() { + QueryBuilder sortById() { return QueryBuilder.apply(this, (query) { return query.addSortBy(0); }); } - QueryBuilder thenByIdDesc() { + QueryBuilder sortByIdDesc() { return QueryBuilder.apply(this, (query) { return query.addSortBy(0, sort: Sort.desc); }); } +} +extension BaumartenQuerySortThenBy + on QueryBuilder { QueryBuilder thenByOrderString( {bool caseSensitive = true}) { return QueryBuilder.apply(this, (query) { @@ -6252,6 +6240,18 @@ extension BaumartenQuerySortThenBy return query.addSortBy(32, sort: Sort.desc); }); } + + QueryBuilder thenById() { + return QueryBuilder.apply(this, (query) { + return query.addSortBy(0); + }); + } + + QueryBuilder thenByIdDesc() { + return QueryBuilder.apply(this, (query) { + return query.addSortBy(0, sort: Sort.desc); + }); + } } extension BaumartenQueryWhereDistinct @@ -6405,12 +6405,6 @@ extension BaumartenQueryWhereDistinct extension BaumartenQueryProperty1 on QueryBuilder { - QueryBuilder idProperty() { - return QueryBuilder.apply(this, (query) { - return query.addProperty(0); - }); - } - QueryBuilder orderStringProperty() { return QueryBuilder.apply(this, (query) { return query.addProperty(1); @@ -6609,16 +6603,16 @@ extension BaumartenQueryProperty1 return query.addProperty(32); }); } -} -extension BaumartenQueryProperty2 - on QueryBuilder { - QueryBuilder idProperty() { + QueryBuilder idProperty() { return QueryBuilder.apply(this, (query) { return query.addProperty(0); }); } +} +extension BaumartenQueryProperty2 + on QueryBuilder { QueryBuilder orderStringProperty() { return QueryBuilder.apply(this, (query) { return query.addProperty(1); @@ -6825,16 +6819,16 @@ extension BaumartenQueryProperty2 return query.addProperty(32); }); } -} -extension BaumartenQueryProperty3 - on QueryBuilder { - QueryBuilder idProperty() { + QueryBuilder idProperty() { return QueryBuilder.apply(this, (query) { return query.addProperty(0); }); } +} +extension BaumartenQueryProperty3 + on QueryBuilder { QueryBuilder orderStringProperty() { return QueryBuilder.apply(this, (query) { @@ -7043,6 +7037,12 @@ extension BaumartenQueryProperty3 return query.addProperty(32); }); } + + QueryBuilder idProperty() { + return QueryBuilder.apply(this, (query) { + return query.addProperty(0); + }); + } } // ************************************************************************** diff --git a/lib/src/domain/entity/massnahme/massnahme.dart b/lib/src/domain/entity/massnahme/massnahme.dart index 2d758df..bd34180 100644 --- a/lib/src/domain/entity/massnahme/massnahme.dart +++ b/lib/src/domain/entity/massnahme/massnahme.dart @@ -15,10 +15,9 @@ part 'massnahme.g.dart'; @JsonSerializable(explicitToJson: true) @collection -class Massnahme extends BaseEntity { +class Massnahme extends BaseEntity with EntityWithId { Massnahme(); - late int id; @JsonKey(name: 'order') String? orderString; @JsonKey(name: 'Maßnahmenbezeichung') diff --git a/lib/src/domain/entity/massnahme/massnahme.g.dart b/lib/src/domain/entity/massnahme/massnahme.g.dart index 069991a..ed27b8d 100644 --- a/lib/src/domain/entity/massnahme/massnahme.g.dart +++ b/lib/src/domain/entity/massnahme/massnahme.g.dart @@ -1054,7 +1054,6 @@ int serializeMassnahme(IsarWriter writer, Massnahme object) { @isarProtected Massnahme deserializeMassnahme(IsarReader reader) { final object = Massnahme(); - object.id = IsarCore.readId(reader); object.orderString = IsarCore.readString(reader, 1); object.name = IsarCore.readString(reader, 2); { @@ -1723,14 +1722,13 @@ Massnahme deserializeMassnahme(IsarReader reader) { } } } + object.id = IsarCore.readId(reader); return object; } @isarProtected dynamic deserializeMassnahmeProp(IsarReader reader, int property) { switch (property) { - case 0: - return IsarCore.readId(reader); case 1: return IsarCore.readString(reader, 1); case 2: @@ -2472,6 +2470,8 @@ dynamic deserializeMassnahmeProp(IsarReader reader, int property) { } } } + case 0: + return IsarCore.readId(reader); default: throw ArgumentError('Unknown property: $property'); } @@ -3028,87 +3028,6 @@ extension MassnahmeQueryBuilderUpdate extension MassnahmeQueryFilter on QueryBuilder { - QueryBuilder idEqualTo( - int value, - ) { - return QueryBuilder.apply(this, (query) { - return query.addFilterCondition( - EqualCondition( - property: 0, - value: value, - ), - ); - }); - } - - QueryBuilder idGreaterThan( - int value, - ) { - return QueryBuilder.apply(this, (query) { - return query.addFilterCondition( - GreaterCondition( - property: 0, - value: value, - ), - ); - }); - } - - QueryBuilder - idGreaterThanOrEqualTo( - int value, - ) { - return QueryBuilder.apply(this, (query) { - return query.addFilterCondition( - GreaterOrEqualCondition( - property: 0, - value: value, - ), - ); - }); - } - - QueryBuilder idLessThan( - int value, - ) { - return QueryBuilder.apply(this, (query) { - return query.addFilterCondition( - LessCondition( - property: 0, - value: value, - ), - ); - }); - } - - QueryBuilder idLessThanOrEqualTo( - int value, - ) { - return QueryBuilder.apply(this, (query) { - return query.addFilterCondition( - LessOrEqualCondition( - property: 0, - value: value, - ), - ); - }); - } - - QueryBuilder idBetween( - int lower, - int upper, - ) { - return QueryBuilder.apply(this, (query) { - return query.addFilterCondition( - BetweenCondition( - property: 0, - lower: lower, - upper: upper, - ), - ); - }); - } - QueryBuilder orderStringIsNull() { return QueryBuilder.apply(this, (query) { @@ -11025,6 +10944,87 @@ extension MassnahmeQueryFilter ); }); } + + QueryBuilder idEqualTo( + int value, + ) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition( + EqualCondition( + property: 0, + value: value, + ), + ); + }); + } + + QueryBuilder idGreaterThan( + int value, + ) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition( + GreaterCondition( + property: 0, + value: value, + ), + ); + }); + } + + QueryBuilder + idGreaterThanOrEqualTo( + int value, + ) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition( + GreaterOrEqualCondition( + property: 0, + value: value, + ), + ); + }); + } + + QueryBuilder idLessThan( + int value, + ) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition( + LessCondition( + property: 0, + value: value, + ), + ); + }); + } + + QueryBuilder idLessThanOrEqualTo( + int value, + ) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition( + LessOrEqualCondition( + property: 0, + value: value, + ), + ); + }); + } + + QueryBuilder idBetween( + int lower, + int upper, + ) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition( + BetweenCondition( + property: 0, + lower: lower, + upper: upper, + ), + ); + }); + } } extension MassnahmeQueryObject @@ -11038,18 +11038,6 @@ extension MassnahmeQueryObject } extension MassnahmeQuerySortBy on QueryBuilder { - QueryBuilder sortById() { - return QueryBuilder.apply(this, (query) { - return query.addSortBy(0); - }); - } - - QueryBuilder sortByIdDesc() { - return QueryBuilder.apply(this, (query) { - return query.addSortBy(0, sort: Sort.desc); - }); - } - QueryBuilder sortByOrderString( {bool caseSensitive = true}) { return QueryBuilder.apply(this, (query) { @@ -11838,22 +11826,22 @@ extension MassnahmeQuerySortBy on QueryBuilder { ); }); } -} -extension MassnahmeQuerySortThenBy - on QueryBuilder { - QueryBuilder thenById() { + QueryBuilder sortById() { return QueryBuilder.apply(this, (query) { return query.addSortBy(0); }); } - QueryBuilder thenByIdDesc() { + QueryBuilder sortByIdDesc() { return QueryBuilder.apply(this, (query) { return query.addSortBy(0, sort: Sort.desc); }); } +} +extension MassnahmeQuerySortThenBy + on QueryBuilder { QueryBuilder thenByOrderString( {bool caseSensitive = true}) { return QueryBuilder.apply(this, (query) { @@ -12383,6 +12371,18 @@ extension MassnahmeQuerySortThenBy return query.addSortBy(62, sort: Sort.desc, caseSensitive: caseSensitive); }); } + + QueryBuilder thenById() { + return QueryBuilder.apply(this, (query) { + return query.addSortBy(0); + }); + } + + QueryBuilder thenByIdDesc() { + return QueryBuilder.apply(this, (query) { + return query.addSortBy(0, sort: Sort.desc); + }); + } } extension MassnahmeQueryWhereDistinct @@ -12655,12 +12655,6 @@ extension MassnahmeQueryWhereDistinct extension MassnahmeQueryProperty1 on QueryBuilder { - QueryBuilder idProperty() { - return QueryBuilder.apply(this, (query) { - return query.addProperty(0); - }); - } - QueryBuilder orderStringProperty() { return QueryBuilder.apply(this, (query) { return query.addProperty(1); @@ -13075,16 +13069,16 @@ extension MassnahmeQueryProperty1 return query.addProperty(63); }); } -} -extension MassnahmeQueryProperty2 - on QueryBuilder { - QueryBuilder idProperty() { + QueryBuilder idProperty() { return QueryBuilder.apply(this, (query) { return query.addProperty(0); }); } +} +extension MassnahmeQueryProperty2 + on QueryBuilder { QueryBuilder orderStringProperty() { return QueryBuilder.apply(this, (query) { return query.addProperty(1); @@ -13516,16 +13510,16 @@ extension MassnahmeQueryProperty2 return query.addProperty(63); }); } -} -extension MassnahmeQueryProperty3 - on QueryBuilder { - QueryBuilder idProperty() { + QueryBuilder idProperty() { return QueryBuilder.apply(this, (query) { return query.addProperty(0); }); } +} +extension MassnahmeQueryProperty3 + on QueryBuilder { QueryBuilder orderStringProperty() { return QueryBuilder.apply(this, (query) { @@ -13961,6 +13955,12 @@ extension MassnahmeQueryProperty3 return query.addProperty(63); }); } + + QueryBuilder idProperty() { + return QueryBuilder.apply(this, (query) { + return query.addProperty(0); + }); + } } // ************************************************************************** diff --git a/lib/src/packages/ambito_api/base.dart b/lib/src/packages/ambito_api/base.dart index 47dcab6..10f7bf2 100644 --- a/lib/src/packages/ambito_api/base.dart +++ b/lib/src/packages/ambito_api/base.dart @@ -2,9 +2,10 @@ import 'dart:convert'; import 'package:ambito/src/domain/entity/entities.dart'; import 'package:ambito/src/packages/ambito_api/restclient.dart'; -import 'package:ambito/src/packages/ambito_db/base_db.dart'; +import 'package:flutter_dotenv/flutter_dotenv.dart'; -import '../../../main.dart'; +import '../ambito_db/repositories/baumarten_repository.dart'; +import '../ambito_db/repositories/massnahme_repository.dart'; Map tables = { 'massnahmen': 328253, @@ -26,28 +27,29 @@ Map tables = { }; class BaseApi { + Map tables = {}; + + init() { + tables = jsonDecode(dotenv.get('BASEROW_IDS')); + } + Future getContent(String table) async { + init(); int tableId = tables[table] ?? 0; if (tableId > 0) { var response = await RestClient().get('$tableId/?user_field_names=true&size=200'); if (response.statusCode == 200) { - var json = jsonDecode(utf8.decode(response.body.runes.toList())); + var json = _jsonDecoded(response.body); switch (table) { case 'baumarten': for (var baumart in json['results']) { - BaseDB.put(Baumarten.fromJson(baumart)); - isar.write((isar) { - isar.baumartens.put(Baumarten.fromJson(baumart)); - }); + BaumartenRepository().put(Baumarten.fromJson(baumart)); } break; case 'massnahmen': for (var massnahme in json['results']) { - BaseDB.put(Massnahme.fromJson(massnahme)); - isar.write((isar) { - isar.massnahmes.put(Massnahme.fromJson(massnahme)); - }); + MassnahmeRepository().put(Massnahme.fromJson(massnahme)); } break; } @@ -57,4 +59,8 @@ class BaseApi { } return false; } + + dynamic _jsonDecoded(String input) { + return jsonDecode(utf8.decode(input.runes.toList())); + } } diff --git a/lib/src/packages/ambito_api/restclient.dart b/lib/src/packages/ambito_api/restclient.dart index bc5fb5d..7e9f0b8 100644 --- a/lib/src/packages/ambito_api/restclient.dart +++ b/lib/src/packages/ambito_api/restclient.dart @@ -4,6 +4,7 @@ import 'dart:async'; import 'dart:convert'; import 'package:ambito/main.dart'; +import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:http/http.dart' as http; class RestClient { @@ -19,7 +20,7 @@ class RestClient { var headers = { "Content-Type": contentType, "Accept": accept, - "Authorization": "Token $ambitoToken", + "Authorization": "Token ${dotenv.get('BASEROW_TOKEN')}", }; return headers; } diff --git a/lib/src/packages/ambito_db/base_db.dart b/lib/src/packages/ambito_db/base_db.dart index 7451514..d651d80 100644 --- a/lib/src/packages/ambito_db/base_db.dart +++ b/lib/src/packages/ambito_db/base_db.dart @@ -3,28 +3,26 @@ import 'package:isar/isar.dart'; import '../../../main.dart'; -class BaseDB { - static put(var entity) { - switch (entity.runtimeType.toString()) { - case 'Baumarten': - isar.write((isar) { - isar.baumartens.put(entity); - }); - break; - case 'Massnahme': - isar.write((isar) { - isar.massnahmes.put(entity); - }); - break; - } +abstract class BaseDB { + abstract IsarCollection collection; + + put(BaseEntity entity) { + isar.write((isar) { + collection.put(entity); + }); } - static getAll(String type) { - switch (type) { - case 'Maßnahme': - return isar.massnahmes.where().sortByName().findAll(); - case 'Baumart': - return isar.baumartens.where().findAll(); - } + putAll(List entities) { + isar.write((isar) { + collection.putAll(entities); + }); + } + + get(int id) { + return collection.get(id); + } + + List getAll() { + return collection.where().findAll(); } } diff --git a/lib/src/packages/ambito_db/repositories/baumarten_repository.dart b/lib/src/packages/ambito_db/repositories/baumarten_repository.dart new file mode 100644 index 0000000..0f75431 --- /dev/null +++ b/lib/src/packages/ambito_db/repositories/baumarten_repository.dart @@ -0,0 +1,9 @@ +import 'package:ambito/src/domain/entity/entities.dart'; +import 'package:isar/isar.dart'; + +import '../../../../main.dart'; +import '../base_db.dart'; + +class BaumartenRepository extends BaseDB { + IsarCollection collection = isar.baumartens; +} diff --git a/lib/src/packages/ambito_db/repositories/massnahme_repository.dart b/lib/src/packages/ambito_db/repositories/massnahme_repository.dart new file mode 100644 index 0000000..e4200bb --- /dev/null +++ b/lib/src/packages/ambito_db/repositories/massnahme_repository.dart @@ -0,0 +1,9 @@ +import 'package:ambito/src/domain/entity/entities.dart'; +import 'package:ambito/src/packages/ambito_db/base_db.dart'; +import 'package:isar/isar.dart'; + +import '../../../../main.dart'; + +class MassnahmeRepository extends BaseDB { + IsarCollection collection = isar.massnahmes; +} diff --git a/lib/src/pages/actions/actions_page.dart b/lib/src/pages/actions/actions_page.dart index f944174..2f44f7d 100644 --- a/lib/src/pages/actions/actions_page.dart +++ b/lib/src/pages/actions/actions_page.dart @@ -1,7 +1,6 @@ -import 'package:ambito/src/domain/entity/id_value_color/id_value_color.dart'; import 'package:ambito/src/domain/entity/massnahme/massnahme.dart'; import 'package:ambito/src/extensions/extensions.dart'; -import 'package:ambito/src/packages/ambito_db/base_db.dart'; +import 'package:ambito/src/packages/ambito_db/repositories/massnahme_repository.dart'; import 'package:ambito/src/widgets/form/fields/field_dropdown.dart'; import 'package:ambito/src/widgets/form/fields/field_monthsrangepicker.dart'; import 'package:ambito/src/widgets/form/form_widget.dart'; @@ -33,10 +32,12 @@ class ActionsPageState extends State { Set support = {}; String? filterMonths; Set months = {}; + List massnahmen = []; @override void initState() { super.initState(); + massnahmen = MassnahmeRepository().getAll(); effort = []; effect = []; type = {}; @@ -45,61 +46,53 @@ class ActionsPageState extends State { support = {}; } - @override Widget build(BuildContext context) { - List massnahmen = BaseDB.getAll('Maßnahme'); - Set updatedTypes = {}; - Set updatedAreaTypes = {}; - Set updatedSupports = {}; - Set updatedMonths = {}; + // Step 1: Collect all distinct values in each Set in a single loop + final updatedTypes = {}; + final updatedAreaTypes = {}; + final updatedSupports = {}; + final updatedMonths = {}; - for (var massnahme in massnahmen) { - if (massnahme.actionGroup != null) { + for (final massnahme in massnahmen) { + if (massnahme.actionGroup?.value != null) { updatedTypes.add(massnahme.actionGroup!.value!); } - if (massnahme.factsheetAreaType != null) { - for (IdValueColor aType in massnahme.factsheetAreaType!) { - updatedAreaTypes.add(aType.value!); - } - } - if (massnahme.fundingPrograms != null) { - for (IdValueColor aType in massnahme.fundingPrograms!) { - updatedSupports.add(aType.value!); - } - } - if (massnahme.timeFrame != null) { - logger.d(massnahme.timeFrame); - for (IdValueColor tfType in massnahme.timeFrame!) { - updatedMonths.add(tfType.value!); - } - } + + massnahme.factsheetAreaType?.forEach((aType) { + updatedAreaTypes.add(aType.value!); + }); + + massnahme.fundingPrograms?.forEach((aType) { + updatedSupports.add(aType.value!); + }); + + massnahme.timeFrame?.forEach((tfType) { + updatedMonths.add(tfType.value!); + }); } - logger.d(updatedMonths); - + // Step 2: Update state with collected data in a single setState() call setState(() { type.addAll(updatedTypes); areaType.addAll(updatedAreaTypes); support.addAll(updatedSupports); - months.addAll(updatedMonths.toList()); + months.addAll(updatedMonths); }); - List actionCards = massnahmen.map((massnahme) { - bool typeMatches = filterType == null || - (massnahme.actionGroup != null && - massnahme.actionGroup!.value == filterType); - - bool areaTypeMatches = filterAreaType == null || + // Step 3: Generate the list of action cards with matching filters + final actionCards = massnahmen.map((massnahme) { + final typeMatches = + filterType == null || massnahme.actionGroup?.value == filterType; + final areaTypeMatches = filterAreaType == null || (massnahme.factsheetAreaType ?.any((aType) => aType.value == filterAreaType) ?? false); - - bool supportMatches = filterSupport == null || + final supportMatches = filterSupport == null || (massnahme.fundingPrograms ?.any((aType) => aType.value == filterSupport) ?? false); - // Update visibility based on the matches + // Update visibility in a single batch setState() setState(() { visible[massnahme.id] = typeMatches && areaTypeMatches && supportMatches; @@ -108,8 +101,9 @@ class ActionsPageState extends State { return getCard(context, massnahme); }).toList(); + // Step 4: Return UI widget structure return Padding( - padding: const EdgeInsets.only(left: 32, right: 32), + padding: const EdgeInsets.symmetric(horizontal: 32), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -126,19 +120,13 @@ class ActionsPageState extends State { Expanded( child: Row( crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.start, children: [ - SizedBox( - width: 300, - child: getFilter(context), - ), - const SizedBox( - width: 16, - ), + SizedBox(width: 300, child: getFilter(context)), + const SizedBox(width: 16), Expanded( child: SingleChildScrollView( - child: Wrap( - direction: Axis.horizontal, + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, children: actionCards, ), ), @@ -225,101 +213,20 @@ class ActionsPageState extends State { .add(FlutterI18n.translate(context, 'general.lists.months.$i')); } - /*var monthsSorted = months.toList(); - monthsSorted.sort((a, b) => a.toLowerCase().compareTo(b.toLowerCase()));*/ - - /*fields.add( - FieldDropdown( - name: 'months', - label: 'Beginn der Maßnahme', - filterValue: filterMonths, - onClear: () { - setState(() { - filterMonths = null; - }); - }, - onSelected: ((String? value) { - setState(() { - filterMonths = value; - }); - }), - entries: monthsSorted, - ), - );*/ - - logger.d(monthsSorted); fields.add( FieldMonthsRangepicker( name: 'months', label: 'Beginn der Maßnahme', filterValue: filterMonths, onClear: () {}, - onSelected: (String? value) {}, + onSelected: (String? value) { + logger.d(value); + }, entries: monthsSorted, ), ); return FormWidget(type: FormWidgetType.vertical, fields: fields); - - /*return Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - DropdownMenuWidget( - formKey: _keyAreaType, - label: 'Ort der Maßnahme', - controller: _controllerAreaType, - filterValue: filterAreaType, - onClear: () { - setState(() { - filterAreaType = null; - }); - _controllerAreaType.clear(); - }, - onSelected: (String? selection) { - setState(() { - filterAreaType = selection; - }); - }, - entries: areaType.toList(), - ), - DropdownMenuWidget( - formKey: _keyType, - label: 'Art der Maßnahme', - controller: _controllerType, - filterValue: filterType, - onClear: () { - setState(() { - filterType = null; - }); - _controllerType.clear(); - }, - onSelected: (String? selection) { - setState(() { - filterType = selection; - }); - }, - entries: type.toList(), - ), - DropdownMenuWidget( - formKey: _keySupport, - label: 'Förderprogramm', - controller: _controllerSupport, - filterValue: filterSupport, - onClear: () { - setState(() { - filterSupport = null; - }); - _controllerSupport.clear(); - }, - onSelected: (String? selection) { - setState(() { - filterSupport = selection; - }); - }, - entries: support.toList(), - ), - ], - );*/ } Widget getCard(BuildContext context, Massnahme massnahme) { @@ -340,27 +247,41 @@ class ActionsPageState extends State { return Visibility( visible: visible[massnahme.id] ?? false, child: SizedBox( - width: 400, + width: 800, child: Card( color: background, child: Padding( padding: const EdgeInsets.all(32), - child: Column( + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, children: [ - if (image != null) image, + (image != null) + ? image + : const SizedBox( + width: 300, + height: 140, + ), const SizedBox( - height: 8, + width: 16, ), - Text(massnahme.name!, - style: Theme.of(context).textTheme.headlineSmall), - const SizedBox( - height: 8, - ), - ExpandableText( - massnahme.factsheetDefinition ?? '', - maxLines: 3, - expandText: 'mehr', - collapseText: 'weniger', + Expanded( + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(massnahme.name!, + style: Theme.of(context).textTheme.headlineSmall), + const SizedBox( + height: 8, + ), + ExpandableText( + massnahme.factsheetDefinition ?? '', + maxLines: 3, + expandText: 'mehr', + collapseText: 'weniger', + ) + ], + ), ) ], ), diff --git a/lib/src/pages/loading/loading_page.dart b/lib/src/pages/loading/loading_page.dart new file mode 100644 index 0000000..862f927 --- /dev/null +++ b/lib/src/pages/loading/loading_page.dart @@ -0,0 +1,39 @@ +import 'package:ambito/src/pages/start/start_page.dart'; +import 'package:flutter/material.dart'; + +class LoadingPage extends StatelessWidget { + const LoadingPage({super.key}); + + @override + Widget build(BuildContext context) { + return FutureBuilder( + future: Future.delayed( + const Duration(seconds: 1), + () { + Navigator.pushAndRemoveUntil( + context, + MaterialPageRoute( + builder: (context) { + return const StartPage(); + }, + ), + (route) => false, + ); + }, + ), + builder: (context, snapshot) { + if (snapshot.connectionState != ConnectionState.done) { + return Center( + child: Hero( + tag: 'logo', + child: Image.asset('assets/images/logo_trans.png')), + ); + } + return Center( + child: Hero( + tag: 'logo', child: Image.asset('assets/images/logo_trans.png')), + ); + }, + ); + } +} diff --git a/lib/src/pages/start/start_page.dart b/lib/src/pages/start/start_page.dart index 14b1dbd..c7a1605 100644 --- a/lib/src/pages/start/start_page.dart +++ b/lib/src/pages/start/start_page.dart @@ -32,9 +32,13 @@ class StartPageState extends State { const SizedBox( width: 30, ), - Image.asset( - 'images/logo.png', - scale: .8, + Hero( + tag: 'logo', + child: Image.asset( + 'assets/images/logo_trans.png', + width: 50, + height: 50, + ), ), const SizedBox( width: 30, diff --git a/pubspec.lock b/pubspec.lock index b880e8a..eb2354c 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -26,10 +26,10 @@ packages: dependency: transitive description: name: args - sha256: "7cf60b9f0cc88203c5a190b4cd62a99feea42759a7fa695010eb5de1c0b2252a" + sha256: bf9f5caeea8d8fe6721a9c358dd8a5c1947b27f1cfaa18b39c301273594919e6 url: "https://pub.dev" source: hosted - version: "2.5.0" + version: "2.6.0" async: dependency: transitive description: @@ -323,14 +323,22 @@ packages: url: "https://pub.dev" source: hosted version: "0.8.0" + flutter_dotenv: + dependency: "direct main" + description: + name: flutter_dotenv + sha256: b7c7be5cd9f6ef7a78429cabd2774d3c4af50e79cb2b7593e3d5d763ef95c61b + url: "https://pub.dev" + source: hosted + version: "5.2.1" flutter_form_builder: dependency: "direct main" description: name: flutter_form_builder - sha256: b42ad8a9b3e8a629eb0fee8e4feaf7c2862fc40808ebf9f7ddc9da798e890136 + sha256: c278ef69b08957d484f83413f0e77b656a39b7a7bb4eb8a295da3a820ecc6545 url: "https://pub.dev" source: hosted - version: "9.4.1" + version: "9.5.0" flutter_i18n: dependency: "direct main" description: @@ -1011,26 +1019,26 @@ packages: dependency: transitive description: name: syncfusion_flutter_core - sha256: "7130fc3259247946b59fe9b76ee89500c775c3f7e5c1d0826f3105e1dd0bebf6" + sha256: becd190595cba56feac5ec17b805b35df9f006171c131c209f79b5c58fc780eb url: "https://pub.dev" source: hosted - version: "27.1.52" + version: "27.1.53" syncfusion_flutter_datepicker: dependency: "direct main" description: name: syncfusion_flutter_datepicker - sha256: "61efc09e962d7b7cc3c7d33a2e44ec027112403af49590d5cc1025a255cc34fa" + sha256: "5638805bea1c70a6d46dea9d39ef67f0085176e1c15cf57f7036cf67c1568816" url: "https://pub.dev" source: hosted - version: "27.1.52" + version: "27.1.53" syncfusion_localizations: dependency: "direct main" description: name: syncfusion_localizations - sha256: d04b86990411e1f0c896e273bbdb312b1ed52d8009010ddc2af9cbea5ed90e09 + sha256: "742cd5df17f6438628655b7a16d1ee87624166a9dd0362cb818d9f6968ffbc10" url: "https://pub.dev" source: hosted - version: "27.1.52" + version: "27.1.53" synchronized: dependency: transitive description: @@ -1171,10 +1179,10 @@ packages: dependency: transitive description: name: xml2json - sha256: dbe79a85d902674d95c7608c8048355ce2ec5846640da1c0f91389ccdad5b5a8 + sha256: "9523203b99032ce419672804010cce72ea47fc277b3135f77bbb7ac8fa391664" url: "https://pub.dev" source: hosted - version: "6.2.4" + version: "6.2.5" yaml: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index e37b603..fef18cd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -42,6 +42,7 @@ dependencies: flutter_form_builder: ^9.4.1 syncfusion_flutter_datepicker: ^27.1.50 syncfusion_localizations: ^27.1.52 + flutter_dotenv: ^5.2.1 dev_dependencies: @@ -53,6 +54,7 @@ dev_dependencies: flutter: uses-material-design: true assets: + - .env - assets/ - assets/i18n/ - assets/images/ diff --git a/web/index.html b/web/index.html index f6ab613..396594f 100644 --- a/web/index.html +++ b/web/index.html @@ -98,7 +98,7 @@ -
+