I dont know how to insert date data in database laragon in flutter app. I have done the GUI for the insert date using package "flutter_datetime_picker: ^1.1.5" but I dont know how to forward date data selected to database.
I have dont the select date as shown in code .dart below. I'm not sure how to connect it to api from database.
insertdate.dart
RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0)),
elevation: 4.0,
onPressed: () {
DatePicker.showDatePicker(context,
theme: DatePickerTheme(
containerHeight: 210.0,
),
showTitleActions: true,
minTime: DateTime(2019, 1, 1),
maxTime: DateTime(2030, 12, 31), onConfirm: (date) {
print('confirm $date');
departDate = '${date.year} - ${date.month} - ${date.day}';
setState(() {});
}, currentTime: DateTime.now(), locale: LocaleType.en);
},
child: Container(
alignment: Alignment.center,
height: 50.0,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
children: <Widget>[
Container(
child: Row(
children: <Widget>[
Icon(
Icons.date_range,
size: 25.0,
color: Colors.black.withOpacity(0.5),
),
new Text(
// controller: dateDepartController,
" $departDate",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 18.0),
),
],
),
)
],
),
Text(
" Change",
style: TextStyle(
color: Colors.black.withOpacity(0.5),
fontWeight: FontWeight.bold,
fontSize: 18.0),
),
],
),
),
color: Colors.white.withOpacity(0.8),
),
Below is the API for post data date in laravel. All data can be updated when I test run API in the Postman. I just cant figured out how to post data in the flutter.
api
public function PostTrip(Request $request)
{
$id = $request->id;
$fr_country = $request->fr_country;
$ar_country = $request->ar_country;
$traveller_id = $request->taveller_id;
$departDate = $request->departDate;
$returnDate = $request->returnDate;
$getId = User::where('id',$id)->first()->id;
//// called country based on id ////
$getFCountry = Countries::where('id',$fr_country)->first()->country;
$getACountry = Countries::where('id',$ar_country)->first()->country;
$user = PosTrip::create([
'fr_country' =>$getFCountry,
'ar_country' =>$getACountry,
'traveller_id'=>$getId,
'departDate'=>$departDate,
'returnDate'=>$returnDate,
]);
$datamsg = response()->json([
'success' => array("text"=>"Done!")
]);
return $datamsg->content();
}
I want the date update in table in database.