frontend groundwork
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
|
||||
import 'package:anyway/layout.dart';
|
||||
import 'package:anyway/structs/preferences.dart';
|
||||
import 'package:anyway/utils/fetch_trip.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import "package:anyway/structs/trip.dart";
|
||||
|
||||
|
||||
|
||||
class NewTripPage extends StatefulWidget {
|
||||
const NewTripPage({Key? key}) : super(key: key);
|
||||
@@ -9,22 +15,71 @@ class NewTripPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _NewTripPageState extends State<NewTripPage> {
|
||||
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
||||
final TextEditingController latController = TextEditingController();
|
||||
final TextEditingController lonController = TextEditingController();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('New Trip'),
|
||||
),
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
const Text(
|
||||
'Create a new trip',
|
||||
body: Form(
|
||||
key: _formKey,
|
||||
child:
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(15.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
||||
children: <Widget>[
|
||||
TextFormField(
|
||||
decoration: const InputDecoration(hintText: 'Lat'),
|
||||
controller: latController,
|
||||
validator: (String? value) {
|
||||
if (value == null || value.isEmpty || double.tryParse(value) == null){
|
||||
return 'Please enter a floating point number';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
TextFormField(
|
||||
decoration: const InputDecoration(hintText: 'Lon'),
|
||||
controller: lonController,
|
||||
|
||||
validator: (String? value) {
|
||||
if (value == null || value.isEmpty || double.tryParse(value) == null){
|
||||
return 'Please enter a floating point number';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
Divider(height: 15, color: Colors.transparent),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
List<double> startPoint = [
|
||||
double.parse(latController.text),
|
||||
double.parse(lonController.text)
|
||||
];
|
||||
UserPreferences preferences = UserPreferences();
|
||||
preferences.load();
|
||||
Future<Trip> trip = fetchTrip(startPoint, preferences);
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => BasePage(mainScreen: "map", trip: trip)
|
||||
)
|
||||
);
|
||||
}
|
||||
},
|
||||
child: const Text('Create trip'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user