android 有关抖动滑块的问题(errors_patch.dart ->Assert错误抛出新错误)

np8igboo  于 2022-12-31  发布在  Android
关注(0)|答案(1)|浏览(126)

我对Flutter还是个新手,我尝试使用外部 *syncfusion_flutter_slider * 库实现一个带除法的水平滑块。
下面是我的实现尝试:

class SliderExample extends StatefulWidget {
  const SliderExample({super.key});
  @override
  State<SliderExample> createState() => _SliderExampleState();
}

class _SliderExampleState extends State<SliderExample> {
  final double _min = 0;
  final double _max = 100;
  double _value = 40.0;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: SfSlider(
          min: _min,
          max: _max,
          value: _value,
          interval: 20,
          showTicks: true,
          showLabels: true,
          onChanged: (dynamic newValue) {
            setState(() {
              _value = newValue;
            });
          },
        ),
      ),
    );
  }
}

在另一个无状态路由中调用上述有状态小部件时,会抛出以下错误:

错误-〉错误补丁.dart

@pragma("vm:external-name", "AssertionError_throwNew")
external static _doThrowNew(
    int assertionStart, int assertionEnd, Object? message);

打电话

return Scaffold(
  body:
    Container(
      alignment: Alignment.center,
      decoration: const BoxDecoration(
          gradient: LinearGradient(colors: [Colors.orangeAccent, Colors.deepOrange]),
      ),
      child: ListView(
        children: const <Widget>[
          Text('\n\n\nHow Many People Did You Meet Today?',
              textAlign: TextAlign.justify,
              style: TextStyle(fontSize: 40, color: Colors.black, fontWeight: FontWeight.bold)
          ),
          MaterialApp(
            home: SliderExample(), // <-- HERE
          )
        ]
      ),
  ),
);

flutter库的资源如下:https://pub.dev/packages/syncfusion_flutter_sliders ;请原谅,如果这是一个基本的修复,鉴于事实上,我正试图通过使用Flutter Docs从头开始制作一个应用程序来学习。

x6h2sr28

x6h2sr281#

尝试将代码的这一部分更改为

child: ListView(
        children: const <Widget>[
          Text('\n\n\nHow Many People Did You Meet Today?',
              textAlign: TextAlign.justify,
              style: TextStyle(fontSize: 40, color: Colors.black, fontWeight: FontWeight.bold)
          ),
          SliderExample(),
        ]
      ),

你不应该在那里打电话给MaterialApp(home: )
_SliderExampleState中,将以下部分更改为以下内容

Widget build(BuildContext context) {
  return SfSlider(
    min: _min,
    max: _max,
    value: _value,
    interval: 20,
    showTicks: true,
    showLabels: true,
    onChanged: (dynamic newValue) {
      setState(() {
        _value = newValue;
      });
    },
  );
}

拆下ScaffoldCenter中的 Package 。

相关问题