如何在 Flutter 中存储来自 DatePicker 的数据
How to store the data from the DatePicker in Flutter
如何存储用户设置的日期,以便每次 he/she 打开应用程序时,选择的日期都保留在那里,而不是每次都刷新为初始日期.此外,我如何将我拥有的数据从假定的 Screen1.dart 传输到 Screen2.dart
Future<Null> _selectDate(BuildContext context) async {
final DateTime picked = await showDatePicker(
context: context,
initialDate: selectedDate,
firstDate: DateTime(2015, 8),
lastDate: DateTime(2101));
if (picked != null && picked != selectedDate)
setState(() {
selectedDate = picked;
});
}
数据是selectedDate
。转移是指在其他地方使用这个给定的数据来表示找到两个选定日期之间的差异。
您可以使用共享首选项来实现这一点,这是一个与您的情况类似的示例:
saving: prefs.setString('dateTimeLastClicked', currentTime);
loading: reftime_string = prefs.getString('dateTimeLastClicked');
如何存储用户设置的日期,以便每次 he/she 打开应用程序时,选择的日期都保留在那里,而不是每次都刷新为初始日期.此外,我如何将我拥有的数据从假定的 Screen1.dart 传输到 Screen2.dart
Future<Null> _selectDate(BuildContext context) async {
final DateTime picked = await showDatePicker(
context: context,
initialDate: selectedDate,
firstDate: DateTime(2015, 8),
lastDate: DateTime(2101));
if (picked != null && picked != selectedDate)
setState(() {
selectedDate = picked;
});
}
数据是selectedDate
。转移是指在其他地方使用这个给定的数据来表示找到两个选定日期之间的差异。
您可以使用共享首选项来实现这一点,这是一个与您的情况类似的示例:
saving: prefs.setString('dateTimeLastClicked', currentTime);
loading: reftime_string = prefs.getString('dateTimeLastClicked');