如何解决此“生成函数返回null”错误?

时间:2019-04-18 20:21:06

标签: android flutter stream-builder

我知道这个问题已经问过几次了,我已经尝试了建议的内容,即在正确的位置放置“ return”。我也按照控制台中的说明进行操作,并尝试添加一个空的Container,但是发生的是屏幕变黑。所以这是我的代码:

class SettingsPage extends StatefulWidget {
  @override
  _SettingsPageState createState() => _SettingsPageState();
}

class _SettingsPageState extends State<SettingsPage> {
  @override
  Widget build(BuildContext context) {
    bool isSystemSelected;
    final stream = AllowedCallInheritedWidget.of(context).allowedCallStream;
    return StreamBuilder<String>(
      stream: stream,
      builder: (context, snapshot) {
        if (snapshot.data.toString().contains('PRIORITY_SENDERS_CONTACTS')) {
          isSystemSelected = true;
          return AlertDialog(
            backgroundColor: isSystemSelected ? Colors.blueGrey : Colors.amber,
            title: Text(snapshot.data),
          );
        } else if (snapshot.data
            .toString()
            .contains('PRIORITY_SENDERS_STARRED')) {
          isSystemSelected = true;
          return AlertDialog(
            backgroundColor: isSystemSelected ? Colors.blueGrey : Colors.amber,
            title: Text(snapshot.data),
          );
        } else if (snapshot.data.toString().contains('PRIORITY_SENDERS_ANY')) {
          isSystemSelected = true;
          return AlertDialog(
            backgroundColor: isSystemSelected ? Colors.blueGrey : Colors.amber,
            title: Text(snapshot.data),
          );
        }
      },
    );
  }
}

我想做的是实时更新android系统更改。感谢您的帮助!

编辑:我应该补充一点,“有问题的小部件是:StreamBuilder”

0 个答案:

没有答案