Skip to content

Commit

Permalink
fix: openfoodfacts#1395 - refactoring make variable private
Browse files Browse the repository at this point in the history
  • Loading branch information
cli1005 committed Apr 11, 2022
1 parent 238da17 commit 52ac3c7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class ContinuousScanModel with ChangeNotifier {
_addBarcode(code);
}

Future<bool> onCreate(String? barcode) async {
Future<bool> onCreateProduct(String? barcode) async {
if (barcode == null) {
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/smooth_app/lib/helpers/picture_capture_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ Future<bool> uploadCapturedPicture(
);
return false;
}
await updateContinuousScanModel(context, barcode);
await _updateContinuousScanModel(context, barcode);
return true;
}

Future<void> updateContinuousScanModel(
Future<void> _updateContinuousScanModel(
BuildContext context, String barcode) async {
final ContinuousScanModel? model =
await ContinuousScanModel().load(context.read<LocalDatabase>());
await model?.onCreate(barcode);
await model?.onCreateProduct(barcode);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ class _AddNewProductPageState extends State<AddNewProductPage> {
final Map<ImageField, List<File>> _uploadedImages =
<ImageField, List<File>>{};

bool isProductLoaded = false;
bool _isProductLoaded = false;

@override
Widget build(BuildContext context) {
final AppLocalizations appLocalizations = AppLocalizations.of(context)!;
final ThemeData themeData = Theme.of(context);
return Scaffold(
appBar: AppBar(automaticallyImplyLeading: !isProductLoaded),
appBar: AppBar(automaticallyImplyLeading: !_isProductLoaded),
body: Padding(
padding: const EdgeInsets.only(
top: VERY_LARGE_SPACE,
Expand Down Expand Up @@ -79,7 +79,7 @@ class _AddNewProductPageState extends State<AddNewProductPage> {
text: appLocalizations.finish,
onPressed: () {
Navigator.maybePop(
context, isProductLoaded ? widget.barcode : null);
context, _isProductLoaded ? widget.barcode : null);
},
),
),
Expand Down Expand Up @@ -144,7 +144,7 @@ class _AddNewProductPageState extends State<AddNewProductPage> {
_uploadedImages[imageType] = _uploadedImages[imageType] ?? <File>[];
_uploadedImages[imageType]!.add(initialPhoto);
setState(() {
isProductLoaded = true;
_isProductLoaded = true;
});
}
initialPhoto.delete();
Expand Down
16 changes: 8 additions & 8 deletions packages/smooth_app/lib/widgets/smooth_product_carousel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ class _SmoothProductCarouselState extends State<SmoothProductCarousel> {
bool _returnToSearchCard = false;

int get _searchCardAdjustment => widget.containSearchCard ? 1 : 0;
late ContinuousScanModel model;
late ContinuousScanModel _model;

@override
void didChangeDependencies() {
super.didChangeDependencies();
model = context.watch<ContinuousScanModel>();
barcodes = model.getBarcodes();
_model = context.watch<ContinuousScanModel>();
barcodes = _model.getBarcodes();
_returnToSearchCard = InheritedDataManager.of(context).showSearchCard;
if (_controller.ready) {
if (_returnToSearchCard && widget.containSearchCard) {
Expand All @@ -52,7 +52,7 @@ class _SmoothProductCarouselState extends State<SmoothProductCarousel> {

@override
Widget build(BuildContext context) {
barcodes = model.getBarcodes();
barcodes = _model.getBarcodes();
return CarouselSlider.builder(
itemCount: barcodes.length + _searchCardAdjustment,
itemBuilder: (BuildContext context, int itemIndex, int itemRealIndex) {
Expand Down Expand Up @@ -89,10 +89,10 @@ class _SmoothProductCarouselState extends State<SmoothProductCarousel> {
return Container();
}
final String barcode = barcodes[index];
switch (model.getBarcodeState(barcode)!) {
switch (_model.getBarcodeState(barcode)!) {
case ScannedProductState.FOUND:
case ScannedProductState.CACHED:
final Product product = model.getProduct(barcode);
final Product product = _model.getProduct(barcode);
return ScanProductCard(product);
case ScannedProductState.LOADING:
return SmoothProductCardLoading(barcode: barcode);
Expand All @@ -103,9 +103,9 @@ class _SmoothProductCarouselState extends State<SmoothProductCarousel> {
// Remove the "Add New Product" card. The user may have added it
// already.
if (barcodeLoaded == null) {
model.getBarcodes().remove(barcode);
_model.getBarcodes().remove(barcode);
} else {
await model.refresh();
await _model.refresh();
}
setState(() {});
},
Expand Down

0 comments on commit 52ac3c7

Please sign in to comment.