SfDateRangePicker在Flutter中使用时出现错误。

huangapple go评论63阅读模式
英文:

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(),
    ));
  }
}

huangapple
  • 本文由 发表于 2023年2月6日 05:11:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/75355534.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定