我想使用 navigator.pop 将值从第二页传递到第一页,并使用新值initstate或任何其他解决方法刷新或重新加载我的第一页?
我能够在第一页中获取这些值,但无法使用新值刷新或重新加载页面,initstate其中我想在 API 中传递新数据并获取响应...
有什么帮助吗?
我正在从此重定向到列表页面...
getBrand(BuildContext context) async {
tempBrand = await Navigator.push(context,
MaterialPageRoute(builder: (context) => BrandList(widget.subCatID)));
selectedBrand = tempBrand.name;
selectedBrandID = tempBrand.id;
}
Run Code Online (Sandbox Code Playgroud)
现在我在这里传递这些值 navigator.pop
在此处获取价值并传回第一页。
Container(
padding: EdgeInsets.all(10),
child: ListView.separated(
separatorBuilder: (context, index) =>
Divider(color: Color(0xffcccccc)),
itemCount: prodBrands.length,
itemBuilder: (BuildContext context, int index) {
return GestureDetector(
child: InkWell(
onTap: () {
tempProdBrand = ProdBrandListModel.Message(
id: prodBrands[index].id,
name: prodBrands[index].name,
);
Navigator.pop(context, tempProdBrand);
},
child: Container(
child: Text(prodBrands[index].name),
padding: EdgeInsets.all(10.0),
),
),
); …Run Code Online (Sandbox Code Playgroud) 我正在尝试从 flutter 的默认日期选择器小部件中获取日期,但是当我选择日期时,我有时间使用它。我只想要日期而不是时间。如果可能,& 还想更改日期格式。
这是我从某个地方的示例中使用的。
DateTime selectedDate = DateTime.now();
Future<Null> _selectDate(BuildContext context) async {
final DateTime picked = await showDatePicker(
context: context,
initialDate: selectedDate,
firstDate: DateTime(2019),
lastDate: DateTime(2020));
if (picked != null && picked != selectedDate)
setState(() {
selectedDate = picked;
});
}
Run Code Online (Sandbox Code Playgroud)
这是我获得字符串价值的地方。它打印为“2019-04-16 12:18:06.018950”
child: FlatButton(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
onPressed: () {
_selectDate(context);
print("Selected Date = $selectedDate");
},
child: Text(selectedDate == null
? "Select Date"
: selectedDate.toString()),
)),
Run Code Online (Sandbox Code Playgroud)
我只想要这个“2019-04-16 12:18:06.018950”的日期,并改变日期显示的格式,如“dd-mm-yyyy”
这可能吗?