Skip to content

Commit

Permalink
bus_screen 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian0KIM committed Nov 29, 2024
1 parent c61505a commit 48f781f
Show file tree
Hide file tree
Showing 3 changed files with 191 additions and 6 deletions.
178 changes: 178 additions & 0 deletions front/lib/bus_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
class BusScreen extends StatelessWidget {
const BusScreen({super.key});

// 버스 노선별 색상 지정
Color getBusColor(String routeNumber) {
switch (routeNumber) {
case "9":
return const Color(0xff33CC99); // 지선버스
case "1112":
return const Color(0xffE60012); // 지선버스
case "5100":
return const Color(0xffE60012); // 광역버스
case "7000":
return const Color(0xffE60012); // 광역버스
case "M5107":
return const Color(0xff006896); // M버스
case "1560A":
return const Color(0xffE60012); // 지선버스
case "1560B":
return const Color(0xffE60012); // 지선버스
default:
return Colors.black;
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('버스 정보'),
),
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
_buildBusRouteCard(
routeNumber: "9",
operationTime: "기점 평일 06:30~22:50, 주말 06:30~22:50",
routeInfo: "사색의광장<->금곡LG1단지.와이씨티6단지)",
),
const SizedBox(height: 10),
_buildBusRouteCard(
routeNumber: "1112",
operationTime: "기점 평일 04:40~22:30, 주말 04:40~22:30",
routeInfo: "사색의광장<->테크노마트앞.강변역(C)",
),
const SizedBox(height: 10),
_buildBusRouteCard(
routeNumber: "5100",
operationTime: "기점 평일 05:30~00:10, 주말 05:30~23:20",
routeInfo: "사색의광장<->신분당선강남역(중)",
),
const SizedBox(height: 10),
_buildBusRouteCard(
routeNumber: "7000",
operationTime: "기점 평일 05:30~00:00, 주말 05:30~23:30",
routeInfo: "사색의광장<->사당역4번출구",
),
const SizedBox(height: 10),
_buildBusRouteCard(
routeNumber: "M5107",
operationTime: "기점 평일 05:00~23:00, 주말 05:00~23:00",
routeInfo: "경희대학교<->서울역버스환승센터(6번승강장)(중)",
),
const SizedBox(height: 10),
_buildBusRouteCard(
routeNumber: "1560A",
operationTime: "기점 평일 05:30~11:30, 주말 05:00~11:20",
routeInfo: "경희대학교<->신분당선강남역(중)",
),
_buildBusRouteCard(
routeNumber: "1560B",
operationTime: "기점 평일 11:50~22:30, 주말 11:50~22:30",
routeInfo: "경희대학교<->신분당선강남역(중)",
),
],
),
),
),
);
}

Widget _buildBusRouteCard({
required String routeNumber,
required String operationTime,
required String routeInfo,
}) {
return Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0),
side: const BorderSide(color: Colors.lightBlue, width: 2),
),
elevation: 4,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(
Icons.directions_bus,
size: 24,
color: getBusColor(routeNumber), // 노선별 색상 적용
),
const SizedBox(width: 8),
Text(
routeNumber,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: getBusColor(routeNumber), // 노선 번호도 같은 색상 적용
),
),
],
),
const SizedBox(height: 12),
Row(
children: [
const Icon(Icons.access_time, size: 16),
const SizedBox(width: 8),
Expanded(
child: Text(
operationTime,
style: const TextStyle(fontSize: 14),
),
),
],
),
const SizedBox(height: 8),
Row(
children: [
const Icon(Icons.route, size: 16),
const SizedBox(width: 8),
Expanded(
child: Text(
routeInfo,
style: const TextStyle(fontSize: 14),
),
),
],
),
const SizedBox(height: 12),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
OutlinedButton(
style: OutlinedButton.styleFrom(
foregroundColor: Colors.lightBlue,
side: const BorderSide(color: Colors.lightBlue),
),
onPressed: () {
// 버스 시간표 조회 기능 구현
},
child: const Text('버스 시간표 조회'),
),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
foregroundColor: Colors.white,
),
onPressed: () {
// 버스 도착 정보 조회 기능 구현
},
child: const Text('버스 도착 정보 조회'),
),
],
),
],
),
),
);
}
}
5 changes: 3 additions & 2 deletions front/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'dart:convert';
import 'bus_company.dart';
import "bus_info.dart";
import "passed_bus_page.dart";
import "bus_screen.dart";
void main() {
runApp(const MyApp());
}
Expand Down Expand Up @@ -204,7 +205,7 @@ class _NavigationBarScreenState extends State<NavigationBarScreen> {
super.initState();
_pages = [
const ComplaintServiceScreen(), // 민원 화면
const Center(child: Text('버스 화면')), // 버스 화면
const BusScreen(), // 버스 화면
const Center(child: Text('지도 화면')), // 지도 화면
const Center(child: Text("정류장 화면")), // 정류장 화면
UserInfoScreen(
Expand Down Expand Up @@ -653,7 +654,7 @@ class CompanyInfoPage extends StatelessWidget {
icon: const Icon(Icons.arrow_back),
onPressed: () => Navigator.pop(context),
),
title: Text('${company['name']} 서비스'),
title: Text('${company['name']}'),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
Expand Down
14 changes: 10 additions & 4 deletions front/lib/passed_bus_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class _PassedBusPageState extends State<PassedBusPage> {
value: "203000125",
label: Text("정문방향"),
),

],
selected: {currentStationId},
onSelectionChanged: (Set<String> newSelection) {
Expand All @@ -86,6 +87,11 @@ class _PassedBusPageState extends State<PassedBusPage> {
});
fetchBusData();
},
style: ButtonStyle(
side: WidgetStateProperty.all(
const BorderSide(color: Colors.blue),
),
),
),
],
),
Expand All @@ -97,18 +103,18 @@ class _PassedBusPageState extends State<PassedBusPage> {
itemCount: busData.length,
itemBuilder: (context, index) {
final bus = busData[index];
final expectedArrival = DateTime.parse(bus['expectedArrival']).toLocal();

final expectedArrival = DateTime.parse(bus['expectedArrival']);
final formattedTime = '${expectedArrival.hour.toString().padLeft(2, '0')}:${expectedArrival.minute.toString().padLeft(2, '0')}';
return Card(
margin: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
child: ListTile(
leading: const Icon(Icons.check, color: Colors.blue),
leading: const Icon(Icons.directions_bus, color: Colors.blue),
title: Text(
bus['routeName'],
style: const TextStyle(fontWeight: FontWeight.bold),
),
subtitle: Text(
'${bus['plateNo']}\n${expectedArrival.hour}:${expectedArrival.minute.toString().padLeft(2, '0')} 도착 예정',
'${bus['plateNo']}\n$formattedTime 도착 예정',
),
),
);
Expand Down

0 comments on commit 48f781f

Please sign in to comment.