- 创建了控制器,但是在别的页面中,无法引用控制器里面的某些变量
如下图:后来发现,是命名的问题, 如果是以 _ 下划线开头的变量,那么就无法被引用
- The following StackOverflowError was thrown building FutureBuilder(dirty, state: _FutureBuilderState#9b90b):
Stack Overflow
The relevant error-causing widget was:
ScreenUtilInit ScreenUtilInit:file:///E:/xxx/TestC.dart:28:25
When the exception was thrown, this was the stack:
#0 new Map._fromLiteral (dart:core-patch/map_patch.dart:17:3)
#1 new RxNotifier (package:get/get_rx/src/rx_types/rx_core/rx_impl.dart:149:63)
原因:错误代码如下
class HomePage extends StatelessWidget{
final MainController mainController = Get.put(MainController());
CupertinoSlidingSegmentedControl<Sky>(
backgroundColor: CupertinoColors.systemGrey2,
thumbColor: Color(0xff16C87A)!,
groupValue: mainController .selectedSegment.value.value,
....
}
正确代码如下:
class HomePage extends StatelessWidget{
// final MainController mainController = Get.put(MainController());
@override
Widget build(BuildContext context) {
return Obx(() => Column(
children: [
CupertinoSlidingSegmentedControl<Sky>(
backgroundColor: CupertinoColors.systemGrey2,
thumbColor: Color(0xff16C87A)!,
groupValue: Get.find<MainController>().selectedSegment.value.value,
....
}