Skip to content

Commit

Permalink
Extract torch button
Browse files Browse the repository at this point in the history
  • Loading branch information
WezSieTato committed Dec 29, 2024
1 parent c7de24f commit feeadd1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
12 changes: 3 additions & 9 deletions lib/pages/scan/scan.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:pola_flutter/pages/scan/scan_event.dart';
import 'package:pola_flutter/pages/scan/scan_state.dart';
import 'package:pola_flutter/i18n/strings.g.dart';
import 'package:pola_flutter/pages/scan/scan_vibration.dart';
import 'package:pola_flutter/pages/scan/torch_button.dart';
import 'package:pola_flutter/pages/scan/torch_controller.dart';
import 'package:pola_flutter/theme/assets.gen.dart';
import 'package:pola_flutter/theme/colors.dart';
Expand Down Expand Up @@ -125,18 +126,11 @@ class _MainPageState extends State<MainPage> {
child: CompaniesList(state, listScrollController)),
Column(
children: [
GestureDetector(
TorchButton(
isTorchOn: state.isTorchOn,
onTap: () {
_scanBloc.add(ScanEvent.torchSwitched());
},
child: Container(
decoration: BoxDecoration(
boxShadow: [],
),
child: state.isTorchOn
? Assets.scan.flashlightOn.svg()
: Assets.scan.flashlightOff.svg(),
),
)
],
)
Expand Down
24 changes: 24 additions & 0 deletions lib/pages/scan/torch_button.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:flutter/material.dart';
import 'package:pola_flutter/theme/assets.gen.dart';

class TorchButton extends StatelessWidget {
final bool isTorchOn;
final VoidCallback onTap;

TorchButton({required this.isTorchOn, required this.onTap});

@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: onTap,
child: Container(
decoration: BoxDecoration(
boxShadow: [],
),
child: isTorchOn
? Assets.scan.flashlightOn.svg()
: Assets.scan.flashlightOff.svg(),
),
);
}
}

0 comments on commit feeadd1

Please sign in to comment.