From 7c2f5369ab564d6d78fe0bdec2db8ba542dd092a Mon Sep 17 00:00:00 2001 From: Sven Carstensen Date: Mon, 13 May 2024 15:44:50 +0200 Subject: [PATCH] Fehlerkorrekturen, #578 --- lib/content_views/approach_area_page.dart | 64 +++++++++----- lib/model/pictures.dart | 1 - lib/model/rank.dart | 2 + lib/model/rank.g.dart | 101 +++++++++++++++++++--- lib/tools/mqtt_core.dart | 8 +- pubspec.lock | 40 +++++++++ pubspec.yaml | 3 +- 7 files changed, 183 insertions(+), 36 deletions(-) diff --git a/lib/content_views/approach_area_page.dart b/lib/content_views/approach_area_page.dart index 36eee39..10be342 100644 --- a/lib/content_views/approach_area_page.dart +++ b/lib/content_views/approach_area_page.dart @@ -11,6 +11,7 @@ import 'package:stadtbote/tools/constants.dart'; import 'package:stadtbote/tools/message_service.dart'; import 'package:stadtbote/tools/messages/publish_payload_message.dart'; import 'package:stadtbote/tools/messages/ranking_updated.dart'; +import 'package:badges/badges.dart' as badges; import '../tools/util.dart'; @@ -138,29 +139,48 @@ class _ApproachAreaPageState extends State { var vehicle = rank.vehicles[j]; var imageFilename = vehicle.self == true ? "assets/mein_${mapVehicleTypeToImageName(vehicle.type)}" : "assets/${mapVehicleTypeToImageName(vehicle.type)}"; - entries.add(Container( - padding: const EdgeInsets.all(4), - margin: const EdgeInsets.all(2), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10), - color: Colors.white, - border: Border.all( - color: Colors.grey, - width: 0.5, - ), - ), - width: 80, - height: 60, - child: Column( - children: [ - Image.asset(imageFilename, width: 30, height: 30), - const SizedBox(width: 10), - Text( - mapVehicleTypeToText(vehicle.type) + entries.add( + badges.Badge( + showBadge: vehicle.cnt != null && vehicle.cnt! > 0, + position: badges.BadgePosition.topEnd(top: -12, end: 0), + badgeContent: Text( + vehicle.cnt.toString(), + style: const TextStyle( + color: Colors.white, + fontSize: 12, + ), ), - ], - ), - )); + badgeStyle: badges.BadgeStyle( + badgeColor: Colors.red, + padding: const EdgeInsets.all(8), + borderRadius: BorderRadius.circular(4), + borderSide: const BorderSide(color: Colors.white, width: 0), + elevation: 0, + ), + child: Container( + padding: const EdgeInsets.all(4), + margin: const EdgeInsets.all(2), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10), + color: Colors.white, + border: Border.all( + color: Colors.grey, + width: 0.5, + ), + ), + width: 80, + height: 60, + child: Column( + children: [ + Image.asset(imageFilename, width: 30, height: 30), + const SizedBox(width: 10), + Text( + mapVehicleTypeToText(vehicle.type) + ), + ], + ), + )), + ); } columns.add(Align( diff --git a/lib/model/pictures.dart b/lib/model/pictures.dart index 6007d2e..9444da9 100644 --- a/lib/model/pictures.dart +++ b/lib/model/pictures.dart @@ -1,4 +1,3 @@ -import 'package:flutter/foundation.dart'; import 'package:isar/isar.dart'; part 'pictures.g.dart'; diff --git a/lib/model/rank.dart b/lib/model/rank.dart index ea66b4a..373b7e5 100644 --- a/lib/model/rank.dart +++ b/lib/model/rank.dart @@ -44,6 +44,8 @@ class Vehicle { late int type; + late int? cnt; + @JsonKey(name: 'self', defaultValue: false) late bool? self; diff --git a/lib/model/rank.g.dart b/lib/model/rank.g.dart index cbb717d..4797fbf 100644 --- a/lib/model/rank.g.dart +++ b/lib/model/rank.g.dart @@ -949,18 +949,23 @@ const VehicleSchema = Schema( name: r'Vehicle', id: -21624847921258799, properties: { - r'id': PropertySchema( + r'cnt': PropertySchema( id: 0, + name: r'cnt', + type: IsarType.long, + ), + r'id': PropertySchema( + id: 1, name: r'id', type: IsarType.long, ), r'self': PropertySchema( - id: 1, + id: 2, name: r'self', type: IsarType.bool, ), r'type': PropertySchema( - id: 2, + id: 3, name: r'type', type: IsarType.long, ) @@ -986,9 +991,10 @@ void _vehicleSerialize( List offsets, Map> allOffsets, ) { - writer.writeLong(offsets[0], object.id); - writer.writeBool(offsets[1], object.self); - writer.writeLong(offsets[2], object.type); + writer.writeLong(offsets[0], object.cnt); + writer.writeLong(offsets[1], object.id); + writer.writeBool(offsets[2], object.self); + writer.writeLong(offsets[3], object.type); } Vehicle _vehicleDeserialize( @@ -998,9 +1004,10 @@ Vehicle _vehicleDeserialize( Map> allOffsets, ) { final object = Vehicle(); - object.id = reader.readLong(offsets[0]); - object.self = reader.readBoolOrNull(offsets[1]); - object.type = reader.readLong(offsets[2]); + object.cnt = reader.readLongOrNull(offsets[0]); + object.id = reader.readLong(offsets[1]); + object.self = reader.readBoolOrNull(offsets[2]); + object.type = reader.readLong(offsets[3]); return object; } @@ -1012,10 +1019,12 @@ P _vehicleDeserializeProp

