in Education by
I'm working on a program that displays a list from an SQFlite table. The future for the snapshot list is being fired for no reason that I can determine. It fires approximately 3 times more than is needed. The only times that it needs to fire are (1) the first time that program activates, and (2) when it returns from the update screen which can create, read, update, and delete. Consequently, I set a flag on return from that screen to indicate that the snapshot needs to be refreshed. Then in the function that selects the data, I check if the flag is set, and only then do I select the table. Just running the program now for some additions and deletions resulted in the following for the select for the snapshot: "I/flutter (24769): Fetched = false, Fetch attempts = 20, Fetched = 7" This indicates that only 7 selects were needed, but 20 were requested. Can someone advise me the correct way to prevent the Future firing when not necessary? Relevant code is below: body: Container( padding: EdgeInsets.all(16.0), child: FutureBuilder>( future: _fetchDataFromDb(), builder: (context, AsyncSnapshot> snapshot) { if (snapshot.connectionState == ConnectionState.done) { if (!snapshot.hasError && snapshot.hasData) { return ListView.builder( itemCount: snapshot == null ? 0 : snapshot.data.length, itemBuilder: (context, index) { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ ListTile( leading: (IconButton /* Edit */ ( color: Colors.blue, icon: Icon(Icons.edit), onPressed: () => _showEditScreen( Crud.eUpdate, snapshot.data[index]))), title: Text(snapshot.data[index]['title']), subtitle: Text(snapshot.data[index]['detail']), onLongPress: () => _showEditScreen( Crud.eRead, snapshot.data[index]), trailing: (IconButton( color: Colors.red, icon: Icon(Icons.delete), onPressed: () => _showEditScreen( Crud.eDelete, snapshot.data[index])))), ]); }); } } })), Future> _fetchDataFromDb() async { bool tfFetched = false; _iFetchAttempts++; if (_tfGetData) { print("Fetching data"); _snapshot = await _dbHelper.getNoteRecs(); tfFetched = true; _tfGetData = false; _iFetched++; setState(() => _iCount = _snapshot.length); } print( "Fetched = $tfFetched, Fetch attempts = $_iFetchAttempts, Fetched = $_iFetched"); return _snapshot; } void _showEditScreen(Crud eCrud, data) async { try { NoteRec noteRec = data == null ? null : NoteRec(data['id'], data['title'], data['detail']); await Navigator.push( context, MaterialPageRoute( builder: (BuildContext context) => NoteEntry(g_crud: eCrud, g_noteRec: noteRec))); _tfGetData = true; // SET FLAG TO INDICATE SELECT IS REQUIRED } catch (error) { print("Error on navigation = ${error.toString()}"); } } JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
After some research, I believe that the answer to this question is that the selection of data from a database or elsewhere should be separate from the rebuild. The rebuild is given this data as part of the rebuild, but it is not selected as part of the rebuild.

Related questions

0 votes
    I have this operation EventModel data = EventModel(_nameEvent, _passEvent, _localEvent, _dateEventString); HashMap ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 13, 2022 in Education by JackTerrance
0 votes
    I am adding an background image to the Splash screen, but is not rendering the image. Sometime it load ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    I'm getting Authorization failure when trying to display a map in a flutter project using the google maps ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I'm new to Flutter Redux, I got a problem and I have no idea how to deal with it at all! ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    I am trying to implement the reCaptcha function to my flutter app, but in the captcha registration I need ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I need to build a pop up dialog box in my app. I am using Dialog class and wrapped it with ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 3, 2022 in Education by JackTerrance
0 votes
    I'm new to flutter and can't resolve the issue. Your application could not be compiled, because its ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    I'm new to flutter and can't resolve the issue. Your application could not be compiled, because its ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 15, 2022 in Education by JackTerrance
0 votes
    Video does not capture in the right orientation when running the Camera Plugin example app on my iPhone X in Landscape. It works well ... .0+1 environment: sdk: ">=2.0.0-dev.68.0...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    I am using Python 2.6.6 and SQLAlchemy 0.6.6 to handle a one to many relationship in my database ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 4, 2022 in Education by JackTerrance
0 votes
    I'd like to ensure my RAII class is always allocated on the stack. How do I prevent a class from ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    I'd like to ensure my RAII class is always allocated on the stack. How do I prevent a class from ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    This question's answers are a community effort. Edit existing answers to improve this post. It is not ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    On the left you will notice the google logo rendered by IE, I drew a black line at the top and ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    On the left you will notice the google logo rendered by IE, I drew a black line at the top and ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
...