Public Access
feat(ui): show journeys on homescreen and add route to journeyDetails
also clean up clutter from homescreen
This commit is contained in:
+135
-31
@@ -24,7 +24,8 @@ class MyApp extends StatelessWidget {
|
||||
theme: ThemeData(
|
||||
colorScheme: .fromSeed(seedColor: Colors.yellow),
|
||||
),
|
||||
home: const MyHomePage(title: 'Oeffimaster'), //this is what matters
|
||||
// home: const MyHomePage(title: 'Oeffimaster'), //this is what matters
|
||||
home: const JourneyOverviewPage(),
|
||||
// routes: {
|
||||
// //'/': (context) => const MyHomePage(title: 'Oeffimaster'),
|
||||
// '/stations': (context) => const ChooseStationPage(),
|
||||
@@ -49,17 +50,6 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
List<Station> stationList = [];
|
||||
String id = '';
|
||||
|
||||
void _incrementCounter() {
|
||||
setState(() {
|
||||
// This call to setState tells the Flutter framework that something has
|
||||
// changed in this State, which causes it to rerun the build method below
|
||||
// so that the display can reflect the updated values. If we changed
|
||||
// _counter without calling setState(), then the build method would not be
|
||||
// called again, and so nothing would appear to happen.
|
||||
_counter++;
|
||||
});
|
||||
}
|
||||
|
||||
// TODO :find a better way to show the list
|
||||
void showResult(Future<List<Station>> futureId) async {
|
||||
stationList = await futureId;
|
||||
@@ -87,19 +77,19 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
child: Column(
|
||||
mainAxisAlignment: .center,
|
||||
children: [
|
||||
const Text('You have pushed the button this many times:'),
|
||||
Text(
|
||||
'$_counter',
|
||||
style: Theme.of(context).textTheme.headlineMedium,
|
||||
),
|
||||
Text('API key from ENV is $API_KEY'),
|
||||
MaterialButton(
|
||||
onPressed: () {
|
||||
showResult(ApiHandler.findStations('S Biesdorf'));
|
||||
},
|
||||
child: Text('Search for \'S Biesdorf\''),
|
||||
),
|
||||
Text(id),
|
||||
// const Text('You have pushed the button this many times:'),
|
||||
// Text(
|
||||
// '$_counter',
|
||||
// style: Theme.of(context).textTheme.headlineMedium,
|
||||
// ),
|
||||
// Text('API key from ENV is $API_KEY'),
|
||||
// MaterialButton(
|
||||
// onPressed: () {
|
||||
// showResult(ApiHandler.findStations('S Biesdorf'));
|
||||
// },
|
||||
// child: Text('Search for \'S Biesdorf\''),
|
||||
// ),
|
||||
// Text(id),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
@@ -113,8 +103,13 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: _incrementCounter,
|
||||
tooltip: 'Increment',
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => ChooseStationPage()),
|
||||
);
|
||||
},
|
||||
tooltip: 'Start a route',
|
||||
child: const Icon(Icons.add),
|
||||
),
|
||||
);
|
||||
@@ -514,17 +509,120 @@ class _JourneyOverviewPageState extends State<JourneyOverviewPage> {
|
||||
List<Journey> allJourneys = <Journey>[];
|
||||
|
||||
@override
|
||||
initState() async {
|
||||
initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
// void retry() async {
|
||||
// // retry with setstate
|
||||
// await Future.delayed(Duration(milliseconds: 1300));
|
||||
// setState(() {});
|
||||
// }
|
||||
|
||||
Future<List<Journey>> loadJourneys() async {
|
||||
// TODO: implement batch query to get a list (all) of journeys
|
||||
allJourneys = await Journey.dbGetAll();
|
||||
List<Journey> journeys;
|
||||
if (allJourneys.isEmpty) {
|
||||
await Future.delayed(Duration(milliseconds: 500));
|
||||
journeys = await Journey.dbGetAll();
|
||||
allJourneys = journeys;
|
||||
} else {
|
||||
journeys = allJourneys;
|
||||
}
|
||||
return journeys;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
child: JourneyList(journeys: allJourneys),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
FutureBuilder(
|
||||
future: loadJourneys(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
spacing: 16,
|
||||
children: [
|
||||
const CircularProgressIndicator(),
|
||||
const Text('Loading Journeys...'),
|
||||
],
|
||||
);
|
||||
}
|
||||
if (snapshot.hasError) {
|
||||
return Column(
|
||||
children: [
|
||||
Text('couldn\'t load Journeys'),
|
||||
// ElevatedButton(
|
||||
// onPressed: () {
|
||||
// Future.delayed(Duration(milliseconds: 300));
|
||||
// setState(() {});
|
||||
// },
|
||||
// child: const Text('retry'),
|
||||
// ),
|
||||
],
|
||||
);
|
||||
}
|
||||
if (snapshot.hasData == false) {
|
||||
return Column(
|
||||
children: [
|
||||
Text('No journeys found'),
|
||||
// ElevatedButton(
|
||||
// onPressed: () {
|
||||
// Future.delayed(Duration(milliseconds: 300));
|
||||
// setState(() {});
|
||||
// },
|
||||
// child: const Text('retry'),
|
||||
// ),
|
||||
],
|
||||
);
|
||||
}
|
||||
return Expanded(
|
||||
child: SizedBox(
|
||||
height: 1,
|
||||
child: JourneyList(
|
||||
journeys: snapshot.data!,
|
||||
onTapped: _handleJourneyTapped,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ChooseStationPage(),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: const Text('Start a route'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => ChooseStationPage()),
|
||||
);
|
||||
},
|
||||
tooltip: 'Start a route',
|
||||
child: const Icon(Icons.add),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _handleJourneyTapped(Journey journey) async {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => JourneyDetailPage(singleJourney: journey),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -532,9 +630,12 @@ class _JourneyOverviewPageState extends State<JourneyOverviewPage> {
|
||||
|
||||
class JourneyList extends StatelessWidget {
|
||||
final List<Journey> journeys;
|
||||
final Function onTapped;
|
||||
|
||||
const JourneyList({
|
||||
super.key,
|
||||
required this.journeys,
|
||||
required this.onTapped,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -542,7 +643,10 @@ class JourneyList extends StatelessWidget {
|
||||
return ListView(
|
||||
children: [
|
||||
for (Journey jour in journeys)
|
||||
ListTile(title: Text('${jour.startStation} to ${jour.endStation}')),
|
||||
ListTile(
|
||||
title: Text('${jour.startStation} to ${jour.endStation}'),
|
||||
onTap: () => onTapped(jour),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user