desktop push
This commit is contained in:
@@ -3,9 +3,12 @@ import 'package:bus_infotainment/backend/live_information.dart';
|
||||
import 'package:bus_infotainment/pages/components/ibus_display.dart';
|
||||
import 'package:bus_infotainment/remaster/dashboard.dart';
|
||||
import 'package:bus_infotainment/tfl_datasets.dart';
|
||||
import 'package:bus_infotainment/utils/delegates.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_scroll_shadow/flutter_scroll_shadow.dart';
|
||||
import 'package:network_info_plus/network_info_plus.dart';
|
||||
import 'package:qr_flutter/qr_flutter.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
|
||||
class ArcDashboard extends StatefulWidget {
|
||||
@@ -17,260 +20,207 @@ class ArcDashboard extends StatefulWidget {
|
||||
class _ArcDashboardState extends State<ArcDashboard> {
|
||||
_closeDialogueChecker closeDialogWidget = _closeDialogueChecker();
|
||||
|
||||
late ListenerReceipt<BusRouteVariant?> onRouteVariantChange;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
// TODO: implement initState
|
||||
super.initState();
|
||||
|
||||
onRouteVariantChange = LiveInformation().routeVariantDelegate.addListener((value) {
|
||||
print("Route variant changed");
|
||||
setState(() {
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
// TODO: implement dispose
|
||||
super.dispose();
|
||||
|
||||
LiveInformation().routeVariantDelegate.removeListener(onRouteVariantChange);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PopScope(
|
||||
|
||||
// Force landscape mode
|
||||
Future.delayed(Duration(seconds: 1), () {
|
||||
SystemChrome.setPreferredOrientations([
|
||||
DeviceOrientation.landscapeRight,
|
||||
DeviceOrientation.landscapeLeft,
|
||||
]);
|
||||
});
|
||||
onPopInvoked: (isPop) {
|
||||
|
||||
return Scaffold(
|
||||
try {
|
||||
LiveInformation().leaveRoom();
|
||||
print("Left room");
|
||||
} catch (e) {
|
||||
print("Error leaving room: $e");
|
||||
}
|
||||
|
||||
body: Container(
|
||||
child: Row(
|
||||
|
||||
children: [
|
||||
},
|
||||
|
||||
const SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
child: Scaffold(
|
||||
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 10,
|
||||
body: Container(
|
||||
child: Row(
|
||||
|
||||
children: [
|
||||
|
||||
const SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
|
||||
child: IntrinsicWidth(
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 10,
|
||||
),
|
||||
|
||||
if (LiveInformation().roomDocumentID != null)
|
||||
Tooltip(
|
||||
child: ShadButton(
|
||||
icon: const Icon(Icons.network_check),
|
||||
child: IntrinsicWidth(
|
||||
child: Column(
|
||||
children: [
|
||||
|
||||
ShadButton.outline(
|
||||
icon: const Icon(Icons.menu),
|
||||
width: double.infinity,
|
||||
border: Border.all(
|
||||
width: 2,
|
||||
color: Colors.grey.shade400,
|
||||
),
|
||||
padding: const EdgeInsets.all(0),
|
||||
borderRadius: const BorderRadius.all(Radius.circular(10)),
|
||||
onPressed: () {
|
||||
bool multiMode = ModalRoute.of(context)!.settings.name!.contains("multi");
|
||||
|
||||
showShadSheet(
|
||||
context: context,
|
||||
side: ShadSheetSide.left,
|
||||
|
||||
builder: (context) {
|
||||
return ShadSheet(
|
||||
padding: const EdgeInsets.all(10),
|
||||
content: Column(
|
||||
children: [
|
||||
Text("Room ID: ${LiveInformation().roomDocumentID}"),
|
||||
],
|
||||
padding: const EdgeInsets.all(0),
|
||||
content: Container(
|
||||
width: 225,
|
||||
height: MediaQuery.of(context).size.height,
|
||||
padding: const EdgeInsets.all(10),
|
||||
child: Column(
|
||||
children: [
|
||||
|
||||
Expanded(
|
||||
child: Column(
|
||||
children: [
|
||||
|
||||
ShadButton(
|
||||
text: Text("Rooom Information"),
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
showShadSheet(
|
||||
context: context,
|
||||
side: ShadSheetSide.left,
|
||||
builder: (context) {
|
||||
return ShadSheet(
|
||||
padding: const EdgeInsets.all(10),
|
||||
content: Column(
|
||||
children: [
|
||||
Text("Room ID: ${LiveInformation().roomDocumentID}"),
|
||||
Text("IP Address: ${LiveInformation().networkingModule.localIP}"),
|
||||
QrImageView(
|
||||
data: LiveInformation().generateRoomInfo(),
|
||||
size: 270,
|
||||
backgroundColor: Colors.white,
|
||||
),
|
||||
ShadButton(
|
||||
text: Text("Copy Room Info"),
|
||||
onPressed: () {
|
||||
Clipboard.setData(ClipboardData(text: LiveInformation().generateRoomInfo()));
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text("Copied room info to clipboard"),
|
||||
)
|
||||
);
|
||||
},
|
||||
)
|
||||
],
|
||||
|
||||
),
|
||||
);
|
||||
}
|
||||
);
|
||||
},
|
||||
)
|
||||
|
||||
],
|
||||
)
|
||||
),
|
||||
|
||||
if (!multiMode)
|
||||
ShadButton(
|
||||
text: Text("Return to route selection"),
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
)
|
||||
else
|
||||
ShadButton(
|
||||
text: Text("Route selection"),
|
||||
onPressed: () {
|
||||
Navigator.popAndPushNamed(context, '/multi/routes');
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
},
|
||||
),
|
||||
message: "Room information",
|
||||
),
|
||||
|
||||
SizedBox(
|
||||
height: 220,
|
||||
child: RotatedBox(
|
||||
quarterTurns: 3,
|
||||
child: Column(
|
||||
children: [
|
||||
ShadButton(
|
||||
text: const Text("Manual Announcements"),
|
||||
width: double.infinity,
|
||||
borderRadius: const BorderRadius.all(Radius.circular(10)),
|
||||
onPressed: () {
|
||||
SizedBox(
|
||||
height: 220,
|
||||
child: RotatedBox(
|
||||
quarterTurns: 3,
|
||||
child: Column(
|
||||
children: [
|
||||
ShadButton(
|
||||
text: const Text("Manual Announcements"),
|
||||
width: double.infinity,
|
||||
borderRadius: const BorderRadius.all(Radius.circular(10)),
|
||||
onPressed: () {
|
||||
|
||||
List<Widget> announcements = [];
|
||||
List<Widget> announcements = [];
|
||||
|
||||
for (var announcement in LiveInformation().announcementModule.manualAnnouncements) {
|
||||
for (var announcement in LiveInformation().announcementModule.manualAnnouncements) {
|
||||
|
||||
announcements.add(
|
||||
ShadButton(
|
||||
text: SizedBox(
|
||||
width: 200-42,
|
||||
child: Text(announcement.shortName),
|
||||
),
|
||||
onPressed: () {
|
||||
|
||||
if (closeDialogWidget.closeDialog) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
|
||||
LiveInformation().announcementModule.queueAnnouncementByInfoIndex(
|
||||
infoIndex: LiveInformation().announcementModule.manualAnnouncements.indexOf(announcement),
|
||||
);
|
||||
},
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
print(announcements.length);
|
||||
|
||||
showShadSheet(
|
||||
context: context,
|
||||
side: ShadSheetSide.left,
|
||||
|
||||
builder: (context) {
|
||||
return ShadSheet(
|
||||
padding: const EdgeInsets.all(0),
|
||||
|
||||
content: Container(
|
||||
height: MediaQuery.of(context).size.height,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 5,
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 10,
|
||||
),
|
||||
alignment: Alignment.bottomCenter,
|
||||
height: double.infinity,
|
||||
width: 35,
|
||||
child: RotatedBox(
|
||||
quarterTurns: 3,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
"Manual Ann'",
|
||||
style: ShadTheme.of(context).textTheme.h3
|
||||
),
|
||||
SizedBox(
|
||||
width: 16,
|
||||
),
|
||||
Container(
|
||||
width: 1,
|
||||
height: 200,
|
||||
color: Colors.grey,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
closeDialogWidget
|
||||
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
|
||||
// width: 220,
|
||||
height: MediaQuery.of(context).size.height,
|
||||
|
||||
child: Scrollbar(
|
||||
thumbVisibility: true,
|
||||
child: SingleChildScrollView(
|
||||
reverse: true,
|
||||
child: Container(
|
||||
margin: const EdgeInsets.fromLTRB(
|
||||
0,
|
||||
10,
|
||||
10,
|
||||
10
|
||||
),
|
||||
child: Column(
|
||||
children: announcements.reversed.toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
announcements.add(
|
||||
ShadButton(
|
||||
text: SizedBox(
|
||||
width: 200-42,
|
||||
child: Text(announcement.shortName),
|
||||
),
|
||||
),
|
||||
onPressed: () {
|
||||
|
||||
if (closeDialogWidget.closeDialog) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
|
||||
LiveInformation().announcementModule.queueAnnouncementByInfoIndex(
|
||||
infoIndex: LiveInformation().announcementModule.manualAnnouncements.indexOf(announcement),
|
||||
);
|
||||
},
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
},
|
||||
),
|
||||
ShadButton(
|
||||
text: const Text("Bus Stop Announcements"),
|
||||
width: double.infinity,
|
||||
borderRadius: const BorderRadius.all(Radius.circular(10)),
|
||||
onPressed: () {
|
||||
print(announcements.length);
|
||||
|
||||
showShadSheet(
|
||||
showShadSheet(
|
||||
context: context,
|
||||
side: ShadSheetSide.left,
|
||||
|
||||
builder: (context) {
|
||||
|
||||
List<Widget> announcements = [];
|
||||
|
||||
LiveInformation info = LiveInformation();
|
||||
|
||||
for (var busStop in info.getRouteVariant()!.busStops) {
|
||||
|
||||
if (info.trackerModule.nearestStop == busStop) {
|
||||
announcements.add(
|
||||
ShadButton(
|
||||
text: SizedBox(
|
||||
width: 200-42,
|
||||
child: Text(
|
||||
"-> ${busStop.formattedStopName}",
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
backgroundColor: Colors.amber,
|
||||
onPressed: () {
|
||||
if (closeDialogWidget.closeDialog) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
LiveInformation().announcementModule.queueAnnounceByAudioName(
|
||||
displayText: busStop.formattedStopName,
|
||||
audioNames: [busStop.getAudioFileName()],
|
||||
);
|
||||
},
|
||||
)
|
||||
);
|
||||
} else {
|
||||
announcements.add(
|
||||
ShadButton(
|
||||
text: SizedBox(
|
||||
width: 200-42,
|
||||
child: Text(
|
||||
busStop.formattedStopName,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
onPressed: () {
|
||||
if (closeDialogWidget.closeDialog) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
LiveInformation().announcementModule.queueAnnounceByAudioName(
|
||||
displayText: busStop.formattedStopName,
|
||||
audioNames: [busStop.getAudioFileName()],
|
||||
);
|
||||
},
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
ScrollController controller = ScrollController();
|
||||
|
||||
// Scroll to the current bus stop
|
||||
WidgetsBinding.instance!.addPostFrameCallback((_) {
|
||||
|
||||
double offset = (info.getRouteVariant()!.busStops.indexOf(info.trackerModule.nearestStop!) * 50);
|
||||
|
||||
// Offset the offset so that its in the middle of the screen
|
||||
offset -= (MediaQuery.of(context).size.height / 2) - 25;
|
||||
|
||||
// controller.jumpTo(offset);
|
||||
});
|
||||
|
||||
return ShadSheet(
|
||||
padding: const EdgeInsets.all(0),
|
||||
|
||||
@@ -297,8 +247,8 @@ class _ArcDashboardState extends State<ArcDashboard> {
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
"Bus Stops",
|
||||
style: ShadTheme.of(context).textTheme.h3
|
||||
"Manual Ann'",
|
||||
style: ShadTheme.of(context).textTheme.h3
|
||||
),
|
||||
SizedBox(
|
||||
width: 16,
|
||||
@@ -324,16 +274,14 @@ class _ArcDashboardState extends State<ArcDashboard> {
|
||||
|
||||
child: Scrollbar(
|
||||
thumbVisibility: true,
|
||||
controller: controller,
|
||||
child: SingleChildScrollView(
|
||||
reverse: true,
|
||||
controller: controller,
|
||||
child: Container(
|
||||
margin: const EdgeInsets.fromLTRB(
|
||||
0,
|
||||
10,
|
||||
10,
|
||||
10
|
||||
0,
|
||||
10,
|
||||
10,
|
||||
10
|
||||
),
|
||||
child: Column(
|
||||
children: announcements.reversed.toList(),
|
||||
@@ -347,108 +295,272 @@ class _ArcDashboardState extends State<ArcDashboard> {
|
||||
),
|
||||
);
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
ShadButton(
|
||||
text: const Text("Bus Stop Announcements"),
|
||||
enabled: LiveInformation().getRouteVariant() != null,
|
||||
width: double.infinity,
|
||||
borderRadius: const BorderRadius.all(Radius.circular(10)),
|
||||
onPressed: () {
|
||||
|
||||
showShadSheet(
|
||||
context: context,
|
||||
side: ShadSheetSide.left,
|
||||
|
||||
builder: (context) {
|
||||
|
||||
List<Widget> announcements = [];
|
||||
|
||||
LiveInformation info = LiveInformation();
|
||||
|
||||
for (var busStop in info.getRouteVariant()!.busStops) {
|
||||
|
||||
if (info.trackerModule.nearestStop == busStop) {
|
||||
announcements.add(
|
||||
ShadButton(
|
||||
text: SizedBox(
|
||||
width: 200-42,
|
||||
child: Text(
|
||||
"-> ${busStop.formattedStopName}",
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
backgroundColor: Colors.amber,
|
||||
onPressed: () {
|
||||
if (closeDialogWidget.closeDialog) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
LiveInformation().announcementModule.queueAnnounceByAudioName(
|
||||
displayText: busStop.formattedStopName,
|
||||
audioNames: [busStop.getAudioFileName()],
|
||||
);
|
||||
},
|
||||
)
|
||||
);
|
||||
} else {
|
||||
announcements.add(
|
||||
ShadButton(
|
||||
text: SizedBox(
|
||||
width: 200-42,
|
||||
child: Text(
|
||||
busStop.formattedStopName,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
onPressed: () {
|
||||
if (closeDialogWidget.closeDialog) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
LiveInformation().announcementModule.queueAnnounceByAudioName(
|
||||
displayText: busStop.formattedStopName,
|
||||
audioNames: [busStop.getAudioFileName()],
|
||||
);
|
||||
},
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
ScrollController controller = ScrollController();
|
||||
|
||||
// Scroll to the current bus stop
|
||||
WidgetsBinding.instance!.addPostFrameCallback((_) {
|
||||
|
||||
double offset = (info.getRouteVariant()!.busStops.indexOf(info.trackerModule.nearestStop!) * 50);
|
||||
|
||||
// Offset the offset so that its in the middle of the screen
|
||||
offset -= (MediaQuery.of(context).size.height / 2) - 25;
|
||||
|
||||
// controller.jumpTo(offset);
|
||||
});
|
||||
|
||||
return ShadSheet(
|
||||
padding: const EdgeInsets.all(0),
|
||||
|
||||
content: Container(
|
||||
height: MediaQuery.of(context).size.height,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 5,
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 10,
|
||||
),
|
||||
alignment: Alignment.bottomCenter,
|
||||
height: double.infinity,
|
||||
width: 35,
|
||||
child: RotatedBox(
|
||||
quarterTurns: 3,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
"Bus Stops",
|
||||
style: ShadTheme.of(context).textTheme.h3
|
||||
),
|
||||
SizedBox(
|
||||
width: 16,
|
||||
),
|
||||
Container(
|
||||
width: 1,
|
||||
height: 200,
|
||||
color: Colors.grey,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
closeDialogWidget
|
||||
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
|
||||
// width: 220,
|
||||
height: MediaQuery.of(context).size.height,
|
||||
|
||||
child: Scrollbar(
|
||||
thumbVisibility: true,
|
||||
controller: controller,
|
||||
child: SingleChildScrollView(
|
||||
reverse: true,
|
||||
controller: controller,
|
||||
child: Container(
|
||||
margin: const EdgeInsets.fromLTRB(
|
||||
0,
|
||||
10,
|
||||
10,
|
||||
10
|
||||
),
|
||||
child: Column(
|
||||
children: announcements.reversed.toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
},
|
||||
),
|
||||
],
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
const ShadButton(
|
||||
icon: Icon(Icons.stop),
|
||||
width: double.infinity,
|
||||
borderRadius: BorderRadius.all(Radius.circular(10)),
|
||||
),
|
||||
|
||||
ShadButton(
|
||||
// text: const Text("Announce Destination"),
|
||||
icon: const Icon(Icons.bus_alert),
|
||||
width: double.infinity,
|
||||
borderRadius: const BorderRadius.all(Radius.circular(10)),
|
||||
onPressed: () {
|
||||
LiveInformation info = LiveInformation();
|
||||
|
||||
BusRouteVariant? routeVariant = info.getRouteVariant();
|
||||
|
||||
if (routeVariant != null) {
|
||||
info.announcementModule.queueAnnouncementByRouteVariant(
|
||||
routeVariant: routeVariant,
|
||||
sendToServer: ModalRoute.of(context)!.settings.name!.contains("multi")
|
||||
);
|
||||
}
|
||||
|
||||
},
|
||||
),
|
||||
|
||||
|
||||
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
),
|
||||
|
||||
Expanded(
|
||||
child: Container(
|
||||
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.black,
|
||||
borderRadius: BorderRadius.all(Radius.circular(10)),
|
||||
|
||||
),
|
||||
|
||||
margin: const EdgeInsets.all(10),
|
||||
padding: const EdgeInsets.all(10),
|
||||
|
||||
width: double.infinity,
|
||||
height: double.infinity,
|
||||
|
||||
child: Stack(
|
||||
children: [
|
||||
Container(
|
||||
|
||||
alignment: Alignment.center,
|
||||
|
||||
child: ibus_display(
|
||||
hasBorder: false,
|
||||
),
|
||||
|
||||
),
|
||||
Container(
|
||||
|
||||
alignment: Alignment.bottomRight,
|
||||
|
||||
child: ShadButton.ghost(
|
||||
icon: const Icon(Icons.fullscreen),
|
||||
padding: const EdgeInsets.all(8),
|
||||
onPressed: () {
|
||||
Navigator.pushNamed(context, '/display');
|
||||
},
|
||||
),
|
||||
|
||||
),
|
||||
Container(
|
||||
|
||||
alignment: Alignment.bottomLeft,
|
||||
|
||||
child: ShadButton.ghost(
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
padding: const EdgeInsets.all(8),
|
||||
onPressed: () {
|
||||
Navigator.popUntil(context, (route) {
|
||||
return route.settings.name == '/multi' || route.settings.name == '/routes';
|
||||
});
|
||||
},
|
||||
),
|
||||
|
||||
)
|
||||
),
|
||||
|
||||
const ShadButton(
|
||||
icon: Icon(Icons.stop),
|
||||
width: double.infinity,
|
||||
),
|
||||
|
||||
ShadButton(
|
||||
// text: const Text("Announce Destination"),
|
||||
icon: const Icon(Icons.location_on),
|
||||
width: double.infinity,
|
||||
borderRadius: const BorderRadius.all(Radius.circular(10)),
|
||||
onPressed: () {
|
||||
LiveInformation info = LiveInformation();
|
||||
|
||||
BusRouteVariant? routeVariant = info.getRouteVariant();
|
||||
|
||||
if (routeVariant != null) {
|
||||
info.announcementModule.queueAnnouncementByRouteVariant(
|
||||
routeVariant: routeVariant,
|
||||
sendToServer: false
|
||||
);
|
||||
}
|
||||
|
||||
},
|
||||
)
|
||||
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
),
|
||||
|
||||
Expanded(
|
||||
child: Container(
|
||||
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.black,
|
||||
borderRadius: BorderRadius.all(Radius.circular(10)),
|
||||
|
||||
),
|
||||
|
||||
margin: const EdgeInsets.all(10),
|
||||
padding: const EdgeInsets.all(10),
|
||||
|
||||
width: double.infinity,
|
||||
height: double.infinity,
|
||||
|
||||
child: Stack(
|
||||
children: [
|
||||
Container(
|
||||
|
||||
alignment: Alignment.center,
|
||||
|
||||
child: ibus_display(
|
||||
hasBorder: false,
|
||||
),
|
||||
|
||||
),
|
||||
Container(
|
||||
|
||||
alignment: Alignment.bottomRight,
|
||||
|
||||
child: ShadButton.ghost(
|
||||
icon: const Icon(Icons.fullscreen),
|
||||
padding: const EdgeInsets.all(8),
|
||||
onPressed: () {
|
||||
Navigator.pushNamed(context, '/display');
|
||||
},
|
||||
),
|
||||
|
||||
),
|
||||
Container(
|
||||
|
||||
alignment: Alignment.bottomLeft,
|
||||
|
||||
child: ShadButton.ghost(
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
padding: const EdgeInsets.all(8),
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
],
|
||||
],
|
||||
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
),
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ class _page2State extends State<_page2> {
|
||||
|
||||
child: SizedBox(
|
||||
|
||||
width: double.infinity,
|
||||
// width: double.infinity,
|
||||
|
||||
child: Column(
|
||||
|
||||
@@ -162,7 +162,6 @@ class _page2State extends State<_page2> {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
||||
children: [
|
||||
|
||||
Text(
|
||||
"Permissions",
|
||||
style: TextStyle(
|
||||
@@ -175,105 +174,172 @@ class _page2State extends State<_page2> {
|
||||
height: 16,
|
||||
),
|
||||
|
||||
ShadCard(
|
||||
width: double.infinity,
|
||||
title: Text(
|
||||
"Location",
|
||||
),
|
||||
description: Text(
|
||||
"Your location is required for automatically updating your nearest bus stop."
|
||||
),
|
||||
content: Container(
|
||||
child: Column(
|
||||
children: [
|
||||
SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
|
||||
SizedBox(
|
||||
height: 4,
|
||||
// mainAxisSize: MainAxisSize.min,
|
||||
// crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
||||
children: [
|
||||
ShadCard(
|
||||
width: 300,
|
||||
height: 200,
|
||||
title: Text(
|
||||
"Location",
|
||||
),
|
||||
|
||||
FutureBuilder(
|
||||
future: Permission.location.isGranted,
|
||||
builder: (context, val) {
|
||||
bool isEnabled = true;
|
||||
String text = "Request permission";
|
||||
Color color = Colors.white;
|
||||
|
||||
if (val.hasData) {
|
||||
isEnabled = !val.data!;
|
||||
}
|
||||
if (!isEnabled) {
|
||||
text = "Permission granted!";
|
||||
color = Colors.green.shade400;
|
||||
}
|
||||
|
||||
return ShadButton(
|
||||
text: Text(text),
|
||||
onPressed: () async {
|
||||
await Permission.location.request();
|
||||
setState(() {
|
||||
|
||||
});
|
||||
},
|
||||
enabled: isEnabled,
|
||||
backgroundColor: color,
|
||||
);
|
||||
},
|
||||
description: Text(
|
||||
"Your location is required for automatically updating your nearest bus stop."
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
content: Container(
|
||||
child: Column(
|
||||
children: [
|
||||
|
||||
SizedBox(
|
||||
height: 16,
|
||||
),
|
||||
SizedBox(
|
||||
height: 4,
|
||||
),
|
||||
|
||||
ShadCard(
|
||||
width: double.infinity,
|
||||
title: Text(
|
||||
"Storage",
|
||||
),
|
||||
description: Text(
|
||||
"Storage access is required to access recorded announcements."
|
||||
),
|
||||
content: Container(
|
||||
child: Column(
|
||||
children: [
|
||||
FutureBuilder(
|
||||
future: Permission.location.isGranted,
|
||||
builder: (context, val) {
|
||||
bool isEnabled = true;
|
||||
String text = "Request permission";
|
||||
Color color = Colors.white;
|
||||
|
||||
SizedBox(
|
||||
height: 4,
|
||||
if (val.hasData) {
|
||||
isEnabled = !val.data!;
|
||||
}
|
||||
if (!isEnabled) {
|
||||
text = "Permission granted!";
|
||||
color = Colors.green.shade400;
|
||||
}
|
||||
|
||||
return ShadButton(
|
||||
text: Text(text),
|
||||
onPressed: () async {
|
||||
await Permission.location.request();
|
||||
setState(() {
|
||||
|
||||
});
|
||||
},
|
||||
enabled: isEnabled,
|
||||
backgroundColor: color,
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
FutureBuilder(
|
||||
future: Permission.manageExternalStorage.isGranted,
|
||||
builder: (context, val) {
|
||||
bool isEnabled = true;
|
||||
String text = "Request permission";
|
||||
Color color = Colors.white;
|
||||
SizedBox(
|
||||
width: 16,
|
||||
),
|
||||
|
||||
if (val.hasData) {
|
||||
isEnabled = !val.data!;
|
||||
}
|
||||
if (!isEnabled) {
|
||||
text = "Permission granted!";
|
||||
color = Colors.green.shade400;
|
||||
}
|
||||
ShadCard(
|
||||
width: 300,
|
||||
height: 200,
|
||||
title: Text(
|
||||
"Storage",
|
||||
),
|
||||
description: Text(
|
||||
"Storage access is required to access recorded announcements."
|
||||
),
|
||||
content: Container(
|
||||
child: Column(
|
||||
children: [
|
||||
|
||||
return ShadButton(
|
||||
text: Text(text),
|
||||
onPressed: () async {
|
||||
await Permission.manageExternalStorage.request();
|
||||
setState(() {
|
||||
SizedBox(
|
||||
height: 4,
|
||||
),
|
||||
|
||||
});
|
||||
},
|
||||
enabled: isEnabled,
|
||||
backgroundColor: color,
|
||||
);
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
FutureBuilder(
|
||||
future: Permission.manageExternalStorage.isGranted,
|
||||
builder: (context, val) {
|
||||
bool isEnabled = true;
|
||||
String text = "Request permission";
|
||||
Color color = Colors.white;
|
||||
|
||||
if (val.hasData) {
|
||||
isEnabled = !val.data!;
|
||||
}
|
||||
if (!isEnabled) {
|
||||
text = "Permission granted!";
|
||||
color = Colors.green.shade400;
|
||||
}
|
||||
|
||||
return ShadButton(
|
||||
text: Text(text),
|
||||
onPressed: () async {
|
||||
await Permission.manageExternalStorage.request();
|
||||
setState(() {
|
||||
|
||||
});
|
||||
},
|
||||
enabled: isEnabled,
|
||||
backgroundColor: color,
|
||||
);
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
SizedBox(
|
||||
width: 16,
|
||||
),
|
||||
|
||||
ShadCard(
|
||||
width: 300,
|
||||
height: 200,
|
||||
title: Text(
|
||||
"Network",
|
||||
),
|
||||
description: Text(
|
||||
"Network access is required for commincation between devices for multi mode."
|
||||
),
|
||||
content: Container(
|
||||
child: Column(
|
||||
children: [
|
||||
|
||||
SizedBox(
|
||||
height: 4,
|
||||
),
|
||||
|
||||
FutureBuilder(
|
||||
future: Permission.nearbyWifiDevices.isGranted,
|
||||
builder: (context, val) {
|
||||
bool isEnabled = true;
|
||||
String text = "Request permission";
|
||||
Color color = Colors.white;
|
||||
|
||||
if (val.hasData) {
|
||||
isEnabled = !val.data!;
|
||||
}
|
||||
if (!isEnabled) {
|
||||
text = "Permission granted!";
|
||||
color = Colors.green.shade400;
|
||||
}
|
||||
|
||||
return ShadButton(
|
||||
text: Text(text),
|
||||
onPressed: () async {
|
||||
await Permission.manageExternalStorage.request();
|
||||
setState(() {
|
||||
|
||||
});
|
||||
},
|
||||
enabled: isEnabled,
|
||||
backgroundColor: color,
|
||||
);
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -306,7 +372,6 @@ class _page2State extends State<_page2> {
|
||||
);
|
||||
},
|
||||
)
|
||||
|
||||
],
|
||||
),
|
||||
)
|
||||
|
||||
@@ -4,15 +4,40 @@
|
||||
import 'package:bus_infotainment/pages/tfl_dataset_test.dart';
|
||||
import 'package:bus_infotainment/remaster/DashboardArc.dart';
|
||||
import 'package:bus_infotainment/remaster/InitialStartup.dart';
|
||||
import 'package:bus_infotainment/remaster/SearchArc.dart';
|
||||
import 'package:bus_infotainment/remaster/dashboard.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
import 'WebSocketTest.dart';
|
||||
|
||||
class RemasteredApp extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// TODO: implement build
|
||||
|
||||
// Force landscape mode
|
||||
SystemChrome.setPreferredOrientations([
|
||||
DeviceOrientation.landscapeLeft,
|
||||
DeviceOrientation.landscapeRight,
|
||||
]);
|
||||
|
||||
// Hide navigation bar and status bar
|
||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive, overlays: [
|
||||
SystemUiOverlay.bottom,
|
||||
SystemUiOverlay.top,
|
||||
]);
|
||||
|
||||
// Hide the gesture navigation bar
|
||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky, overlays: [
|
||||
SystemUiOverlay.bottom,
|
||||
SystemUiOverlay.top,
|
||||
]);
|
||||
|
||||
|
||||
|
||||
return ShadApp(
|
||||
darkTheme: ShadThemeData(
|
||||
brightness: Brightness.dark,
|
||||
@@ -20,16 +45,22 @@ class RemasteredApp extends StatelessWidget {
|
||||
background: Colors.grey.shade900,
|
||||
primary: Colors.grey.shade50,
|
||||
primaryForeground: Colors.grey.shade900,
|
||||
border: Colors.grey.shade900,
|
||||
border: Colors.grey.shade400,
|
||||
input: Colors.grey.shade400,
|
||||
),
|
||||
// force dark mode
|
||||
),
|
||||
themeMode: ThemeMode.dark,
|
||||
|
||||
// remove debug banner
|
||||
debugShowCheckedModeBanner: false,
|
||||
|
||||
routes: {
|
||||
'/setup': (context) => InitialStartup(),
|
||||
'/': (context) => HomePage_Re(),
|
||||
'/routes': (context) => RoutePage(),
|
||||
|
||||
'/routes': (context) => SearchArc(),
|
||||
'/multi/routes': (context) => RoutePage(),
|
||||
|
||||
'/enroute': (context) => ArcDashboard(),
|
||||
'/legacy': (context) => TfL_Dataset_Test(),
|
||||
'/multi': (context) => MultiModeSetup(),
|
||||
@@ -38,6 +69,7 @@ class RemasteredApp extends StatelessWidget {
|
||||
'/multi/register': (context) => MultiModeRegister(),
|
||||
'/display': (context) => FullscreenDisplay(),
|
||||
'/multi/join': (context) => MultiModeJoin(),
|
||||
'/websocket': (context) => WebSocketWidget(),
|
||||
|
||||
},
|
||||
|
||||
|
||||
346
lib/remaster/SearchArc.dart
Normal file
346
lib/remaster/SearchArc.dart
Normal file
@@ -0,0 +1,346 @@
|
||||
|
||||
|
||||
import 'package:bus_infotainment/backend/live_information.dart';
|
||||
import 'package:bus_infotainment/remaster/dashboard.dart';
|
||||
import 'package:bus_infotainment/tfl_datasets.dart';
|
||||
import 'package:bus_infotainment/utils/OrdinanceSurveyUtils.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart' hide NavigationBar;
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
import 'package:vector_math/vector_math.dart' hide Colors;
|
||||
|
||||
import '../backend/modules/tube_info.dart';
|
||||
|
||||
class SearchArc extends StatefulWidget {
|
||||
|
||||
@override
|
||||
State<SearchArc> createState() => _SearchArcState();
|
||||
}
|
||||
|
||||
class _SearchArcState extends State<SearchArc> {
|
||||
TextEditingController searchController = TextEditingController();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
List<Widget> nearbyRoutes = _getNearbyRoutes(context);
|
||||
List<Widget> pastRoutes = _getPastRoutes(context);
|
||||
|
||||
List<Widget> routeCards = [];
|
||||
|
||||
if (searchController.text.isNotEmpty) {
|
||||
// Detect if the search query is a route number
|
||||
// Examples of route numbers: 1, A1, 1A, A1A ...
|
||||
// If it isnt a route number, it is a stop name
|
||||
// Examples of stop names: "Euston Station", "Baker Street", "Kings Cross"
|
||||
bool containsNumber = RegExp(r'\d').hasMatch(searchController.text);
|
||||
|
||||
List<BusRoute> searchResults = [];
|
||||
|
||||
// Loop through all bus routes
|
||||
for (BusRoute route in LiveInformation().busSequences.routes.values) {
|
||||
if (containsNumber) {
|
||||
if (route.routeNumber.contains(searchController.text) && !searchResults.contains(route)) {
|
||||
routeCards.add(_getRouteCard(context, route));
|
||||
searchResults.add(route);
|
||||
}
|
||||
} else {
|
||||
for (BusRouteVariant variant in route.routeVariants.values) {
|
||||
for (BusRouteStop stop in variant.busStops) {
|
||||
if (stop.formattedStopName.toLowerCase().contains(
|
||||
searchController.text.toLowerCase()) && !searchResults.contains(route)) {
|
||||
routeCards.add(_getRouteCard(context, route));
|
||||
searchResults.add(route);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (routeCards.isEmpty){
|
||||
routeCards.add(
|
||||
Text("No results found", style: ShadTheme.of(context).textTheme.h3,)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
body: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Container(
|
||||
padding: EdgeInsets.fromLTRB(32, 16, 32, 0),
|
||||
height: MediaQuery.of(context).size.height,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadInput(
|
||||
placeholder: Text("Search for route or stop (Can be laggy)"),
|
||||
controller: searchController,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
// Update search results
|
||||
});
|
||||
},
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
if (routeCards.isNotEmpty)
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
"Search results",
|
||||
style: ShadTheme.of(context).textTheme.h3,
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
Expanded(
|
||||
child: GridView.extent(
|
||||
shrinkWrap: true,
|
||||
maxCrossAxisExtent: 100,
|
||||
scrollDirection: Axis.vertical,
|
||||
crossAxisSpacing: 8,
|
||||
mainAxisSpacing: 8,
|
||||
children: routeCards,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
else
|
||||
Expanded(
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
"Nearby routes",
|
||||
style: ShadTheme.of(context).textTheme.h3,
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
Expanded(
|
||||
child: GridView.extent(
|
||||
shrinkWrap: true,
|
||||
maxCrossAxisExtent: 100,
|
||||
scrollDirection: Axis.vertical,
|
||||
crossAxisSpacing: 8,
|
||||
mainAxisSpacing: 8,
|
||||
children: _getNearbyRoutes(context, multiMode: true),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Container(
|
||||
width: 2,
|
||||
color: Colors.grey.shade300,
|
||||
),
|
||||
|
||||
RotatedBox(
|
||||
quarterTurns: 3,
|
||||
child: NavigationBar(),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
List<Widget> _getNearbyRoutes(context, {bool multiMode = false}) {
|
||||
|
||||
print("Getting nearby routes");
|
||||
|
||||
LiveInformation liveInformation = LiveInformation();
|
||||
BusSequences busSequences = liveInformation.busSequences;
|
||||
|
||||
List<BusRoute> nearbyRoutes = [];
|
||||
|
||||
Position? currentLocation = liveInformation.trackerModule.position;
|
||||
|
||||
Vector2 currentVector = Vector2(0, 0);
|
||||
|
||||
if (currentLocation == null && !kDebugMode) {
|
||||
return [];
|
||||
} else if (currentLocation != null){
|
||||
currentVector = OSGrid.toNorthingEasting(currentLocation!.latitude, currentLocation.longitude);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (kDebugMode) {
|
||||
currentVector = OSGrid.toNorthingEasting(51.583781262560926, -0.020359583104595073);
|
||||
}
|
||||
|
||||
for (BusRoute route in busSequences.routes.values) {
|
||||
for (BusRouteVariant variant in route.routeVariants.values) {
|
||||
for (BusRouteStop stop in variant.busStops) {
|
||||
|
||||
Vector2 stopVector = Vector2(stop.easting.toDouble(), stop.northing.toDouble());
|
||||
|
||||
double distance = currentVector.distanceTo(stopVector);
|
||||
|
||||
if (distance < 1000) {
|
||||
nearbyRoutes.add(route);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (nearbyRoutes.contains(route)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (nearbyRoutes.contains(route)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
List<Widget> routeCards = [];
|
||||
|
||||
for (BusRoute route in nearbyRoutes) {
|
||||
routeCards.add(_getRouteCard(context, route, multiMode: multiMode));
|
||||
}
|
||||
|
||||
return routeCards;
|
||||
|
||||
}
|
||||
|
||||
Widget _getRouteCard(context, BusRoute route, {bool multiMode = false}) {
|
||||
|
||||
String rr = "";
|
||||
|
||||
if (route.routeNumber.toLowerCase().startsWith("ul")) {
|
||||
|
||||
rr = "Rail replacement";
|
||||
|
||||
TubeLine? line = LiveInformation().tubeStations.getClosestLine(route.routeVariants.values.first);
|
||||
|
||||
rr = line?.name ?? rr;
|
||||
|
||||
if (!["London Overground", "DLR", "Rail replacement", "Elizabeth Line"].contains(rr)) {
|
||||
rr += " line";
|
||||
}
|
||||
if (rr == "Hammersmith and City line") {
|
||||
rr = "Hammersmith & City";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return ElevatedButton(
|
||||
onPressed: () {
|
||||
showShadSheet(
|
||||
side: ShadSheetSide.right,
|
||||
context: context,
|
||||
builder: (context) {
|
||||
|
||||
List<Widget> variantWidgets = [];
|
||||
|
||||
for (BusRouteVariant variant in route.routeVariants.values) {
|
||||
variantWidgets.add(
|
||||
ShadButton.outline(
|
||||
text: SizedBox(
|
||||
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text("${variant.busStops.first.formattedStopName} ->"),
|
||||
const SizedBox(
|
||||
height: 2,
|
||||
),
|
||||
Text(variant.busStops.last.formattedStopName)
|
||||
],
|
||||
),
|
||||
),
|
||||
width: double.infinity,
|
||||
height: 50,
|
||||
padding: const EdgeInsets.all(8),
|
||||
onPressed: () async {
|
||||
LiveInformation liveInformation = LiveInformation();
|
||||
await liveInformation.setRouteVariant(variant);
|
||||
|
||||
if (!multiMode) {
|
||||
Navigator.popAndPushNamed(context, "/enroute");
|
||||
} else {
|
||||
Navigator.popAndPushNamed(context, "/multi/enroute");
|
||||
}
|
||||
|
||||
},
|
||||
)
|
||||
);
|
||||
|
||||
variantWidgets.add(const SizedBox(
|
||||
height: 4,
|
||||
));
|
||||
}
|
||||
|
||||
return ShadSheet(
|
||||
title: Text("Route ${route.routeNumber} - Variants"),
|
||||
|
||||
content: Container(
|
||||
width: 300,
|
||||
height: MediaQuery.of(context).size.height - 52,
|
||||
child: Scrollbar(
|
||||
thumbVisibility: true,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: [
|
||||
...variantWidgets
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
padding: const EdgeInsets.all(8),
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
);
|
||||
},
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
|
||||
Text(
|
||||
"Route \n ${route.routeNumber}",
|
||||
style: ShadTheme.of(context).textTheme.h4.copyWith(
|
||||
height: 1.1
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
if (route.routeNumber.toLowerCase().startsWith("ul"))
|
||||
Text(rr, style: const TextStyle(fontSize: 12, fontWeight: FontWeight.w400, height: 1), textAlign: TextAlign.center,)
|
||||
|
||||
|
||||
],
|
||||
),
|
||||
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: EdgeInsets.all(10),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
),
|
||||
);;
|
||||
}
|
||||
|
||||
List<Widget> _getPastRoutes(context) {
|
||||
return [];
|
||||
}
|
||||
189
lib/remaster/WebSocketTest.dart
Normal file
189
lib/remaster/WebSocketTest.dart
Normal file
@@ -0,0 +1,189 @@
|
||||
import 'dart:async';
|
||||
import 'dart:isolate';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:web_socket_channel/web_socket_channel.dart';
|
||||
import 'package:web_socket_channel/status.dart' as status;
|
||||
import 'package:network_info_plus/network_info_plus.dart';
|
||||
import 'package:flutter/foundation.dart' show kIsWeb;
|
||||
|
||||
import '../utils/web_socket_server.dart';
|
||||
|
||||
class WebSocketWidget extends StatefulWidget {
|
||||
@override
|
||||
_WebSocketWidgetState createState() => _WebSocketWidgetState();
|
||||
}
|
||||
|
||||
class _WebSocketWidgetState extends State<WebSocketWidget> {
|
||||
WebSocketChannel? _channel;
|
||||
TextEditingController _controller = TextEditingController();
|
||||
TextEditingController _urlController = TextEditingController(text: 'ws://localhost:8080');
|
||||
List<String> _messages = [];
|
||||
Isolate? _serverIsolate;
|
||||
bool _isServerRunning = false;
|
||||
String? _localIpAddress;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_getLocalIpAddress().then((ip) {
|
||||
setState(() {
|
||||
_localIpAddress = ip;
|
||||
_urlController.text = 'ws://$_localIpAddress:8080';
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Future<String> _getLocalIpAddress() async {
|
||||
if (kIsWeb) {
|
||||
return '127.0.0.1'; // Web does not support getting the local IP address
|
||||
}
|
||||
|
||||
if (Platform.isAndroid || Platform.isIOS) {
|
||||
final info = NetworkInfo();
|
||||
String? ip = await info.getWifiIP();
|
||||
return ip ?? '127.0.0.1'; // Fallback to localhost if no IP is found
|
||||
}
|
||||
|
||||
for (var interface in await NetworkInterface.list()) {
|
||||
for (var addr in interface.addresses) {
|
||||
if (addr.type == InternetAddressType.IPv4 && !addr.isLoopback) {
|
||||
return addr.address;
|
||||
}
|
||||
}
|
||||
}
|
||||
return '127.0.0.1'; // Fallback to localhost if no IP is found
|
||||
}
|
||||
|
||||
void _startServer() async {
|
||||
final receivePort = ReceivePort();
|
||||
_serverIsolate = await Isolate.spawn(webSocketServer, receivePort.sendPort);
|
||||
receivePort.listen((message) {
|
||||
print(message);
|
||||
setState(() {
|
||||
_isServerRunning = true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void _stopServer() {
|
||||
_serverIsolate?.kill(priority: Isolate.immediate);
|
||||
setState(() {
|
||||
_isServerRunning = false;
|
||||
});
|
||||
}
|
||||
|
||||
void _joinWebSocket() {
|
||||
if (_channel != null) {
|
||||
_channel!.sink.close();
|
||||
}
|
||||
setState(() {
|
||||
_channel = WebSocketChannel.connect(Uri.parse(_urlController.text));
|
||||
_channel!.stream.listen((message) {
|
||||
setState(() {
|
||||
_messages.add(message);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void _sendMessage(String message) {
|
||||
if (_channel != null) {
|
||||
_channel!.sink.add(message);
|
||||
setState(() {
|
||||
_messages.add('You: $message'); // Display the sent message
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _closeConnection() {
|
||||
if (_channel != null) {
|
||||
_channel!.sink.close(status.goingAway);
|
||||
setState(() {
|
||||
_channel = null;
|
||||
_messages.clear();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_closeConnection();
|
||||
_stopServer();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
// force portrait mode
|
||||
SystemChrome.setPreferredOrientations([
|
||||
DeviceOrientation.portraitUp,
|
||||
DeviceOrientation.portraitDown,
|
||||
]);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('WebSocket Demo'),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: Icon(Icons.close),
|
||||
onPressed: _closeConnection,
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
children: [
|
||||
if (!_isServerRunning)
|
||||
ElevatedButton(
|
||||
onPressed: _startServer,
|
||||
child: Text('Start WebSocket Server'),
|
||||
)
|
||||
else
|
||||
ElevatedButton(
|
||||
onPressed: _stopServer,
|
||||
child: Text('Stop WebSocket Server'),
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
if (_localIpAddress != null)
|
||||
Text('Server URL: ws://$_localIpAddress:8080'),
|
||||
SizedBox(height: 10),
|
||||
TextField(
|
||||
controller: _urlController,
|
||||
decoration: InputDecoration(labelText: 'WebSocket URL'),
|
||||
onSubmitted: (value) => _joinWebSocket(),
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
ElevatedButton(
|
||||
onPressed: _joinWebSocket,
|
||||
child: Text('Join WebSocket'),
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: _messages.length,
|
||||
itemBuilder: (context, index) {
|
||||
return ListTile(
|
||||
title: Text(_messages[index]),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
TextField(
|
||||
controller: _controller,
|
||||
decoration: InputDecoration(labelText: 'Send a message'),
|
||||
onSubmitted: (text) {
|
||||
_sendMessage(text);
|
||||
_controller.clear();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user