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(
|
theme: ThemeData(
|
||||||
colorScheme: .fromSeed(seedColor: Colors.yellow),
|
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: {
|
// routes: {
|
||||||
// //'/': (context) => const MyHomePage(title: 'Oeffimaster'),
|
// //'/': (context) => const MyHomePage(title: 'Oeffimaster'),
|
||||||
// '/stations': (context) => const ChooseStationPage(),
|
// '/stations': (context) => const ChooseStationPage(),
|
||||||
@@ -49,17 +50,6 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
List<Station> stationList = [];
|
List<Station> stationList = [];
|
||||||
String id = '';
|
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
|
// TODO :find a better way to show the list
|
||||||
void showResult(Future<List<Station>> futureId) async {
|
void showResult(Future<List<Station>> futureId) async {
|
||||||
stationList = await futureId;
|
stationList = await futureId;
|
||||||
@@ -87,19 +77,19 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: .center,
|
mainAxisAlignment: .center,
|
||||||
children: [
|
children: [
|
||||||
const Text('You have pushed the button this many times:'),
|
// const Text('You have pushed the button this many times:'),
|
||||||
Text(
|
// Text(
|
||||||
'$_counter',
|
// '$_counter',
|
||||||
style: Theme.of(context).textTheme.headlineMedium,
|
// style: Theme.of(context).textTheme.headlineMedium,
|
||||||
),
|
// ),
|
||||||
Text('API key from ENV is $API_KEY'),
|
// Text('API key from ENV is $API_KEY'),
|
||||||
MaterialButton(
|
// MaterialButton(
|
||||||
onPressed: () {
|
// onPressed: () {
|
||||||
showResult(ApiHandler.findStations('S Biesdorf'));
|
// showResult(ApiHandler.findStations('S Biesdorf'));
|
||||||
},
|
// },
|
||||||
child: Text('Search for \'S Biesdorf\''),
|
// child: Text('Search for \'S Biesdorf\''),
|
||||||
),
|
// ),
|
||||||
Text(id),
|
// Text(id),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
@@ -113,8 +103,13 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: FloatingActionButton(
|
||||||
onPressed: _incrementCounter,
|
onPressed: () {
|
||||||
tooltip: 'Increment',
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(builder: (context) => ChooseStationPage()),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
tooltip: 'Start a route',
|
||||||
child: const Icon(Icons.add),
|
child: const Icon(Icons.add),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -514,17 +509,120 @@ class _JourneyOverviewPageState extends State<JourneyOverviewPage> {
|
|||||||
List<Journey> allJourneys = <Journey>[];
|
List<Journey> allJourneys = <Journey>[];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
initState() async {
|
initState() {
|
||||||
super.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
|
// 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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: Center(
|
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 {
|
class JourneyList extends StatelessWidget {
|
||||||
final List<Journey> journeys;
|
final List<Journey> journeys;
|
||||||
|
final Function onTapped;
|
||||||
|
|
||||||
const JourneyList({
|
const JourneyList({
|
||||||
super.key,
|
super.key,
|
||||||
required this.journeys,
|
required this.journeys,
|
||||||
|
required this.onTapped,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -542,7 +643,10 @@ class JourneyList extends StatelessWidget {
|
|||||||
return ListView(
|
return ListView(
|
||||||
children: [
|
children: [
|
||||||
for (Journey jour in journeys)
|
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