Erweiterungen
This commit is contained in:
1 parent
fcda77177a
commit
00d320ec8f
4 files changed
+90
-26
No files matched your search
@@ -22,13 +22,13 @@ import '../tools/util.dart';
|
|||||||
|
|
||||||
class MainPage extends ContentViewWidget {
|
class MainPage extends ContentViewWidget {
|
||||||
final ValueNotifier<String> _zipValueNotifier = ValueNotifier("----");
|
final ValueNotifier<String> _zipValueNotifier = ValueNotifier("----");
|
||||||
final ValueNotifier<String> _sidValueNotifier = ValueNotifier("----");
|
final ValueNotifier<String> sidValueNotifier = ValueNotifier("----");
|
||||||
|
|
||||||
MainPage({super.key}) {
|
MainPage({super.key}) {
|
||||||
Status? status = MyApp.isarInstance.status.where().findFirstSync();
|
Status? status = MyApp.isarInstance.status.where().findFirstSync();
|
||||||
if (status != null) {
|
if (status != null) {
|
||||||
_zipValueNotifier.value = status.locZip;
|
_zipValueNotifier.value = status.locZip;
|
||||||
_sidValueNotifier.value = status.sid;
|
sidValueNotifier.value = status.sid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ class MainPage extends ContentViewWidget {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 5),
|
const SizedBox(height: 5),
|
||||||
ValueListenableBuilder<String>(
|
ValueListenableBuilder<String>(
|
||||||
valueListenable: _sidValueNotifier,
|
valueListenable: sidValueNotifier,
|
||||||
builder: (context, value, child) {
|
builder: (context, value, child) {
|
||||||
return Text(
|
return Text(
|
||||||
value,
|
value,
|
||||||
@@ -244,7 +244,7 @@ class _MainPageState extends State<MainPage> {
|
|||||||
|
|
||||||
_initMessages() {
|
_initMessages() {
|
||||||
BroadcastReceiver().subscribe<StatusInfoUpdate>(Constants.messageTopicStatusInfoUpdate, (statusInfoUpdateMessage) {
|
BroadcastReceiver().subscribe<StatusInfoUpdate>(Constants.messageTopicStatusInfoUpdate, (statusInfoUpdateMessage) {
|
||||||
widget._sidValueNotifier.value = statusInfoUpdateMessage.status.sid;
|
widget.sidValueNotifier.value = statusInfoUpdateMessage.status.sid;
|
||||||
});
|
});
|
||||||
|
|
||||||
BroadcastReceiver().subscribe<JobReceivedMessage>(Constants.messageTopicJobReceived, (JobReceivedMessage jobReceivedMessage) {
|
BroadcastReceiver().subscribe<JobReceivedMessage>(Constants.messageTopicJobReceived, (JobReceivedMessage jobReceivedMessage) {
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_chat_ui/flutter_chat_ui.dart';
|
import 'package:flutter_chat_ui/flutter_chat_ui.dart';
|
||||||
import 'package:flutter_chat_types/flutter_chat_types.dart' as types;
|
import 'package:flutter_chat_types/flutter_chat_types.dart' as types;
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:isar/isar.dart';
|
||||||
import 'package:stadtbote/content_views/utils/content_view_widget.dart';
|
import 'package:stadtbote/content_views/utils/content_view_widget.dart';
|
||||||
import 'package:stadtbote/content_views/utils/header_info.dart';
|
import 'package:stadtbote/content_views/utils/header_info.dart';
|
||||||
|
import 'package:stadtbote/main.dart';
|
||||||
|
import 'package:stadtbote/model/message.dart' as sbmessage;
|
||||||
|
import 'package:stadtbote/model/status.dart';
|
||||||
import 'package:stadtbote/popups/infos_popup.dart';
|
import 'package:stadtbote/popups/infos_popup.dart';
|
||||||
|
import 'package:uuid/uuid.dart';
|
||||||
|
|
||||||
import '../tools/util.dart';
|
import '../tools/util.dart';
|
||||||
|
|
||||||
@@ -17,26 +22,13 @@ class MessagesPage extends ContentViewWidget {
|
|||||||
@override
|
@override
|
||||||
Future<HeaderInfo> getHeaderInfo(BuildContext context) async {
|
Future<HeaderInfo> getHeaderInfo(BuildContext context) async {
|
||||||
return HeaderInfo(
|
return HeaderInfo(
|
||||||
titleWidget: Container(
|
titleWidget: const Text(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 3),
|
'Nachrichten',
|
||||||
child: const Column(children: [
|
|
||||||
Text(
|
|
||||||
'Zeile 1',
|
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
fontSize: 18.0,
|
fontSize: 24.0,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: 5),
|
|
||||||
Text(
|
|
||||||
'Zeile 2',
|
|
||||||
style: TextStyle(
|
|
||||||
color: Colors.white,
|
|
||||||
fontSize: 18.0,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]),
|
|
||||||
),
|
|
||||||
rightButtonEnabled: true,
|
rightButtonEnabled: true,
|
||||||
rightButtonVisible: true,
|
rightButtonVisible: true,
|
||||||
rightButtonImage: Util.fetchFutureIcon(const Icon(Icons.info_outline, size: 20.0, color: Colors.white)),
|
rightButtonImage: Util.fetchFutureIcon(const Icon(Icons.info_outline, size: 20.0, color: Colors.white)),
|
||||||
@@ -47,27 +39,97 @@ class MessagesPage extends ContentViewWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _MessagesPageState extends State<MessagesPage> {
|
class _MessagesPageState extends State<MessagesPage> {
|
||||||
|
bool _initCompleted = false;
|
||||||
|
|
||||||
|
late String _sid;
|
||||||
|
|
||||||
late final List<types.Message> _messages = [];
|
late final List<types.Message> _messages = [];
|
||||||
|
|
||||||
final _user = const types.User(
|
final _user = const types.User(
|
||||||
id: '82091008-a484-4a89-ae75-a22bf8d6f3ac',
|
id: '82091008-a484-4a89-ae75-a22bf8d6f3ac',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
final _central = const types.User(
|
||||||
|
id: '82091008-a484-4a89-ae75-a22bf8d6f3ad',
|
||||||
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
Future.delayed(const Duration(seconds: 0), () async {
|
||||||
|
var status = await MyApp.isarInstance.status.where().findFirst();
|
||||||
|
_sid = status != null ? status.sid : 'Unbekannt';
|
||||||
|
|
||||||
|
await _fetchMessages();
|
||||||
|
|
||||||
|
_initCompleted = true;
|
||||||
|
|
||||||
|
setState(() {});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
if (!_initCompleted) {
|
||||||
|
return Util.getWaitWidget(context);
|
||||||
|
}
|
||||||
|
|
||||||
return Stack(
|
return Stack(
|
||||||
children: [
|
children: [
|
||||||
Chat(
|
Chat(
|
||||||
messages: _messages,
|
messages: _messages,
|
||||||
onSendPressed: _handleSendPressed,
|
onSendPressed: _handleSendPressed,
|
||||||
showUserAvatars: true,
|
showUserAvatars: false,
|
||||||
showUserNames: true,
|
showUserNames: false,
|
||||||
user: _user,
|
user: _user,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleSendPressed(types.PartialText p1) {
|
void _handleSendPressed(types.PartialText text) async {
|
||||||
|
var message = sbmessage.Message();
|
||||||
|
message.text = [text.text];
|
||||||
|
message.from = _sid;
|
||||||
|
message.subj = '';
|
||||||
|
message.time = DateFormat("yyyy.mm.dd HH:mm").format(DateTime.now());
|
||||||
|
message.id = 0;
|
||||||
|
|
||||||
|
await MyApp.isarInstance.writeTxn(() async {
|
||||||
|
await MyApp.isarInstance.messages.put(message);
|
||||||
|
});
|
||||||
|
|
||||||
|
_messages.insert(0, types.TextMessage(
|
||||||
|
author: _user,
|
||||||
|
createdAt: DateTime.now().millisecondsSinceEpoch,
|
||||||
|
id: const Uuid().v4().toString(),
|
||||||
|
text: text.text,
|
||||||
|
));
|
||||||
|
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _fetchMessages() async {
|
||||||
|
_messages.clear();
|
||||||
|
|
||||||
|
var messages = await MyApp.isarInstance.messages.where().findAll();
|
||||||
|
for (var message in messages) {
|
||||||
|
var text = '';
|
||||||
|
for (var textLine in message.text) {
|
||||||
|
text += '$textLine\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
_messages.add(types.TextMessage(
|
||||||
|
author: message.from == _sid ? _user : _central,
|
||||||
|
createdAt: DateTime.now().millisecondsSinceEpoch,
|
||||||
|
id: Uuid().v4().toString(),
|
||||||
|
text: text,
|
||||||
|
));
|
||||||
|
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
|
||||||
|
Util.logInfo('');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
-1
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_broadcast_receiver/flutter_broadcast_receiver.dart';
|
import 'package:flutter_broadcast_receiver/flutter_broadcast_receiver.dart';
|
||||||
import 'package:isar/isar.dart';
|
import 'package:isar/isar.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
import 'package:stadtbote/model/message.dart';
|
||||||
import 'package:stadtbote/model/task_info.dart';
|
import 'package:stadtbote/model/task_info.dart';
|
||||||
import 'package:stadtbote/tools/colored_safe_area.dart';
|
import 'package:stadtbote/tools/colored_safe_area.dart';
|
||||||
import 'package:stadtbote/model/status.dart';
|
import 'package:stadtbote/model/status.dart';
|
||||||
@@ -24,7 +25,8 @@ Future<void> main() async {
|
|||||||
MyApp.isarInstance = await Isar.open([
|
MyApp.isarInstance = await Isar.open([
|
||||||
StatusSchema,
|
StatusSchema,
|
||||||
JobSchema,
|
JobSchema,
|
||||||
TaskInfoSchema
|
TaskInfoSchema,
|
||||||
|
MessageSchema,
|
||||||
], directory: dir.path);
|
], directory: dir.path);
|
||||||
|
|
||||||
runZonedGuarded(() {
|
runZonedGuarded(() {
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ class MqttCore {
|
|||||||
await MyApp.isarInstance.messages.put(newMessage);
|
await MyApp.isarInstance.messages.put(newMessage);
|
||||||
});
|
});
|
||||||
|
|
||||||
BroadcastReceiver().publish<MessageReceivedMessage>(Constants.messageTopicJobReceived, arguments: MessageReceivedMessage(message: newMessage));
|
BroadcastReceiver().publish<MessageReceivedMessage>(Constants.messageTopicMessageReceived, arguments: MessageReceivedMessage(message: newMessage));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _startReconnectTimer() {
|
void _startReconnectTimer() {
|
||||||
|
|||||||
Reference in new issue
Block a user