( ) { switch (propertyId) { case 0: - return (reader.readLong(offset)) as P; + return (reader.readLongOrNull(offset)) as P; case 1: - return (reader.readBoolOrNull(offset)) as P; + return (reader.readLong(offset)) as P; case 2: + return (reader.readBoolOrNull(offset)) as P; + case 3: return (reader.readLong(offset)) as P; default: throw IsarError('Unknown property with id $propertyId'); @@ -1024,6 +1033,74 @@ P _vehicleDeserializeProp

( extension VehicleQueryFilter on QueryBuilder { + QueryBuilder cntIsNull() { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(const FilterCondition.isNull( + property: r'cnt', + )); + }); + } + + QueryBuilder cntIsNotNull() { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(const FilterCondition.isNotNull( + property: r'cnt', + )); + }); + } + + QueryBuilder cntEqualTo(int? value) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(FilterCondition.equalTo( + property: r'cnt', + value: value, + )); + }); + } + + QueryBuilder cntGreaterThan( + int? value, { + bool include = false, + }) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(FilterCondition.greaterThan( + include: include, + property: r'cnt', + value: value, + )); + }); + } + + QueryBuilder cntLessThan( + int? value, { + bool include = false, + }) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(FilterCondition.lessThan( + include: include, + property: r'cnt', + value: value, + )); + }); + } + + QueryBuilder cntBetween( + int? lower, + int? upper, { + bool includeLower = true, + bool includeUpper = true, + }) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(FilterCondition.between( + property: r'cnt', + lower: lower, + includeLower: includeLower, + upper: upper, + includeUpper: includeUpper, + )); + }); + } + QueryBuilder idEqualTo(int value) { return QueryBuilder.apply(this, (query) { return query.addFilterCondition(FilterCondition.equalTo( @@ -1191,10 +1268,12 @@ Map _$RankToJson(Rank instance) => { Vehicle _$VehicleFromJson(Map json) => Vehicle() ..id = json['id'] as int ..type = json['type'] as int + ..cnt = json['cnt'] as int? ..self = json['self'] as bool? ?? false; Map _$VehicleToJson(Vehicle instance) => { 'id': instance.id, 'type': instance.type, + 'cnt': instance.cnt, 'self': instance.self, }; diff --git a/lib/tools/mqtt_core.dart b/lib/tools/mqtt_core.dart index bf523b3..2961777 100644 --- a/lib/tools/mqtt_core.dart +++ b/lib/tools/mqtt_core.dart @@ -52,6 +52,8 @@ import 'util.dart'; enum ConnectionStateEnum { notConnected, connected } +//const AndroidInitializationSettings initializationSettingsAndroid = AndroidInitializationSettings('app_icon'); + class MqttCore { late ConnectionStateEnum connectionState = ConnectionStateEnum.notConnected; @@ -356,6 +358,8 @@ class MqttCore { await Util.playMp3('asbeep.mp3'); + + MessageService().publish(Constants.messageTopicMessageReceived, arguments: MessageReceivedMessage(message: newMessage)); } @@ -442,7 +446,9 @@ class MqttCore { var jsonMap = handshakeMessage.toJson(); var json = Uri.encodeFull(jsonEncode(jsonMap)); - var uri = "https://test-app-server.assecutor.org/bootstrap?json=$json"; + //var uri = "https://test-app-server.assecutor.org/bootstrap?json=$json"; + var uri = "https://bootstrap.assecutor.de/bootstrap?json=$json"; + Util.logInfo("Bootstrap request: $uri"); var response = await http.get(Uri.parse(uri)); diff --git a/pubspec.lock b/pubspec.lock index becbe0a..1c0c0a2 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -305,6 +305,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.2.0" + dbus: + dependency: transitive + description: + name: dbus + sha256: "365c771ac3b0e58845f39ec6deebc76e3276aa9922b0cc60840712094d9047ac" + url: "https://pub.dev" + source: hosted + version: "0.7.10" device_info_plus: dependency: "direct main" description: @@ -502,6 +510,30 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.3" + flutter_local_notifications: + dependency: "direct main" + description: + name: flutter_local_notifications + sha256: "40e6fbd2da7dcc7ed78432c5cdab1559674b4af035fddbfb2f9a8f9c2112fcef" + url: "https://pub.dev" + source: hosted + version: "17.1.2" + flutter_local_notifications_linux: + dependency: transitive + description: + name: flutter_local_notifications_linux + sha256: "33f741ef47b5f63cc7f78fe75eeeac7e19f171ff3c3df054d84c1e38bedb6a03" + url: "https://pub.dev" + source: hosted + version: "4.0.0+1" + flutter_local_notifications_platform_interface: + dependency: transitive + description: + name: flutter_local_notifications_platform_interface + sha256: "340abf67df238f7f0ef58f4a26d2a83e1ab74c77ab03cd2b2d5018ac64db30b7" + url: "https://pub.dev" + source: hosted + version: "7.1.0" flutter_map: dependency: "direct main" description: @@ -1357,6 +1389,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" + timezone: + dependency: transitive + description: + name: timezone + sha256: a6ccda4a69a442098b602c44e61a1e2b4bf6f5516e875bbf0f427d5df14745d5 + url: "https://pub.dev" + source: hosted + version: "0.9.3" timing: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 15277cd..ab90401 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 303.0.0+303 +version: 306.0.0+306 environment: sdk: '>=2.19.6 <3.0.0' @@ -71,6 +71,7 @@ dependencies: package_info_plus: ^5.0.1 device_info_plus: ^9.1.2 is_lock_screen: ^2.0.0 + flutter_local_notifications: ^17.1.2 dev_dependencies: flutter_test: