Skip to content

Commit

Permalink
fix: handling of back tap in select products list screen (openfoodfac…
Browse files Browse the repository at this point in the history
…ts#3019)

* fix : handle backtap for select products list

* chore : formatting

* chore : reverted git

* chore
  • Loading branch information
anshpathania7 authored Sep 17, 2022
1 parent e60f6b8 commit c459397
Showing 1 changed file with 55 additions and 37 deletions.
92 changes: 55 additions & 37 deletions packages/smooth_app/lib/pages/product/common/product_list_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ class _ProductListPageState extends State<ProductListPage>
productList = widget.productList;
}

//returns bool to handle WillPopScope
Future<bool> _handleUserBacktap() async {
if (_selectionMode) {
setState(
() {
_selectionMode = false;
_selectedBarcodes.clear();
},
);
return false;
} else {
return true;
}
}

@override
Widget build(BuildContext context) {
final LocalDatabase localDatabase = context.watch<LocalDatabase>();
Expand Down Expand Up @@ -192,45 +207,48 @@ class _ProductListPageState extends State<ProductListPage>
InheritedDataManager.of(context).resetShowSearchCard(true);
},
)
: RefreshIndicator(
//if it is in selectmode then refresh indicator is not shown
notificationPredicate:
_selectionMode ? (_) => false : (_) => true,
onRefresh: () async => _refreshListProducts(
products,
localDatabase,
appLocalizations,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
if (_selectionMode)
Padding(
padding: const EdgeInsets.all(SMALL_SPACE),
child: _buildCompareBar(products, appLocalizations),
),
Expanded(
child: Consumer<UpToDateProductProvider>(
builder: (
_,
final UpToDateProductProvider provider,
__,
) =>
ListView.builder(
itemCount: products.length,
itemBuilder: (BuildContext context, int index) {
return _buildItem(
dismissible,
products,
index,
localDatabase,
appLocalizations,
);
},
: WillPopScope(
onWillPop: _handleUserBacktap,
child: RefreshIndicator(
//if it is in selectmode then refresh indicator is not shown
notificationPredicate:
_selectionMode ? (_) => false : (_) => true,
onRefresh: () async => _refreshListProducts(
products,
localDatabase,
appLocalizations,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
if (_selectionMode)
Padding(
padding: const EdgeInsets.all(SMALL_SPACE),
child: _buildCompareBar(products, appLocalizations),
),
Expanded(
child: Consumer<UpToDateProductProvider>(
builder: (
_,
final UpToDateProductProvider provider,
__,
) =>
ListView.builder(
itemCount: products.length,
itemBuilder: (BuildContext context, int index) {
return _buildItem(
dismissible,
products,
index,
localDatabase,
appLocalizations,
);
},
),
),
),
),
],
],
),
),
),
);
Expand Down

0 comments on commit c459397

Please sign in to comment.