Merge pull request #7 from LinlyBoi/minute-touches

Minute touches
This commit is contained in:
Linly
2023-12-27 19:48:01 +02:00
committed by GitHub
6 changed files with 68 additions and 52 deletions

View File

@@ -1,16 +1,9 @@
# witl
# WITL
A new Flutter project.
"We cannot tell you why the tram is late But surely can predict (sort of) its arrival"
## Getting Started
This project is a starting point for a Flutter application.
Flutter project aimed as a cross-platform extension of the [Native Android Version](https://github.com/LinlyBoi/WITL) of WITL.
A few resources to get you started if this is your first Flutter project:
- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)
For help getting started with Flutter development, view the
[online documentation](https://docs.flutter.dev/), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
Also includes actual usage of our [From Scratch API](https://github.com/LinlyBoi/witl-api) written in Rust and Docker-deployed.

View File

@@ -1,4 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:label="witl"
android:name="${applicationName}"

View File

@@ -15,7 +15,7 @@ Future<List<Arrival>> fetchArrivals() async {
// }));
Iterable I = json.decode(response.body);
List<Arrival> arrivals = List<Arrival>.from(I.map((model)=>Arrival.fromJson(model)));
return arrivals;
return arrivals.reversed.toList();
} else {
throw Exception('Failed to load Arrival');
}

View File

@@ -17,51 +17,71 @@ class _FetchAPIState extends State<FetchAPI> {
return Scaffold(
appBar: AppBar(
title: const Text("Fetching API"),
),
body: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Expanded(
child: SizedBox(
child: FutureBuilder<List<Arrival>>(
future: fetchedArrivals,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const CircularProgressIndicator();
} else if (snapshot.hasError) {
return Text('Failed to fetch data.\nError: ${snapshot.error}');
} else {
return ListView.builder(
itemCount: snapshot.data!.length,
itemBuilder: (context, index) {
return ListTile(
title: Text("Arrival Time: ${snapshot.data![index].timeOfDay}"),
titleAlignment: ListTileTitleAlignment.center,
subtitle: Text("Week Day: ${weekNumToString(snapshot.data![index].weekDay)}"),
);
},
);
}
},
),
),
),
const SizedBox(height: 30,),
InkWell(
onTap: () {
Navigator.pushNamedAndRemoveUntil(context, '/', (route) => false);
actions: [
IconButton(
onPressed: () {
setState(() {
fetchedArrivals = fetchArrivals();
});
},
child: Container(
padding: const EdgeInsets.all(20.0),
child: const Text("Homescreen"),
),
icon: const Icon(Icons.refresh_sharp),
),
const SizedBox(height: 35,),
const SizedBox(width: 30,),
],
),
body: RefreshIndicator(
onRefresh: _refreshData,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Expanded(
child: SizedBox(
child: FutureBuilder<List<Arrival>>(
future: fetchedArrivals,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const CircularProgressIndicator();
} else if (snapshot.hasError) {
return Text('Failed to fetch data.\nError: ${snapshot.error}');
} else {
return ListView.builder(
itemCount: snapshot.data!.length,
itemBuilder: (context, index) {
return ListTile(
title: Text("Arrival Time: ${snapshot.data![index].timeOfDay}"),
titleAlignment: ListTileTitleAlignment.center,
subtitle: Text("Week Day: ${weekNumToString(snapshot.data![index].weekDay)}"),
);
},
);
}
},
),
),
),
const SizedBox(height: 30,),
InkWell(
onTap: () {
Navigator.pushNamedAndRemoveUntil(context, '/', (route) => false);
},
child: Container(
padding: const EdgeInsets.all(20.0),
child: const Text("Homescreen"),
),
),
const SizedBox(height: 35,),
],
),
),
);
}
Future<void> _refreshData() async {
setState(() {
fetchedArrivals = fetchArrivals();
});
}
@override
void initState() {
super.initState();
@@ -88,4 +108,4 @@ String weekNumToString(int weekday) {
}
throw "AAAAAAAAA";
}
}

View File

@@ -24,7 +24,7 @@ class HomeScreen extends StatelessWidget {
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
const Row(
mainAxisAlignment: MainAxisAlignment.center,
children:[
Text("We may not be able to tell you why.\nBut surely are able to predict when."),

View File

@@ -4,5 +4,7 @@
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
</dict>
</plist>