-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
158 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": "경희대정문(사색행)" | ||
|
||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')} 도착 예정', | ||
), | ||
), | ||
); | ||
}, | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |