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 ## 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: Also includes actual usage of our [From Scratch API](https://github.com/LinlyBoi/witl-api) written in Rust and Docker-deployed.
- [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.

View File

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

View File

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

View File

@@ -17,51 +17,71 @@ class _FetchAPIState extends State<FetchAPI> {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: const Text("Fetching API"), title: const Text("Fetching API"),
), actions: [
body: Column( IconButton(
mainAxisAlignment: MainAxisAlignment.start, onPressed: () {
children: [ setState(() {
Expanded( fetchedArrivals = fetchArrivals();
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( icon: const Icon(Icons.refresh_sharp),
padding: const EdgeInsets.all(20.0),
child: const Text("Homescreen"),
),
), ),
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 @override
void initState() { void initState() {
super.initState(); super.initState();

View File

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

View File

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