Skip to content

Commit

Permalink
Fix json parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
gereonelvers committed Jan 13, 2024
1 parent 2b0a75e commit 6f9cfe6
Show file tree
Hide file tree
Showing 8 changed files with 584 additions and 349 deletions.
494 changes: 310 additions & 184 deletions lib/screens/booking_screen.dart

Large diffs are not rendered by default.

26 changes: 9 additions & 17 deletions lib/screens/landing_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:value_voyage/util/application_screen.dart';
import 'package:intl/intl.dart';

import '../state/application/application_bloc.dart';
import '../util/utils.dart';

class LandingScreen extends StatelessWidget {
const LandingScreen({super.key});
Expand All @@ -27,21 +28,23 @@ class LandingScreen extends StatelessWidget {
Padding(
padding: const EdgeInsets.all(24.0),
child: DefaultTextStyle(
style: GoogleFonts.inter(textStyle: const TextStyle(fontSize: 48, color: Colors.white)),
style: GoogleFonts.inter(textStyle: const TextStyle(fontSize: 60, color: Colors.white, fontWeight: FontWeight.w400)),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Padding(
padding: EdgeInsets.only(bottom: 40.0),
child: Text("Make your journey "),
child: Text(
"Make your journey ",
),
),
Stack(
children: [
const Center(
child: SizedBox(
height: 200,
width: 300,
height: 235,
width: 400,
),
),
Center(
Expand Down Expand Up @@ -198,23 +201,12 @@ class LandingScreen extends StatelessWidget {
}

submit(ApplicationBloc bloc, BuildContext context) async {
bloc.getMockRoutes();
bloc.getRoutes();
if (bloc.originTextController.text != "" && bloc.destinationTextController.text != "") {
bloc.currentScreen = ApplicationScreen.selection;
bloc.add(UpdateScreenEvent());
} else {
MotionToast(
icon: Icons.error_outline,
displaySideBar: false,
primaryColor: Colors.red,
title: const Text("Error"),
description: const Text("Please fill out all fields."),
position: MotionToastPosition.bottom,
animationType: AnimationType.fromBottom,
animationCurve: Curves.bounceOut,
animationDuration: const Duration(milliseconds: 250),
toastDuration: const Duration(seconds: 2),
).show(context);
Utils.showToast(context, "Error", "Please fill out all fields.");
}
}
}
8 changes: 4 additions & 4 deletions lib/screens/selection_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ class SelectionScreen extends StatelessWidget {
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text("Going from "),
const Text("Connections from "),
MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
onTap: () => applicationBloc.navigateTo(ApplicationScreen.landing),
child: Text(
applicationBloc.originTextController.text,
style: const TextStyle(decoration: TextDecoration.underline, color: Colors.black45),
style: const TextStyle(fontWeight: FontWeight.bold),
)),
),
const Text(" to "),
Expand All @@ -57,7 +57,7 @@ class SelectionScreen extends StatelessWidget {
onTap: () => applicationBloc.navigateTo(ApplicationScreen.landing),
child: Text(
applicationBloc.destinationTextController.text,
style: const TextStyle(decoration: TextDecoration.underline, color: Colors.black45),
style: const TextStyle(fontWeight: FontWeight.bold),
)),
),
const Text(" on "),
Expand All @@ -67,7 +67,7 @@ class SelectionScreen extends StatelessWidget {
onTap: () => applicationBloc.navigateTo(ApplicationScreen.landing),
child: Text(
DateFormat("dd.MM.yy 'after' hh:mm a").format(applicationBloc.time),
style: const TextStyle(decoration: TextDecoration.underline, color: Colors.black45),
style: const TextStyle(fontWeight: FontWeight.bold),
)),
),
],
Expand Down
20 changes: 13 additions & 7 deletions lib/state/application/application_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import 'dart:convert';
import 'dart:math';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:http/http.dart' as http;

import '../../util/application_screen.dart';
import '../../util/route.dart';
import '../../util/utils.dart';

part 'application_event.dart';

Expand All @@ -18,7 +20,14 @@ class ApplicationBloc extends Bloc<ApplicationEvent, ApplicationState> {

List<String> cities = const ["Hamburg", "Berlin", "Munich"];
List<NavigationRoute> routes = [];
int selectedRoute = 0;
NavigationRoute selectedRoute = NavigationRoute(
arrivalTime: DateTime.now(),
departureTime: DateTime.now(),
startAddress: "",
endAddress: "",
steps: const [],
fare: 99.90,
);

double currentInsuranceValue = 2000;
int selectedInsuranceCard = 0;
Expand All @@ -27,7 +36,7 @@ class ApplicationBloc extends Bloc<ApplicationEvent, ApplicationState> {
DateTime time = DateTime.now();

ApplicationBloc() : super(ApplicationInitial()) {
sessionID = generateRandomString(10);
sessionID = Utils.randomString(10);
on<ApplicationEvent>((event, emit) {});
on<UpdateScreenEvent>((event, emit) {
emit(ApplicationUpdating());
Expand Down Expand Up @@ -58,6 +67,7 @@ class ApplicationBloc extends Bloc<ApplicationEvent, ApplicationState> {
departureTime: DateTime.now(),
startAddress: "Hamburg Central Station",
endAddress: "Munich Central Station",
fare: 99.9,
steps: [
NavigationRouteStep(
departureStop: "Hamburg Central Station",
Expand Down Expand Up @@ -100,6 +110,7 @@ class ApplicationBloc extends Bloc<ApplicationEvent, ApplicationState> {
lineShortName: 'N150',
punctuality: 0.58),
],
fare: 99.9,
),
];
add(UpdateScreenEvent());
Expand All @@ -115,11 +126,6 @@ class ApplicationBloc extends Bloc<ApplicationEvent, ApplicationState> {
print(res.body);
}

String generateRandomString(int len) {
var r = Random();
return String.fromCharCodes(List.generate(len, (index) => r.nextInt(33) + 89));
}

navigateTo(ApplicationScreen screen) {
currentScreen = screen;
add(UpdateScreenEvent());
Expand Down
Loading

0 comments on commit 6f9cfe6

Please sign in to comment.