POST broke ;-;
This commit is contained in:
@@ -4,8 +4,11 @@ import 'package:http/http.dart' as http;
|
||||
import 'package:witl/arrival.dart';
|
||||
|
||||
Future<Arrival> insertArrival(String date, int weekday, int line, bool direction) async {
|
||||
final client = http.Client();
|
||||
|
||||
try {
|
||||
// POST response as JSON
|
||||
final response = await http.post(
|
||||
final response = await client.post(
|
||||
Uri.parse('http://141.144.238.26:48502/arrivals/insert'),
|
||||
headers: <String, String> {
|
||||
// Headers used
|
||||
@@ -18,11 +21,16 @@ Future<Arrival> insertArrival(String date, int weekday, int line, bool direction
|
||||
'tram_line': line,
|
||||
'direction': direction,
|
||||
})
|
||||
);
|
||||
).timeout(const Duration(seconds: 10));
|
||||
|
||||
if (response.statusCode == 201) {
|
||||
return Arrival.fromJson(jsonDecode(response.body) as Map<String, dynamic>);
|
||||
} else {
|
||||
throw Exception('Insertion Failure.');
|
||||
}
|
||||
} catch (error) {
|
||||
throw Exception("Error Posting: $error");
|
||||
} finally {
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,8 @@ class MyApp extends StatefulWidget {
|
||||
@override
|
||||
State<MyApp> createState() => _MyAppState();
|
||||
|
||||
static _MyAppState of(BuildContext context) => context.findAncestorStateOfType<_MyAppState>()!;
|
||||
static _MyAppState of(BuildContext context) =>
|
||||
context.findAncestorStateOfType<_MyAppState>()!;
|
||||
}
|
||||
|
||||
class _MyAppState extends State<MyApp> {
|
||||
@@ -67,10 +68,13 @@ class _MyAppState extends State<MyApp> {
|
||||
switch(newTheme) {
|
||||
case "Light":
|
||||
_theme = ThemeMode.light;
|
||||
break;
|
||||
case "Dark":
|
||||
_theme = ThemeMode.dark;
|
||||
break;
|
||||
case "System Default":
|
||||
_theme = ThemeMode.system;
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user