Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/firebase-hosting-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
flutter create --project-name floaty .
flutter config --enable-web
flutter pub get
flutter build web --no-tree-shake-icons
flutter build web --no-tree-shake-icons --dart-define=ENV=prod
- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: '${{ secrets.GITHUB_TOKEN }}'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/firebase-hosting-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
flutter create --project-name floaty .
flutter config --enable-web
flutter pub get
flutter build web --no-tree-shake-icons
flutter build web --no-tree-shake-icons --dart-define=ENV=prod
- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: '${{ secrets.GITHUB_TOKEN }}'
Expand Down
Binary file added assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion lib/CookieAuth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class CookieAuth implements Authentication {

@override
Future<void> applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) async {
final uri = Uri.parse(BASE_URL); // The URL your API is hosted at
final uri = Uri.parse(backendUrl); // The URL your API is hosted at
final cookies = await cookieJar.loadForRequest(uri);

// Find the session token
Expand Down
204 changes: 204 additions & 0 deletions lib/add_flight_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
import 'package:cookie_jar/cookie_jar.dart';
import 'package:floaty/flight_service.dart';
import 'package:floaty/ui_components.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
import 'CookieAuth.dart';
import 'model.dart';

class AddFlightPage extends StatefulWidget {
const AddFlightPage();

@override
_AddFlightPageState createState() => _AddFlightPageState();
}

class _AddFlightPageState extends State<AddFlightPage> {
final _formKey = GlobalKey<FormState>();
bool isFormValid = false;

final TextEditingController dateController = TextEditingController();
final TextEditingController takeoffController = TextEditingController();
final TextEditingController durationController = TextEditingController();
final TextEditingController descriptionController = TextEditingController();

final DateFormat formatter = DateFormat("yyyy-MM-dd'T'HH:mm:ss");

CookieAuth _getCookieAuth() {
CookieJar cookieJar = Provider.of<CookieJar>(context, listen: false);
return CookieAuth(cookieJar);
}

Future<void> _saveNewFlight() async {
try {
final formattedDate = formatter.format(DateTime.parse(dateController.text));

Flight flight = Flight(
flightId: "",
dateTime: formattedDate,
takeOff: takeoffController.text,
duration: int.parse(durationController.text),
description: descriptionController.text,
);

await addFlight(flight, _getCookieAuth());
Navigator.pop(context); // Return to FlightsPage after saving the flight
} catch (e) {
print("Failed to save flight, error: $e");
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: [
const FloatyBackgroundWidget(), // The background remains in the stack
Positioned(
left: 0,
right: 0,
top: 0,
child: Header(), // Header is at the top
),
Positioned(
top: 120.0, // Adjust for header space
left: 0,
right: 0,
bottom: 0, // Ensure the form takes up the remaining space
child: AddFlightContainer(
headerText: "Add New Flight",
child: Form(
key: _formKey,
autovalidateMode: AutovalidateMode.onUserInteraction,
onChanged: () {
setState(() {
isFormValid = _formKey.currentState?.validate() ?? false;
});
},
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TextFormField(
controller: dateController,
decoration: InputDecoration(labelText: "Date (YYYY-MM-DD)"),
validator: (value) {
if (value == null || value.isEmpty || DateTime.tryParse(value) == null || DateTime.parse(value).isAfter(DateTime.now())) {
return "Please enter a valid date.";
}
return null;
},
),
TextFormField(
controller: takeoffController,
decoration: InputDecoration(labelText: "Takeoff Location"),
validator: (value) {
if (value == null || value.isEmpty) {
return "Please enter a takeoff location.";
}
return null;
},
),
TextFormField(
controller: durationController,
decoration: InputDecoration(labelText: "Flight Duration (minutes)"),
validator: (value) {
if (value == null || value.isEmpty || int.tryParse(value) == null) {
return "Please enter a valid duration in minutes.";
}
return null;
},
),
TextFormField(
controller: descriptionController,
decoration: InputDecoration(labelText: "Description"),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// Save Button
ElevatedButton(
onPressed: isFormValid ? _saveNewFlight : null,
child: Text("Save Flight"),
),
SizedBox(width: 16),
// Cancel Button
ElevatedButton(
onPressed: () {
Navigator.pop(context); // Navigate back to the Flights page
},
child: Text("Cancel"),
),
],
),
),
],
),
),
),
),
],
),
);
}
}


class AddFlightContainer extends StatelessWidget {
final String headerText;
final Widget child;

const AddFlightContainer({
Key? key,
required this.headerText,
required this.child,
}) : super(key: key);

@override
Widget build(BuildContext context) {
return Center(
child: Container(
width: 400,
height: 550,
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.7),
borderRadius: BorderRadius.circular(6.0),
),
child: Column(
children: [
// Header Box
Container(
width: double.infinity,
height: 100,
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.8),
borderRadius: const BorderRadius.vertical(
top: Radius.circular(12.0),
),
),
alignment: Alignment.center,
child: Text(
headerText,
style: const TextStyle(
color: Colors.white,
fontSize: 24.0,
fontWeight: FontWeight.bold,
),
),
),
// Child widget (the form input logic)
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 32.0, vertical: 16.0),
child: child,
),
),
],
),
),
);
}
}

2 changes: 1 addition & 1 deletion lib/auth_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'CookieAuth.dart';
import 'constants.dart';

Future<void> logout(int userId, CookieAuth cookieAuth) async {
final apiClient = api.ApiClient(basePath: BASE_URL, authentication: cookieAuth);
final apiClient = api.ApiClient(basePath: backendUrl, authentication: cookieAuth);

final usersApi = api.AuthApi(apiClient);

Expand Down
15 changes: 15 additions & 0 deletions lib/config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Config {
// For Android Emulator use 10.0.2.2
// For iOS Simulator use 127.0.0.1
// For web use actual IP on host
static String get backendUrl {
const String env = String.fromEnvironment('ENV', defaultValue: 'dev');
switch (env) {
case 'prod':
return 'https://test.floatyfly.com'; // TODO: Switch to prod once staging is there.
case 'dev':
default:
return 'http://localhost:8080'; // Local development URL
}
}
}
16 changes: 7 additions & 9 deletions lib/constants.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
const BASE_URL = 'https://test.floatyfly.com';
// const BASE_URL = 'http://localhost:8080';
// const BASE_URL = 'http://10.0.2.2:8080'; // can be used for debugging TODO: Make configurable
// For Android Emulator use 10.0.2.2
// For iOS Simulator use 127.0.0.1
// For web use actual IP on host
// For real device, use actual IP
import 'config.dart';

const HOME_ROUTE = '/';
var backendUrl = Config.backendUrl;

const HOME_ROUTE = '/register';
const LOGIN_ROUTE = '/login';
const REGISTER_ROUTE = '/register';
const FORGOT_PASSWORD_ROUTE = '/forgot-password';
const PROFILE_ROUTE = '/profile';
const FLIGHTS_ROUTE = '/flights';
const FLIGHTS_ROUTE = '/flights';
const ADD_FLIGHT_ROUTE = '/add-flight';
const EMAIL_VERIFICATION_ROUTE = '/email-validation';
Loading
Loading