简体   繁体   中英

flutter TabBarView sometimes not triggering on gesture swipe

I am using Flutter -Android studio. I have main screen with TabBarView control (2 pages). each page get data from sqfite database. both have same statefull widget class, but I pass parameter to look into database and display. Issue : when I click tabbar header , data displayed is Ok. But when I swipe tabs, it sometimes work and sometimes does not work. as per below video. I have check and seems that Build event is not trigger every if Swipe was done. Main widget with tabbarview

screen record

Note that 1st tab has only 1 record, while second has 6 records. tabClick works fine, but swipe sometime not work properly.

body: TabBarView(
    controller: _tabController,
    children: [
      DisplayTransactions(
        tmptransType: TransactionType.enIncome,
        transacBloc: _transacBloc,
        SelectedItemsCount: bRowSelectionCount,
        onSelectionChanged: (count) {
          setState(() {
            bRowSelectionCount = count;
          });
        },
      ),
      // Center(child: Text("Page 1")),
      DisplayTransactions(
        tmptransType: TransactionType.enExpense,
        transacBloc: _transacBloc,
        SelectedItemsCount: bRowSelectionCount,
        onSelectionChanged: (count) {
          setState(() {
            bRowSelectionCount = count;
          });
        },
        //Center(child: Text("Page 2")),
      )
    ],
  ),

------ > Widget to display data into listview for each tabbar page

class DisplayTransactions extends StatefulWidget {
final TransactionType tmptransType;
final FinanceTransBlock transacBloc;
final Function onSelectionChanged;
int SelectedItemsCount;

/// -1 expense  1 income
DisplayTransactions(
{Key key,
@required this.tmptransType,
@required this.transacBloc,
this.SelectedItemsCount,
this.onSelectionChanged})
: super(key: key);

@override
_DisplayTransactionsState createState() => _DisplayTransactionsState();
}

class _DisplayTransactionsState extends State<DisplayTransactions> {
var isSelected = false;
var mycolor = Colors.white;

// int iselectionCount = 0;


@override
Widget build(BuildContext context) {
widget.transacBloc.transacType = widget.tmptransType;
debugPrint("----------------------------- ${widget.tmptransType}");
if (widget.SelectedItemsCount == 0) {// if no rows selected, then reload database based on trans type, eg expense, or income.. etc
widget.transacBloc.refresh();
}

return StreamBuilder<List<FinanceTransaction>>(
stream: widget.transacBloc.transacations,
builder: (context, snapshot) {
if (snapshot.hasData) {
List<FinanceTransaction> list = snapshot.data;
// return  buildTaskListWal(snapshot.data);
return Padding(

It looks like the app is taking some time to retrieve the new data. Try checking for null on the snapshot.data and display a circularProgressIndicator.

if (snapshot.data == null) {
  return CirgularProgressIndicator();
 } else {
//display data
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM