Skip to content

Commit

Permalink
More abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
M123-dev committed Jan 9, 2022
1 parent 9b2b1f7 commit ee0249b
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 128 deletions.
67 changes: 5 additions & 62 deletions packages/smooth_app/lib/pages/scan/continuous_scan_page.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.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/scan_page_helper.dart'
as scan_page_helper;
import 'package:smooth_app/widgets/smooth_product_carousel.dart';
import 'package:smooth_app/pages/scan/scan_page_helper.dart';
import 'package:smooth_ui_library/smooth_ui_library.dart';
import 'package:visibility_detector/visibility_detector.dart';

Expand Down Expand Up @@ -35,38 +32,17 @@ class _ContinuousScanPageState extends State<ContinuousScanPage> {
},
child: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
final Size screenSize = MediaQuery.of(context).size;
final Size scannerSize = Size(
screenSize.width * 0.6,
screenSize.width * 0.33,
);
final double carouselHeight = constraints.maxHeight /
1.81; // roughly 55% of the available height
final double buttonRowHeight =
scan_page_helper.areButtonsRendered(_model) ? 48 : 0;
final double availableScanHeight =
constraints.maxHeight - carouselHeight - buttonRowHeight;
// Padding for the qr code scanner. This ensures the scanner has equal spacing between buttons and carousel.
final EdgeInsets qrScannerPadding = EdgeInsets.only(
top: (availableScanHeight - scannerSize.height) / 2 +
buttonRowHeight);
final double viewFinderBottomOffset = carouselHeight / 2.0;
return Scaffold(
appBar: AppBar(toolbarHeight: 0.0),
body: Stack(
children: <Widget>[
Container(
alignment: Alignment.center,
color: Colors.black,
child: Padding(
padding: qrScannerPadding,
child: SvgPicture.asset(
'assets/actions/scanner_alt_2.svg',
width: 60.0,
height: 60.0,
color: Colors.white,
),
),
...getScannerWidgets(
context,
constraints,
_model,
),
SmoothRevealAnimation(
delay: 400,
Expand All @@ -83,39 +59,6 @@ class _ContinuousScanPageState extends State<ContinuousScanPage> {
onQRViewCreated: setupScanner,
),
),
SmoothRevealAnimation(
delay: 400,
startOffset: const Offset(0.0, 0.1),
animationCurve: Curves.easeInOutBack,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Padding(
padding: qrScannerPadding,
child: SmoothViewFinder(
boxSize: scannerSize,
lineLength: screenSize.width * 0.8,
),
),
],
),
),
SmoothRevealAnimation(
delay: 400,
startOffset: const Offset(0.0, -0.1),
animationCurve: Curves.easeInOutBack,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
scan_page_helper.buildButtonsRow(context, _model),
const Spacer(),
SmoothProductCarousel(
showSearchCard: true,
height: carouselHeight,
),
],
),
),
],
),
);
Expand Down
71 changes: 5 additions & 66 deletions packages/smooth_app/lib/pages/scan/ml_kit_scan_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@ import 'package:camera/camera.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_svg/svg.dart';
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/scan_page_helper.dart'
as scan_page_helper;
import 'package:smooth_app/widgets/smooth_product_carousel.dart';
import 'package:smooth_app/pages/scan/scan_page_helper.dart';
import 'package:smooth_ui_library/animations/smooth_reveal_animation.dart';
import 'package:smooth_ui_library/widgets/smooth_view_finder.dart';
import 'package:visibility_detector/visibility_detector.dart';

