This commit is contained in:
1 parent
f89ca690c8
commit
96544ca924
22 files changed
+1026
-381
No files matched your search
+23
-133
@@ -1,11 +1,9 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:isar/isar.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:shared_map/shared_map.dart';
|
||||
import 'package:stadtbote/messages/pop_content_view_message.dart';
|
||||
import 'package:stadtbote/model/enqueued_message.dart';
|
||||
@@ -22,6 +20,8 @@ import 'package:stadtbote/tools/connection_status.dart';
|
||||
import 'package:stadtbote/tools/message_service.dart';
|
||||
import 'package:stadtbote/tools/messages/job_deleted_message.dart';
|
||||
import 'package:stadtbote/tools/messages/job_received_message.dart';
|
||||
import 'package:stadtbote/tools/messages/refresh_badges_message.dart';
|
||||
import 'package:stadtbote/tools/messages/remove_job_message.dart';
|
||||
import 'package:stadtbote/tools/mqtt_core.dart';
|
||||
|
||||
import 'content_views/main_page.dart';
|
||||
@@ -48,8 +48,6 @@ Future<void> main() async {
|
||||
PictureSchema
|
||||
], directory: dir.path, name: "database_v1");
|
||||
|
||||
var status = await Permission.storage.request();
|
||||
|
||||
await _clearLog();
|
||||
|
||||
runApp(const MyApp());
|
||||
@@ -169,15 +167,6 @@ class _MainState extends State<Main> with SingleTickerProviderStateMixin {
|
||||
|
||||
late Widget _currentTitleWidget;
|
||||
|
||||
late Widget _leftIconButton;
|
||||
late Widget _rightIconButton;
|
||||
|
||||
late bool _leftButtonVisible = false;
|
||||
late bool _rightButtonVisible = false;
|
||||
|
||||
late Function _rightButtonOnPressed;
|
||||
late Function _leftButtonOnPressed;
|
||||
|
||||
bool _initCompleted = false;
|
||||
|
||||
final ValueNotifier<bool> _connectionLostValueNotifier = ValueNotifier<bool>(true);
|
||||
@@ -207,22 +196,9 @@ class _MainState extends State<Main> with SingleTickerProviderStateMixin {
|
||||
|
||||
_startCheckForNewState0JobsJobsTimer();
|
||||
|
||||
_currentContent = MainPage();
|
||||
_currentContent = const MainPage();
|
||||
|
||||
var headerInfo = await _currentContent.getHeaderInfo(MyApp.appNavigatorKey.currentContext!);
|
||||
_currentTitleWidget = headerInfo.titleWidget;
|
||||
|
||||
_leftButtonVisible = false;
|
||||
_leftIconButton = const Icon(Icons.arrow_back, size: 20.0, color: Colors.white);
|
||||
_leftButtonOnPressed = () {
|
||||
_popContentView(1);
|
||||
};
|
||||
|
||||
_rightButtonVisible = headerInfo.rightButtonVisible;
|
||||
_rightButtonOnPressed = headerInfo.rightButtonOnPressed;
|
||||
if (headerInfo.rightButtonEnabled) {
|
||||
_rightIconButton = await headerInfo.rightButtonImage as Widget;
|
||||
}
|
||||
_currentTitleWidget = await _currentContent.getHeaderWidget(MyApp.appNavigatorKey.currentContext!);
|
||||
|
||||
_initCompleted = true;
|
||||
|
||||
@@ -256,66 +232,11 @@ class _MainState extends State<Main> with SingleTickerProviderStateMixin {
|
||||
child: SizedBox(
|
||||
height: 100,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8),
|
||||
padding: const EdgeInsets.all(0),
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Visibility(
|
||||
visible: _leftButtonVisible,
|
||||
child: Container(
|
||||
width: 60,
|
||||
height: 60,
|
||||
decoration: const BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: Colors.white,
|
||||
),
|
||||
child: FittedBox(
|
||||
child: GestureDetector(
|
||||
onTap: () async {
|
||||
_leftButtonOnPressed();
|
||||
},
|
||||
child: CircleAvatar(
|
||||
radius: 15,
|
||||
backgroundColor: Constants.colorPrimary,
|
||||
child: Padding(padding: const EdgeInsets.all(1.0), child: _leftIconButton),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Visibility(
|
||||
visible: _rightButtonVisible,
|
||||
child: Container(
|
||||
width: 60,
|
||||
height: 60,
|
||||
decoration: const BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: Colors.red,
|
||||
),
|
||||
child: FittedBox(
|
||||
child: GestureDetector(
|
||||
onTap: () async {
|
||||
_rightButtonOnPressed();
|
||||
},
|
||||
child: CircleAvatar(
|
||||
backgroundColor: Constants.colorPrimary,
|
||||
radius: 15,
|
||||
child: Padding(padding: const EdgeInsets.all(1.0), child: _rightIconButton),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(
|
||||
height: 100,
|
||||
width: 300,
|
||||
child: Center(heightFactor: 1, child: _currentTitleWidget),
|
||||
),
|
||||
Center(heightFactor: 1, child: _currentTitleWidget),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -361,29 +282,34 @@ class _MainState extends State<Main> with SingleTickerProviderStateMixin {
|
||||
}
|
||||
|
||||
void _initMessages() {
|
||||
MessageService().unsubscribe(Constants.messageTopicPushContentView, this);
|
||||
MessageService().unsubscribe(Constants.messageTopicPopContentView, this);
|
||||
MessageService().unsubscribe(Constants.messageTopicReplaceContentView, this);
|
||||
MessageService().unsubscribe(Constants.messageTopicHideRightButton, this);
|
||||
MessageService().unsubscribe(Constants.messageTopicConnectionStatusChanged, this);
|
||||
MessageService().unsubscribe(Constants.messageTopicJobReceived, this);
|
||||
MessageService().unsubscribeAll(this);
|
||||
|
||||
MessageService().subscribe<ContentViewWidget>(Constants.messageTopicPushContentView, this, (ContentViewWidget widget) {
|
||||
_pushContentView(widget);
|
||||
});
|
||||
|
||||
MessageService().subscribe<PopContentViewMessage>(Constants.messageTopicPopContentView, this, (PopContentViewMessage message) {
|
||||
_popContentView(message.count);
|
||||
});
|
||||
|
||||
MessageService().subscribe<ContentViewWidget>(Constants.messageTopicReplaceContentView, this, (ContentViewWidget widget) {
|
||||
_replaceContentView(widget);
|
||||
});
|
||||
MessageService().subscribe<bool>(Constants.messageTopicHideRightButton, this, (hideButton) {
|
||||
_hideRightButton(hideButton);
|
||||
});
|
||||
|
||||
MessageService().subscribe<ConnectionStatus>(Constants.messageTopicConnectionStatusChanged, this, (ConnectionStatus connectionStatus) {
|
||||
_connectionStatusChanged(connectionStatus);
|
||||
});
|
||||
|
||||
MessageService().subscribe<RemoveJobMessage>(Constants.messageTopicRemoveJob, this, (RemoveJobMessage job) async {
|
||||
await MyApp.isarInstance.writeTxn(() async {
|
||||
await MyApp.isarInstance.jobs.where().filter().idEqualTo(job.id).deleteAll();
|
||||
});
|
||||
|
||||
await MessageService().publish<JobDeletedMessage>(Constants.messageTopicJobDeleted, arguments: JobDeletedMessage(id: job.id));
|
||||
|
||||
await MessageService().publish<RefreshBadgesMessage>(Constants.messageTopicUpdateBadges, arguments: RefreshBadgesMessage());
|
||||
});
|
||||
|
||||
MessageService().subscribe<JobReceivedMessage>(Constants.messageTopicJobReceived, this, (JobReceivedMessage jobReceivedMessage) async {
|
||||
if (jobReceivedMessage.job.state == 0) {
|
||||
await _jobMap!.put(jobReceivedMessage.job.id, jobReceivedMessage.job);
|
||||
@@ -403,16 +329,7 @@ class _MainState extends State<Main> with SingleTickerProviderStateMixin {
|
||||
_currentContent = widget;
|
||||
});
|
||||
|
||||
var headerInfo = await _currentContent.getHeaderInfo(context);
|
||||
_currentTitleWidget = headerInfo.titleWidget;
|
||||
_rightButtonVisible = headerInfo.rightButtonVisible;
|
||||
_rightButtonOnPressed = headerInfo.rightButtonOnPressed;
|
||||
|
||||
if (headerInfo.rightButtonEnabled) {
|
||||
_rightIconButton = await headerInfo.rightButtonImage as Widget;
|
||||
}
|
||||
|
||||
_leftButtonVisible = false;
|
||||
_currentTitleWidget = await _currentContent.getHeaderWidget(context);
|
||||
|
||||
setState(() {});
|
||||
});
|
||||
@@ -428,18 +345,7 @@ class _MainState extends State<Main> with SingleTickerProviderStateMixin {
|
||||
|
||||
_currentContent = previousContentView;
|
||||
|
||||
var headerInfo = await _currentContent.getHeaderInfo(context);
|
||||
_currentTitleWidget = headerInfo.titleWidget;
|
||||
_rightButtonVisible = headerInfo.rightButtonVisible;
|
||||
_rightButtonOnPressed = headerInfo.rightButtonOnPressed;
|
||||
|
||||
if (headerInfo.rightButtonEnabled) {
|
||||
_rightIconButton = await headerInfo.rightButtonImage as Widget;
|
||||
}
|
||||
|
||||
if (contentStack.isEmpty) {
|
||||
_leftButtonVisible = false;
|
||||
}
|
||||
_currentTitleWidget = await _currentContent.getHeaderWidget(context);
|
||||
|
||||
setState(() {});
|
||||
});
|
||||
@@ -451,28 +357,12 @@ class _MainState extends State<Main> with SingleTickerProviderStateMixin {
|
||||
|
||||
_currentContent = widget;
|
||||
|
||||
var headerInfo = await _currentContent.getHeaderInfo(context);
|
||||
|
||||
_currentTitleWidget = headerInfo.titleWidget;
|
||||
_rightButtonVisible = headerInfo.rightButtonVisible;
|
||||
_rightButtonOnPressed = headerInfo.rightButtonOnPressed;
|
||||
|
||||
if (headerInfo.rightButtonEnabled) {
|
||||
_rightIconButton = await headerInfo.rightButtonImage as Widget;
|
||||
}
|
||||
|
||||
_leftButtonVisible = true;
|
||||
_currentTitleWidget = await _currentContent.getHeaderWidget(context);
|
||||
|
||||
setState(() {});
|
||||
});
|
||||
}
|
||||
|
||||
void _hideRightButton(bool hideButton) {
|
||||
setState(() {
|
||||
_rightButtonVisible = !hideButton;
|
||||
});
|
||||
}
|
||||
|
||||
void _connectionStatusChanged(ConnectionStatus newConnectionStatus) {
|
||||
var currentConnectionStatus = newConnectionStatus.status;
|
||||
|
||||
|
||||
Reference in new issue
Block a user