只能在具有State对象的类中使用:setState方法只能在具有State对象的类中使用。如果您尝试在没有State对象的类中使用setState方法,将会出现编译错误。 不要在build方法中使用:build方法是用于构建小部件的方法,您不应该在其中使用setState方法。这是因为,每次调用setState方法时,Flutter框架都会重新调用build方法来重建小部...
import 'package:flutter/material.dart'; void main() => runApp(const MenuApp()); class MyCascadingMenu extends StatefulWidget { const MyCascadingMenu({super.key, required this.message}); final String message; @override State<MyCascadingMenu> createState() => _MyCascadingMenuState(); } class...
I'm calling setState on the value of the switch when it's changed. In this example, I'm trying to prevent anything from happening. However, if the user manually slides the switch back, _attemptChange is still called yet the switch does n...