英文:
Error when using SfDateRangePicker Flutter
问题
这个错误是在添加导入语句后立即发生的:
import 'package:syncfusion_flutter_datepicker/datepicker.dart';
不需要剩余的代码来重现这个错误。
错误信息:
../../snap/flutter/common/flutter/.pub-cache/hosted/pub.dartlang.org/syncfusion_flutter_datepicker-20.4.48/lib/src/date_picker/date_picker.dart:7596:37: 错误: 参数类型 'ScrollableState?' 无法分配给参数类型 'ScrollableState',因为 'ScrollableState?' 是可空的,而 'ScrollableState' 不是。
- 'ScrollableState' 来自 'package:flutter/src/widgets/scrollable.dart' ('../../snap/flutter/common/flutter/packages/flutter/lib/src/widgets/scrollable.dart')。
scrollableState: Scrollable.of(context),
希望这对你有帮助。
英文:
This error happens as soon as I add the import statement:
import 'package:syncfusion_flutter_datepicker/datepicker.dart';
Remaining code is not needed to recreate this error
Code:
import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_datepicker/datepicker.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
// static const String _title = 'Flutter Code Sample';
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child: SfDateRangePicker(),
));
}
}
Error:
../../snap/flutter/common/flutter/.pub-cache/hosted/pub.dartlang.org/syncfusion_flutter_datepicker-20.4.48/lib/src/date_picker/date_picker.dart:7596:37: Error: The argument type 'ScrollableState?' can't be assigned to the parameter type 'ScrollableState' because 'ScrollableState?' is nullable and 'ScrollableState' isn't.
- 'ScrollableState' is from 'package:flutter/src/widgets/scrollable.dart' ('../../snap/flutter/common/flutter/packages/flutter/lib/src/widgets/scrollable.dart').
scrollableState: Scrollable.of(context),
答案1
得分: 2
这个错误在这个问题中提到。
https://github.com/syncfusion/flutter-examples/issues/730
你应该在pubspec.yaml文件中修复syncfusion_flutter_datepicker的版本。
不要使用版本:
syncfusion_flutter_datepicker: ^20.4.48
使用这样:
syncfusion_flutter_datepicker: "20.4.44"
https://github.com/syncfusion/flutter-examples/issues/730#issuecomment-1413788831
英文:
This error is mentioned on this issue.
https://github.com/syncfusion/flutter-examples/issues/730
You should fix version of syncfusion_flutter_datepicker in pubspec.yaml
Don't use version:
syncfusion_flutter_datepicker: ^20.4.48
Use like this:
syncfusion_flutter_datepicker: "20.4.44"
https://github.com/syncfusion/flutter-examples/issues/730#issuecomment-1413788831
答案2
得分: -1
用MaterialApp包装你的脚手架
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SfDateRangePicker(),
));
}
}
英文:
Wrap your scaffold with MaterialApp
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SfDateRangePicker(),
));
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论