Skip to content

Commit

Permalink
fix: lifecycle refactoring (#995)
Browse files Browse the repository at this point in the history
Renamed file:
* `lifecycle_manager.dart`: was `scanner_state_manager.dart`; renamed `onStop` in `onPause`

Impacted files:
* `continuous_scan_page.dart`: refactored
* `labeler.yaml`: refactored
* `ml_kit_scan_page.dart`: refactored
  • Loading branch information
monsieurtanuki authored Jan 22, 2022
1 parent 72a2f27 commit 3d4bc59
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ scan:
- packages/smooth_app/lib/pages/scan/continuous_scan_page.dart
- packages/smooth_app/lib/pages/scan/scan_page.dart
- packages/smooth_app/lib/pages/scan/scanner_overlay.dart
- packages/smooth_app/lib/pages/scan/scanner_state_manager.dart
- packages/smooth_app/lib/pages/scan/lifecycle_manager.dart

mlkit:
- packages/smooth_app/lib/pages/scan/ml_kit_scan_page.dart
Expand Down
4 changes: 2 additions & 2 deletions packages/smooth_app/lib/pages/scan/continuous_scan_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:qr_code_scanner/qr_code_scanner.dart';
import 'package:smooth_app/data_models/continuous_scan_model.dart';
import 'package:smooth_app/pages/scan/scanner_state_manager.dart';
import 'package:smooth_app/pages/scan/lifecycle_manager.dart';

class ContinuousScanPage extends StatefulWidget {
const ContinuousScanPage();
Expand All @@ -27,7 +27,7 @@ class _ContinuousScanPageState extends State<ContinuousScanPage> {

return LifeCycleManager(
onResume: _resumeLiveFeed,
onStop: _stopLiveFeed,
onPause: _stopLiveFeed,
child: QRView(
overlay: QrScannerOverlayShape(
// We use [SmoothViewFinder] instead of the overlay.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import 'package:visibility_detector/visibility_detector.dart';
class LifeCycleManager extends StatefulWidget {
const LifeCycleManager({
required this.onResume,
required this.onStop,
required this.onPause,
required this.child,
Key? key,
}) : super(key: key);

final Function() onResume;
final Function() onStop;
final Function() onPause;
final Widget child;

@override
Expand Down Expand Up @@ -41,7 +41,7 @@ class LifeCycleManagerState extends State<LifeCycleManager>
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.inactive) {
widget.onStop.call();
widget.onPause.call();
} else if (state == AppLifecycleState.resumed) {
widget.onResume.call();
}
Expand All @@ -53,7 +53,7 @@ class LifeCycleManagerState extends State<LifeCycleManager>
key: const ValueKey<String>('VisibilityDetector'),
onVisibilityChanged: (VisibilityInfo info) {
if (info.visibleFraction == 0.0) {
widget.onStop.call();
widget.onPause.call();
} else {
widget.onResume.call();
}
Expand Down
4 changes: 2 additions & 2 deletions packages/smooth_app/lib/pages/scan/ml_kit_scan_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:google_ml_barcode_scanner/google_ml_barcode_scanner.dart';
import 'package:provider/provider.dart';
import 'package:smooth_app/data_models/continuous_scan_model.dart';
import 'package:smooth_app/main.dart';
import 'package:smooth_app/pages/scan/scanner_state_manager.dart';
import 'package:smooth_app/pages/scan/lifecycle_manager.dart';

class MLKitScannerPage extends StatefulWidget {
const MLKitScannerPage({Key? key}) : super(key: key);
Expand Down Expand Up @@ -71,7 +71,7 @@ class MLKitScannerPageState extends State<MLKitScannerPage> {

return LifeCycleManager(
onResume: _startLiveFeed,
onStop: _stopImageStream,
onPause: _stopImageStream,
child: _buildScannerWidget(),
);
}
Expand Down

0 comments on commit 3d4bc59

Please sign in to comment.