Skip to content

Commit

Permalink
Added vibration to all buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
guyluz11 committed Oct 19, 2024
1 parent 7f40d09 commit f3f998c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 24 deletions.
1 change: 1 addition & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class MyApp extends StatelessWidget {
return MaterialApp(
theme: theme.light(),
darkTheme: theme.dark(),
debugShowCheckedModeBanner: false,
title: AppThemeData.appName,
localizationsDelegates: context.localizationDelegates,
supportedLocales: context.supportedLocales,
Expand Down
24 changes: 14 additions & 10 deletions lib/presentation/atoms/button_atom.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ class ButtonAtom extends StatelessWidget {
this.disabled = false,
this.disableActionType = false,
this.translate = true,
this.isVibrating = true,
});

final ButtonVariant variant;
final VoidCallback onPressed;
final String? text;
final IconData? icon;
final bool isVibrating;

double get width => 150;

Expand All @@ -27,7 +29,9 @@ class ButtonAtom extends StatelessWidget {
final bool disableActionType;

void onPressVibrate() {
VibrationController.instance.vibrate(VibrationType.light);
if (isVibrating) {
VibrationController.instance.vibrate(VibrationType.light);
}
onPressed();
}

Expand Down Expand Up @@ -57,7 +61,7 @@ class ButtonAtom extends StatelessWidget {
if (icon == null) {
return buttonConstraints(
child: FilledButton(
onPressed: disabled ? null : onPressed,
onPressed: disabled ? null : onPressVibrate,
style: disabled
? null
: FilledButton.styleFrom().copyWith(
Expand All @@ -72,7 +76,7 @@ class ButtonAtom extends StatelessWidget {
}
return buttonConstraints(
child: FilledButton.icon(
onPressed: disabled ? null : onPressed,
onPressed: disabled ? null : onPressVibrate,
style: disabled
? null
: FilledButton.styleFrom().copyWith(
Expand All @@ -89,7 +93,7 @@ class ButtonAtom extends StatelessWidget {
if (icon == null) {
return buttonConstraints(
child: FilledButton.tonal(
onPressed: disabled ? null : onPressed,
onPressed: disabled ? null : onPressVibrate,
style: disabled
? null
: FilledButton.styleFrom().copyWith(
Expand All @@ -104,7 +108,7 @@ class ButtonAtom extends StatelessWidget {
}
return buttonConstraints(
child: FilledButton.tonalIcon(
onPressed: disabled ? null : onPressed,
onPressed: disabled ? null : onPressVibrate,
style: disabled
? null
: FilledButton.styleFrom().copyWith(
Expand All @@ -120,14 +124,14 @@ class ButtonAtom extends StatelessWidget {
if (icon == null) {
return buttonConstraints(
child: OutlinedButton(
onPressed: disabled ? null : onPressed,
onPressed: disabled ? null : onPressVibrate,
child: label(textTheme, color: colorScheme.primary),
),
);
}
return buttonConstraints(
child: OutlinedButton.icon(
onPressed: disabled ? null : onPressed,
onPressed: disabled ? null : onPressVibrate,
icon: Icon(icon, color: colorScheme.primary),
label: label(textTheme, color: colorScheme.primary),
),
Expand All @@ -136,21 +140,21 @@ class ButtonAtom extends StatelessWidget {
if (icon == null) {
return buttonConstraints(
child: TextButton(
onPressed: disabled ? null : onPressed,
onPressed: disabled ? null : onPressVibrate,
child: label(textTheme, color: colorScheme.primary),
),
);
}
return buttonConstraints(
child: TextButton.icon(
onPressed: disabled ? null : onPressed,
onPressed: disabled ? null : onPressVibrate,
icon: Icon(icon, color: colorScheme.primary),
label: label(textTheme, color: colorScheme.primary),
),
);
case ButtonVariant.lowEmphasisIcon:
return IconButton(
onPressed: onPressed,
onPressed: onPressVibrate,
color: colorScheme.primary,
icon: Icon(icon),
);
Expand Down
5 changes: 0 additions & 5 deletions lib/presentation/organisms/ready_for_session_organism.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:confetti/confetti.dart';
import 'package:flutter/material.dart';
import 'package:infinite_horizons/domain/controllers/controllers.dart';
import 'package:infinite_horizons/domain/objects/tip.dart';
import 'package:infinite_horizons/domain/objects/work_type_abstract.dart';
import 'package:infinite_horizons/presentation/atoms/atoms.dart';
Expand All @@ -25,10 +24,6 @@ class _ReadyForSessionOrganismState extends State<ReadyForSessionOrganism> {
bool confettiGotPlayed = false;

void onPressed() {
if (nextPressed) {
return;
}
VibrationController.instance.vibrate(VibrationType.light);
setState(() {
nextPressed = true;
});
Expand Down
5 changes: 1 addition & 4 deletions lib/presentation/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,7 @@ class HomePageState extends State<HomePage> {
ButtonAtom(
text: 'Start',
variant: ButtonVariant.mediumEmphasisOutlined,
onPressed: () {
VibrationController.instance.vibrate(VibrationType.light);
onClick();
},
onPressed: onClick,
),
],
),
Expand Down
6 changes: 1 addition & 5 deletions lib/presentation/pages/intro_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:infinite_horizons/domain/controllers/controllers.dart';
import 'package:infinite_horizons/domain/objects/energy_level.dart';
import 'package:infinite_horizons/domain/objects/tip.dart';
import 'package:infinite_horizons/domain/objects/work_type_abstract.dart';
Expand Down Expand Up @@ -41,10 +40,7 @@ class _IntroPageState extends State<IntroPage> {
});
}

void nextPage() {
VibrationController.instance.vibrate(VibrationType.light);
_introKey.currentState?.next();
}
void nextPage() => _introKey.currentState?.next();

void onDone(BuildContext context) => Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => ActivityPage()));
Expand Down

0 comments on commit f3f998c

Please sign in to comment.