小编ica*_*edo的帖子

setState 不更新用户界面

在使用在计时器的帮助下自我更新的有状态小部件时,我一直面临一些与 setState 函数相关的问题。下面的代码显示了 2 个主要类,它们复制了我是如何发现此错误的。文本小部件“Lorem”应在 10 秒内插入 - 确实如此 - 但它从未显示。我尝试调试数组“Items”,它确实在 5 秒后包含“lorem”文本小部件,它应该如此。“构建”函数运行但在 UI 中没有任何区别。

class textList extends StatefulWidget {

  @override
  State<StatefulWidget> createState() =>
      new _textListState();
}

class _textListState extends State<textList>
    with TickerProviderStateMixin {

  List<Widget> items = new List();
  Widget lorem = new textClass("Lorem");
  Timer timer;

  @override
  void initState() {
    super.initState();

    items.add(new textClass("test"));
    items.add(new textClass("test"));

    timer = new Timer.periodic(new Duration(seconds: 5), (Timer timer) {
      setState(() {
        items.removeAt(0);
        items.add(lorem);
      });
    });
  }

  @override
  void dispose() {
    super.dispose(); …
Run Code Online (Sandbox Code Playgroud)

dart dart-async flutter

3
推荐指数
1
解决办法
5772
查看次数

如何使用 Firebase 数据库插件从 References 获取所有数据

I'm using the Firebase Database plugin to Flutter and I'm trying to get all the data from the "schedules" row.

I have this code and I'm already connected to the Firebase server.

  FirebaseDatabase.instance.reference().child('schedules');
Run Code Online (Sandbox Code Playgroud)

My data is stored like this: screenshot of Firebase

I wanted to get the data and insert it on a List so I can use it later.

The data have to be stored like this in Firebase because I need all those 3 values together when I …

dart firebase firebase-realtime-database flutter

1
推荐指数
1
解决办法
1877
查看次数