我不知道如何在颤振应用程序的数据库 laragon 中插入日期数据。我已经使用包“flutter_datetime_picker:^1.1.5”完成了插入日期的 GUI,但我不知道如何将选择的日期数据转发到数据库。
我没有选择日期,如下面的代码 .dart 所示。我不知道如何将它从数据库连接到 api。
插入日期.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),
),
以下是 laravel 中发布数据日期的 API。当我在 Postman 中测试运行 API 时,所有数据都可以更新。我只是不知道如何在颤动中发布数据。
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();
}
我想要数据库表中的日期更新。