2

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.

First Screen:

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) {
    ......
    }

Second screen:

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

                      debtorBloc.addDebtor(newDebtor);

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

_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.

Nagaraj
  • 29
  • 1
  • 6

1 Answers1

6

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(() {});
            },
AgainPsychoX
  • 1,527
  • 1
  • 16
  • 20