从页面混乱返回时如何刷新上一个屏幕/页面列表? [英] How to refresh previous screen/page list when come back from a page in flutter?

查看:93
本文介绍了从页面混乱返回时如何刷新上一个屏幕/页面列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个页面,一个是列表视图,另一个是表单类型的页面。将sqflite与streambuilder一起用于crud操作时,一旦我输入了输入并从第二个屏幕的屏幕视图中保存,就应该更新。

I have two pages one is list view and another is form kind of page. Using sqflite with streambuilder for crud operation, Once i enter input and save from second screen list view from screen one should be updated.

第一个屏幕:

列表视图将从这样的sqflite数据库返回。

List view will be return from sqflite datatbase like this.

    Widget getDebtorsWidget() {
    return StreamBuilder(
      stream: debtorBloc.debtors,
      builder: (BuildContext context, AsyncSnapshot<List<Debtor>> snapshot) {
        return getDebtorCardWidget(snapshot);
      },
    );
  }

-----------------------------------------------------------------------------
        floatingActionButton: FloatingActionButton(
                tooltip: 'Add an entry',
                child: Icon(Icons.add),
                onPressed: () {
                    Navigator.push(
                      context,
                      MaterialPageRoute(
                        builder: (BuildContext context) => DebtorFormFullScreenDialog(),
                        fullscreenDialog: true,
                      ));
                      //_showAddDebtorSheet(context);
                },
              ),

     void _showAddDebtorSheet(BuildContext context) {
    ......
    }

第二个屏幕:

onPressed: () {
                    final newDebtor =
                        Debtor(name: _debtorNameFormController.value.text);
                    if (newDebtor.name.isNotEmpty) {

                      debtorBloc.addDebtor(newDebtor);

                      //dismisses the bottomsheet
                      Navigator.pop(context, false);
                    }
                  },

_showAddDebtorSheet()在输入数据时在同一屏幕上此列表视图中的会立即更新。但是,当我在第二个屏幕上执行操作时,即使当我导航回到第一个屏幕时,列表视图也不会更新。

_showAddDebtorSheet() is on same screen when enter data with in this listview updates immediately. But when when do it on second screen is not listview not updates even when i navigate back to first screen.

注意:请告知我是否需要其他信息。

Note: Pls notify me if you need extra information.

推荐答案

对于等待 .flutter.dev / flutter / widgets / Navigator / push.html rel = nofollow noreferrer> Navigator.of(context).push (可以还从第二页 Navigator.of接收返回值。 (context).pop(value)),然后在首页上下文中先<< c $ c> setState((){}); 刷新它。

You can await for Navigator.of(context).push (which could also receive return value from second page Navigator.of(context).pop(value)) and then setState(() {}); in first page context to make it refresh.

在您的示例中,它看起来像:

In your example it would look like:

            onPressed: () async {
                await Navigator.push(
                  context,
                  MaterialPageRoute(
                    builder: (BuildContext context) => DebtorFormFullScreenDialog(),
                    fullscreenDialog: true,
                  )
                );
                setState(() {});
            },

这篇关于从页面混乱返回时如何刷新上一个屏幕/页面列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