0

当我开始调试应用程序(单击运行)时,CupertinoPicker 运行良好,但是当我重新启动应用程序(不调试,关闭应用程序,然后在我的设备上打开它)时,即使列表已成功初始化,Cupertino 也没有显示任何内容. SharedPrefences 在 initState 函数中初始化的列表。可能是什么原因?

List<Widget> modelBuilder<M>(
      List<M> models, Widget Function(int index, M model) builder) =>
  models
      .asMap()
      .map<int, Widget>(
          (index, model) => MapEntry(index, builder(index, model)))
      .values
      .toList();
Widget buildChosenExeOrRestPicker() => SizedBox(
    height: 170,
    child: CupertinoPicker(
      scrollController: ctrl,
      magnification: 1.3,
      useMagnifier: true,
      itemExtent: 45,
      diameterRatio: 1.1,
      looping: false,
      onSelectedItemChanged: (index){
        setState((){
          this.indexOfExeOrRest = index;
          if (timeCounters[indexOfExeOrRest] ==
              timerCountersToInitilalize[indexOfExeOrRest]) {
            visibleRefresh = false;
          } else {
            visibleRefresh = true;
          }
        });
      },
      selectionOverlay: CupertinoPickerDefaultSelectionOverlay(
        background: (pickerExeOrRest.length > 0)
            ? Colors.cyanAccent.withOpacity(0.12)
            : Colors.transparent,
      ),
      children: modelBuilder<PickerExeOrRest>(
        pickerExeOrRest,
        (index, value) {
          final isSelected = this.indexOfExeOrRest == index;
          final color = isSelected ? Colors.pink : Colors.black;

          return Center(
            child: Text(
              '${value.time + ', ' + value.name}',
              style: TextStyle(
                  color: color.withOpacity(opacityCupertino), fontSize: 24),
            ),
          );
        },
      ),
    ),
  );

列表 (pickerExeOrRest) 在 initState 方法中从 SharedPrefences 获取数据。

4

0 回答 0