More
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
import 'package:bus_infotainment/pages/components/ibus_display.dart';
|
||||
import 'package:bus_infotainment/singletons/live_information.dart';
|
||||
import 'package:bus_infotainment/tfl_datasets.dart';
|
||||
import 'package:bus_infotainment/utils/delegates.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
|
||||
@@ -64,9 +66,12 @@ class pages_Home extends StatelessWidget {
|
||||
]
|
||||
),
|
||||
|
||||
child: _QuickAnnouncements_IBUS(
|
||||
child: ManualAnnouncementPicker(
|
||||
backgroundColor: Colors.grey.shade900,
|
||||
outlineColor: Colors.white70,
|
||||
announcements: [
|
||||
...LiveInformation().manualAnnouncements
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -77,6 +82,38 @@ class pages_Home extends StatelessWidget {
|
||||
color: Colors.white70,
|
||||
),
|
||||
|
||||
Container(
|
||||
|
||||
margin: EdgeInsets.all(20),
|
||||
|
||||
child: Container(
|
||||
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade900,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.3),
|
||||
blurRadius: 2,
|
||||
spreadRadius: 4
|
||||
)
|
||||
]
|
||||
),
|
||||
|
||||
child: DelegateBuilder<BusRouteVariant>(
|
||||
delegate: LiveInformation().routeVariantDelegate,
|
||||
builder: (context, routeVariant) {
|
||||
print("rebuilt stop announcement picker");
|
||||
return StopAnnouncementPicker(
|
||||
routeVariant: routeVariant,
|
||||
backgroundColor: Colors.grey.shade900,
|
||||
outlineColor: Colors.white70,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
),
|
||||
|
||||
Container(
|
||||
|
||||
margin: EdgeInsets.all(20),
|
||||
@@ -153,38 +190,46 @@ class pages_Home extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class _QuickAnnouncements_IBUS extends StatefulWidget {
|
||||
class ManualAnnouncementPicker extends StatefulWidget {
|
||||
|
||||
final Color backgroundColor;
|
||||
final Color outlineColor;
|
||||
final List<InformationAnnouncementEntry> announcements;
|
||||
|
||||
_QuickAnnouncements_IBUS({super.key, required this.backgroundColor, required this.outlineColor});
|
||||
const ManualAnnouncementPicker({super.key, required this.backgroundColor, required this.outlineColor, required this.announcements});
|
||||
|
||||
@override
|
||||
State<_QuickAnnouncements_IBUS> createState() => _QuickAnnouncementsState_IBUS();
|
||||
State<ManualAnnouncementPicker> createState() => _ManualAnnouncementPickerState();
|
||||
}
|
||||
|
||||
class _QuickAnnouncementsState_IBUS extends State<_QuickAnnouncements_IBUS> {
|
||||
class _ManualAnnouncementPickerState extends State<ManualAnnouncementPicker> {
|
||||
|
||||
List<Widget> announcements = [];
|
||||
List<Widget> announcementWidgets = [];
|
||||
|
||||
int _currentIndex = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
// TODO: implement initState
|
||||
super.initState();
|
||||
|
||||
_QuickAnnouncementsState_IBUS() {
|
||||
LiveInformation liveInformation = LiveInformation();
|
||||
|
||||
for (ManualAnnouncementEntry announcement in liveInformation.manualAnnouncements) {
|
||||
announcements.add(
|
||||
_QuickAnnouncement_IBUS(
|
||||
if (widget.announcements.isEmpty){
|
||||
return;
|
||||
}
|
||||
|
||||
for (InformationAnnouncementEntry announcement in widget.announcements!) {
|
||||
announcementWidgets.add(
|
||||
_ManualAnnouncementEntry(
|
||||
announcement: announcement,
|
||||
index: liveInformation.manualAnnouncements.indexOf(announcement),
|
||||
outlineColor: Colors.white70
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
@@ -219,8 +264,8 @@ class _QuickAnnouncementsState_IBUS extends State<_QuickAnnouncements_IBUS> {
|
||||
color: widget.outlineColor,
|
||||
),
|
||||
|
||||
if (_currentIndex < announcements.length)
|
||||
announcements[_currentIndex + 0]
|
||||
if (_currentIndex < announcementWidgets.length)
|
||||
announcementWidgets[_currentIndex + 0]
|
||||
else
|
||||
Container(
|
||||
height: 50,
|
||||
@@ -240,8 +285,8 @@ class _QuickAnnouncementsState_IBUS extends State<_QuickAnnouncements_IBUS> {
|
||||
color: widget.outlineColor,
|
||||
),
|
||||
|
||||
if (_currentIndex + 1 < announcements.length)
|
||||
announcements[_currentIndex + 1]
|
||||
if (_currentIndex + 1 < announcementWidgets.length)
|
||||
announcementWidgets[_currentIndex + 1]
|
||||
else
|
||||
Container(
|
||||
height: 50,
|
||||
@@ -261,8 +306,8 @@ class _QuickAnnouncementsState_IBUS extends State<_QuickAnnouncements_IBUS> {
|
||||
color: widget.outlineColor,
|
||||
),
|
||||
|
||||
if (_currentIndex + 2 < announcements.length)
|
||||
announcements[_currentIndex + 2]
|
||||
if (_currentIndex + 2 < announcementWidgets.length)
|
||||
announcementWidgets[_currentIndex + 2]
|
||||
else
|
||||
Container(
|
||||
height: 50,
|
||||
@@ -282,8 +327,8 @@ class _QuickAnnouncementsState_IBUS extends State<_QuickAnnouncements_IBUS> {
|
||||
color: widget.outlineColor,
|
||||
),
|
||||
|
||||
if (_currentIndex + 3 < announcements.length)
|
||||
announcements[_currentIndex + 3]
|
||||
if (_currentIndex + 3 < announcementWidgets.length)
|
||||
announcementWidgets[_currentIndex + 3]
|
||||
else
|
||||
Container(
|
||||
height: 50,
|
||||
@@ -354,7 +399,7 @@ class _QuickAnnouncementsState_IBUS extends State<_QuickAnnouncements_IBUS> {
|
||||
Positioned.fill(
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
_currentIndex = wrap(_currentIndex - 4, 0, announcements.length);
|
||||
_currentIndex = wrap(_currentIndex - 4, 0, announcementWidgets.length);
|
||||
setState(() {});
|
||||
print(_currentIndex);
|
||||
},
|
||||
@@ -407,7 +452,7 @@ class _QuickAnnouncementsState_IBUS extends State<_QuickAnnouncements_IBUS> {
|
||||
Positioned.fill(
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
_currentIndex = wrap(_currentIndex + 4, 0, announcements.length);
|
||||
_currentIndex = wrap(_currentIndex + 4, 0, announcementWidgets.length);
|
||||
setState(() {});
|
||||
print(_currentIndex);
|
||||
},
|
||||
@@ -447,17 +492,40 @@ class _QuickAnnouncementsState_IBUS extends State<_QuickAnnouncements_IBUS> {
|
||||
}
|
||||
}
|
||||
|
||||
class StopAnnouncementPicker extends ManualAnnouncementPicker {
|
||||
final BusRouteVariant routeVariant;
|
||||
|
||||
StopAnnouncementPicker({
|
||||
Key? key,
|
||||
required this.routeVariant,
|
||||
required Color backgroundColor,
|
||||
required Color outlineColor,
|
||||
}) : super(
|
||||
key: key,
|
||||
backgroundColor: backgroundColor,
|
||||
outlineColor: outlineColor,
|
||||
announcements: [
|
||||
for (BusRouteStops stop in routeVariant.busStops)
|
||||
InformationAnnouncementEntry(
|
||||
shortName: stop.formattedStopName,
|
||||
informationText: stop.formattedStopName,
|
||||
audioSources: []
|
||||
)
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
int wrap(int i, int j, int length) {
|
||||
return ((i - j) % length + length) % length;
|
||||
}
|
||||
|
||||
class _QuickAnnouncement_IBUS extends StatelessWidget {
|
||||
class _ManualAnnouncementEntry extends StatelessWidget {
|
||||
|
||||
final ManualAnnouncementEntry announcement;
|
||||
final InformationAnnouncementEntry announcement;
|
||||
final int index;
|
||||
final Color outlineColor;
|
||||
|
||||
_QuickAnnouncement_IBUS({super.key, required this.announcement, required this.index, required this.outlineColor});
|
||||
_ManualAnnouncementEntry({super.key, required this.announcement, required this.index, required this.outlineColor});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -541,164 +609,4 @@ class _QuickAnnouncement_IBUS extends StatelessWidget {
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class QuickAnnouncement extends StatelessWidget {
|
||||
|
||||
List<Widget> announcementButtons = [];
|
||||
|
||||
QuickAnnouncement({super.key}){
|
||||
|
||||
LiveInformation liveInformation = LiveInformation();
|
||||
|
||||
for (ManualAnnouncementEntry entry in liveInformation.manualAnnouncements) {
|
||||
announcementButtons.add(
|
||||
_QuickAnnouncement_Entry(manualAnnouncementEntry: entry)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int _currentIndex = 0;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
List<Widget> UsingAnnouncements = [];
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
|
||||
Widget widget = announcementButtons[wrap(_currentIndex + i, 0, announcementButtons.length)];
|
||||
|
||||
UsingAnnouncements.add(widget);
|
||||
UsingAnnouncements.add(
|
||||
SizedBox(
|
||||
height: 10,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// TODO: implement build
|
||||
return Container(
|
||||
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.all(Radius.circular(10)),
|
||||
color: Colors.grey.shade900,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.3),
|
||||
blurRadius: 4,
|
||||
spreadRadius: 4
|
||||
)
|
||||
]
|
||||
),
|
||||
|
||||
padding: EdgeInsets.all(10),
|
||||
|
||||
child: Column(
|
||||
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
||||
children: [
|
||||
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade800,
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
),
|
||||
|
||||
padding: EdgeInsets.all(8),
|
||||
|
||||
child: Text(
|
||||
"Quick Announcements",
|
||||
style: GoogleFonts.montserrat(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
height: 1
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Container
|
||||
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
_currentIndex = wrap(_currentIndex + 4, 0, announcementButtons.length);
|
||||
// setState(() {});
|
||||
},
|
||||
child: const Icon(
|
||||
Icons.arrow_back,
|
||||
color: Colors.white,
|
||||
)
|
||||
),
|
||||
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
_currentIndex = wrap(_currentIndex + 4, 0, announcementButtons.length);
|
||||
// setState(() {});
|
||||
},
|
||||
child: const Icon(
|
||||
Icons.arrow_forward,
|
||||
color: Colors.white,
|
||||
)
|
||||
)
|
||||
|
||||
],
|
||||
),
|
||||
|
||||
Container(
|
||||
margin: EdgeInsets.symmetric(vertical: 10),
|
||||
height: 1,
|
||||
color: Colors.grey.shade600,
|
||||
),
|
||||
|
||||
...UsingAnnouncements,
|
||||
|
||||
],
|
||||
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class _QuickAnnouncement_Entry extends StatelessWidget {
|
||||
|
||||
final ManualAnnouncementEntry manualAnnouncementEntry;
|
||||
|
||||
const _QuickAnnouncement_Entry({super.key, required this.manualAnnouncementEntry});
|
||||
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// TODO: implement build
|
||||
return Container(
|
||||
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade800,
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
),
|
||||
|
||||
padding: EdgeInsets.all(8),
|
||||
|
||||
width: double.infinity,
|
||||
|
||||
child: Text(
|
||||
manualAnnouncementEntry.shortName,
|
||||
style: GoogleFonts.montserrat(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white
|
||||
),
|
||||
),
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user