我该如何解决这个弱警告? "The field doesn’t override an inherited getter or setter."
how can I fix this weak warning? "The field doesn’t override an inherited getter or setter."
显示的是:"The field doesn’t override an inherited getter or setter."
由于这个问题,我无法将我的代码推送到 Git,因为它在测试和分析时失败了。
有什么解决办法的建议吗?我将 _startDate
和 _endDate
移出 Override 但现在它显示: "The method doesn’t override an inherited method."
for displayDatePicker.
import 'package:intl/intl.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:date_range_picker/date_range_picker.dart' as DateRagePicker;
class Datepicker extends StatefulWidget {
@override
_DatepickerState createState() => _DatepickerState();
}
class _DatepickerState extends State<Datepicker> {
DateTime _startDate = DateTime.now();
DateTime _endDate = DateTime.now().add(Duration(days: 7));
@override
Future displayDatePicker(BuildContext context) async {
{
final List<DateTime> picked = await DateRagePicker.showDatePicker(
context: context,
initialFirstDate: _startDate,
initialLastDate: _endDate,
firstDate: new DateTime(DateTime.now().year),
lastDate: new DateTime(DateTime.now().year + 2));
if (picked != null && picked.length == 2) {
setState(() {
_startDate = picked[0];
_endDate = picked[1];
});
}
}
}
@override
Widget build(BuildContext context) {
return Container(
child: Column(
children: [
RaisedButton(
child: Text('select Date'),
onPressed: () async {
await displayDatePicker(context);
},
color: Colors.red,
textColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
side: BorderSide(color: Colors.red)),
),
//Text("from:${_startDate}"),
//Text("until:${_endDate}"),
Text(
"from:${DateFormat('MM/dd/yyyy').format(_startDate).toString()}"),
Text("until:${DateFormat('MM/dd/yyyy').format(_endDate).toString()}")
],
),
);
}
}
displayDatePicker
不是 State<Datepicker>
的方法,因此,我们只需要删除 Future displayDatePicker
:
上面的 @override
行
// remove this line ---> @override
Future displayDatePicker(BuildContext context) async {
{
final List<DateTime> picked = await DateRagePicker.showDatePicker(
context: context,
initialFirstDate: _startDate,
initialLastDate: _endDate,
firstDate: new DateTime(DateTime.now().year),
lastDate: new DateTime(DateTime.now().year + 2));
if (picked != null && picked.length == 2) {
setState(() {
_startDate = picked[0];
_endDate = picked[1];
});
}
}
}
显示的是:"The field doesn’t override an inherited getter or setter."
由于这个问题,我无法将我的代码推送到 Git,因为它在测试和分析时失败了。
有什么解决办法的建议吗?我将 _startDate
和 _endDate
移出 Override 但现在它显示: "The method doesn’t override an inherited method."
for displayDatePicker.
import 'package:intl/intl.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:date_range_picker/date_range_picker.dart' as DateRagePicker;
class Datepicker extends StatefulWidget {
@override
_DatepickerState createState() => _DatepickerState();
}
class _DatepickerState extends State<Datepicker> {
DateTime _startDate = DateTime.now();
DateTime _endDate = DateTime.now().add(Duration(days: 7));
@override
Future displayDatePicker(BuildContext context) async {
{
final List<DateTime> picked = await DateRagePicker.showDatePicker(
context: context,
initialFirstDate: _startDate,
initialLastDate: _endDate,
firstDate: new DateTime(DateTime.now().year),
lastDate: new DateTime(DateTime.now().year + 2));
if (picked != null && picked.length == 2) {
setState(() {
_startDate = picked[0];
_endDate = picked[1];
});
}
}
}
@override
Widget build(BuildContext context) {
return Container(
child: Column(
children: [
RaisedButton(
child: Text('select Date'),
onPressed: () async {
await displayDatePicker(context);
},
color: Colors.red,
textColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
side: BorderSide(color: Colors.red)),
),
//Text("from:${_startDate}"),
//Text("until:${_endDate}"),
Text(
"from:${DateFormat('MM/dd/yyyy').format(_startDate).toString()}"),
Text("until:${DateFormat('MM/dd/yyyy').format(_endDate).toString()}")
],
),
);
}
}
displayDatePicker
不是 State<Datepicker>
的方法,因此,我们只需要删除 Future displayDatePicker
:
@override
行
// remove this line ---> @override
Future displayDatePicker(BuildContext context) async {
{
final List<DateTime> picked = await DateRagePicker.showDatePicker(
context: context,
initialFirstDate: _startDate,
initialLastDate: _endDate,
firstDate: new DateTime(DateTime.now().year),
lastDate: new DateTime(DateTime.now().year + 2));
if (picked != null && picked.length == 2) {
setState(() {
_startDate = picked[0];
_endDate = picked[1];
});
}
}
}