class MLKitScannerPage extends StatefulWidget {
Expand Down Expand Up @@ -105,37 +101,13 @@ class MLKitScannerPageState extends State<MLKitScannerPage> {

return LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
final Size screenSize = MediaQuery.of(context).size;
final Size scannerSize = Size(
screenSize.width * 0.6,
screenSize.width * 0.33,
);
final double carouselHeight =
constraints.maxHeight / 1.81; // roughly 55% of the available height
final double buttonRowHeight =
scan_page_helper.areButtonsRendered(_model) ? 48 : 0;
final double availableScanHeight =
constraints.maxHeight - carouselHeight - buttonRowHeight;
// Padding for the qr code scanner. This ensures the scanner has equal spacing between buttons and carousel.
final EdgeInsets qrScannerPadding = EdgeInsets.only(
top: (availableScanHeight - scannerSize.height) / 2 +
buttonRowHeight);

return Stack(
fit: StackFit.expand,
children: <Widget>[
Container(
alignment: Alignment.center,
color: Colors.black,
child: Padding(
padding: qrScannerPadding,
child: SvgPicture.asset(
'assets/actions/scanner_alt_2.svg',
width: 60.0,
height: 6,
color: Colors.white,
),
),
...getScannerWidgets(
context,
constraints,
_model,
),
SmoothRevealAnimation(
delay: 400,
Expand All @@ -150,39 +122,6 @@ class MLKitScannerPageState extends State<MLKitScannerPage> {
),
),
),
SmoothRevealAnimation(
delay: 400,
startOffset: const Offset(0.0, 0.1),
animationCurve: Curves.easeInOutBack,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Padding(
padding: qrScannerPadding,
child: SmoothViewFinder(
boxSize: scannerSize,
lineLength: screenSize.width * 0.8,
),
),
],
),
),
SmoothRevealAnimation(
delay: 400,
startOffset: const Offset(0.0, -0.1),
animationCurve: Curves.easeInOutBack,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
scan_page_helper.buildButtonsRow(context, _model),
const Spacer(),
SmoothProductCarousel(
showSearchCard: true,
height: carouselHeight,
),
],
),
),
],
);
},
Expand Down
73 changes: 73 additions & 0 deletions packages/smooth_app/lib/pages/scan/scan_page_helper.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_svg/svg.dart';
import 'package:provider/provider.dart';
import 'package:smooth_app/data_models/continuous_scan_model.dart';
import 'package:smooth_app/pages/personalized_ranking_page.dart';
import 'package:smooth_app/widgets/ranking_floating_action_button.dart';
import 'package:smooth_app/widgets/smooth_product_carousel.dart';
import 'package:smooth_ui_library/animations/smooth_reveal_animation.dart';
import 'package:smooth_ui_library/util/ui_helpers.dart';
import 'package:smooth_ui_library/widgets/smooth_view_finder.dart';

bool areButtonsRendered(ContinuousScanModel model) =>
model.hasMoreThanOneProduct;
Expand Down Expand Up @@ -64,3 +68,72 @@ Widget buildButtonsRow(BuildContext context, ContinuousScanModel model) {
),
);
}

List<Widget> getScannerWidgets(
BuildContext context,
BoxConstraints constraints,
ContinuousScanModel model,
) {
final Size screenSize = MediaQuery.of(context).size;
final Size scannerSize = Size(
screenSize.width * 0.6,
screenSize.width * 0.33,
);
final double carouselHeight =
constraints.maxHeight / 1.81; // roughly 55% of the available height
final double buttonRowHeight = areButtonsRendered(model) ? 48 : 0;
final double availableScanHeight =
constraints.maxHeight - carouselHeight - buttonRowHeight;
// Padding for the qr code scanner. This ensures the scanner has equal spacing between buttons and carousel.
final EdgeInsets qrScannerPadding = EdgeInsets.only(
top: (availableScanHeight - scannerSize.height) / 2 + buttonRowHeight);

return <Widget>[
Container(
alignment: Alignment.center,
color: Colors.black,
child: Padding(
padding: qrScannerPadding,
child: SvgPicture.asset(
'assets/actions/scanner_alt_2.svg',
width: 60.0,
height: 6,
color: Colors.white,
),
),
),
SmoothRevealAnimation(
delay: 400,
startOffset: const Offset(0.0, 0.1),
animationCurve: Curves.easeInOutBack,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Padding(
padding: qrScannerPadding,
child: SmoothViewFinder(
boxSize: scannerSize,
lineLength: screenSize.width * 0.8,
),
),
],
),
),
SmoothRevealAnimation(
delay: 400,
startOffset: const Offset(0.0, -0.1),
animationCurve: Curves.easeInOutBack,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
buildButtonsRow(context, model),
const Spacer(),
SmoothProductCarousel(
showSearchCard: true,
height: carouselHeight,
),
],
),
),
];
}

0 comments on commit ee0249b

Please sign in to comment.