diff --git a/packages/smooth_app/lib/pages/product/common/product_list_page.dart b/packages/smooth_app/lib/pages/product/common/product_list_page.dart index 3fbe883c1dd2..5f3813d9233a 100644 --- a/packages/smooth_app/lib/pages/product/common/product_list_page.dart +++ b/packages/smooth_app/lib/pages/product/common/product_list_page.dart @@ -106,14 +106,6 @@ class _ProductListPageState extends State { overflow: TextOverflow.fade, ), ), - if ((!_selectionMode) && products.isNotEmpty) - IconButton( - icon: const Icon(Icons.refresh), - onPressed: () async => _refreshListProducts( - products, - localDatabase, - ), - ), if ((!_selectionMode) && products.isNotEmpty) Flexible( child: ElevatedButton( @@ -150,80 +142,90 @@ class _ProductListPageState extends State { ) ], ) - : ListView.builder( - itemCount: products.length, - itemBuilder: (BuildContext context, int index) { - final Product product = products[index]; - final String barcode = product.barcode!; - final bool selected = _selectedBarcodes.contains(barcode); - void onTap() => setState( - () { - if (selected) { - _selectedBarcodes.remove(barcode); - } else { - _selectedBarcodes.add(barcode); + : RefreshIndicator( + //if it is in selectmode then refresh indicator is not shown + notificationPredicate: + _selectionMode ? (_) => false : (_) => true, + onRefresh: () async => _refreshListProducts( + products, + localDatabase, + ), + child: ListView.builder( + itemCount: products.length, + itemBuilder: (BuildContext context, int index) { + final Product product = products[index]; + final String barcode = product.barcode!; + final bool selected = _selectedBarcodes.contains(barcode); + void onTap() => setState( + () { + if (selected) { + _selectedBarcodes.remove(barcode); + } else { + _selectedBarcodes.add(barcode); + } + }, + ); + final Widget child = GestureDetector( + onTap: _selectionMode ? onTap : null, + child: Container( + padding: EdgeInsets.symmetric( + horizontal: _selectionMode ? 0 : 12.0, + vertical: 8.0, + ), + child: Row( + children: [ + if (_selectionMode) + Icon( + selected + ? Icons.check_box + : Icons.check_box_outline_blank, + ), + Expanded( + child: ProductListItemSimple( + product: product, + onTap: _selectionMode ? onTap : null, + onLongPress: !_selectionMode + ? () => setState(() => _selectionMode = true) + : null, + ), + ), + ], + ), + ), + ); + if (dismissible) { + return Dismissible( + background: Container(color: colorScheme.background), + key: Key(product.barcode!), + onDismissed: (final DismissDirection direction) async { + final bool removed = + productList.remove(product.barcode!); + if (removed) { + await daoProductList.put(productList); + _selectedBarcodes.remove(product.barcode); + setState(() => products.removeAt(index)); } + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text( + removed + ? appLocalizations.product_removed_history + : appLocalizations.product_could_not_remove, + ), + duration: const Duration(seconds: 3), + ), + ); + // TODO(monsieurtanuki): add a snackbar ("put back the food") }, + child: child, ); - final Widget child = GestureDetector( - onTap: _selectionMode ? onTap : null, - child: Container( - padding: EdgeInsets.symmetric( - horizontal: _selectionMode ? 0 : 12.0, - vertical: 8.0, - ), - child: Row( - children: [ - if (_selectionMode) - Icon( - selected - ? Icons.check_box - : Icons.check_box_outline_blank, - ), - Expanded( - child: ProductListItemSimple( - product: product, - onTap: _selectionMode ? onTap : null, - onLongPress: !_selectionMode - ? () => setState(() => _selectionMode = true) - : null, - ), - ), - ], - ), - ), - ); - if (dismissible) { - return Dismissible( - background: Container(color: colorScheme.background), + } + return Container( key: Key(product.barcode!), - onDismissed: (final DismissDirection direction) async { - final bool removed = productList.remove(product.barcode!); - if (removed) { - await daoProductList.put(productList); - _selectedBarcodes.remove(product.barcode); - setState(() => products.removeAt(index)); - } - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text( - removed - ? appLocalizations.product_removed_history - : appLocalizations.product_could_not_remove, - ), - duration: const Duration(seconds: 3), - ), - ); - // TODO(monsieurtanuki): add a snackbar ("put back the food") - }, child: child, ); - } - return Container( - key: Key(product.barcode!), - child: child, - ); - }, + }, + ), ), ); } diff --git a/packages/smooth_app/lib/pages/product/new_product_page.dart b/packages/smooth_app/lib/pages/product/new_product_page.dart index b722e9eee939..647d7d86aa02 100644 --- a/packages/smooth_app/lib/pages/product/new_product_page.dart +++ b/packages/smooth_app/lib/pages/product/new_product_page.dart @@ -183,94 +183,97 @@ class _ProductPageState extends State { } Widget _buildProductBody(BuildContext context) { - return ListView(children: [ - Align( - heightFactor: 0.7, - alignment: Alignment.topLeft, - child: ProductImageCarousel( - _product, - height: 200, - onUpload: _refreshProduct, - ), - ), - Padding( - padding: const EdgeInsets.symmetric( - horizontal: SMALL_SPACE, - ), - child: Hero( - tag: _product.barcode ?? '', - child: SummaryCard( + return RefreshIndicator( + onRefresh: () => _refreshProduct(context), + child: ListView(children: [ + Align( + heightFactor: 0.7, + alignment: Alignment.topLeft, + child: ProductImageCarousel( _product, - _productPreferences, - isFullVersion: true, - showUnansweredQuestions: true, - refreshProductCallback: _refreshProduct, + height: 200, + onUpload: _refreshProduct, ), ), - ), - _buildKnowledgePanelCards(), - Padding( - padding: const EdgeInsets.all(SMALL_SPACE), - child: SmoothActionButton( - text: 'Edit product', // TODO(monsieurtanuki): translations - onPressed: () async { - final bool? refreshed = await Navigator.push( - context, - MaterialPageRoute( - builder: (BuildContext context) => EditProductPage(_product), - ), - ); - if (refreshed ?? false) { - setState(() {}); - } - }, + Padding( + padding: const EdgeInsets.symmetric( + horizontal: SMALL_SPACE, + ), + child: Hero( + tag: _product.barcode ?? '', + child: SummaryCard( + _product, + _productPreferences, + isFullVersion: true, + showUnansweredQuestions: true, + refreshProductCallback: _refreshProduct, + ), + ), ), - ), - if (context.read().getFlag( - UserPreferencesDevMode.userPreferencesFlagAdditionalButton) ?? - false) - ElevatedButton( - onPressed: () async { - if (_product.categoriesTags == null) { - // TODO(monsieurtanuki): that's another story: how to set an initial category? - return; - } - if (_product.categoriesTags!.length < 2) { - // TODO(monsieurtanuki): no father, we need to do something with roots - return; - } - final String currentTag = - _product.categoriesTags![_product.categoriesTags!.length - 1]; - final String fatherTag = - _product.categoriesTags![_product.categoriesTags!.length - 2]; - final CategoryCache categoryCache = - CategoryCache(ProductQuery.getLanguage()!); - final Map? siblingsData = - await categoryCache.getCategorySiblingsAndFather( - fatherTag: fatherTag, - ); - if (siblingsData == null) { - // TODO(monsieurtanuki): what shall we do? - return; - } - final String? newTag = await Navigator.push( - context, - MaterialPageRoute( - builder: (BuildContext context) => CategoryPickerPage( - barcode: _product.barcode!, - initialMap: siblingsData, - initialTree: _product.categoriesTags!, - categoryCache: categoryCache, + _buildKnowledgePanelCards(), + Padding( + padding: const EdgeInsets.all(SMALL_SPACE), + child: SmoothActionButton( + text: 'Edit product', // TODO(monsieurtanuki): translations + onPressed: () async { + final bool? refreshed = await Navigator.push( + context, + MaterialPageRoute( + builder: (BuildContext context) => EditProductPage(_product), ), - ), - ); - if (newTag != null && newTag != currentTag) { - setState(() {}); - } - }, - child: const Text('Additional Button'), + ); + if (refreshed ?? false) { + setState(() {}); + } + }, + ), ), - ]); + if (context.read().getFlag( + UserPreferencesDevMode.userPreferencesFlagAdditionalButton) ?? + false) + ElevatedButton( + onPressed: () async { + if (_product.categoriesTags == null) { + // TODO(monsieurtanuki): that's another story: how to set an initial category? + return; + } + if (_product.categoriesTags!.length < 2) { + // TODO(monsieurtanuki): no father, we need to do something with roots + return; + } + final String currentTag = + _product.categoriesTags![_product.categoriesTags!.length - 1]; + final String fatherTag = + _product.categoriesTags![_product.categoriesTags!.length - 2]; + final CategoryCache categoryCache = + CategoryCache(ProductQuery.getLanguage()!); + final Map? siblingsData = + await categoryCache.getCategorySiblingsAndFather( + fatherTag: fatherTag, + ); + if (siblingsData == null) { + // TODO(monsieurtanuki): what shall we do? + return; + } + final String? newTag = await Navigator.push( + context, + MaterialPageRoute( + builder: (BuildContext context) => CategoryPickerPage( + barcode: _product.barcode!, + initialMap: siblingsData, + initialTree: _product.categoriesTags!, + categoryCache: categoryCache, + ), + ), + ); + if (newTag != null && newTag != currentTag) { + setState(() {}); + } + }, + child: const Text('Additional Button'), + ), + ]), + ); } FutureBuilder _buildKnowledgePanelCards() {