paradigm shift

This commit is contained in:
ImBenji
2024-05-03 14:03:51 +01:00
parent 673891923d
commit 1f48f8f4b0
17 changed files with 2440 additions and 547 deletions

View File

@@ -11,6 +11,7 @@ import 'package:bus_infotainment/utils/delegates.dart';
import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:shadcn_ui/shadcn_ui.dart';
class pages_Home extends StatelessWidget {
const pages_Home({super.key});
@@ -60,7 +61,7 @@ class pages_Home extends StatelessWidget {
outlineColor: Colors.white70,
announcements: [
for (NamedAnnouncementQueueEntry announcement in LiveInformation().announcementModule.manualAnnouncements)
_AnnouncementEntry(
AnnouncementEntry(
label: announcement.shortName,
index: LiveInformation().announcementModule.manualAnnouncements.indexOf(announcement),
outlineColor: Colors.white70,
@@ -92,12 +93,12 @@ class pages_Home extends StatelessWidget {
color: Colors.grey.shade900,
),
child: DelegateBuilder<BusRouteVariant>(
child: DelegateBuilder<BusRouteVariant?>(
delegate: LiveInformation().routeVariantDelegate,
builder: (context, routeVariant) {
print("rebuilt stop announcement picker");
return StopAnnouncementPicker(
routeVariant: routeVariant,
routeVariant: routeVariant!,
backgroundColor: Colors.grey.shade900,
outlineColor: Colors.white70,
);
@@ -133,11 +134,6 @@ class pages_Home extends StatelessWidget {
ElevatedButton(
onPressed: () async {
LiveInformation liveInformation = LiveInformation();
final commandModule = liveInformation.commandModule;
// commandModule.executeCommand(
// "announce dest"
// );
liveInformation.announcementModule.queueAnnouncementByRouteVariant(
routeVariant: liveInformation.getRouteVariant()!
@@ -147,75 +143,7 @@ class pages_Home extends StatelessWidget {
child: Text("Announce current destination"),
),
// Container(
//
// margin: EdgeInsets.all(20),
//
// height: 300-45,
//
// child: ListView(
//
// scrollDirection: Axis.vertical,
//
// children: [
//
// ElevatedButton(
// onPressed: () async {
// LiveInformation liveInformation = LiveInformation();
// liveInformation.queueAnnouncement(await liveInformation.getDestinationAnnouncement(liveInformation.getRouteVariant()!, sendToServer: false));
// },
// child: Text("Test announcement"),
// ),
//
// ElevatedButton(
// onPressed: () {
// LiveInformation liveInformation = LiveInformation();
// liveInformation.updateServer();
// },
// child: Text("Update server"),
// ),
//
// SizedBox(
//
// width: 100,
//
// child: TextField(
// onChanged: (String value) {
// LiveInformation liveInformation = LiveInformation();
// // liveInformation.documentID = value;
// },
// ),
// ),
//
// SizedBox(
//
// width: 200,
//
// child: TextField(
// onSubmitted: (String value) {
// LiveInformation liveInformation = LiveInformation();
// liveInformation.queueAnnouncement(AnnouncementQueueEntry(
// displayText: value,
// audioSources: []
// ));
// },
// ),
// ),
//
// ElevatedButton(
// onPressed: () {
// LiveInformation liveInformation = LiveInformation();
// liveInformation.pullServer();
// },
// child: Text("Pull server"),
// ),
//
// ],
//
// ),
//
// ),
],
),
@@ -366,8 +294,9 @@ class AnnouncementPicker extends StatefulWidget {
final Color backgroundColor;
final Color outlineColor;
final List<Widget> announcements;
final String label;
const AnnouncementPicker({super.key, required this.backgroundColor, required this.outlineColor, required this.announcements});
const AnnouncementPicker({super.key, required this.backgroundColor, required this.outlineColor, required this.announcements, this.label = ""});
@override
State<AnnouncementPicker> createState() => _AnnouncementPickerState();
@@ -411,9 +340,9 @@ class _AnnouncementPickerState extends State<AnnouncementPicker> {
color: widget.backgroundColor,
border: Border.all(
color: widget.outlineColor,
width: 2
width: 1
),
borderRadius: BorderRadius.circular(8)
),
@@ -428,118 +357,26 @@ class _AnnouncementPickerState extends State<AnnouncementPicker> {
child: Column(
children: [
Container(
height: 2,
color: widget.outlineColor,
),
if (_currentIndex < announcementWidgets.length)
announcementWidgets[_currentIndex + 0]
else
Container(
height: 50,
decoration: BoxDecoration(
color: widget.backgroundColor,
border: Border.symmetric(
vertical: BorderSide(
color: widget.outlineColor,
width: 2
)
),
),
),
Container(
height: 2,
color: widget.outlineColor,
),
if (_currentIndex + 1 < announcementWidgets.length)
announcementWidgets[_currentIndex + 1]
else
Container(
height: 50,
decoration: BoxDecoration(
color: widget.backgroundColor,
border: Border.symmetric(
vertical: BorderSide(
color: widget.outlineColor,
width: 2
)
),
),
),
Container(
height: 2,
color: widget.outlineColor,
),
if (_currentIndex + 2 < announcementWidgets.length)
announcementWidgets[_currentIndex + 2]
else
Container(
height: 50,
decoration: BoxDecoration(
color: widget.backgroundColor,
border: Border.symmetric(
vertical: BorderSide(
color: widget.outlineColor,
width: 2
)
),
),
),
Container(
height: 2,
color: widget.outlineColor,
),
if (_currentIndex + 3 < announcementWidgets.length)
announcementWidgets[_currentIndex + 3]
else
Container(
height: 50,
decoration: BoxDecoration(
color: widget.backgroundColor,
border: Border.symmetric(
vertical: BorderSide(
color: widget.outlineColor,
width: 2
)
),
),
),
Container(
height: 2,
color: widget.outlineColor,
),
Container(
height: 40,
decoration: BoxDecoration(
color: widget.backgroundColor,
border: Border.symmetric(
vertical: BorderSide(
color: widget.outlineColor,
width: 2
)
border: Border.all(
color: widget.outlineColor,
width: 1
),
borderRadius: BorderRadius.circular(4)
),
alignment: Alignment.centerRight,
child: Row(
mainAxisSize: MainAxisSize.min,
// height: 100,
child: Column(
children: [
Container(
width: 40,
height: 40,
if (_currentIndex < announcementWidgets.length)
announcementWidgets[_currentIndex + 0]
else
Container(
height: 50,
decoration: BoxDecoration(
color: widget.backgroundColor,
border: Border.symmetric(
@@ -549,50 +386,18 @@ class _AnnouncementPickerState extends State<AnnouncementPicker> {
)
),
),
margin: const EdgeInsets.symmetric(
horizontal: 4
),
child: Container(
child: Stack(
children: [
Container(
width: 40,
height: 40,
child: Icon(
Icons.arrow_upward,
color: widget.outlineColor,
),
),
Positioned.fill(
child: ElevatedButton(
onPressed: () {
_currentIndex = wrap(_currentIndex - 4, 0, announcementWidgets.length, increment: 4);
setState(() {});
print(_currentIndex);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.transparent,
shadowColor: Colors.transparent,
surfaceTintColor: Colors.transparent,
foregroundColor: Colors.transparent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(0),
),
),
child: const Text(""),
),
)
],
),
)
),
),
Container(
width: 40,
height: 40,
height: 1,
color: widget.outlineColor,
),
if (_currentIndex + 1 < announcementWidgets.length)
announcementWidgets[_currentIndex + 1]
else
Container(
height: 50,
decoration: BoxDecoration(
color: widget.backgroundColor,
border: Border.symmetric(
@@ -602,55 +407,200 @@ class _AnnouncementPickerState extends State<AnnouncementPicker> {
)
),
),
),
margin: const EdgeInsets.symmetric(
horizontal: 4
),
child: Container(
child: Stack(
children: [
Container(
width: 40,
height: 40,
child: Icon(
Icons.arrow_downward,
color: widget.outlineColor,
),
),
Positioned.fill(
child: ElevatedButton(
onPressed: () {
_currentIndex = wrap(_currentIndex + 4, 0, announcementWidgets.length, increment: 4);
setState(() {});
print(_currentIndex);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.transparent,
shadowColor: Colors.transparent,
surfaceTintColor: Colors.transparent,
foregroundColor: Colors.transparent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(0),
),
),
child: const Text(""),
),
)
],
),
)
Container(
height: 1,
color: widget.outlineColor,
),
]
if (_currentIndex + 2 < announcementWidgets.length)
announcementWidgets[_currentIndex + 2]
else
Container(
height: 50,
decoration: BoxDecoration(
color: widget.backgroundColor,
border: Border.symmetric(
vertical: BorderSide(
color: widget.outlineColor,
width: 2
)
),
),
),
Container(
height: 1,
color: widget.outlineColor,
),
if (_currentIndex + 3 < announcementWidgets.length)
announcementWidgets[_currentIndex + 3]
else
Container(
height: 50,
decoration: BoxDecoration(
color: widget.backgroundColor,
border: Border.symmetric(
vertical: BorderSide(
color: widget.outlineColor,
width: 2
)
),
),
),
Container(
height: 1,
color: widget.outlineColor,
),
Container(
height: 40,
decoration: BoxDecoration(
color: widget.backgroundColor,
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Container(
padding: const EdgeInsets.symmetric(
horizontal: 8,
),
child: Text(
widget.label,
style: ShadTheme.of(context).textTheme.h4.copyWith(
shadows: [
Shadow(
color: Colors.blueAccent.shade700,
blurRadius: 8
)
],
color: Colors.blueAccent.shade700
)
),
),
Expanded(child: Container()),
Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: widget.backgroundColor,
border: Border.symmetric(
vertical: BorderSide(
color: widget.outlineColor,
width: 1
)
),
),
margin: const EdgeInsets.symmetric(
horizontal: 4
),
child: Container(
child: Stack(
children: [
Container(
width: 40,
height: 40,
child: Icon(
Icons.arrow_upward,
color: widget.outlineColor,
),
),
Positioned.fill(
child: ElevatedButton(
onPressed: () {
_currentIndex = wrap(_currentIndex - 4, 0, announcementWidgets.length, increment: 4);
setState(() {});
print(_currentIndex);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.transparent,
shadowColor: Colors.transparent,
surfaceTintColor: Colors.transparent,
foregroundColor: Colors.transparent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(0),
),
),
child: const Text(""),
),
)
],
),
)
),
Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: widget.backgroundColor,
border: Border.symmetric(
vertical: BorderSide(
color: widget.outlineColor,
width: 1
)
),
),
margin: const EdgeInsets.symmetric(
horizontal: 4
),
child: Container(
child: Stack(
children: [
Container(
width: 40,
height: 40,
child: Icon(
Icons.arrow_downward,
color: widget.outlineColor,
),
),
Positioned.fill(
child: ElevatedButton(
onPressed: () {
_currentIndex = wrap(_currentIndex + 4, 0, announcementWidgets.length, increment: 4);
setState(() {});
print(_currentIndex);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.transparent,
shadowColor: Colors.transparent,
surfaceTintColor: Colors.transparent,
foregroundColor: Colors.transparent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(0),
),
),
child: const Text(""),
),
)
],
),
)
),
]
),
),
],
),
),
Container(
height: 2,
color: widget.outlineColor,
),
]
@@ -669,13 +619,14 @@ class StopAnnouncementPicker extends AnnouncementPicker {
required this.routeVariant,
required Color backgroundColor,
required Color outlineColor,
String label = "Stops"
}) : super(
key: key,
backgroundColor: backgroundColor,
outlineColor: outlineColor,
announcements: [
for (BusRouteStop stop in routeVariant.busStops)
_AnnouncementEntry(
AnnouncementEntry(
label: stop.formattedStopName,
onPressed: () {
LiveInformation liveInformation = LiveInformation();
@@ -688,7 +639,8 @@ class StopAnnouncementPicker extends AnnouncementPicker {
outlineColor: outlineColor,
alert: LiveInformation().announcementModule.announcementCache[stop.getAudioFileName()] == null,
)
]
],
label: label
);
}
@@ -709,7 +661,7 @@ int wrap(int i, int j, int length, {int increment = -1}) {
}
}
class _AnnouncementEntry extends StatelessWidget {
class AnnouncementEntry extends StatelessWidget {
final String label;
@@ -719,7 +671,7 @@ class _AnnouncementEntry extends StatelessWidget {
bool alert = false;
_AnnouncementEntry({super.key, required this.label, required this.onPressed, required this.index, required this.outlineColor, this.alert = false});
AnnouncementEntry({super.key, required this.label, required this.onPressed, required this.index, required this.outlineColor, this.alert = false});
@override
Widget build(BuildContext context) {
@@ -730,12 +682,6 @@ class _AnnouncementEntry extends StatelessWidget {
decoration: BoxDecoration(
color: Colors.transparent,
border: Border.symmetric(
vertical: BorderSide(
color: outlineColor,
width: 2
)
),
),
padding: const EdgeInsets.symmetric(
@@ -760,7 +706,7 @@ class _AnnouncementEntry extends StatelessWidget {
label,
style: GoogleFonts.teko(
fontSize: 25,
color: outlineColor,
color: Colors.white,
),
overflow: TextOverflow.ellipsis,
),