-
-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure options in users list modal work well (#4482)
- Loading branch information
Showing
5 changed files
with
156 additions
and
127 deletions.
There are no files selected for viewing
153 changes: 153 additions & 0 deletions
153
packages/smooth_app/lib/pages/all_product_list_modal.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; | ||
import 'package:provider/provider.dart'; | ||
import 'package:smooth_app/data_models/product_list.dart'; | ||
import 'package:smooth_app/database/dao_product_list.dart'; | ||
import 'package:smooth_app/database/local_database.dart'; | ||
import 'package:smooth_app/generic_lib/design_constants.dart'; | ||
import 'package:smooth_app/pages/preferences/user_preferences_list_tile.dart'; | ||
import 'package:smooth_app/pages/product/common/product_list_popup_items.dart'; | ||
import 'package:smooth_app/pages/product/common/product_query_page_helper.dart'; | ||
|
||
/// Page that lists all product lists. | ||
class AllProductListModal extends StatelessWidget { | ||
AllProductListModal({ | ||
required this.currentList, | ||
}); | ||
|
||
final ProductList currentList; | ||
|
||
final List<ProductList> _hardcodedProductLists = <ProductList>[ | ||
ProductList.scanSession(), | ||
ProductList.scanHistory(), | ||
ProductList.history(), | ||
]; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final LocalDatabase localDatabase = context.watch<LocalDatabase>(); | ||
final DaoProductList daoProductList = DaoProductList(localDatabase); | ||
|
||
final List<String> userLists = daoProductList.getUserLists(); | ||
final List<ProductList> productLists = | ||
List<ProductList>.from(_hardcodedProductLists); | ||
for (final String userList in userLists) { | ||
productLists.add(ProductList.user(userList)); | ||
} | ||
|
||
return SliverList( | ||
delegate: SliverChildBuilderDelegate( | ||
childCount: productLists.length, | ||
(final BuildContext context, final int index) { | ||
final ProductList productList = productLists[index]; | ||
return Column( | ||
children: <Widget>[ | ||
ConstrainedBox( | ||
constraints: BoxConstraints( | ||
minWidth: double.infinity, | ||
minHeight: 80.0 * MediaQuery.of(context).textScaleFactor, | ||
), | ||
child: FutureBuilder<void>( | ||
future: daoProductList.get(productList), | ||
builder: | ||
(BuildContext context, AsyncSnapshot<void> snapshot) { | ||
if (snapshot.connectionState != ConnectionState.done) { | ||
return const Center( | ||
child: CircularProgressIndicator.adaptive(), | ||
); | ||
} | ||
return _ModalProductListItem( | ||
productList: productList, | ||
selected: productList.listType == currentList.listType && | ||
productList.parameters == currentList.parameters, | ||
); | ||
}, | ||
), | ||
), | ||
if (index < productLists.length - 1) const Divider(height: 1.0), | ||
], | ||
); | ||
}, | ||
), | ||
); | ||
} | ||
} | ||
|
||
class _ModalProductListItem extends StatelessWidget { | ||
const _ModalProductListItem({ | ||
required this.productList, | ||
required this.selected, | ||
}); | ||
|
||
final ProductList productList; | ||
final bool selected; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final LocalDatabase localDatabase = context.watch<LocalDatabase>(); | ||
|
||
final AppLocalizations appLocalizations = AppLocalizations.of(context); | ||
|
||
final int productsLength = productList.barcodes.length; | ||
final bool enableRename = productList.listType == ProductListType.USER; | ||
final bool hasProducts = productsLength > 0; | ||
|
||
return UserPreferencesListTile( | ||
title: Text( | ||
ProductQueryPageHelper.getProductListLabel( | ||
productList, | ||
appLocalizations, | ||
), | ||
), | ||
subtitle: Text( | ||
appLocalizations.user_list_length(productsLength), | ||
), | ||
trailing: (enableRename || hasProducts || productList.isEditable) | ||
? PopupMenuButton<ProductListPopupMenuEntry>( | ||
itemBuilder: (BuildContext context) { | ||
final List<ProductListPopupItem> list = <ProductListPopupItem>[ | ||
if (enableRename) ProductListPopupRename(), | ||
if (hasProducts) ProductListPopupShare(), | ||
if (hasProducts) ProductListPopupOpenInWeb(), | ||
if (hasProducts) ProductListPopupClear(), | ||
if (productList.isEditable) ProductListPopupDelete(), | ||
]; | ||
final List<PopupMenuEntry<ProductListPopupMenuEntry>> result = | ||
<PopupMenuEntry<ProductListPopupMenuEntry>>[]; | ||
for (final ProductListPopupItem item in list) { | ||
result.add( | ||
PopupMenuItem<ProductListPopupMenuEntry>( | ||
value: item.getEntry(), | ||
child: ListTile( | ||
leading: Icon(item.getIconData()), | ||
title: Text(item.getTitle(appLocalizations)), | ||
contentPadding: EdgeInsets.zero, | ||
onTap: () async { | ||
Navigator.of(context).pop(); | ||
await item.doSomething( | ||
productList: productList, | ||
localDatabase: localDatabase, | ||
context: context, | ||
); | ||
}, | ||
), | ||
), | ||
); | ||
} | ||
return result; | ||
}, | ||
icon: const Icon(Icons.more_vert), | ||
) | ||
: null, | ||
selected: selected, | ||
selectedColor: Theme.of(context).primaryColor.withOpacity(0.2), | ||
contentPadding: const EdgeInsetsDirectional.only( | ||
start: VERY_LARGE_SPACE, | ||
end: LARGE_SPACE, | ||
top: VERY_SMALL_SPACE, | ||
bottom: VERY_SMALL_SPACE, | ||
), | ||
onTap: () => Navigator.of(context).pop(productList), | ||
); | ||
} | ||
} |
124 changes: 0 additions & 124 deletions
124
packages/smooth_app/lib/pages/all_product_list_page.dart
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters