208 lines
6.8 KiB
Dart
208 lines
6.8 KiB
Dart
import 'package:dart_mq/dart_mq.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:stadtbote/content_views/utils/content_view_widget.dart';
|
|
import 'package:stadtbote/messages/pop_content_view_message.dart';
|
|
import 'package:stadtbote/network_messages/set_desired_zip_message.dart';
|
|
import 'package:stadtbote/tools/messages/publish_payload_message.dart';
|
|
|
|
import '../tools/constants.dart';
|
|
import '../tools/util.dart';
|
|
|
|
class SetDesiredZipPage extends ContentViewWidget {
|
|
const SetDesiredZipPage({super.key});
|
|
|
|
@override
|
|
State<SetDesiredZipPage> createState() => _SetDesiredZipPageState();
|
|
|
|
@override
|
|
Future<Widget> getHeaderWidget(BuildContext context) async {
|
|
await Future.delayed(const Duration(microseconds: 0));
|
|
|
|
return _HeaderWidget();
|
|
}
|
|
}
|
|
|
|
class _SetDesiredZipPageState extends State<SetDesiredZipPage>
|
|
with ProducerMixin {
|
|
TextEditingController textEditController = TextEditingController();
|
|
|
|
@override
|
|
void initState() {
|
|
var savedDesiredZip =
|
|
Util.preferencesGetString(Constants.prefsDesiredZip, null);
|
|
if (savedDesiredZip != null) {
|
|
textEditController.text = savedDesiredZip;
|
|
}
|
|
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: Column(children: [
|
|
const Text("Bitte geben Sie Ihr Wunschziel für heute ein"),
|
|
const SizedBox(height: 20),
|
|
Row(
|
|
mainAxisAlignment:
|
|
MainAxisAlignment.center, // Zentriert das Textfeld horizontal
|
|
children: [
|
|
SizedBox(
|
|
width: 120, // Festlegen der Breite des Textfelds
|
|
child: Util.getDefaultTextField('PLZ',
|
|
textInputType: TextInputType.number,
|
|
formatter: [
|
|
// Erlaubt nur Ziffern
|
|
FilteringTextInputFormatter.digitsOnly,
|
|
// Begrenzt die maximale Eingabelänge auf 5 Zeichen
|
|
LengthLimitingTextInputFormatter(5),
|
|
],
|
|
controller: textEditController,
|
|
maxLength: 5,
|
|
autofocus: true),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 20),
|
|
getDefaultButton(
|
|
'Übernehmen',
|
|
() => {
|
|
if (textEditController.text.isEmpty ||
|
|
textEditController.text.length == 5)
|
|
{
|
|
Util.preferencesSaveString(
|
|
Constants.prefsDesiredZip, textEditController.text),
|
|
_sendDesiredZipMessage(textEditController.text),
|
|
sendMessage(
|
|
routingKey: Constants.messageTopicPopContentView,
|
|
payload: PopContentViewMessage(count: 1),
|
|
)
|
|
}
|
|
else
|
|
{
|
|
showAlertDialog("Fehler",
|
|
"Das Feld muss leer sein, oder es müssen fünf Zahlen eingegeben werden")
|
|
}
|
|
})
|
|
]),
|
|
);
|
|
}
|
|
|
|
_sendDesiredZipMessage(String desiredZip) {
|
|
var desiredZipMessage = SetDesiredZipMessage();
|
|
desiredZipMessage.desiredZip = desiredZip;
|
|
|
|
sendMessage(
|
|
routingKey: Constants.messageTopicPublishPayload,
|
|
payload: PublishPayloadMessage(
|
|
topic: "set_desired_zip",
|
|
message: desiredZipMessage.toJson(),
|
|
acknowledgeRequired: true),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _HeaderWidget extends StatefulWidget {
|
|
@override
|
|
State<_HeaderWidget> createState() => _HeaderWidgetState();
|
|
}
|
|
|
|
class _HeaderWidgetState extends State<_HeaderWidget> with ProducerMixin {
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
var cellWidth = (MediaQuery.of(context).size.width - 60 - 60 - 25) / 2;
|
|
|
|
return Padding(
|
|
padding: const EdgeInsets.all(8),
|
|
child: Stack(
|
|
alignment: Alignment.center,
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Visibility(
|
|
visible: true,
|
|
child: Container(
|
|
width: 60,
|
|
height: 60,
|
|
decoration: const BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
color: Colors.white,
|
|
),
|
|
child: FittedBox(
|
|
child: GestureDetector(
|
|
onTap: () async {
|
|
sendMessage(
|
|
routingKey: Constants.messageTopicPopContentView,
|
|
payload: PopContentViewMessage(count: 1),
|
|
);
|
|
},
|
|
child: const CircleAvatar(
|
|
radius: 10,
|
|
backgroundColor: Constants.colorPrimary,
|
|
child: Padding(
|
|
padding: EdgeInsets.all(1.0),
|
|
child: Icon(Icons.arrow_back,
|
|
size: 20.0, color: Colors.white)),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
Visibility(
|
|
visible: false,
|
|
child: Container(
|
|
width: 60,
|
|
height: 60,
|
|
decoration: const BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
color: Colors.red,
|
|
),
|
|
child: FittedBox(
|
|
child: GestureDetector(
|
|
onTap: () async {
|
|
sendMessage(
|
|
routingKey: Constants.messageTopicPopContentView,
|
|
payload: PopContentViewMessage(count: 1),
|
|
);
|
|
},
|
|
child: const CircleAvatar(
|
|
backgroundColor: Constants.colorPrimary,
|
|
radius: 10,
|
|
child: Padding(
|
|
padding: EdgeInsets.all(1.0),
|
|
child: Icon(Icons.info_outline,
|
|
size: 20.0, color: Colors.white))),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
SizedBox(
|
|
height: 100,
|
|
width: cellWidth * 2,
|
|
child: const Center(
|
|
child: Text(
|
|
textAlign: TextAlign.center,
|
|
"Wunschziel für heute",
|
|
style: TextStyle(
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 18,
|
|
color: Colors.white),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|