0% found this document useful (0 votes)
2 views

add driver code

The document outlines a Flutter widget for adding a new trip, featuring a form with fields for start time, vehicle selection, source address, and driver ID. It includes validation for required fields and navigates to a trip details screen upon submission. The widget utilizes various custom components for input and date selection, and handles the display of results through a popup function.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

add driver code

The document outlines a Flutter widget for adding a new trip, featuring a form with fields for start time, vehicle selection, source address, and driver ID. It includes validation for required fields and navigates to a trip details screen upon submission. The widget utilizes various custom components for input and date selection, and handles the display of results through a popup function.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

import 'package:flutter/material.

dart';
import 'package:intl/intl.dart';
import
'package:list_of_projects/yaantrac/new_module/Screens/view_TripDetailsScreen.dart';

import '../Widgets/Custom_TextField.dart';
import '../Widgets/dateTimeComponent.dart';

class AddNewTripScreen extends StatelessWidget {

final TextEditingController startTimeController = TextEditingController();


final TextEditingController selectVehicleController = TextEditingController();
final TextEditingController sourceAddressController = TextEditingController();
final TextEditingController driverIdController = TextEditingController();

final GlobalKey<FormState> formKey = GlobalKey<FormState>();

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Add New Trip"),
leading: IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () {

},
),
backgroundColor: Colors.blue,
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: SingleChildScrollView(
child: Form(
key: formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Center(
child: Text(
"Driver Details",
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
),
const SizedBox(height: 10),
DateComponent(
Controller:startTimeController ,
placholder: "Select Date and Time",
name: "dateTime",
firtstDate: DateTime.now(),
//dateFormat: DateFormat('dd/MM/yyyy HH:mm'), // Custom format
for DD/MM/YYYY HH:mm
// initialDate: DateTime.now(),
labelName: "Start Time",
onchange: (selectedDate) {
print(selectedDate); // Do something with the selected date
},
),
AutoCustomTextField(
name: "select_vehicle",
placeHolder: "Select Vehicle",
labelName: "Select Vehicle",
suffixIcon: const Icon(Icons.arrow_drop_down),
textEditingController: selectVehicleController,
suffixClick: () {
print('object');

},
validators: [
(value) {
if (value == null || value.isEmpty) {
return "Vehicle is required";
}
return null;
},
],
),
AutoCustomTextField(
name: "source_address",
placeHolder: "Search Location",
labelName: "Source Address",
suffixIcon: const Icon(Icons.search),
textEditingController: sourceAddressController,
onTap: () {

},
validators: [
(value) {
if (value == null || value.isEmpty) {
return "Source Address is required";
}
return null;
},
],
),
AutoCustomTextField(
name: "driver_id",
placeHolder: "Driver ID",
labelName: "Driver ID",
textEditingController: driverIdController,
validators: [
(value) {
if (value == null || value.isEmpty) {
return "Driver ID is required";
}
return null;
},
],
),

const SizedBox(height: 5),


Center(
child: ElevatedButton(
onPressed: () async {
if (formKey.currentState!.validate()) {
final tripDetails = {
"start_time": startTimeController.text,
"select_vehicle": selectVehicleController.text,
"source_address": sourceAddressController.text,
"driver_id": driverIdController.text,
};
startTimeController.text.trim();
sourceAddressController.text.trim();
// Navigate to TripDetailsScreen and wait for result
final result = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => TripDetailsScreen(
tripDetails: tripDetails,
),
),
);

if (result != null ) {
PopUpFunction(result);
print(result.toString());
print("result.toString()");

print(result.toString().length);

}
}
},
child: const Text("Submit"),
),
),

],
),
),
),
),
);
}
PopUpFunction(result)
{
startTimeController.text = result["start_time"] ?? "";
selectVehicleController.text =
result["select_vehicle"] ?? "";
sourceAddressController.text =
result["source_address"] ?? "";
driverIdController.text = result["driver_id"] ?? "";
}
}

You might also like