Skip to content

Commit

Permalink
passedby
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian0KIM committed Nov 28, 2024
1 parent 19c353e commit c61505a
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 4 deletions.
2 changes: 1 addition & 1 deletion back/database/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ function getStaOrder(stationId, routeId) {
}

let lastApiCall = null;
const API_CALL_INTERVAL = 5000; // 5초
const API_CALL_INTERVAL = 1000; // 5초

// 캐시 파일 경로
const CACHE_FILE_PATH = path.join(__dirname, 'pastBusCache.json');
Expand Down
File renamed without changes.
24 changes: 24 additions & 0 deletions front/lib/bus_info.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const Map<String,String> busRouteMap={
"200000103": "9",
"234000016": "1112",
"200000115": "5100",
"200000112": "7000",
"234001243": "M5107",
"234000884": "1560A",
"228000433": "1560B"
};
const Map<String,String> stationMap = {
"228001174": "사색의광장(정문행)",
"228000704": "생명과학대.산업대학(정문행)",
"228000703": "경희대체육대학.외대(정문행)",
"203000125": "경희대학교(정문행)",
"228000723": "경희대정문(사색행)",
"228000710": "외국어대학(사색행)",
"228000709": "생명과학대(사색행)",
"228000708": "사색의광장(사색행)",
"228000706": "경희대차고지(1)",
"228000707": "경희대차고지(2)"
//"203000037": "경희대정문(사색행)"


};
14 changes: 11 additions & 3 deletions front/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'busCompany.dart';
import 'bus_company.dart';
import "bus_info.dart";
import "passed_bus_page.dart";
void main() {
runApp(const MyApp());
}
Expand All @@ -26,7 +28,7 @@ class LoginScreen extends StatefulWidget {
const LoginScreen({super.key});

@override
_LoginScreenState createState() => _LoginScreenState();
State<LoginScreen> createState() => _LoginScreenState();
}

class _LoginScreenState extends State<LoginScreen> {
Expand Down Expand Up @@ -189,7 +191,7 @@ class NavigationBarScreen extends StatefulWidget {
});

@override
_NavigationBarScreenState createState() => _NavigationBarScreenState();
State<NavigationBarScreen> createState() => _NavigationBarScreenState();
}

class _NavigationBarScreenState extends State<NavigationBarScreen> {
Expand Down Expand Up @@ -513,6 +515,12 @@ class ComplaintServiceScreen extends StatelessWidget {
),
onPressed: () {
// 방금 지나간 버스 버튼 동작
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const PassedBusPage(),
),
);
},
child: const Text('방금 지나간 버스'),
),
Expand Down
122 changes: 122 additions & 0 deletions front/lib/passed_bus_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';

class PassedBusPage extends StatefulWidget {
const PassedBusPage({super.key});

@override
State<PassedBusPage> createState() => _PassedBusPageState();
}

class _PassedBusPageState extends State<PassedBusPage> {
String currentStationId = "228000723"; // 기본값: 사색방향
List<dynamic> busData = [];
bool isLoading = false;

@override
void initState() {
super.initState();
fetchBusData();
}

Future<void> fetchBusData() async {
setState(() {
isLoading = true;
});

try {
final response = await http.get(
Uri.parse('http://localhost:8081/complain/$currentStationId/passedby'),
);

if (response.statusCode == 200) {
final data = json.decode(response.body);
if (data['ok']) {
setState(() {
busData = data['data'];
});
}
}
} catch (e) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('오류 발생: $e')),
);
}
} finally {
setState(() {
isLoading = false;
});
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: IconButton(
icon: const Icon(Icons.arrow_back),
onPressed: () => Navigator.pop(context),
),
title: const Text('방금 지나간 버스'),
),
body: Column(
children: [
Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SegmentedButton<String>(
segments: const [
ButtonSegment<String>(
value: "228000723",
label: Text("사색방향"),
),
ButtonSegment<String>(
value: "203000125",
label: Text("정문방향"),
),
],
selected: {currentStationId},
onSelectionChanged: (Set<String> newSelection) {
setState(() {
currentStationId = newSelection.first;
});
fetchBusData();
},
),
],
),
),
Expanded(
child: isLoading
? const Center(child: CircularProgressIndicator())
: ListView.builder(
itemCount: busData.length,
itemBuilder: (context, index) {
final bus = busData[index];
final expectedArrival = DateTime.parse(bus['expectedArrival']).toLocal();

return Card(
margin: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
child: ListTile(
leading: const Icon(Icons.check, 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')} 도착 예정',
),
),
);
},
),
),
],
),
);
}
}

0 comments on commit c61505a

Please sign in to comment.